push manifest verification to as late as possible to avoid

unwarranted 400ms CPU hits for every manifest seen.
This commit is contained in:
gardners 2012-06-26 16:54:40 +09:30
parent e542b41746
commit aab400164f
3 changed files with 27 additions and 10 deletions

View File

@ -42,6 +42,7 @@ int rhizome_manifest_verify(rhizome_manifest *m)
} }
if (m->sig_count==0) { if (m->sig_count==0) {
WHYF("Manifest has zero valid signatures");
m->errors++; m->errors++;
} }

View File

@ -379,9 +379,11 @@ int rhizome_position_candidate(int position)
return 0; return 0;
} }
/* Verifies manifests as late as possible to avoid wasting time. */
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
struct sockaddr_in *peerip) struct sockaddr_in *peerip)
{ {
IN();
/* must free manifest when done with it */ /* must free manifest when done with it */
char *id=rhizome_manifest_get(m,"id",NULL,0); char *id=rhizome_manifest_get(m,"id",NULL,0);
long long filesize=rhizome_manifest_get_ll(m,"filesize"); long long filesize=rhizome_manifest_get_ll(m,"filesize");
@ -401,7 +403,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
DEBUG("We already have that manifest or newer."); DEBUG("We already have that manifest or newer.");
} }
rhizome_manifest_free(m); rhizome_manifest_free(m);
return -1; RETURN(-1);
} else { } else {
if (1||debug&DEBUG_RHIZOMESYNC) { if (1||debug&DEBUG_RHIZOMESYNC) {
long long stored_version; long long stored_version;
@ -413,7 +415,6 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
} }
} }
/* work out where to put it in the list */ /* work out where to put it in the list */
for(i=0;i<candidate_count;i++) for(i=0;i<candidate_count;i++)
{ {
@ -432,14 +433,20 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
/* this version is older than the one in the list, /* this version is older than the one in the list,
so don't list this one */ so don't list this one */
rhizome_manifest_free(m); rhizome_manifest_free(m);
return 0; RETURN(0);
} else { } else {
/* replace listed version with this newer version */ /* replace listed version with this newer version */
if (rhizome_manifest_verify(m)) {
WHY("Error verifying manifest when considering queuing for import");
rhizome_manifest_free(m);
RETURN(-1);
}
rhizome_manifest_free(candidates[i].manifest); rhizome_manifest_free(candidates[i].manifest);
candidates[i].manifest=m; candidates[i].manifest=m;
/* update position in list */ /* update position in list */
rhizome_position_candidate(i); rhizome_position_candidate(i);
return 0; RETURN(0);
} }
} }
@ -454,8 +461,15 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
if (i>=MAX_CANDIDATES) { if (i>=MAX_CANDIDATES) {
/* our list is already full of higher-priority items */ /* our list is already full of higher-priority items */
rhizome_manifest_free(m); rhizome_manifest_free(m);
return -1; RETURN(-1);
} }
if (rhizome_manifest_verify(m)) {
WHY("Error verifying manifest when considering queuing for import");
rhizome_manifest_free(m);
RETURN(-1);
}
if (candidate_count==MAX_CANDIDATES) { if (candidate_count==MAX_CANDIDATES) {
/* release manifest structure for whoever we are bumping from the list */ /* release manifest structure for whoever we are bumping from the list */
rhizome_manifest_free(candidates[MAX_CANDIDATES-1].manifest); rhizome_manifest_free(candidates[MAX_CANDIDATES-1].manifest);
@ -484,7 +498,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
candidates[j].size,candidates[j].priority); candidates[j].size,candidates[j].priority);
} }
return 0; RETURN(0);
} }
void rhizome_enqueue_suggestions() void rhizome_enqueue_suggestions()

View File

@ -427,10 +427,12 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
WHY("Error importing manifest body"); WHY("Error importing manifest body");
rhizome_manifest_free(m); rhizome_manifest_free(m);
m = NULL; m = NULL;
} else if (rhizome_manifest_verify(m)) { /* PGS @20120626 - Used to verify manifest here, which is before
WHY("Error verifying manifest body when importing"); checking if we already have the bundle or newer. Trouble is
rhizome_manifest_free(m); that signature verification is VERY expensive (~400ms on the ideos
m = NULL; phones), so we now defer it to inside
rhizome_suggest_queue_manifest_import(), where it only gets called
after checking that it is worth adding to the queue. */
} else if (m->errors) { } else if (m->errors) {
if (debug&DEBUG_RHIZOME) DEBUGF("Verifying manifest %s* revealed errors -- not storing.", manifest_id_prefix); if (debug&DEBUG_RHIZOME) DEBUGF("Verifying manifest %s* revealed errors -- not storing.", manifest_id_prefix);
rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000); rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000);