Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 432 lines (385 sloc) 15.053 kB
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
1 /*
2 Serval Distributed Numbering Architecture (DNA)
3 Copyright (C) 2010 Paul Gardner-Stephen
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
1eb4c34 @gardners Renamed mphlr.h to serval.h
gardners authored
20 #include "serval.h"
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
21 #include "rhizome.h"
22 #include <stdlib.h>
23
24 int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar)
25 {
26 /* BAR = Bundle Advertisement Record.
27 Basically a 32byte precis of a given manifest, that includes version, time-to-live
28 and geographic bounding box information that is used to help manage flooding of
29 bundles.
30
31 64 bits - manifest ID prefix.
32 56 bits - low 56 bits of version number.
33 8 bits - TTL of bundle in hops.
34 64 bits - length of associated file.
35 16 bits - min latitude (-90 - +90).
36 16 bits - min longitude (-180 - +180).
37 16 bits - max latitude (-90 - +90).
38 16 bits - max longitude (-180 - +180).
39 */
40
41 if (!m) return WHY("null manifest passed in");
42
43 int i;
44
45 /* Manifest prefix */
46 for(i=0;i<8;i++) bar[i]=m->cryptoSignPublic[i];
47 /* Version */
48 for(i=0;i<7;i++) bar[8+6-i]=(m->version>>(8*i))&0xff;
49 /* TTL */
50 if (m->ttl>0) bar[15]=m->ttl-1; else bar[15]=0;
51 /* file length */
52 for(i=0;i<8;i++) bar[16+7-i]=(m->fileLength>>(8*i))&0xff;
53 /* geo bounding box */
54 double minLat=rhizome_manifest_get_double(m,"min_lat",-90);
55 if (minLat<-90) minLat=-90; if (minLat>90) minLat=90;
56 double minLong=rhizome_manifest_get_double(m,"min_long",-180);
57 if (minLong<-180) minLong=-180; if (minLong>180) minLong=180;
58 double maxLat=rhizome_manifest_get_double(m,"max_lat",+90);
59 if (maxLat<-90) maxLat=-90; if (maxLat>90) maxLat=90;
60 double maxLong=rhizome_manifest_get_double(m,"max_long",+180);
61 if (maxLong<-180) maxLong=-180; if (maxLong>180) maxLong=180;
62
63 unsigned short v;
64 v=(minLat+90)*(65535/180); bar[24]=(v>>8)&0xff; bar[25]=(v>>0)&0xff;
65 v=(minLong+180)*(65535/360); bar[26]=(v>>8)&0xff; bar[27]=(v>>0)&0xff;
66 v=(maxLat+90)*(65535/180); bar[28]=(v>>8)&0xff; bar[29]=(v>>0)&0xff;
67 v=(maxLong+180)*(65535/360); bar[30]=(v>>8)&0xff; bar[31]=(v>>0)&0xff;
68
69 return 0;
70 }
71
72 int bundles_available=-1;
73 int bundle_offset[2]={0,0};
74 int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
75 {
29bb86d @gardners first cut at supressing rhizome activity during calls.
gardners authored
76 int voice_mode=0;
77
78 /* behave differently during voice mode.
79 Basically don't encourage people to grab stuff from us, but keep
80 just enough activity going so that it is possible to send a (small)
81 message/file during a call.
82
83 XXX Eventually only advertise small/recently changed files during voice calls.
84 We need to change manifest table to include payload length to make our life
85 easy here (also would let us order advertisements by size of payload).
86 For now, we will just advertised only occassionally.
87 */
88 long long now=overlay_gettime_ms();
89 if (now<rhizome_voice_timeout) voice_mode=1;
90 if (voice_mode) if (random()&3) return 0;
91
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
92 int pass;
93 int bytes=e->sizeLimit-e->length;
94 int overhead=1+8+1+3+1+1+1; /* maximum overhead */
95 int slots=(bytes-overhead)/RHIZOME_BAR_BYTES;
96 if (slots>30) slots=30;
97 int slots_used=0;
98 int bytes_used=0;
99 int bytes_available=bytes-overhead-1 /* one byte held for expanding RFS */;
100 int bundles_advertised=0;
101
102 if (slots<1) return WHY("No room for node advertisements");
103
104 if (!rhizome_db) return WHY("Rhizome not enabled");
105
106 if (ob_append_byte(e,OF_TYPE_RHIZOME_ADVERT))
107 return WHY("could not add rhizome bundle advertisement header");
108 ob_append_byte(e,1); /* TTL */
109 int rfs_offset=e->length; /* remember where the RFS byte gets stored
110 so that we can patch it later */
111 ob_append_byte(e,1+8+1+1+1+RHIZOME_BAR_BYTES*slots_used/* RFS */);
112
113 /* Stuff in dummy address fields */
114 ob_append_byte(e,OA_CODE_BROADCAST);
115 { int i; for(i=0;i<8;i++) ob_append_byte(e,random()&0xff); } /* BPI for broadcast */
116 ob_append_byte(e,OA_CODE_PREVIOUS);
117 ob_append_byte(e,OA_CODE_SELF);
118
119 /* Randomly choose whether to advertise manifests or BARs first. */
120 int skipmanifests=random()&1;
121 /* Version of rhizome advert block:
122 1 = manifests then BARs,
123 2 = BARs only */
124 ob_append_byte(e,1+skipmanifests);
125
126 /* XXX Should add priority bundles here.
127 XXX Should prioritise bundles for subscribed groups, Serval-authorised files
128 etc over common bundles.
129 XXX Should wait a while after going through bundle list so that we don't waste
130 CPU on db queries if there are not many bundles. Actually, we probably just
131 shouldn't be sending bundles blindly on every tick.
132 XXX How do we indicate group membership with BARs? Or do groups actively poll?
720ab89 @gardners Debugging fiddles and fixed bug where only the first few manifests
gardners authored
133
134 XXX XXX XXX We should cache database results so that we don't waste all our time
135 and energy asking the database much the same questions possibly many times per
136 second.
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
137 */
138
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
139 if (debug&DEBUG_RHIZOME) {
140 #warning WHY("Group handling not completely thought out here yet.");
141 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
142
143 /* Get number of bundles available if required */
144 bundles_available=sqlite_exec_int64("SELECT COUNT(BAR) FROM MANIFESTS;");
145 if (bundles_available==-1||(bundle_offset[0]>=bundles_available))
146 bundle_offset[0]=0;
147 if (bundles_available==-1||(bundle_offset[1]>=bundles_available))
148 bundle_offset[1]=0;
6759a26 @gardners Cleaned out some debugging output after tracking down and fixing
gardners authored
149 if(0)
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
150 WHYF("%d bundles in database (%d %d), slots=%d.",bundles_available,
70497df @gardners More work on MDP. Removed some debug fluff.
gardners authored
151 bundle_offset[0],bundle_offset[1],slots);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
152
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
153 sqlite3_stmt *statement=NULL;
154 sqlite3_blob *blob=NULL;
155
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
156 for(pass=skipmanifests;pass<2;pass++)
157 {
158 char query[1024];
159 switch(pass) {
160 case 0: /* Full manifests */
161 snprintf(query,1024,"SELECT MANIFEST,ROWID FROM MANIFESTS LIMIT %d,%d",
162 bundle_offset[pass],slots);
163 break;
164 case 1: /* BARs */
165 snprintf(query,1024,"SELECT BAR,ROWID FROM MANIFESTS LIMIT %d,%d",
166 bundle_offset[pass],slots);
167 break;
6a83f24 @gardners cleaned up some debug output, among other things.
gardners authored
168 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
169
170 switch (sqlite3_prepare_v2(rhizome_db,query,-1,&statement,NULL))
171 {
172 case SQLITE_OK: case SQLITE_DONE: case SQLITE_ROW:
173 break;
174 default:
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
175 sqlite3_finalize(statement); statement=NULL;
176 sqlite3_close(rhizome_db); rhizome_db=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
177 WHY(query);
178 WHY(sqlite3_errmsg(rhizome_db));
179 return WHY("Could not prepare sql statement for fetching BARs for advertisement.");
180 }
181 while((bytes_used<bytes_available)&&(sqlite3_step(statement)==SQLITE_ROW)&&
182 (e->length+RHIZOME_BAR_BYTES<=e->sizeLimit))
183 {
184 int column_type=sqlite3_column_type(statement, 0);
185 switch(column_type) {
186 case SQLITE_BLOB:
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
187 if (blob) sqlite3_blob_close(blob); blob=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
188 if (sqlite3_blob_open(rhizome_db,"main","manifests",
189 pass?"bar":"manifest",
190 sqlite3_column_int64(statement,1) /* rowid */,
191 0 /* read only */,&blob)!=SQLITE_OK)
192 {
193 WHY("Couldn't open blob");
194 continue;
195 }
196 int blob_bytes=sqlite3_blob_bytes(blob);
197 if (pass&&(blob_bytes!=RHIZOME_BAR_BYTES)) {
198 if (debug&DEBUG_RHIZOME)
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
199 WHY("Found a BAR that is the wrong size - ignoring");
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
200 sqlite3_blob_close(blob); blob=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
201 continue;
202 }
203
204 /* Only include manifests that are <=1KB inline.
205 Longer ones are only advertised by BAR */
720ab89 @gardners Debugging fiddles and fixed bug where only the first few manifests
gardners authored
206 if (blob_bytes>1024) {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
207 WHY("blob>1k - ignoring");
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
208 sqlite3_blob_close(blob); blob=NULL;
720ab89 @gardners Debugging fiddles and fixed bug where only the first few manifests
gardners authored
209 continue;
210 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
211
bd99913 @gardners Added note about inscrutable frame construction.
gardners authored
212 /* XXX This whole section is too hard to follow how the frame gets
213 built up. In particular the calculations for space required etc
214 are quite opaque... and I wrote it! */
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
215 int overhead=0;
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
216 int frameFull=0;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
217 if (!pass) overhead=2;
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
218 if (0) WHYF("e=%p, e->bytes=%p,e->length=%d, e->allocSize=%d",
bd99913 @gardners Added note about inscrutable frame construction.
gardners authored
219 e,e->bytes,e->length,e->allocSize);
13d1d30 @gardners Various fixes to track down memory handling bugs.
gardners authored
220
2b42f77 @gardners Fixed some bounds checking, and added some fairly rigorous memory
gardners authored
221 if (ob_makespace(e,overhead+2+blob_bytes)) {
e319b14 @gardners cleaned up some debugging.
gardners authored
222 if (0&&debug&DEBUG_RHIZOME)
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
223 WHYF("Stopped cramming %s into Rhizome advertisement frame.",
e319b14 @gardners cleaned up some debugging.
gardners authored
224 pass?"BARs":"manifests");
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
225 frameFull=1;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
226 }
227 if (!pass) {
228 /* put manifest length field and manifest ID */
2b42f77 @gardners Fixed some bounds checking, and added some fairly rigorous memory
gardners authored
229 /* XXX why on earth is this being done this way, instead of
230 with ob_append_byte() ??? */
13d1d30 @gardners Various fixes to track down memory handling bugs.
gardners authored
231 ob_setbyte(e,e->length,(blob_bytes>>8)&0xff);
232 ob_setbyte(e,e->length+1,(blob_bytes>>0)&0xff);
3866352 @gardners further improvements to supressing broken manifest time wasting
gardners authored
233 if (0&&debug&DEBUG_RHIZOME)
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
234 WHYF("length bytes written at offset 0x%x",e->length);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
235 }
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
236 if (frameFull) {
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
237 sqlite3_blob_close(blob); blob=NULL;
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
238 goto stopStuffing;
239 }
2b42f77 @gardners Fixed some bounds checking, and added some fairly rigorous memory
gardners authored
240 if (e->length+overhead+blob_bytes>=e->allocSize) {
241 WHY("Reading blob will overflow overlay_buffer");
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
242 sqlite3_blob_close(blob); blob=NULL;
6759a26 @gardners Cleaned out some debugging output after tracking down and fixing
gardners authored
243 continue;
2b42f77 @gardners Fixed some bounds checking, and added some fairly rigorous memory
gardners authored
244 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
245 if (sqlite3_blob_read(blob,&e->bytes[e->length+overhead],blob_bytes,0)
246 !=SQLITE_OK) {
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
247 if (!pass) {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
248 if (0) {
249 WHY(" Manifest:");
250 int i;
251 for(i=0;i<blob_bytes;i++) WHYF(" %c",e->bytes[e->length+overhead+i]);
252 }
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
253 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
254 if (debug&DEBUG_RHIZOME) WHY("Couldn't read from blob");
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
255 sqlite3_blob_close(blob); blob=NULL;
1eb4c34 @gardners Renamed mphlr.h to serval.h
gardners authored
256 dump("buffer (225)",(unsigned char *)e,sizeof(*e));
257
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
258 continue;
259 }
76ef948 @gardners Added back rather vital line that was mistakenly removed during a deb…
gardners authored
260 e->length+=overhead+blob_bytes;
1eb4c34 @gardners Renamed mphlr.h to serval.h
gardners authored
261 if (e->length>e->allocSize) {
262 WHY("e->length > e->size");
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
263 sqlite3_blob_close(blob); blob=NULL;
1eb4c34 @gardners Renamed mphlr.h to serval.h
gardners authored
264 abort();
265 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
266 bytes_used+=overhead+blob_bytes;
267 bundles_advertised++;
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
268 bundle_offset[pass]=sqlite3_column_int64(statement,1);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
269
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
270 sqlite3_blob_close(blob); blob=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
271 }
272 }
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
273 stopStuffing:
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
274 if (blob) sqlite3_blob_close(blob); blob=NULL;
275 if (statement) sqlite3_finalize(statement); statement=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
276 if (!pass)
277 {
278 /* Mark end of whole manifests by writing 0xff, which is more than the MSB
279 of a manifest's length is allowed to be. */
280 ob_append_byte(e,0xff);
1b9f706 @gardners fixed bug in dispatch of rhizome advertisements.
gardners authored
281 bytes_used++;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
282 }
283 }
76663d1 @gardners fixed sqlite handle leaks when advertising rhizome manifests.
gardners authored
284
285 if (blob) sqlite3_blob_close(blob); blob=NULL;
286 if (statement) sqlite3_finalize(statement); statement=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
287
3866352 @gardners further improvements to supressing broken manifest time wasting
gardners authored
288 if (0&&debug&DEBUG_RHIZOME) WHYF("Appended %d rhizome advertisements to packet using %d bytes.",bundles_advertised,bytes_used);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
289 int rfs_value=1+8+1+1+1+bytes_used;
290 if (rfs_value<0xfa)
13d1d30 @gardners Various fixes to track down memory handling bugs.
gardners authored
291 ob_setbyte(e,rfs_offset,rfs_value);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
292 else
293 {
294 ob_makespace(e,1);
13d1d30 @gardners Various fixes to track down memory handling bugs.
gardners authored
295 ob_bcopy(e,rfs_offset,rfs_offset+1,
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
296 e->length-rfs_offset);
13d1d30 @gardners Various fixes to track down memory handling bugs.
gardners authored
297 ob_setbyte(e,rfs_offset,0xfa+(rfs_value-250)/256);
298 ob_setbyte(e,rfs_offset+1,(rfs_value-250)&0xff);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
299 e->length++;
300 }
76ef948 @gardners Added back rather vital line that was mistakenly removed during a deb…
gardners authored
301
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
302 return 0;
303 }
304
305 int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
306 {
307 if (!f) return -1;
6a83f24 @gardners cleaned up some debug output, among other things.
gardners authored
308 if (debug&DEBUG_RHIZOME) {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
309 WHYF("rhizome f->bytecount=%d",f->payload->length);
6a83f24 @gardners cleaned up some debug output, among other things.
gardners authored
310 // dump("payload",f->payload->bytes,f->payload->length);
f562a63 @gardners completed working around strbuf_* bugs so that rhizome works again.
gardners authored
311 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
312
313 int ofs=0;
314 int ad_frame_type=f->payload->bytes[ofs++];
315 int manifest_length;
316 rhizome_manifest *m=NULL;
317
318 if (ad_frame_type==1)
319 {
320 /* Extract whole manifests */
321 while(ofs<f->payload->length) {
60e4209 @quixotique Diagnose and fix rhizome MeshMS
quixotique authored
322 char manifest_id_buf[RHIZOME_MANIFEST_ID_STRLEN + 1];
323 char *manifest_id = NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
324 manifest_length=(f->payload->bytes[ofs]<<8)+f->payload->bytes[ofs+1];
325 if (manifest_length>=0xff00) {
326 ofs++;
327 break;
ce2afbe @gardners Various fixes and addition of memory corruption framework (not yet ac…
gardners authored
328 }
329 if (ofs+manifest_length>f->payload->length) {
330 WHY("Illegal manifest length field in rhizome advertisement frame.");
331 break;
332 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
333
334 ofs+=2;
335 if (manifest_length==0) continue;
336
337 /* Read manifest without verifying signatures (which would waste lots of
338 energy, everytime we see a manifest that we already have).
339 In fact, it would be better here to do a really rough and ready parser
340 to get the id and version fields out, and avoid the memory copies that
115cb94 @gardners included fix for suppressing bad behaviour due to signature-less mani…
gardners authored
341 otherwise happen.
342 But we do need to make sure that at least one signature is there.
343 */
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
344 m=rhizome_read_manifest_file((char *)&f->payload->bytes[ofs],
345 manifest_length,RHIZOME_DONTVERIFY);
115cb94 @gardners included fix for suppressing bad behaviour due to signature-less mani…
gardners authored
346 /* Crude signature presence test */
347 for(i=m->manifest_all_bytes-1;i>0;i++)
348 if (!m->manifestdata[i]) {
349 /* A null in the middle says we have a signature */
350 break;
351 }
352 if (!i) {
353 /* ignore the announcement, but don't ignore other people
354 offering the same manifest */
355 WHY("Ignoring manifest announcment with no signature");
356 rhizome_manifest_free(m);
357 return 0;
358 }
359 int importManifest=0;
8e93964 @gardners adding ignored manifest list to let us ignore repeated offerings
gardners authored
360 if (rhizome_ignore_manifest_check(m,(struct sockaddr_in *)f->recvaddr))
361 {
362 /* Ignoring manifest that has caused us problems recently */
a9be08b @gardners supress bad rhizome manifest messages.
gardners authored
363 if (0) WHYF("Ignoring manifest with errors: %s",
364 rhizome_manifest_get(m,"id",NULL,0));
8e93964 @gardners adding ignored manifest list to let us ignore repeated offerings
gardners authored
365 }
366 else if (m&&(!m->errors))
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
367 {
368 /* Manifest is okay, so see if it is worth storing */
423fb58 @gardners Bug fixes to rhizome manifest:version cache.
gardners authored
369 if (rhizome_manifest_version_cache_lookup(m)) {
370 /* We already have this version or newer */
371 if (debug&DEBUG_RHIZOMESYNC) {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
372 WHYF("manifest id=%s, version=%lld",
6a83f24 @gardners cleaned up some debug output, among other things.
gardners authored
373 rhizome_manifest_get(m,"id",NULL,0),
423fb58 @gardners Bug fixes to rhizome manifest:version cache.
gardners authored
374 rhizome_manifest_get_ll(m,"version"));
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
375 WHY("We already have that manifest or newer.");
423fb58 @gardners Bug fixes to rhizome manifest:version cache.
gardners authored
376 }
377 importManifest=0;
378 } else {
379 if (debug&DEBUG_RHIZOMESYNC) {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
380 WHYF("manifest id=%s, version=%lld is new to us.",
423fb58 @gardners Bug fixes to rhizome manifest:version cache.
gardners authored
381 rhizome_manifest_get(m,"id",NULL,0),
382 rhizome_manifest_get_ll(m,"version"));
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
383 }
423fb58 @gardners Bug fixes to rhizome manifest:version cache.
gardners authored
384 importManifest=1;
385 }
386
60e4209 @quixotique Diagnose and fix rhizome MeshMS
quixotique authored
387 manifest_id = rhizome_manifest_get(m, "id", manifest_id_buf, sizeof manifest_id_buf);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
388 }
389 else
390 {
c3350bb @gardners fix bug introduced in using snprintf instead of strbuf_*
gardners authored
391 if (debug&DEBUG_RHIZOME) WHY("Unverified manifest has errors - so not processing any further.");
8e93964 @gardners adding ignored manifest list to let us ignore repeated offerings
gardners authored
392 /* Don't waste any time on this manifest in future attempts for at least
393 a minute. */
394 rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
395 }
1349c04 @gardners fixed a null pointer dereference.
gardners authored
396 if (m) rhizome_manifest_free(m);
8e93964 @gardners adding ignored manifest list to let us ignore repeated offerings
gardners authored
397 m=NULL;
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
398
399 if (importManifest) {
400 /* Okay, so the manifest looks like it is potentially interesting to us,
401 i.e., we don't already have it or a later version of it.
402 Now reread the manifest, this time verifying signatures */
403 m=rhizome_read_manifest_file((char *)&f->payload->bytes[ofs],
404 manifest_length,RHIZOME_VERIFY);
405 if (m->errors) {
60e4209 @quixotique Diagnose and fix rhizome MeshMS
quixotique authored
406 if (debug&DEBUG_RHIZOME) WHYF("Verifying manifest %s revealed errors -- not storing.", manifest_id);
8e93964 @gardners adding ignored manifest list to let us ignore repeated offerings
gardners authored
407 rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000);
9296839 @gardners oops, missed a file on last commit.
gardners authored
408 rhizome_manifest_free(m);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
409 } else {
60e4209 @quixotique Diagnose and fix rhizome MeshMS
quixotique authored
410 if (debug&DEBUG_RHIZOME) WHYF("Verifying manifest %s revealed no errors -- will try to store.", manifest_id);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
411
41daec5 @gardners Fixed all zeroes manifestid problem.
gardners authored
412 /* Add manifest to import queue. We need to know originating IPv4 address
413 so that we can transfer by HTTP. */
e3387fb @gardners periodic sucking in from rhizome prioritised list now works.
gardners authored
414 if (0) WHY("Suggesting fetching of a bundle");
60e4209 @quixotique Diagnose and fix rhizome MeshMS
quixotique authored
415 rhizome_suggest_queue_manifest_import(m,(struct sockaddr_in *)f->recvaddr);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
416 }
417 }
9296839 @gardners oops, missed a file on last commit.
gardners authored
418 else
419 rhizome_manifest_free(m);
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
420
720ab89 @gardners Debugging fiddles and fixed bug where only the first few manifests
gardners authored
421 if (!manifest_length) {
422 WHY("Infinite loop in packet decoding");
423 break;
424 }
abb3021 @gardners Added refactored rhizome code in separate files.
gardners authored
425 ofs+=manifest_length;
426 }
427
428 }
429
430 return 0;
431 }
Something went wrong with that request. Please try again.