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;
}