adding ignored manifest list to let us ignore repeated offerings

of broken manifests without wasting effort.
This commit is contained in:
gardners 2012-05-22 14:15:35 +09:30
parent d2c811b4b4
commit 8e9396419c
5 changed files with 95 additions and 7 deletions

View File

@ -376,6 +376,10 @@ long long rhizome_voice_timeout=0;
int rhizome_saw_voice_traffic()
{
/* We are in "voice mode" for a second after sending a voice frame */
rhizome_voice_timeout=overlay_gettime_ms()+1000;
if (rhizome_voice_timeout<overlay_gettime_ms()) {
WHY("Suppressing Rhizome due to voice traffic");
rhizome_voice_timeout=overlay_gettime_ms()+1000;
}
return 0;
}

View File

@ -249,3 +249,7 @@ int rhizome_bk_xor(const char *author,
unsigned char bkin[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES],
unsigned char bkout[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES]);
int rhizome_extract_privatekey(rhizome_manifest *m,const char *authorHex);
int rhizome_queue_ignore_manifest(rhizome_manifest *m,
struct sockaddr_in *peerip,int timeout);
int rhizome_ignore_manifest_check(rhizome_manifest *m,
struct sockaddr_in *peerip);

View File

@ -226,6 +226,79 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
}
typedef struct ignored_manifest {
unsigned char bid[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
struct sockaddr_in peer;
long long timeout;
} ignored_manifest;
#define IGNORED_BIN_SIZE 8
#define IGNORED_BIN_COUNT 64
#define IGNORED_BIN_BITS 6
typedef struct ignored_manifest_bin {
int bins_used;
ignored_manifest m[IGNORED_BIN_SIZE];
} ignored_manifest_bin;
typedef struct ignored_manifest_cache {
ignored_manifest_bin bins[IGNORED_BIN_COUNT];
} ignored_manifest_cache;
/* used uninitialised, since the probability of
a collision is exceedingly remote */
ignored_manifest_cache ignored;
int rhizome_ignore_manifest_check(rhizome_manifest *m,
struct sockaddr_in *peerip)
{
int i;
int bin = m->cryptoSignPublic[0]>>(8-IGNORED_BIN_BITS);
int slot;
for(slot=0;slot<IGNORED_BIN_SIZE;i++)
{
if (!memcmp(ignored.bins[bin].m[slot].bid,
m->cryptoSignPublic,
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES))
{
if (ignored.bins[bin].m[slot].timeout>overlay_gettime_ms())
return 1;
else
return 0;
}
}
return 0;
}
int rhizome_queue_ignore_manifest(rhizome_manifest *m,
struct sockaddr_in *peerip,int timeout)
{
/* The supplied manifest from a given IP has errors, so remember
that it isn't worth considering */
int i;
int bin = m->cryptoSignPublic[0]>>(8-IGNORED_BIN_BITS);
int slot;
for(slot=0;slot<IGNORED_BIN_SIZE;i++)
{
if (!memcmp(ignored.bins[bin].m[slot].bid,
m->cryptoSignPublic,
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES))
break;
}
if (slot>=IGNORED_BIN_SIZE) slot=random()%IGNORED_BIN_SIZE;
bcopy(&m->cryptoSignPublic[0],
&ignored.bins[bin].m[slot].bid[0],
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
/* ignore for a while */
ignored.bins[bin].m[slot].timeout=overlay_gettime_ms()+timeout;
bcopy(peerip,
&ignored.bins[bin].m[slot].peer,
sizeof(struct sockaddr_in));
return 0;
}
int rhizome_queue_manifest_import(rhizome_manifest *m,
struct sockaddr_in *peerip)
{
@ -469,7 +542,7 @@ int rhizome_fetch_poll()
{
int rn;
if (!rhizome_poll_fetchP) return 0;
if (debug&DEBUG_RHIZOME) WHYF("Checking %d active fetch requests",
if (0&&debug&DEBUG_RHIZOME) WHYF("Checking %d active fetch requests",
rhizome_file_fetch_queue_count);
for(rn=0;rn<rhizome_file_fetch_queue_count;rn++)
{

View File

@ -150,8 +150,8 @@ int rhizome_server_poll()
/* Process the existing requests.
XXX - should use poll or select here */
if (debug&DEBUG_RHIZOME) WHYF("Checking %d active connections",
rhizome_server_live_request_count);
if (0&&debug&DEBUG_RHIZOME) WHYF("Checking %d active connections",
rhizome_server_live_request_count);
for(rn=0;rn<rhizome_server_live_request_count;rn++)
{
rhizome_http_request *r=rhizome_live_http_requests[rn];

View File

@ -315,7 +315,6 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
int manifest_length;
rhizome_manifest *m=NULL;
if (ad_frame_type==1)
{
/* Extract whole manifests */
@ -342,7 +341,11 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
m=rhizome_read_manifest_file((char *)&f->payload->bytes[ofs],
manifest_length,RHIZOME_DONTVERIFY);
int importManifest=0;
if (m&&(!m->errors))
if (rhizome_ignore_manifest_check(m,(struct sockaddr_in *)f->recvaddr))
{
/* Ignoring manifest that has caused us problems recently */
}
else if (m&&(!m->errors))
{
/* Manifest is okay, so see if it is worth storing */
if (rhizome_manifest_version_cache_lookup(m)) {
@ -368,9 +371,12 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
else
{
if (debug&DEBUG_RHIZOME) WHY("Unverified manifest has errors - so not processing any further.");
/* Don't waste any time on this manifest in future attempts for at least
a minute. */
rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000);
}
if (m) rhizome_manifest_free(m);
m=NULL;
m=NULL;
if (importManifest) {
/* Okay, so the manifest looks like it is potentially interesting to us,
@ -380,6 +386,7 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
manifest_length,RHIZOME_VERIFY);
if (m->errors) {
if (debug&DEBUG_RHIZOME) WHYF("Verifying manifest %s revealed errors -- not storing.",manifest_id);
rhizome_queue_ignore_manifest(m,(struct sockaddr_in*)f->recvaddr,60000);
rhizome_manifest_free(m);
} else {
if (debug&DEBUG_RHIZOME) WHYF("Verifying manifest %s revealed no errors -- will try to store.",manifest_id);