diff options
Diffstat (limited to 'src/trackerlogic.c')
| -rw-r--r-- | src/trackerlogic.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/trackerlogic.c b/src/trackerlogic.c index ddbc430..1f56a2c 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c | |||
| @@ -78,7 +78,7 @@ void add_torrent_from_saved_state(ot_hash const hash, ot_time age, size_t down_c | |||
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount) { | 80 | size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstruct *ws, size_t amount) { |
| 81 | int exactmatch, delta_torrentcount = 0; | 81 | int exactmatch, delta_torrentcount = 0, completed = 0; |
| 82 | ot_torrent *torrent; | 82 | ot_torrent *torrent; |
| 83 | ot_peer *peer_dest; | 83 | ot_peer *peer_dest; |
| 84 | ot_vector *torrents_list = mutex_bucket_lock_by_hash(*ws->hash); | 84 | ot_vector *torrents_list = mutex_bucket_lock_by_hash(*ws->hash); |
| @@ -153,7 +153,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru | |||
| 153 | 153 | ||
| 154 | if (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED) { | 154 | if (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED) { |
| 155 | torrent->down_count++; | 155 | torrent->down_count++; |
| 156 | stats_issue_event(ws, EVENT_COMPLETED, 0, 0); | 156 | completed = 1; /* the event, which may syslog, is issued after unlock */ |
| 157 | } | 157 | } |
| 158 | if (OT_PEERFLAG(ws->peer) & PEER_FLAG_SEEDING) | 158 | if (OT_PEERFLAG(ws->peer) & PEER_FLAG_SEEDING) |
| 159 | peer_list->seed_count++; | 159 | peer_list->seed_count++; |
| @@ -180,7 +180,7 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru | |||
| 180 | peer_list->seed_count++; | 180 | peer_list->seed_count++; |
| 181 | if (!(OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) && (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED)) { | 181 | if (!(OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) && (OT_PEERFLAG(ws->peer) & PEER_FLAG_COMPLETED)) { |
| 182 | torrent->down_count++; | 182 | torrent->down_count++; |
| 183 | stats_issue_event(ws, EVENT_COMPLETED, 0, 0); | 183 | completed = 1; /* the event, which may syslog, is issued after unlock */ |
| 184 | } | 184 | } |
| 185 | if (OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) | 185 | if (OT_PEERFLAG_D(peer_dest, peer_size) & PEER_FLAG_COMPLETED) |
| 186 | OT_PEERFLAG(ws->peer) |= PEER_FLAG_COMPLETED; | 186 | OT_PEERFLAG(ws->peer) |= PEER_FLAG_COMPLETED; |
| @@ -190,12 +190,18 @@ size_t add_peer_to_torrent_and_return_peers(PROTO_FLAG proto, struct ot_workstru | |||
| 190 | #ifdef WANT_SYNC | 190 | #ifdef WANT_SYNC |
| 191 | if (proto == FLAG_MCA) { | 191 | if (proto == FLAG_MCA) { |
| 192 | mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); | 192 | mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); |
| 193 | if (completed) | ||
| 194 | stats_issue_event(ws, EVENT_COMPLETED, 0, 0); | ||
| 193 | return 0; | 195 | return 0; |
| 194 | } | 196 | } |
| 195 | #endif | 197 | #endif |
| 196 | 198 | ||
| 197 | ws->reply_size = return_peers_for_torrent(ws, torrent, amount, ws->reply, proto); | 199 | ws->reply_size = return_peers_for_torrent(ws, torrent, amount, ws->reply, proto); |
| 198 | mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); | 200 | mutex_bucket_unlock_by_hash(*ws->hash, delta_torrentcount); |
| 201 | |||
| 202 | /* Issued after bucket unlock, so a slow syslog cannot stall the bucket */ | ||
| 203 | if (completed) | ||
| 204 | stats_issue_event(ws, EVENT_COMPLETED, 0, 0); | ||
| 199 | return ws->reply_size; | 205 | return ws->reply_size; |
| 200 | } | 206 | } |
| 201 | 207 | ||
