Simple refactoring

This commit is contained in:
Jeremy Lakeman 2012-08-12 16:01:34 +09:30
parent 90cbf8df7e
commit 30d5ed2b6d
3 changed files with 58 additions and 56 deletions

View File

@ -177,6 +177,38 @@ schedule(&_sched_##X); }
return 0;
}
// a frame destined for one of our local addresses, or broadcast, has arrived. Process it.
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, overlay_frame *f){
int id = (interface - overlay_interfaces);
switch(f->type)
{
// route control frames
case OF_TYPE_SELFANNOUNCE:
overlay_route_saw_selfannounce(f,now);
break;
case OF_TYPE_SELFANNOUNCE_ACK:
overlay_route_saw_selfannounce_ack(f,now);
break;
case OF_TYPE_NODEANNOUNCE:
overlay_route_saw_advertisements(id,f,now);
break;
// data frames
case OF_TYPE_RHIZOME_ADVERT:
overlay_rhizome_saw_advertisements(id,f,now);
break;
case OF_TYPE_DATA:
case OF_TYPE_DATA_VOICE:
overlay_saw_mdp_containing_frame(f,now);
break;
default:
DEBUGF("Unsupported f->type=0x%x",f->type);
return WHY("Support for that f->type not yet implemented");
break;
}
return 0;
}
int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f)
{
IN();
@ -270,37 +302,7 @@ int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f)
// process payloads with broadcast or our sid as destination
if (ultimatelyForMe){
int id = (interface - overlay_interfaces);
switch(f->type)
{
case OF_TYPE_SELFANNOUNCE:
overlay_route_saw_selfannounce(f,now);
break;
case OF_TYPE_SELFANNOUNCE_ACK:
overlay_route_saw_selfannounce_ack(f,now);
break;
case OF_TYPE_NODEANNOUNCE:
overlay_route_saw_advertisements(id,f,now);
break;
case OF_TYPE_RHIZOME_ADVERT:
overlay_rhizome_saw_advertisements(id,f,now);
break;
case OF_TYPE_DATA:
case OF_TYPE_DATA_VOICE:
if (0) {
DEBUG("saw mdp containing frame");
DEBUGF(" src = %s\n", alloca_tohex_sid(f->source));
DEBUGF(" nxt = %s\n", alloca_tohex_sid(f->nexthop));
DEBUGF(" dst = %s\n", alloca_tohex_sid(f->destination));
dump("payload", f->payload->bytes, f->payload->length);
}
overlay_saw_mdp_containing_frame(f,now);
break;
default:
DEBUGF("Unsupported f->type=0x%x",f->type);
RETURN(WHY("Support for that f->type not yet implemented"));
break;
}
process_incoming_frame(now, interface, f);
}
RETURN(0);

View File

@ -119,6 +119,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
typedef struct overlay_address_table {
unsigned char epoch;
char sids[256][SID_SIZE];
/* 0x00 = not set, which thus limits us to using only 255 (0x01-0xff) of the indexes for
storing addresses.
By spending an extra 256 bytes we reduce, but not eliminate the problem of collisions.
Will think about a complete solution later.
*/
unsigned char byfirstbyte[256][2];
/* next free entry in sid[] */
unsigned char next_free;
} overlay_address_table;
typedef struct overlay_address_cache {
int size;
int shift; /* Used to calculat lookup function, which is (b[0].b[1].b[2]>>shift) */
sid *sids; /* one entry per bucket, to keep things simple. */
/* XXX Should have a means of changing the hash function so that naughty people can't try
to force our cache to flush with duplicate addresses?
But we must use only the first 24 bits of the address due to abbreviation policies,
so our options are limited.
For now the hash will be the first k bits.
*/
} overlay_address_cache;
overlay_address_table *abbrs=NULL;
overlay_address_cache *cache=NULL;

View File

@ -285,35 +285,10 @@ void keyring_identity_extract(const keyring_identity *id, const unsigned char **
extern int sock;
typedef struct overlay_address_table {
unsigned char epoch;
char sids[256][SID_SIZE];
/* 0x00 = not set, which thus limits us to using only 255 (0x01-0xff) of the indexes for
storing addresses.
By spending an extra 256 bytes we reduce, but not eliminate the problem of collisions.
Will think about a complete solution later.
*/
unsigned char byfirstbyte[256][2];
/* next free entry in sid[] */
unsigned char next_free;
} overlay_address_table;
typedef struct sid {
unsigned char b[SID_SIZE];
} sid;
typedef struct overlay_address_cache {
int size;
int shift; /* Used to calculat lookup function, which is (b[0].b[1].b[2]>>shift) */
sid *sids; /* one entry per bucket, to keep things simple. */
/* XXX Should have a means of changing the hash function so that naughty people can't try
to force our cache to flush with duplicate addresses?
But we must use only the first 24 bits of the address due to abbreviation policies,
so our options are limited.
For now the hash will be the first k bits.
*/
} overlay_address_cache;
extern sid overlay_abbreviate_current_sender;
typedef struct overlay_frame {