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
Maximum number of concurrent socket connections (platform-dependent)
Maximum idle time in seconds before closing peer connections
Time-to-live for cached user addresses (30 minutes)
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 object
Address as (ip, port)
Incoming data buffer
Outgoing data buffer
Whether connection is fully established
ServerConnection
Represents a connection to the Soulseek server.Login credentials as (username, password)
PeerConnection
Represents a connection to another peer.Peer initialization message
Token for indirect connection requests
NetworkInterfaces Class
Handles network interface detection and binding.Methods
get_interface_addresses()
Dictionary mapping interface names to IP addresses
bind_to_interface()
Socket to bind
Name of the network interface
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