Class Protocols.Bittorrent.Torrent
- Description
Bittorrent peer - download and share. Read more about bittorrent at http://bitconjurer.org/BitTorrent/introduction.html
- Example
The smallest usable torrent downloader. As first argument, it expects a filename to a .torrent file.
int main(int ac,array am) { // initialize Torrent from file: Protocols.Bittorrent.Torrent t=Protocols.Bittorrent.Torrent(); t->load_metainfo(am[1]); // Callback when download status changes: // t->downloads_update_status=...; // Callback when pieces status change (when we get new stuff): // t->pieces_update_status=...; // Callback when peer status changes (connect, disconnect, choked...): // t->peer_update_status=...; // Callback when download is completed: t->download_completed_callback= lambda() { call_out(exit,3600,0); // share for an hour, then exit }; // Callback to print warnings (same args as sprintf): // t->warning=werror; // type of progress function used below: void progress(int n,int of) { /* ... */ }; // Initiate targets from Torrent, // if target was created, no need to verify: if (t->fix_targets(1,0,progress)==1) t->verify_targets(progress); // Open port to listen on, // we want to do this to be able to talk to firewalled peers: t->open_port(6881); // Ok, start calling tracker to get peers, // and tell about us: t->start_update_tracker(); // Finally, start the download: t->start_download(); return -1; }
- Variable
do_we_strangle
function
(.Peer
,int
,int
:bool
) Protocols.Bittorrent.Torrent.do_we_strangle- Description
Function to determine if we should strangle this peer. Default is to allow 100000 bytes of data over the ratio, which is 2:1 per default; upload twice as much as we get.
Arguments are the peer, bytes in (downloaded) and bytes out (uploaded). Return 1 to strangle and 0 to allow the peer to proceed downloading again.
- Variable
download_completed_callback
function
(:void
) Protocols.Bittorrent.Torrent.download_completed_callback- Description
If set, called when download is completed.
- Variable
downloads_update_status
function
(:void
) Protocols.Bittorrent.Torrent.downloads_update_status- Description
If set, called when we start to download another piece (no args).
- Variable
peer_update_status
function
(:void
) Protocols.Bittorrent.Torrent.peer_update_status- Description
If set, called when peer status changes.
- Variable
pieces_update_status
function
(:void
) Protocols.Bittorrent.Torrent.pieces_update_status- Description
If set, called when we got another piece downloaded (no args).