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

Class NatCheck

source code

Check if a peer is unreachable behind a NAT.

Instance Methods [hide private]
 
__init__(self, resultfunc, downloadid, peerid, ip, port, rawserver, encrypted=True)
Initialize the instance and start a connection to the peer.
source code
 
answer(self, result)
Close the connection and return the result.
source code
int, method
_read_header(self, s)
Read the protocol header.
source code
int, method
read_header(self, s)
Read the possibly encrypted protocol header.
source code
 
_start_crypto(self)
Setup the connection for encrypted communication.
source code
int, method
read_crypto_header(self, s)
Read the encryption key.
source code
boolean
_search_for_pattern(self, s, pat)
Search for a pattern in the encrypted protocol header.
source code
int, method
read_crypto_block4a(self, s)
Read the encrypted protocol header.
source code
int, method
read_crypto_block4b(self, s)
Read the encrypted protocol mode.
source code
int, method
read_crypto_pad4(self, s)
Read the encrypted protocol padding.
source code
int, method
read_crypto_block4done(self)
Finish with the encrypted header.
source code
int, method
read_encrypted_header(self, s)
Read the regular protocol name header from the encrypted stream.
source code
int, method
read_options(self, s)
Read the options from the header.
source code
int, method
read_download_id(self, s)
Verify the torrent infohash from the header.
source code
None
read_peer_id(self, s)
Verify the peer's ID and return the answer.
source code
 
_write(self, message)
Write a raw message out on the connection.
source code
 
data_came_in(self, connection, s)
Process the incoming data on the connection.
source code
 
_write_buffer(self, s)
Write data back onto the buffer.
source code
 
_read(self, s)
Process the data that came in.
source code
 
connection_lost(self, connection)
Close the connection and return the failure.
source code
 
connection_flushed(self, connection)
Do nothing.
source code
Instance Variables [hide private]
boolean _dc
whether encrypted connections have been disabled
int _max_search
the number of remaining bytes to search for the pattern
string buffer
the buffer of received data from the connection
boolean closed
whether the connection has been closed
DebTorrent.SocketHandler.SingleSocket connection
the connection to the peer
int cryptmode
the type of encryption being used
string downloadid
the info hash of the torrent to use
boolean encrypted
whether to use an encrypted connection
DebTorrent.BTcrypto.Crypto encrypter
the encrypter to use for the connection
string ip
the IP of the peer being checked
method next_func
the next method to use to process incoming data on the connection
int next_len
the next amount of data to read from the connection
string peerid
the peer ID of the peer being checked
int port
the port to connect to the peer on
method read
the method to use to read from the connection
method resultfunc
the method to call with the result when complete
method write
the method to use to write to the connection
Method Details [hide private]

__init__(self, resultfunc, downloadid, peerid, ip, port, rawserver, encrypted=True)
(Constructor)

source code 
Initialize the instance and start a connection to the peer.
Parameters:
  • resultfunc (method) - the method to call with the result when complete
  • downloadid (string) - the info hash of the torrent to use
  • peerid (string) - the peer ID of the peer being checked
  • ip (string) - the IP of the peer being checked
  • port (int) - the port to connect to the peer on
  • rawserver (DebTorrent.RawServer.RawServer) - the server instance to use
  • encrypted (boolean) - whether to use an encrypted connection (optional, defaults to False)

answer(self, result)

source code 
Close the connection and return the result.
Parameters:
  • result (boolean) - whether the peer is connectable

_read_header(self, s)

source code 
Read the protocol header.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_header(self, s)

source code 
Read the possibly encrypted protocol header.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_crypto_header(self, s)

source code 
Read the encryption key.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

_search_for_pattern(self, s, pat)

source code 
Search for a pattern in the encrypted protocol header.
Parameters:
  • s (string) - the incoming data from the connection
  • pat (string) - the pattern to find
Returns: boolean
whether the pattern was found

read_crypto_block4a(self, s)

source code 
Read the encrypted protocol header.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_crypto_block4b(self, s)

source code 
Read the encrypted protocol mode.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_crypto_pad4(self, s)

source code 
Read the encrypted protocol padding.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_crypto_block4done(self)

source code 
Finish with the encrypted header.
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_encrypted_header(self, s)

source code 
Read the regular protocol name header from the encrypted stream.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_options(self, s)

source code 
Read the options from the header.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_download_id(self, s)

source code 
Verify the torrent infohash from the header.
Parameters:
  • s (string) - the incoming data from the connection
Returns: int, method
the next amount of data to read and the method to call with it, or None if there is no next method to call

read_peer_id(self, s)

source code 
Verify the peer's ID and return the answer.
Parameters:
  • s (string) - the incoming data from the connection
Returns: None
None

_write(self, message)

source code 
Write a raw message out on the connection.
Parameters:
  • message (string) - the raw data to write to the connection

data_came_in(self, connection, s)

source code 
Process the incoming data on the connection.
Parameters:

_write_buffer(self, s)

source code 
Write data back onto the buffer.
Parameters:
  • s (string) - the data to rebuffer

_read(self, s)

source code 
Process the data that came in.
Parameters:
  • s (string) - the (unencrypted) incoming data from the connection

connection_lost(self, connection)

source code 
Close the connection and return the failure.
Parameters:

connection_flushed(self, connection)

source code 
Do nothing.
Parameters: