summaryrefslogtreecommitdiff
path: root/ot_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_sync.c')
-rw-r--r--ot_sync.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/ot_sync.c b/ot_sync.c
index dc71ddd..f656bef 100644
--- a/ot_sync.c
+++ b/ot_sync.c
@@ -10,10 +10,8 @@
10#include <sys/types.h> 10#include <sys/types.h>
11#include <sys/uio.h> 11#include <sys/uio.h>
12 12
13/* Libowfat */
14#include "io.h"
15
16/* Opentracker */ 13/* Opentracker */
14#include "ot_fmt.h"
17#include "ot_iovec.h" 15#include "ot_iovec.h"
18#include "ot_mutex.h" 16#include "ot_mutex.h"
19#include "ot_scan.h" 17#include "ot_scan.h"
@@ -51,7 +49,7 @@ int add_changeset_to_tracker(uint8_t *data, size_t len) {
51 data += sizeof(ot_hash); 49 data += sizeof(ot_hash);
52 50
53 /* Scan string length indicator, strictly: bencode writes no leading zeros */ 51 /* Scan string length indicator, strictly: bencode writes no leading zeros */
54 data += (len = scan_udec_bencode((char *)data, &peer_count, (uint64_t)(end - data))); 52 data += (len = scan_uint_bencode((char *)data, &peer_count, (uint64_t)(end - data)));
55 53
56 /* If no long was scanned, it is not divisible by 8, it is not 54 /* If no long was scanned, it is not divisible by 8, it is not
57 followed by a colon or claims to need to much memory, we fail */ 55 followed by a colon or claims to need to much memory, we fail */
@@ -77,7 +75,7 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
77 /* Setup return vector... */ 75 /* Setup return vector... */
78 *iovec_entries = 0; 76 *iovec_entries = 0;
79 *iovector = NULL; 77 *iovector = NULL;
80 if (!(r = iovec_increase(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE))) 78 if (!(r = iovec_new_chunk(iovec_entries, iovector, OT_SYNC_CHUNK_SIZE)))
81 return; 79 return;
82 80
83 /* ... and pointer to end of current output buffer. 81 /* ... and pointer to end of current output buffer.
@@ -105,21 +103,17 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
105 103
106 /* Allocate a fresh output buffer at the end of our buffers list 104 /* Allocate a fresh output buffer at the end of our buffers list
107 release bucket and return, if that fails */ 105 release bucket and return, if that fails */
108 if (!(r = iovec_fix_increase_or_free(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE))) 106 if (!(r = iovec_next_chunk(iovec_entries, iovector, r, OT_SYNC_CHUNK_SIZE)))
109 return mutex_bucket_unlock(bucket); 107 return mutex_bucket_unlock(bucket);
110 108
111 /* Adjust new end of output buffer */ 109 /* Adjust new end of output buffer */
112 re = r + OT_SYNC_CHUNK_SIZE; 110 re = r + OT_SYNC_CHUNK_SIZE;
113 } 111 }
114 112
115 *r++ = '2'; 113 fmt_append(&r, re, "20:");
116 *r++ = '0'; 114 fmt_bytes(&r, re, hash, sizeof(ot_hash));
117 *r++ = ':'; 115 fmt_append(&r, re, "%zd:", byte_count);
118 memmove(r, hash, sizeof(ot_hash)); 116 fmt_bytes(&r, re, peer_list->changeset.data, byte_count);
119 r += sizeof(ot_hash);
120 r += sprintf(r, "%zd:", byte_count);
121 memmove(r, peer_list->changeset.data, byte_count);
122 r += byte_count;
123 } 117 }
124 118
125 /* All torrents done: release lock on currenct bucket */ 119 /* All torrents done: release lock on currenct bucket */
@@ -131,7 +125,7 @@ static void sync_make(size_t *iovec_entries, struct iovec **iovector) {
131 *r++ = 'e'; 125 *r++ = 'e';
132 126
133 /* Release unused memory in current output buffer */ 127 /* Release unused memory in current output buffer */
134 iovec_fixlast(iovec_entries, iovector, r); 128 iovec_trim_last(iovec_entries, iovector, r);
135} 129}
136 130
137/* This is the entry point into this worker thread 131/* This is the entry point into this worker thread