Skip to main content

Crate soulseek_proto

Crate soulseek_proto 

Source
Expand description

The Soulseek wire protocol as Rust types.

The crate provides framing, codecs for every server, peer, init and distributed message, the compressed payloads and the data model. It performs no I/O and contains no async code. A client that connects to the network and exchanges messages with it is soulseek-client.

§Messages

Each message family has one module: server, peer, distributed and init. Each message is a struct whose wire layout is read and written in one place.

The family enum (ServerRequest, PeerMessage, …) ties every variant to its code. Its encode(&self) -> Vec<u8> method produces a complete frame, length prefix included. Its decode(&[u8]) method takes exactly one complete frame, length prefix included: the bytes frame::split reports as consumed.

§Decoding

decode enforces Limits::DEFAULT. PeerMessage::decode_with, peek_search_response and peek_folder_contents_token take the limits as an argument. The configurable limits bound only peer messages, so a client with limits of its own decodes peer frames with PeerMessage::decode_with; PeerMessage::decode ignores them.

§Logging

Decoders log rejected messages at the debug level, and decoded messages at the debug level except distributed pings, distributed searches and embedded messages, which are too frequent to log. A partial frame or bytes past one frame are logged at the warn level. A frame length out of range is returned without being logged, and is left to the caller to log.

§Features

serde, off by default, implements Serialize and Deserialize for the message structs and the data model: files, directories, users, rooms, RemoteFilename, SearchQuery and Limits. The message family enums, the frame types, the errors, Secret and the messages that hold one have no implementations.

Re-exports§

pub use distributed::DistributedMessage;
pub use distributed::SEARCH_IDENTIFIER;
pub use init::InitMessage;
pub use peer::PeerMessage;
pub use peer::peek_folder_contents_token;
pub use peer::peek_search_response;
pub use peer::queue_count;
pub use server::PROTOCOL_MAJOR_VERSION;
pub use server::PROTOCOL_MINOR_VERSION;
pub use server::ServerRequest;
pub use server::ServerResponse;

Modules§

distributed
Distributed search messages.
frame
Message framing.
init
Peer connection init messages.
peer
Peer messages.
server
Messages on the server connection.

Structs§

Limits
Limits that an operator can configure.
RemoteFilename
Path as a peer sent it.
SearchQuery
Free-text search query split into terms and exclusions.
Secret
Password or password hash carried by a message.

Enums§

DecodeError
Reason a frame or message was rejected.
DistributedCode
Message code on a distributed connection.
FieldError
Problem with one field of a message.
FileAttributeType
Type of a file attribute.
InitCode
Code of the first frame on an inbound peer socket.
LoginUsernameError
Reason the server would reject a login username.
PeerCode
Message code on a peer connection.
PeerConnectionType
Type of a peer connection.
RoomNameError
Reason the server would reject a room name in JoinRoom.
RoomType
Type of a room.
ServerCode
Message code on a server connection.
UserPresence
Online state of a user.

Constants§

LIMIT_ATTRIBUTES_PER_FILE
Maximum n_attributes of one file.
LIMIT_BROWSE_MESSAGE_BYTES
Maximum frame len of a browse response, in bytes.
LIMIT_DESCRIPTION_BYTES
Maximum length of a description or greeting, in bytes.
LIMIT_DIRECTORIES_PER_RESPONSE
Maximum number of directories in one response.
LIMIT_DISTRIBUTED_MESSAGE_BYTES
Maximum frame len on distributed connections, in bytes.
LIMIT_FILES_PER_RESPONSE
Maximum number of files in one browse or folder response.
LIMIT_FILES_PER_SEARCH_RESPONSE
Maximum number of files in one search response.
LIMIT_INFLATED_BROWSE_BYTES
Maximum decompressed size of a browse response, in bytes.
LIMIT_INFLATED_FOLDER_BYTES
Maximum decompressed size of a folder contents response, in bytes.
LIMIT_INFLATED_SEARCH_BYTES
Maximum decompressed size of a search response, in bytes.
LIMIT_INIT_MESSAGE_BYTES
Maximum len of the first frame on an inbound socket, in bytes.
LIMIT_PEER_SMALL_MESSAGE_BYTES
Maximum frame len of a small peer message, in bytes.
LIMIT_SERVER_MESSAGE_BYTES
Maximum frame len on the server connection, in bytes.
LIMIT_STRING_BYTES
Maximum length of a single string, in bytes.
LIMIT_USER_INFO_PICTURE_BYTES
Maximum length of the picture in an InfoResponse, in bytes.
SERVER_USERNAME
Pseudo-user name of the server’s own notices.

Functions§

validate_login_username
Checks a username for Login against the server’s rules.
validate_room_name
Checks a room name for JoinRoom against the server’s rules.