Skip to main content
The 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

MAX_SOCKETS
int
default:"512-2048"
Maximum number of concurrent socket connections (platform-dependent)
CONNECTION_MAX_IDLE
int
default:"60"
Maximum idle time in seconds before closing peer connections
USER_ADDRESS_TTL
int
default:"1800"
Time-to-live for cached user addresses (30 minutes)
MAX_INCOMING_MESSAGE_SIZE_LARGE
int
default:"469762048"
Maximum size for large incoming messages (448 MiB)

Methods

start()

def start(self)
Starts the network thread. Automatically called during core initialization.
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.
sock
socket
Socket object
addr
tuple
Address as (ip, port)
in_buffer
bytearray
Incoming data buffer
out_buffer
bytearray
Outgoing data buffer
is_established
bool
Whether connection is fully established

ServerConnection

Represents a connection to the Soulseek server.
login
tuple
Login credentials as (username, password)

PeerConnection

Represents a connection to another peer.
init
PeerInit
Peer initialization message
pierce_token
int
Token for indirect connection requests

NetworkInterfaces Class

Handles network interface detection and binding.

Methods

get_interface_addresses()

@classmethod
def get_interface_addresses(cls)
Returns a dictionary of network interface names and IP addresses.
interfaces
dict
Dictionary mapping interface names to IP addresses
from pynicotine.slskproto import NetworkInterfaces

interfaces = NetworkInterfaces.get_interface_addresses()
for name, ip in interfaces.items():
    print(f"{name}: {ip}")

bind_to_interface()

@classmethod
def bind_to_interface(cls, sock, interface_name, address)
Binds a socket to a specific network interface.
sock
socket
Socket to bind
interface_name
str
Name of the network interface
address
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
from pynicotine.core import core
from pynicotine.slskmessages import WatchUser

# Subscribe to user status updates
core.send_message_to_server(WatchUser("username"))

Build docs developers (and LLMs) love