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

Class Tracker

source code

Track a download swarm.

Instance Methods [hide private]
 
__init__(self, config, rawserver, configdir)
Initialize the instance.
source code
 
cachetimeupdate(self)
Update the cachetime every second.
source code
 
aggregate_senddata(self, query)
Fork sending data to a tracker aggregator.
source code
 
_aggregate_senddata(self, url)
Send a URL request to a tracker data aggregator.
source code
(int, string, dictionary, string)
get_infopage(self)
Format the info page to display for normal browsers.
source code
dictionary
scrapedata(self, hash, return_name=True)
Retrieve the scrape data for a single torrent.
source code
(int, string, dictionary, string)
get_scrape(self, paramslist)
Get the scrape data for all the active torrents.
source code
(int, string, dictionary, string)
get_file(self, hash)
Get the metainfo file for a torrent.
source code
(int, string, dictionary, string)
check_allowed(self, infohash, paramslist)
Determine whether the tracker is tracking this torrent.
source code
int
add_data(self, infohash, event, ip, paramslist)
Add the received data from the peer to the cache.
source code
dictionary
peerlist(self, infohash, stopped, tracker, is_seed, return_type, rsize, supportcrypto)
Create a list of peers to return to the client.
source code
(int, string, dictionary, string)
get(self, connection, path, headers, httpreq)
Respond to a GET request to the tracker.
source code
 
natcheckOK(self, infohash, peerid, ip, port, peer)
Add the unNATed peer to the cache.
source code
 
connectback_result(self, result, downloadid, peerid, ip, port)
Process a NAT check attempt and result.
source code
 
remove_from_state(self, *l)
Remove all the input parameter names from the current state.
source code
 
save_state(self)
Save the state file to disk.
source code
 
parse_allowed(self)
Periodically parse the directory and list for allowed torrents.
source code
 
read_ip_lists(self)
Periodically parse the allowed and banned IPs lists.
source code
 
delete_peer(self, infohash, peerid)
Delete all cached data for the peer.
source code
 
expire_downloaders(self)
Periodically remove all old downloaders from the cached data.
source code
Instance Variables [hide private]
 
cache_default(self)
the default cache entry for new caches
source code
Filter.Filter Filter
the filter to use for disallowing connecting peers
string aggregate_forward
URL to forward all non-multitracker connections to
string aggregate_password
password to use when forwarding non-multitracker connections
string aggregator_key
the password to use to verify connecting trackers
boolean allow_get
whether torrets can be downloaded from the info page
dictionary allowed
the torrents that are allowed to be tracked, keys are the info hashes, values are the torrent data
DebTorrent.subnetparse.IP_List allowed_IPs
the IPs that are allowed to connect, or None if all are
dictionary allowed_dir_blocked
unparseable torrent files found in the allowed directory
dictionary allowed_dir_files
torrent files found in the allowed directory
int allowed_ip_mtime
the last modification time of the allowed IPs file
int allowed_list_mtime
the last modification time of the list of allowed torrents file
DebTorrent.iprangeparse.IP_List banned_IPs
the IPs that are not allowed to connect
int banned_ip_mtime
the last modification time of the banned IPs file
list of list of dictionary becache
keys are the infohashes, values are the cached peer data.
unknown cached
unknown
unknown cached_t
unknown
int cachetime
elasped time since starting for caclulating cache refreshes
dictionary completed
keys are info hashes, values are the number of peers that have completed downloading the entire torrent
dictionary config
the configuration parameters
DebTorrent.ConfigDir.ConfigDir configdir
the configuration and cache directory manager
string dedicated_seed_id
dedicated seed ID to expect from clients
dictionary downloads
keys are info hashes, values are dictionaries with keys the peer IDs of peers connected to that torrent and values the dictionaries of information about the peer
string favicon
file containing x-icon data
boolean is_aggregator
whether to act as a data aggregator rather than a tracker
dictionary is_seeded
keys are info hashes, values are true if the torrent has a dedicated seed connected
boolean keep_dead
whether to keep dead torrents after they expire
int natcheck
how many times to check if a downloader is behind a NAT
boolean only_local_override_ip
whether to ignore the "ip" parameter from machines which aren't on local network IPs
int parse_dir_interval
seconds between reloading of the allowed directory or file, and the lists of allowed and banned IPs
float prevtime
the last time downloaders were expired from the cache
DebTorrent.RawServer.RawServer rawserver
the server to use for scheduling
int reannounce_interval
seconds downloaders should wait between reannouncements
int response_size
default number of peers to send in an info message
int save_state_interval
seconds between saving the state file
dictionary seedcount
keys are info hashes, values are the number of seeds connected to that torrent
boolean show_names
whether to display names from allowed dir
dictionary state
the current state information for the tracking
T2T.T2TList t2tlist
the list of tracker to tracker connections
int timeout_downloaders_interval
seconds between expiring downloaders
dictionary times
keys are info hashes, values are dictionaries with keys the peer IDs of peers connected to that torrent and values the last time the peer was seen
string trackerid
the randomly generated tracker ID of this tracker
boolean uq_broken
whether URL quoting of '+' is broken
Method Details [hide private]

