Package DebTorrent :: Package BT1 :: Module Encrypter :: Class Encoder
[hide private]
[frames] | no frames]

Class Encoder

source code

The collection of all (possibly encrypted) connections.

Instance Methods [hide private]
 
__init__(self, connecter, raw_server, my_id, max_len, schedulefunc, keepalive_delay, download_id, measurefunc, config, bans=<DebTorrent.BT1.Encrypter._dummy_banlist instance at 0x2b55198...)
Initialize the instance.
source code
 
send_keepalives(self)
Periodically send keepalive messages on all the connections.
source code
 
start_connections(self, list)
Add many connections from a list to a queue to start.
source code
 
_start_connection_from_queue(self)
Start a connection in the queue.
source code
boolean
start_connection(self, dns, id, encrypted=None)
Start a connection to a peer.
source code
 
_start_connection(self, dns, id, encrypted=None)
Schedule the start of a connection to a peer.
source code
boolean
check_ip(self, connection=None, ip=None)
Check whether the connection to the IP is allowed.
source code
boolean
got_id(self, connection)
Check whether the connection to the peer ID is allowed.
source code
boolean
external_connection_made(self, connection)
Process an externally made connection.
source code
boolean
externally_handshaked_connection_made(self, connection, options, already_read, encrypted=None)
Process an externally handshaked connection.
source code
 
close_all(self)
Close all the currently open connections.
source code
 
ban(self, ip)
Ban an IP address from ever connecting again.
source code
 
pause(self, flag)
Set the paused flag.
source code
Instance Variables [hide private]
dictionary banned
keys are IP addresses that are banned
dictionary config
the configuration parameters
Connecter.Connecter connecter
the Connecter instance to use
dictionary connections
keys are the DebTorrent.SocketHandler.SingleSocket connections, values are the corresponding Connection instances
string download_id
the infohash of the torrent being downloaded
class external_bans
the instance to check for banned peer's in
int keepalive_delay
the delay between sending keepalive messages
int max_connections
the maximum number of connections to accept
int max_len
the maximum length message to accept
method measurefunc
method to call with the size of incoming data
string my_id
the peer ID to use
boolean paused
whether the download is paused
DebTorrent.RawServer.RawServer raw_server
the server instance to use
method schedulefunc
method to call to schedule future function invocation
list of ((string, int), string, boolean) to_connect
the list of IP address, port, peer ID, and whether to encrypt
Method Details [hide private]

__init__(self, connecter, raw_server, my_id, max_len, schedulefunc, keepalive_delay, download_id, measurefunc, config, bans=<DebTorrent.BT1.Encrypter._dummy_banlist instance at 0x2b55198...)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • connecter (Connecter.Connecter) - the Connecter instance to use
  • raw_server (DebTorrent.RawServer.RawServer) - the server instance to use
  • my_id (string) - the peer ID to use
  • max_len (int) - the maximum length message to accept
  • schedulefunc (method) - method to call to schedule future function invocation
  • keepalive_delay (int) - the delay between sending keepalive messages
  • download_id (string) - the infohash of the torrent being downloaded
  • measurefunc (method) - method to call with the size of incoming data
  • config (dictionary) - the configuration parameters
  • bans (class) - the instance to check for banned peer's in (optional, defaults to an instance of _dummy_banlist)

start_connections(self, list)

source code 
Add many connections from a list to a queue to start.
Parameters:
  • list (list of ((string, int), string, boolean)) - the list of IP address, port, peer ID, and whether to encrypt

start_connection(self, dns, id, encrypted=None)

source code 
Start a connection to a peer.
Parameters:
  • dns ((string, int)) - the IP address and port to connect to
  • id (string) - the peer ID of the peer
  • encrypted (boolean) - whether to encrypt the connection (optional, defaults to True)
Returns: boolean
False if an error occurs

_start_connection(self, dns, id, encrypted=None)

source code 
Schedule the start of a connection to a peer.
Parameters:
  • dns ((string, int)) - the IP address and port to connect to
  • id (string) - the peer ID of the peer
  • encrypted (boolean) - whether to encrypt the connection (optional, defaults to True)

check_ip(self, connection=None, ip=None)

source code 
Check whether the connection to the IP is allowed.
Parameters:
  • connection (DebTorrent.SocketHandler.SingleSocket) - the connection whose IP should be checked (optional, but one of connection/ip must be specified)
  • ip (string) - the IP address of the connection (optional, but one of connection/ip must be specified)
Returns: boolean
whether the connection is allowed

got_id(self, connection)

source code 

Check whether the connection to the peer ID is allowed.

Checks whether the peer ID is ours, or is already connected on another connection. If the security config option is set, it also checks if the IP is already connected, in which case this one is not allowed.
Parameters:
  • connection (Connection) - the connection whose peer ID should be checked
Returns: boolean
whether the connection is allowed

external_connection_made(self, connection)

source code 
Process an externally made connection.
Parameters:
Returns: boolean
whether the connection is accepted

externally_handshaked_connection_made(self, connection, options, already_read, encrypted=None)

source code 
Process an externally handshaked connection.
Parameters:
  • connection (DebTorrent.SocketHandler.SingleSocket) - the connection that was made
  • options (string) - the options read from the externally handshaked connection (optional, defaults to None)
  • already_read (string) - the data that has already been received on the connection
  • encrypted (DebTorrent.BT1Crypto.Crypto) - the already created Crypto instance, if the connection was externally handshaked (optional, defaults to creating a new one)
Returns: boolean
whether the connection is accepted

ban(self, ip)

source code 
Ban an IP address from ever connecting again.
Parameters:
  • ip (string) - the IP address to ban

pause(self, flag)

source code 

Set the paused flag.

When paused, no new connections are made and no keepalives are sent.
Parameters:
  • flag (boolean) - whether the download is paused