Skip to main content

soulseek_proto/
lib.rs

1//! The Soulseek wire protocol as Rust types.
2//!
3//! The crate provides framing, codecs for every server, peer, init and distributed message, the
4//! compressed payloads and the data model. It performs no I/O and contains no async code. A
5//! client that connects to the network and exchanges messages with it is `soulseek-client`.
6//!
7//! # Messages
8//!
9//! Each message family has one module: [`server`], [`peer`], [`distributed`] and [`init`]. Each
10//! message is a struct whose wire layout is read and written in one place.
11//!
12//! The family enum ([`ServerRequest`], [`PeerMessage`], ...) ties every variant to its code. Its
13//! `encode(&self) -> Vec<u8>` method produces a complete frame, length prefix included. Its
14//! `decode(&[u8])` method takes exactly one complete frame, length prefix included: the bytes
15//! [`frame::split`] reports as consumed.
16//!
17//! # Decoding
18//!
19//! `decode` enforces [`Limits::DEFAULT`]. [`PeerMessage::decode_with`],
20//! [`peek_search_response`] and [`peek_folder_contents_token`] take the limits as an argument.
21//! The configurable limits bound only peer messages, so a client with limits of its own decodes
22//! peer frames with [`PeerMessage::decode_with`]; [`PeerMessage::decode`] ignores them.
23//!
24//! # Logging
25//!
26//! Decoders log rejected messages at the `debug` level, and decoded messages at the `debug`
27//! level except distributed pings, distributed searches and embedded messages, which are too
28//! frequent to log. A partial frame or bytes past one frame are logged at the `warn` level. A
29//! frame length out of range is returned without being logged, and is left to the caller to log.
30//!
31//! # Features
32//!
33//! `serde`, off by default, implements `Serialize` and `Deserialize` for the message structs and
34//! the data model: files, directories, users, rooms, [`RemoteFilename`], [`SearchQuery`] and
35//! [`Limits`]. The message family enums, the frame types, the errors, [`Secret`] and the
36//! messages that hold one have no implementations.
37
38#[cfg(doctest)]
39#[doc = include_str!("../README.md")]
40struct ReadmeDoctest;
41
42mod codec;
43mod codes;
44pub mod distributed;
45mod error;
46pub mod frame;
47pub mod init;
48mod limits;
49mod log;
50mod model;
51mod names;
52pub mod peer;
53pub mod server;
54mod wire;
55
56#[cfg(test)]
57mod proptests;
58#[cfg(test)]
59mod testing;
60
61pub use codes::{DistributedCode, InitCode, PeerCode, ServerCode};
62pub use distributed::{DistributedMessage, SEARCH_IDENTIFIER};
63pub use error::{DecodeError, FieldError};
64pub use init::InitMessage;
65pub use limits::*;
66pub use model::*;
67pub use names::{
68  LoginUsernameError, RoomNameError, SERVER_USERNAME, validate_login_username, validate_room_name,
69};
70pub use peer::{PeerMessage, peek_folder_contents_token, peek_search_response, queue_count};
71pub use server::{PROTOCOL_MAJOR_VERSION, PROTOCOL_MINOR_VERSION, ServerRequest, ServerResponse};
72pub use wire::{RemoteFilename, Secret};