mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
push manifest verification to as late as possible to avoid
unwarranted 400ms CPU hits for every manifest seen.
This commit is contained in:
parent
e542b41746
commit
aab400164f
@ -42,6 +42,7 @@ int rhizome_manifest_verify(rhizome_manifest *m)
|
||||
}
|
||||
|
||||
if (m->sig_count==0) {
|
||||
WHYF("Manifest has zero valid signatures");
|
||||
m->errors++;
|
||||
}
|
||||
|
||||
|
@ -379,9 +379,11 @@ int rhizome_position_candidate(int position)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Verifies manifests as late as possible to avoid wasting time. */
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
|
||||
struct sockaddr_in *peerip)
|
||||
{
|
||||
IN();
|
||||
/* must free manifest when done with it */
|
||||
char *id=rhizome_manifest_get(m,"id",NULL,0);
|
||||
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.");
|
||||
}
|
||||
rhizome_manifest_free(m);
|
||||
return -1;
|
||||
RETURN(-1);
|
||||
} else {
|
||||
if (1||debug&DEBUG_RHIZOMESYNC) {
|
||||
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 */
|
||||
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,
|
||||
so don't list this one */
|
||||
rhizome_manifest_free(m);
|
||||
return 0;
|
||||
RETURN(0);
|
||||
} else {
|
||||
/* 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);
|
||||
candidates[i].manifest=m;
|
||||
/* update position in list */
|
||||
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) {
|
||||
/* our list is already full of higher-priority items */
|
||||
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) {
|
||||
/* release manifest structure for whoever we are bumping from the list */
|
||||
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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
RETURN(0);
|
||||
}
|
||||
|
||||
void rhizome_enqueue_suggestions()
|
||||
|
@ -427,10 +427,12 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
|
||||
WHY("Error importing manifest body");
|
||||
rhizome_manifest_free(m);
|
||||
m = NULL;
|
||||
} else if (rhizome_manifest_verify(m)) {
|
||||
WHY("Error verifying manifest body when importing");
|
||||
rhizome_manifest_free(m);
|
||||
m = NULL;
|
||||
/* PGS @20120626 - Used to verify manifest here, which is before
|
||||
checking if we already have the bundle or newer. Trouble is
|
||||
that signature verification is VERY expensive (~400ms on the ideos
|
||||
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) {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user