Send my full sid periodically for any outgoing payload header

This commit is contained in:
Jeremy Lakeman 2012-09-07 10:01:34 +09:30
parent 9e86bb476e
commit 3b55643b08
9 changed files with 75 additions and 43 deletions

View File

@ -1343,6 +1343,10 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
sid_sas_mappings[i].validP=0; sid_sas_mappings[i].validP=0;
sid_sas_mappings[i].last_request_time_in_ms = now; sid_sas_mappings[i].last_request_time_in_ms = now;
// always send our sid in full, it's likely this is a new peer
if (my_subscriber)
my_subscriber->send_full = 1;
/* request mapping (send request auth-crypted). */ /* request mapping (send request auth-crypted). */
overlay_mdp_frame mdp; overlay_mdp_frame mdp;
mdp.packetTypeAndFlags=MDP_TX; mdp.packetTypeAndFlags=MDP_TX;

View File

@ -125,22 +125,31 @@ struct subscriber *find_subscriber(const unsigned char *sid, int len, int create
if start is a valid pointer, the first entry returned will be after this subscriber if start is a valid pointer, the first entry returned will be after this subscriber
if the callback returns non-zero, the process will stop. if the callback returns non-zero, the process will stop.
*/ */
static int walk_tree(struct tree_node *node, int pos, struct subscriber *start, static int walk_tree(struct tree_node *node, int pos,
unsigned char *start, int start_len,
unsigned char *end, int end_len,
int(*callback)(struct subscriber *, void *), void *context){ int(*callback)(struct subscriber *, void *), void *context){
int i=0; int i=0, e=16;
if (start){ if (start && pos < start_len*2){
i=get_nibble(start->sid,pos); i=get_nibble(start,pos);
} }
for (;i<16;i++){ if (end && pos < end_len*2){
e=get_nibble(end,pos) +1;
}
for (;i<e;i++){
if (node->is_tree & (1<<i)){ if (node->is_tree & (1<<i)){
if (walk_tree(node->tree_nodes[i], pos+1, start, callback, context)) if (walk_tree(node->tree_nodes[i], pos+1, start, start_len, end, end_len, callback, context))
return 1;
}else if(node->subscribers[i] && node->subscribers[i] != start){
if (callback(node->subscribers[i], context))
return 1; return 1;
}else if(node->subscribers[i]){
if ((!start) || start_len<SID_SIZE || memcmp(node->subscribers[i]->sid, start, start_len)!=0)
if (callback(node->subscribers[i], context))
return 1;
} }
// stop comparing the start sid after looking at the first branch of the tree
start=NULL;
} }
return 0; return 0;
} }
@ -149,7 +158,7 @@ static int walk_tree(struct tree_node *node, int pos, struct subscriber *start,
walk the tree, starting at start, calling the supplied callback function walk the tree, starting at start, calling the supplied callback function
*/ */
void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context){ void enum_subscribers(struct subscriber *start, int(*callback)(struct subscriber *, void *), void *context){
walk_tree(&root, 0, start, callback, context); walk_tree(&root, 0, start->sid, SID_SIZE, NULL, 0, callback, context);
} }
// quick test to make sure the specified route is valid. // quick test to make sure the specified route is valid.
@ -267,6 +276,32 @@ int overlay_address_append(struct overlay_buffer *b, struct subscriber *subscrib
return 0; return 0;
} }
int overlay_address_append_self(overlay_interface *interface, struct overlay_buffer *b){
static int ticks_per_full_address = -1;
if (ticks_per_full_address == -1) {
ticks_per_full_address = confValueGetInt64Range("mdp.selfannounce.ticks_per_full_address", 4LL, 1LL, 1000000LL);
INFOF("ticks_per_full_address = %d", ticks_per_full_address);
}
if (!my_subscriber)
return WHY("I don't know who I am yet");
if (++interface->ticks_since_sent_full_address < ticks_per_full_address){
interface->ticks_since_sent_full_address = 0;
my_subscriber->send_full=1;
}
if (overlay_address_append(b, my_subscriber))
return WHY("Could not append my sid");
return 0;
}
static int mark_full(struct subscriber *subscriber, void *context){
subscriber->send_full=1;
return 0;
}
int find_subscr_buffer(struct overlay_buffer *b, int len, int create, struct subscriber **subscriber){ int find_subscr_buffer(struct overlay_buffer *b, int len, int create, struct subscriber **subscriber){
unsigned char *id = ob_get_bytes_ptr(b, len); unsigned char *id = ob_get_bytes_ptr(b, len);
if (!id) if (!id)
@ -278,6 +313,9 @@ int find_subscr_buffer(struct overlay_buffer *b, int len, int create, struct sub
if (!*subscriber){ if (!*subscriber){
INFOF("Abbreviation %s not found", alloca_tohex(id, len)); INFOF("Abbreviation %s not found", alloca_tohex(id, len));
// If the abbreviation is too short, mark any subscribers that match to send full SID's
walk_tree(&root, 0, id, len, id, len, mark_full, NULL);
// HACK, imperfect... better to send a sas key request // HACK, imperfect... better to send a sas key request
// always send my full sid when we fail to resolve an abbreviation // always send my full sid when we fail to resolve an abbreviation
// they may not know us either // they may not know us either

View File

@ -105,6 +105,7 @@ int overlay_broadcast_generate_address(struct broadcast *addr);
int overlay_broadcast_append(struct overlay_buffer *b, struct broadcast *broadcast); int overlay_broadcast_append(struct overlay_buffer *b, struct broadcast *broadcast);
int overlay_address_append(struct overlay_buffer *b, struct subscriber *subscriber); int overlay_address_append(struct overlay_buffer *b, struct subscriber *subscriber);
int overlay_address_append_self(overlay_interface *interface, struct overlay_buffer *b);
int overlay_address_parse(struct overlay_buffer *b, struct broadcast *broadcast, struct subscriber **subscriber); int overlay_address_parse(struct overlay_buffer *b, struct broadcast *broadcast, struct subscriber **subscriber);
void overlay_address_clear(void); void overlay_address_clear(void);
void overlay_address_set_sender(struct subscriber *subscriber); void overlay_address_set_sender(struct subscriber *subscriber);

View File

@ -86,7 +86,7 @@ int add_advertisement(struct subscriber *subscriber, void *context){
return 0; return 0;
} }
int overlay_route_add_advertisements(struct overlay_buffer *e) int overlay_route_add_advertisements(overlay_interface *interface, struct overlay_buffer *e)
{ {
/* Construct a route advertisement frame and append it to e. /* Construct a route advertisement frame and append it to e.
@ -133,7 +133,7 @@ int overlay_route_add_advertisements(struct overlay_buffer *e)
ob_append_byte(e,OA_CODE_PREVIOUS); ob_append_byte(e,OA_CODE_PREVIOUS);
overlay_address_append(e, my_subscriber); overlay_address_append_self(interface,e);
overlay_address_set_sender(my_subscriber); overlay_address_set_sender(my_subscriber);
// TODO high priority advertisements first.... // TODO high priority advertisements first....

View File

@ -400,6 +400,10 @@ overlay_interface_init_socket(int interface_index)
interface->state=INTERFACE_STATE_UP; interface->state=INTERFACE_STATE_UP;
INFOF("Interface %s addr %s, is up",interface->name, inet_ntoa(interface->broadcast_address.sin_addr)); INFOF("Interface %s addr %s, is up",interface->name, inet_ntoa(interface->broadcast_address.sin_addr));
// mark our sid to be sent in full
if (my_subscriber)
my_subscriber->send_full = 1;
return 0; return 0;
} }
@ -1059,7 +1063,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
frame->sendBroadcast?alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN):alloca_tohex_sid(next_hop->sid)); frame->sendBroadcast?alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN):alloca_tohex_sid(next_hop->sid));
} }
if (overlay_frame_append_payload(frame, next_hop, packet->buffer)) if (overlay_frame_append_payload(packet->interface, frame, next_hop, packet->buffer))
// payload was not queued // payload was not queued
goto skip; goto skip;
@ -1175,7 +1179,7 @@ overlay_tick_interface(int i, time_ms_t now) {
return WHY("tick failed"); return WHY("tick failed");
/* Add advertisements for ROUTES */ /* Add advertisements for ROUTES */
overlay_route_add_advertisements(packet.buffer); overlay_route_add_advertisements(packet.interface, packet.buffer);
/* Stuff more payloads from queues and send it */ /* Stuff more payloads from queues and send it */
overlay_fill_send_packet(&packet, now); overlay_fill_send_packet(&packet, now);

View File

@ -345,15 +345,6 @@ int overlay_add_selfannouncement(int interface,struct overlay_buffer *b)
if (ob_append_byte(b, OF_TYPE_SELFANNOUNCE)) if (ob_append_byte(b, OF_TYPE_SELFANNOUNCE))
return WHY("Could not add self-announcement header"); return WHY("Could not add self-announcement header");
static int ticks_per_full_address = -1;
if (ticks_per_full_address == -1) {
ticks_per_full_address = confValueGetInt64Range("mdp.selfannounce.ticks_per_full_address", 4LL, 1LL, 1000000LL);
INFOF("ticks_per_full_address = %d", ticks_per_full_address);
}
int send_prefix = ++overlay_interfaces[interface].ticks_since_sent_full_address < ticks_per_full_address;
if (!send_prefix)
overlay_interfaces[interface].ticks_since_sent_full_address = 0;
/* A TTL for this frame. /* A TTL for this frame.
XXX - BATMAN uses various TTLs, but I think that it may just be better to have all TTL=1, XXX - BATMAN uses various TTLs, but I think that it may just be better to have all TTL=1,
and have the onward nodes selectively choose which nodes to on-announce. If we prioritise and have the onward nodes selectively choose which nodes to on-announce. If we prioritise
@ -365,7 +356,7 @@ int overlay_add_selfannouncement(int interface,struct overlay_buffer *b)
/* Add space for Remaining Frame Size field. This will always be a single byte /* Add space for Remaining Frame Size field. This will always be a single byte
for self-announcments as they are always <256 bytes. */ for self-announcments as they are always <256 bytes. */
if (ob_append_rfs(b,1+8+1+(send_prefix?(1+7):SID_SIZE)+4+4+1)) if (ob_append_rfs(b,1+8+1+SID_SIZE+4+4+1))
return WHY("Could not add RFS for self-announcement frame"); return WHY("Could not add RFS for self-announcement frame");
/* Add next-hop address. Always link-local broadcast for self-announcements */ /* Add next-hop address. Always link-local broadcast for self-announcements */
@ -378,20 +369,9 @@ int overlay_add_selfannouncement(int interface,struct overlay_buffer *b)
if (ob_append_byte(b, OA_CODE_PREVIOUS)) if (ob_append_byte(b, OA_CODE_PREVIOUS))
return WHY("Could not add self-announcement header"); return WHY("Could not add self-announcement header");
/* Add our SID to the announcement as sender /* Add our SID to the announcement as sender */
We can likely get away with abbreviating our own address much of the time, since these if (overlay_address_append_self(&overlay_interfaces[interface], b))
frames will be sent on a regular basis. However, we can only abbreviate using a prefix, return -1;
not any of the fancier methods. Indeed, if we tried to use the standard abbreviation
functions they would notice that we are attaching an address which is ourself, and send
a uselessly short address. So instead we will use a simple scheme where we will send our
address in full an arbitrary 1 in 4 times.
*/
if (!send_prefix)
my_subscriber->send_full=1;
if (overlay_address_append(b, my_subscriber))
return WHY("Could not append SID to self-announcement");
overlay_address_set_sender(my_subscriber); overlay_address_set_sender(my_subscriber);

View File

@ -53,7 +53,7 @@ static int op_append_type(struct overlay_buffer *headers, struct overlay_frame *
} }
int overlay_frame_append_payload(struct overlay_frame *p, struct subscriber *next_hop, struct overlay_buffer *b) int overlay_frame_append_payload(overlay_interface *interface, struct overlay_frame *p, struct subscriber *next_hop, struct overlay_buffer *b)
{ {
/* Convert a payload (frame) structure into a series of bytes. /* Convert a payload (frame) structure into a series of bytes.
Assumes that any encryption etc has already been done. Assumes that any encryption etc has already been done.
@ -106,7 +106,12 @@ int overlay_frame_append_payload(struct overlay_frame *p, struct subscriber *nex
overlay_address_append(headers,p->destination); overlay_address_append(headers,p->destination);
else else
ob_append_byte(headers, OA_CODE_PREVIOUS); ob_append_byte(headers, OA_CODE_PREVIOUS);
overlay_address_append(headers,p->source);
if (p->source==my_subscriber){
overlay_address_append_self(interface, headers);
}else{
overlay_address_append(headers,p->source);
}
int addrs_len=headers->position-addrs_start; int addrs_len=headers->position-addrs_start;
int actual_len=addrs_len+p->payload->position; int actual_len=addrs_len+p->payload->position;

View File

@ -117,7 +117,7 @@ int overlay_rhizome_add_advertisements(int interface_number, struct overlay_buff
overlay_broadcast_generate_address(&broadcast_id); overlay_broadcast_generate_address(&broadcast_id);
overlay_broadcast_append(e, &broadcast_id); overlay_broadcast_append(e, &broadcast_id);
ob_append_byte(e, OA_CODE_PREVIOUS); ob_append_byte(e, OA_CODE_PREVIOUS);
overlay_address_append(e, my_subscriber); overlay_address_append_self(&overlay_interfaces[interface_number], e);
/* 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;

View File

@ -580,7 +580,7 @@ int overlay_rx_messages();
#define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __HERE__, (M), (P), (N)) #define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __HERE__, (M), (P), (N))
int overlay_add_selfannouncement(); int overlay_add_selfannouncement();
int overlay_frame_append_payload(struct overlay_frame *p, struct subscriber *next_hop, struct overlay_buffer *b); int overlay_frame_append_payload(overlay_interface *interface, struct overlay_frame *p, struct subscriber *next_hop, struct overlay_buffer *b);
int overlay_interface_args(const char *arg); int overlay_interface_args(const char *arg);
int overlay_sendto(struct sockaddr_in *recipientaddr,unsigned char *bytes,int len); int overlay_sendto(struct sockaddr_in *recipientaddr,unsigned char *bytes,int len);
int overlay_rhizome_add_advertisements(int interface_number,struct overlay_buffer *e); int overlay_rhizome_add_advertisements(int interface_number,struct overlay_buffer *e);
@ -636,7 +636,7 @@ int overlay_route_record_link( time_ms_t now,unsigned char *to,
unsigned char *via,int sender_interface, unsigned char *via,int sender_interface,
unsigned int s1,unsigned int s2,int score,int gateways_en_route); unsigned int s1,unsigned int s2,int score,int gateways_en_route);
int overlay_route_dump(); int overlay_route_dump();
int overlay_route_add_advertisements(struct overlay_buffer *e); int overlay_route_add_advertisements(overlay_interface *interface, struct overlay_buffer *e);
int ovleray_route_please_advertise(overlay_node *n); int ovleray_route_please_advertise(overlay_node *n);
int overlay_route_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now); int overlay_route_saw_advertisements(int i, struct overlay_frame *f, time_ms_t now);