__init__(self, config, rawserver, configdir)
(Constructor)

source code 
Initialize the instance.
Parameters:

aggregate_senddata(self, query)

source code 
Fork sending data to a tracker aggregator.
Parameters:
  • query (string) - the query to send

_aggregate_senddata(self, url)

source code 

Send a URL request to a tracker data aggregator.

Just send, don't attempt to error check, discard any returned data.
Parameters:
  • url (string) - the URL to request

get_infopage(self)

source code 

Format the info page to display for normal browsers.

Formats the currently tracked torrents into a table in human-readable format to display in a browser window.
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and message body

scrapedata(self, hash, return_name=True)

source code 
Retrieve the scrape data for a single torrent.
Parameters:
  • hash (string) - the infohash of the torrent to get scrape data for
  • return_name (boolean) - whether to return the name of the torrent (optional, defaults to True)
Returns: dictionary
the scrape data for the torrent

get_scrape(self, paramslist)

source code 
Get the scrape data for all the active torrents.
Parameters:
  • paramslist (dictionary) - the query parameters from the GET request
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and bencoded message body

get_file(self, hash)

source code 
Get the metainfo file for a torrent.
Parameters:
  • hash (string) - the infohash of the torrent to get the metainfo of
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and bencoded metainfo file

check_allowed(self, infohash, paramslist)

source code 
Determine whether the tracker is tracking this torrent.
Parameters:
  • infohash (string) - the infohash of the torrent to check
  • paramslist (dictionary) - the query parameters from the GET request
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and bencoded message body if the request is not allowed, or None if it is

add_data(self, infohash, event, ip, paramslist)

source code 
Add the received data from the peer to the cache.
Parameters:
  • infohash (string) - the infohash of the torrent to add to
  • event (string) - the type of event being reported by the peer
  • ip (string) - the IP address of the peer
  • paramslist (dictionary) - the query parameters from the GET request
Returns: int
the number of peers to return in a peer list
Raises:
  • ValueError - if the request from the peer is corrupt

peerlist(self, infohash, stopped, tracker, is_seed, return_type, rsize, supportcrypto)

source code 
Create a list of peers to return to the client.
Parameters:
  • infohash (string) - the infohash of the torrent to get peers from
  • stopped (boolean) - whether the peer has stopped
  • tracker (boolean) - whether the peer is a tracker
  • is_seed (boolean) - whether the peer is currently seeding (currently ignored)
  • return_type (int) - the format of the list to return (compact, ...)
  • rsize (int) - the number of peers to return
  • supportcrypto (boolean) - whether the peer supports encrypted communication (not used)
Returns: dictionary
the info to return to the client

get(self, connection, path, headers, httpreq)

source code 

Respond to a GET request to the tracker.

Process a GET request from a peer/tracker/browser. Process the request, calling the helper functions above if needed. Return the response to be returned to the requester.
Parameters:
Returns: (int, string, dictionary, string)
the HTTP status code, status message, headers, and message body

natcheckOK(self, infohash, peerid, ip, port, peer)

source code 
Add the unNATed peer to the cache.
Parameters:
  • infohash (string) - the infohash of the torrent the peer is in
  • peerid (string) - the peer ID of the peer
  • ip (string) - the IP address of the peer
  • port (int) - the port to contact the peer on
  • peer (dictionary) - various information about the peer

connectback_result(self, result, downloadid, peerid, ip, port)

source code 
Process a NAT check attempt and result.
Parameters:
  • result (boolean) - whether the NAT check was successful
  • downloadid (string) - the infohash of the torrent the peer is in
  • peerid (string) - the peer ID of the peer
  • ip (string) - the IP address of the peer
  • port (int) - the port to contact the peer on

delete_peer(self, infohash, peerid)

source code 
Delete all cached data for the peer.
Parameters:
  • infohash (string) - the infohash of the torrent to delete the peer from
  • peerid (string) - the peer ID of the peer to delete

Instance Variable Details [hide private]

becache

keys are the infohashes, values are the cached peer data. peer set format:
   [[l0, s0], [l1, s1], ...]
       l,s   = dictionaries of leechers and seeders (by peer ID)
       l0,s0 = compact representation, don't require crypto
       l1,s1 = compact representation, support crypto
       l2,s2 = [compact representation, crypto_flag], for all peers
   additionally, if --compact_reqd = 0:
       l3,s3 = [ip,port,peerid] for all peers
       l4,l4 = [ip,port] for all peers
Type:
list of list of dictionary