Rewind announcements on sql failures

This commit is contained in:
Jeremy Lakeman 2012-12-06 12:33:44 +10:30
parent ce48ca97b0
commit 7e59df86fe

View File

@ -157,23 +157,8 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
if (slots<1) { RETURN(WHY("No room for node advertisements")); } if (slots<1) { RETURN(WHY("No room for node advertisements")); }
if (overlay_frame_build_header(context, e,
0, OF_TYPE_RHIZOME_ADVERT, 0, 1,
NULL, NULL,
NULL, my_subscriber))
return -1;
/* Randomly choose whether to advertise manifests or BARs first. */ /* Randomly choose whether to advertise manifests or BARs first. */
int skipmanifests=random()&1; int skipmanifests=random()&1;
/* Version of rhizome advert block (1 byte):
1 = manifests then BARs,
2 = BARs only,
3 = HTTP port then manifests then BARs,
4 = HTTP port then BARs only
*/
ob_append_byte(e,3+skipmanifests);
/* Rhizome HTTP server port number (2 bytes) */
ob_append_ui16(e, rhizome_http_server_port);
/* XXX Should add priority bundles here. /* XXX Should add priority bundles here.
XXX Should prioritise bundles for subscribed groups, Serval-authorised files XXX Should prioritise bundles for subscribed groups, Serval-authorised files
@ -211,6 +196,32 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
sqlite3_stmt *statement=NULL; sqlite3_stmt *statement=NULL;
sqlite3_blob *blob=NULL; sqlite3_blob *blob=NULL;
ob_checkpoint(e);
if (overlay_frame_build_header(context, e,
0, OF_TYPE_RHIZOME_ADVERT, 0, 1,
NULL, NULL,
NULL, my_subscriber)){
ob_rewind(e);
return -1;
}
/* Version of rhizome advert block (1 byte):
1 = manifests then BARs,
2 = BARs only,
3 = HTTP port then manifests then BARs,
4 = HTTP port then BARs only
*/
if (ob_append_byte(e,3+skipmanifests)){
ob_rewind(e);
return -1;
}
/* Rhizome HTTP server port number (2 bytes) */
if (ob_append_ui16(e, rhizome_http_server_port)){
ob_rewind(e);
return -1;
}
for(pass=skipmanifests;pass<2;pass++) { for(pass=skipmanifests;pass<2;pass++) {
ob_checkpoint(e); ob_checkpoint(e);
switch(pass) { switch(pass) {
@ -223,8 +234,10 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
} }
if (!statement) { if (!statement) {
sqlite_set_debugmask(oldmask); sqlite_set_debugmask(oldmask);
RETURN(WHY("Could not prepare sql statement for fetching BARs for advertisement")); WHY("Could not prepare sql statement for fetching BARs for advertisement");
goto stopStuffing;
} }
while( sqlite_step_retry(&retry, statement) == SQLITE_ROW while( sqlite_step_retry(&retry, statement) == SQLITE_ROW
&& e->position+RHIZOME_BAR_BYTES<=e->sizeLimit && e->position+RHIZOME_BAR_BYTES<=e->sizeLimit
) { ) {