diff options
Diffstat (limited to 'src/ot_fullscrape.c')
| -rw-r--r-- | src/ot_fullscrape.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/ot_fullscrape.c b/src/ot_fullscrape.c index 85be65d..0cd1910 100644 --- a/src/ot_fullscrape.c +++ b/src/ot_fullscrape.c | |||
| @@ -72,7 +72,8 @@ static void *fullscrape_worker(void *args) { | |||
| 72 | 72 | ||
| 73 | static pthread_t thread_id; | 73 | static pthread_t thread_id; |
| 74 | void fullscrape_init(void) { | 74 | void fullscrape_init(void) { |
| 75 | pthread_create( &thread_id, NULL, fullscrape_worker, NULL ); | 75 | if (pthread_create(&thread_id, NULL, fullscrape_worker, NULL)) |
| 76 | exerr("Cannot create fullscrape worker thread."); | ||
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | void fullscrape_deinit(void) { | 79 | void fullscrape_deinit(void) { |
| @@ -90,9 +91,9 @@ static void fullscrape_write_one( ot_tasktype mode, char **cursor, ot_torrent *t | |||
| 90 | exactly that size */ | 91 | exactly that size */ |
| 91 | char *r = *cursor; | 92 | char *r = *cursor; |
| 92 | const char *r_end = r + OT_SCRAPE_MAXENTRYLEN; | 93 | const char *r_end = r + OT_SCRAPE_MAXENTRYLEN; |
| 93 | size_t seed_count = torrent->peer_list6->seed_count + torrent->peer_list4->seed_count; | 94 | size_t seed_count = torrent_seed_count(torrent); |
| 94 | size_t peer_count = torrent->peer_list6->peer_count + torrent->peer_list4->peer_count; | 95 | size_t peer_count = torrent_peer_count(torrent); |
| 95 | size_t down_count = torrent->peer_list6->down_count + torrent->peer_list4->down_count; | 96 | size_t down_count = torrent->down_count; |
| 96 | 97 | ||
| 97 | switch (mode & TASK_TASK_MASK) { | 98 | switch (mode & TASK_TASK_MASK) { |
| 98 | case TASK_FULLSCRAPE: | 99 | case TASK_FULLSCRAPE: |
| @@ -131,7 +132,7 @@ static void fullscrape_write_one( ot_tasktype mode, char **cursor, ot_torrent *t | |||
| 131 | case TASK_FULLSCRAPE_TRACKERSTATE: | 132 | case TASK_FULLSCRAPE_TRACKERSTATE: |
| 132 | hex_from_hash(r, *hash); | 133 | hex_from_hash(r, *hash); |
| 133 | r += 2 * sizeof(ot_hash); | 134 | r += 2 * sizeof(ot_hash); |
| 134 | fmt_append(&r, r_end, ":%zd:%zd\n", (ssize_t)time_since_minutes(torrent->peer_list6->base), down_count); | 135 | fmt_append(&r, r_end, ":%zd:%zd\n", (ssize_t)(time_wall_minutes() - time_since_minutes(torrent->base)), down_count); |
| 135 | break; | 136 | break; |
| 136 | } | 137 | } |
| 137 | *cursor = r; | 138 | *cursor = r; |
| @@ -188,8 +189,10 @@ static void fullscrape_make(int taskid, ot_tasktype mode) { | |||
| 188 | mutex_bucket_unlock(bucket, 0); | 189 | mutex_bucket_unlock(bucket, 0); |
| 189 | 190 | ||
| 190 | /* Parent thread died? */ | 191 | /* Parent thread died? */ |
| 191 | if (!g_opentracker_running) | 192 | if (!g_opentracker_running) { |
| 193 | free(iovector.iov_base); | ||
| 192 | return; | 194 | return; |
| 195 | } | ||
| 193 | } | 196 | } |
| 194 | 197 | ||
| 195 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) | 198 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) |
| @@ -217,8 +220,10 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { | |||
| 217 | memset(&strm, 0, sizeof(strm)); | 220 | memset(&strm, 0, sizeof(strm)); |
| 218 | strm.next_out = (uint8_t *)iovector.iov_base; | 221 | strm.next_out = (uint8_t *)iovector.iov_base; |
| 219 | strm.avail_out = OT_SCRAPE_CHUNK_SIZE; | 222 | strm.avail_out = OT_SCRAPE_CHUNK_SIZE; |
| 220 | if (deflateInit2(&strm, 7, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY) != Z_OK) | 223 | if (deflateInit2(&strm, 7, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY) != Z_OK) { |
| 221 | fprintf(stderr, "not ok.\n"); | 224 | free(iovector.iov_base); |
| 225 | return; | ||
| 226 | } | ||
| 222 | 227 | ||
| 223 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) { | 228 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) { |
| 224 | strm.next_in = (uint8_t *)"d5:filesd"; | 229 | strm.next_in = (uint8_t *)"d5:filesd"; |
| @@ -250,6 +255,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { | |||
| 250 | 255 | ||
| 251 | if (workqueue_pushchunked(taskid, &iovector)) { | 256 | if (workqueue_pushchunked(taskid, &iovector)) { |
| 252 | free(iovector.iov_base); | 257 | free(iovector.iov_base); |
| 258 | deflateEnd(&strm); | ||
| 253 | mutex_bucket_unlock(bucket, 0); | 259 | mutex_bucket_unlock(bucket, 0); |
| 254 | return; | 260 | return; |
| 255 | } | 261 | } |
| @@ -274,6 +280,7 @@ static void fullscrape_make_gzip(int taskid, ot_tasktype mode) { | |||
| 274 | 280 | ||
| 275 | /* Parent thread died? */ | 281 | /* Parent thread died? */ |
| 276 | if (!g_opentracker_running) { | 282 | if (!g_opentracker_running) { |
| 283 | free(iovector.iov_base); | ||
| 277 | deflateEnd(&strm); | 284 | deflateEnd(&strm); |
| 278 | return; | 285 | return; |
| 279 | } | 286 | } |
| @@ -402,8 +409,11 @@ static void fullscrape_make_zstd(int taskid, ot_tasktype mode) { | |||
| 402 | mutex_bucket_unlock(bucket, 0); | 409 | mutex_bucket_unlock(bucket, 0); |
| 403 | 410 | ||
| 404 | /* Parent thread died? */ | 411 | /* Parent thread died? */ |
| 405 | if (!g_opentracker_running) | 412 | if (!g_opentracker_running) { |
| 413 | free(iovector.iov_base); | ||
| 414 | ZSTD_freeCCtx(zstream); | ||
| 406 | return; | 415 | return; |
| 416 | } | ||
| 407 | } | 417 | } |
| 408 | 418 | ||
| 409 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) { | 419 | if ((mode & TASK_TASK_MASK) == TASK_FULLSCRAPE) { |
