summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
authorerdgeist <>2010-04-22 22:08:42 +0000
committererdgeist <>2010-04-22 22:08:42 +0000
commitd42bf5a0310b8df4babff645ee91c37e9f994bfe (patch)
tree878712aeae9d2c64dc626b2945f11cac50954258 /ot_udp.c
parentae9ab769415f30ccb444bb0b0190a5fcf22275e7 (diff)
** struct ot_workstruct gets ritcher (and will become even ritcher soon).
This is where we encapsulate all per-request data from peer to hash to peer_id, so that it is available everywhere without passing hundreds of pointers down the stack. Most functions that do work down the stack now accept an ot_workstruct and some flags. So it can end up in the stats/event-handler where it will be the default parameter in the future. ** peer_id is now being copied by default and moved to ot_workstruct So it is available in stats and subsequent functions. ** sync scrape madness is gone SYNC_SCRAPE was intended to sync tracker state that would normally be lost on restarts i.e. downloaded counts per torrent. The way was to push it in the tracker cloud after finding all neighbouring trackers. This is madness. It never was tested and can be done per tracker by fetching stats/mode=statedump from time to time and starting opentracker with the -l option later. ** livesync thread has its own ot_workstruct now So it can behave like ot_udp and ot_http against trackerlogic.c and get rid of the first half of the embarrassing global variables. The sending half will be fixed soon [tm]. ** stats can log completed events The author recognizes the needs of original content distributors to keep track of the amount of times a work has been downloaded. While not feasible and used on openbittorrent and other open and anonymous tracker installations, a tracker user can now choose to send those events to syslog.
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/ot_udp.c b/ot_udp.c
index a95a4fa..bc2d6cc 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -29,8 +29,6 @@ static void udp_make_connectionid( uint32_t * connid, const ot_ip6 remoteip ) {
29 29
30/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */ 30/* UDP implementation according to http://xbtt.sourceforge.net/udp_tracker_protocol.html */
31void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { 31void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
32 ot_peer peer;
33 ot_hash *hash = NULL;
34 ot_ip6 remoteip; 32 ot_ip6 remoteip;
35 uint32_t *inpacket = (uint32_t*)ws->inbuf; 33 uint32_t *inpacket = (uint32_t*)ws->inbuf;
36 uint32_t *outpacket = (uint32_t*)ws->outbuf; 34 uint32_t *outpacket = (uint32_t*)ws->outbuf;
@@ -43,6 +41,10 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
43 stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip ); 41 stats_issue_event( EVENT_ACCEPT, FLAG_UDP, (uintptr_t)remoteip );
44 stats_issue_event( EVENT_READ, FLAG_UDP, byte_count ); 42 stats_issue_event( EVENT_READ, FLAG_UDP, byte_count );
45 43
44 /* Initialise hash pointer */
45 ws->hash = NULL;
46 ws->peer_id = NULL;
47
46 /* Minimum udp tracker packet size, also catches error */ 48 /* Minimum udp tracker packet size, also catches error */
47 if( byte_count < 16 ) 49 if( byte_count < 16 )
48 return; 50 return;
@@ -71,33 +73,36 @@ void handle_udp6( int64 serversocket, struct ot_workstruct *ws ) {
71 numwant = ntohl( inpacket[92/4] ); 73 numwant = ntohl( inpacket[92/4] );
72 if (numwant > 200) numwant = 200; 74 if (numwant > 200) numwant = 200;
73 75
74 event = ntohl( inpacket[80/4] ); 76 event = ntohl( inpacket[80/4] );
75 port = *(uint16_t*)( ((char*)inpacket) + 96 ); 77 port = *(uint16_t*)( ((char*)inpacket) + 96 );
76 hash = (ot_hash*)( ((char*)inpacket) + 16 ); 78 ws->hash = (ot_hash*)( ((char*)inpacket) + 16 );
77 79
78 OT_SETIP( &peer, remoteip ); 80 OT_SETIP( &ws->peer, remoteip );
79 OT_SETPORT( &peer, &port ); 81 OT_SETPORT( &ws->peer, &port );
80 OT_PEERFLAG( &peer ) = 0; 82 OT_PEERFLAG( &ws->peer ) = 0;
81 83
82 switch( event ) { 84 switch( event ) {
83 case 1: OT_PEERFLAG( &peer ) |= PEER_FLAG_COMPLETED; break; 85 case 1: OT_PEERFLAG( &ws->peer ) |= PEER_FLAG_COMPLETED; break;
84 case 3: OT_PEERFLAG( &peer ) |= PEER_FLAG_STOPPED; break; 86 case 3: OT_PEERFLAG( &ws->peer ) |= PEER_FLAG_STOPPED; break;
85 default: break; 87 default: break;
86 } 88 }
87 89
88 if( !left ) 90 if( !left )
89 OT_PEERFLAG( &peer ) |= PEER_FLAG_SEEDING; 91 OT_PEERFLAG( &ws->peer ) |= PEER_FLAG_SEEDING;
90 92
91 outpacket[0] = htonl( 1 ); /* announce action */ 93 outpacket[0] = htonl( 1 ); /* announce action */
92 outpacket[1] = inpacket[12/4]; 94 outpacket[1] = inpacket[12/4];
93 95
94 if( OT_PEERFLAG( &peer ) & PEER_FLAG_STOPPED ) /* Peer is gone. */ 96 if( OT_PEERFLAG( &ws->peer ) & PEER_FLAG_STOPPED ) { /* Peer is gone. */
95 byte_count = remove_peer_from_torrent( *hash, &peer, ws->outbuf, FLAG_UDP ); 97 ws->reply = ws->outbuf;
96 else 98 ws->reply_size = remove_peer_from_torrent( FLAG_UDP, ws );
97 byte_count = 8 + add_peer_to_torrent_and_return_peers( *hash, &peer, FLAG_UDP, numwant, ((char*)outpacket) + 8 ); 99 } else {
100 ws->reply = ws->outbuf + 8;
101 ws->reply_size = 8 + add_peer_to_torrent_and_return_peers( FLAG_UDP, ws, numwant );
102 }
98 103
99 socket_send6( serversocket, ws->outbuf, byte_count, remoteip, remoteport, 0 ); 104 socket_send6( serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport, 0 );
100 stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, byte_count ); 105 stats_issue_event( EVENT_ANNOUNCE, FLAG_UDP, ws->reply_size );
101 break; 106 break;
102 107
103 case 2: /* This is a scrape action */ 108 case 2: /* This is a scrape action */