slskproto module implements the Soulseek peer-to-peer network protocol, handling connections, message passing, and distributed network operations.
NetworkThread Class
Manages all network communications in a dedicated thread.Class Attributes
int
default:"512-2048"
Maximum number of concurrent socket connections (platform-dependent)
int
default:"60"
Maximum idle time in seconds before closing peer connections
int
default:"1800"
Time-to-live for cached user addresses (30 minutes)
int
default:"469762048"
Maximum size for large incoming messages (448 MiB)
Methods
start()
The network thread runs continuously, handling all socket I/O operations in a non-blocking manner using a selector.
Connection Classes
Connection
Base class for network connections.socket
Socket object
tuple
Address as (ip, port)
bytearray
Incoming data buffer
bytearray
Outgoing data buffer
bool
Whether connection is fully established
ServerConnection
Represents a connection to the Soulseek server.tuple
Login credentials as (username, password)
PeerConnection
Represents a connection to another peer.PeerInit
Peer initialization message
int
Token for indirect connection requests
NetworkInterfaces Class
Handles network interface detection and binding.Methods
get_interface_addresses()
dict
Dictionary mapping interface names to IP addresses
bind_to_interface()
socket
Socket to bind
str
Name of the network interface
str
IP address of the interface
Message Processing
The network thread processes three types of messages:Server Messages
Messages exchanged with the central Soulseek server.Peer Messages
Messages exchanged directly with other peers.Distributed Messages
Messages propagated through the distributed network for searches.Connection Flow
Performance Characteristics
The network thread uses non-blocking I/O with a selector for efficient handling of multiple concurrent connections:
- Processes ~20-240 events per second depending on activity
- Supports up to 512-2048 concurrent connections
- TCP keepalive ensures stale connections are detected
- Automatic connection timeout after 60 seconds of inactivity