Package DebTorrent :: Package BT1 :: Module Connecter :: Class Connection
[hide private]
[frames] | no frames]

Class Connection

source code

A connection to an individual peer.

Instance Methods [hide private]
 
__init__(self, connection, connecter, ccount)
Initialize the class.
source code
 
get_ip(self, real=True)
Get the IP address of the connection.
source code
string
get_id(self)
Get the Peer ID of the connection.
source code
string
get_readable_id(self)
Get a human readable version of the ID of the connection.
source code
 
close(self)
Close the connection.
source code
boolean
is_locally_initiated(self)
Check whether the connection was established by the client.
source code
boolean
is_encrypted(self)
Check whether the connection is encrypted.
source code
 
send_interested(self)
Send the INTERESTED message.
source code
 
send_not_interested(self)
Send the NOT_INTERESTED message.
source code
 
send_choke(self)
Send the CHOKE message.
source code
 
send_unchoke(self)
Send the UNCHOKE message.
source code
 
send_request(self, index, begin, length)
Send the REQUEST message.
source code
 
send_cancel(self, index, begin, length)
Send the CANCEL message.
source code
 
send_bitfield(self, bitfield)
Send the BITFIELD message.
source code
 
send_have(self, index)
Send the HAVE message.
source code
 
send_keepalive(self)
Send a keepalive message.
source code
 
_send_message(self, s)
Actually send the message.
source code
int
send_partial(self, bytes)
Send a PIECE message containing part of a piece.
source code
Uploader.Upload
get_upload(self)
Get the Uploader.Upload instance for this connection.
source code
Downloader.Downloader
get_download(self)
Get the Downloader.Downloader instance for this connection.
source code
 
set_download(self, download)
Set the Downloader.Downloader instance for this connection.
source code
boolean
backlogged(self)
Check whether the connection is ready to send.
source code
 
got_request(self, i, p, l)
Process a request from a peer for a part of a piece.
source code
Instance Variables [hide private]
int ccount
the number of the connection
Connecter connecter
the collection of all connections
Encrypter.Connection connection
the connection
Downloader.Downloader download
the Downloader instance to use for the connection
boolean got_anything
whether a message has ever been received on the connection
int just_unchoked
the time of a recent UNCHOKE, if it was the first
Encrypter.Connection next_upload
the connection that will next be allowed to upload
list outqueue
the queue of messages to send on the connection that are waiting for the current piece to finish sending
string partial_message
the remaining data in the current piece being sent
boolean send_choke_queued
whether to suppress the next CHOKE message
Uploader.Upload upload
the Uploader instance to use for the connection
Method Details [hide private]

__init__(self, connection, connecter, ccount)
(Constructor)

source code 
Initialize the class.
Parameters:
  • connection (Encrypter.Connection) - the connection
  • connecter (Connecter) - the collection of all connections
  • ccount (int) - the number of the connection

get_ip(self, real=True)

source code 
Get the IP address of the connection.
Parameters:
  • real (boolean) - whether to check that the IP is the real one (optional, defaults to False)

get_id(self)

source code 
Get the Peer ID of the connection.
Returns: string
the ID of the connection

get_readable_id(self)

source code 
Get a human readable version of the ID of the connection.
Returns: string
the ID of the connection

is_locally_initiated(self)

source code 
Check whether the connection was established by the client.
Returns: boolean
whether the connection was established by the client

is_encrypted(self)

source code 
Check whether the connection is encrypted.
Returns: boolean
whether the connection is encrypted

send_request(self, index, begin, length)

source code 
Send the REQUEST message.
Parameters:
  • index (int) - the piece to request some of
  • begin (int) - the starting offset within the piece
  • length (int) - the length of the part of the piece to get

send_cancel(self, index, begin, length)

source code 

Send the CANCEL message.

Cancels a previously sent REQUEST message.
Parameters:
  • index (int) - the piece that was requested
  • begin (int) - the starting offset within the piece
  • length (int) - the length of the part of the piece to get

send_bitfield(self, bitfield)

source code 
Send the BITFIELD message.
Parameters:
  • bitfield (string) - the bitfield to send

send_have(self, index)

source code 
Send the HAVE message.
Parameters:
  • index (int) - the piece index to indicate having

_send_message(self, s)

source code 
Actually send the message.
Parameters:
  • s (string) - the message to send

send_partial(self, bytes)

source code 
Send a PIECE message containing part of a piece.
Parameters:
  • bytes (int) - the number of bytes of piece data to send
Returns: int
the actual number of bytes sent

get_upload(self)

source code 
Get the Uploader.Upload instance for this connection.
Returns: Uploader.Upload
the Upload instance

get_download(self)

source code 
Get the Downloader.Downloader instance for this connection.
Returns: Downloader.Downloader
the Downloader instance

set_download(self, download)

source code 
Set the Downloader.Downloader instance for this connection.
Parameters:

backlogged(self)

source code 
Check whether the connection is ready to send.
Returns: boolean
whether the connection is backlogged

got_request(self, i, p, l)

source code 
Process a request from a peer for a part of a piece.
Parameters:
  • i (int) - the piece index
  • p (int) - the position to start at
  • l (int) - the length to send