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.
- Remote
Filename - Path as a peer sent it.
- Search
Query - Free-text search query split into terms and exclusions.
- Secret
- Password or password hash carried by a message.
Enums§
- Decode
Error - Reason a frame or message was rejected.
- Distributed
Code - Message code on a distributed connection.
- Field
Error - Problem with one field of a message.
- File
Attribute Type - Type of a file attribute.
- Init
Code - Code of the first frame on an inbound peer socket.
- Login
Username Error - Reason the server would reject a login username.
- Peer
Code - Message code on a peer connection.
- Peer
Connection Type - Type of a peer connection.
- Room
Name Error - Reason the server would reject a room name in
JoinRoom. - Room
Type - Type of a room.
- Server
Code - Message code on a server connection.
- User
Presence - Online state of a user.
Constants§
- LIMIT_
ATTRIBUTES_ PER_ FILE - Maximum
n_attributesof one file. - LIMIT_
BROWSE_ MESSAGE_ BYTES - Maximum frame
lenof 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
lenon 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
lenof the first frame on an inbound socket, in bytes. - LIMIT_
PEER_ SMALL_ MESSAGE_ BYTES - Maximum frame
lenof a small peer message, in bytes. - LIMIT_
SERVER_ MESSAGE_ BYTES - Maximum frame
lenon 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
Loginagainst the server’s rules. - validate_
room_ name - Checks a room name for
JoinRoomagainst the server’s rules.