Mark resent packets so they can be dropped

This commit is contained in:
Jeremy Lakeman 2013-05-15 15:56:43 +09:30
parent e519633f7a
commit 5b4e4919cf
7 changed files with 47 additions and 12 deletions

View File

@ -98,6 +98,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define PAYLOAD_FLAG_LONG_PAYLOAD (1<<3)
#define PAYLOAD_FLAG_CIPHERED (1<<4)
#define PAYLOAD_FLAG_SIGNED (1<<5)
#define PAYLOAD_FLAG_DUPLICATE (1<<6)
/* Time-to-live is a 'uint5_t'.
*/

View File

@ -95,6 +95,7 @@ struct broadcast{
struct decode_context{
struct overlay_interface *interface;
int sender_interface;
struct sockaddr_in addr;
int invalid_addresses;
struct overlay_frame *please_explain;

View File

@ -223,7 +223,18 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
frame->type = ftype;
}else
frame->type=OF_TYPE_DATA;
if (flags & PAYLOAD_FLAG_DUPLICATE){
int previous_seq = ob_get(buffer);
if (previous_seq == -1)
RETURN(WHY("Unable to read previous seq"));
// TODO unicast
if (link_received_duplicate(context->sender, context->interface, context->sender_interface, previous_seq, 0)){
if (config.debug.overlayframes)
DEBUG("Don't process or forward duplicate payloads");
forward=process=0;
}
}
frame->modifiers=flags;
// if we can't understand one of the addresses, skip processing the payload
@ -246,11 +257,13 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
int packet_flags = ob_get(buffer);
int sender_interface = 0;
context->sender_interface = 0;
context->interface = interface;
int sender_seq = -1;
if (packet_flags & PACKET_INTERFACE)
sender_interface = ob_get(buffer);
context->sender_interface = ob_get(buffer);
if (packet_flags & PACKET_SEQ)
sender_seq = ob_get(buffer)&0xFF;
@ -288,7 +301,7 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
if (addr && (context->sender->last_probe==0 || now - context->sender->last_probe > interface->tick_ms*10))
overlay_send_probe(context->sender, *addr, interface, OQ_MESH_MANAGEMENT);
link_received_packet(context->sender, interface, sender_interface, sender_seq, packet_flags & PACKET_UNICAST);
link_received_packet(context->sender, interface, context->sender_interface, sender_seq, packet_flags & PACKET_UNICAST);
}
if (addr){

View File

@ -23,8 +23,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "overlay_buffer.h"
#include "overlay_packet.h"
int overlay_frame_build_header(struct decode_context *context, struct overlay_buffer *buff,
int queue, int type, int modifiers, int ttl,
static int overlay_frame_build_header(struct decode_context *context, struct overlay_buffer *buff,
int queue, int type, int modifiers, int ttl, int previous_seq,
struct broadcast *broadcast, struct subscriber *next_hop,
struct subscriber *destination, struct subscriber *source)
{
@ -46,6 +46,8 @@ int overlay_frame_build_header(struct decode_context *context, struct overlay_bu
if (type!=OF_TYPE_DATA)
flags |= PAYLOAD_FLAG_LEGACY_TYPE;
if (previous_seq>=0)
flags |= PAYLOAD_FLAG_DUPLICATE;
if (ob_append_byte(buff, flags)) return -1;
@ -71,6 +73,10 @@ int overlay_frame_build_header(struct decode_context *context, struct overlay_bu
if (flags & PAYLOAD_FLAG_LEGACY_TYPE){
if (ob_append_byte(buff, type)) return -1;
}
if (flags & PAYLOAD_FLAG_DUPLICATE){
if (ob_append_byte(buff, previous_seq)) return -1;
}
return 0;
}
@ -99,7 +105,7 @@ int overlay_frame_append_payload(struct decode_context *context, overlay_interfa
broadcast = &p->broadcast_id;
}
if (overlay_frame_build_header(context, b,
p->queue, p->type, p->modifiers, p->ttl,
p->queue, p->type, p->modifiers, p->ttl, p->sent_seq,
broadcast, p->next_hop,
p->destination, p->source))
goto cleanup;
@ -137,7 +143,7 @@ int single_packet_encapsulation(struct overlay_buffer *b, struct overlay_frame *
if (overlay_frame_build_header(&context, b,
frame->queue, frame->type,
frame->modifiers, frame->ttl,
frame->modifiers, frame->ttl, -1,
broadcast, frame->next_hop,
frame->destination, frame->source))
return -1;

View File

@ -744,6 +744,22 @@ int link_state_ack_soon(struct subscriber *subscriber){
return 0;
}
// our neighbour is sending a duplicate frame, did we see the original?
int link_received_duplicate(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int previous_seq, int unicast)
{
// TODO better handling of unicast routes
if (unicast)
return 0;
struct neighbour *neighbour = get_neighbour(subscriber, 1);
struct neighbour_link *link=get_neighbour_link(neighbour, interface, sender_interface, unicast);
int offset = (link->ack_sequence - 1 - previous_seq)&0xFF;
if (offset < 32)
return link->ack_mask & (1<<offset);
return 0;
}
// track stats for receiving packets from this neighbour
int link_received_packet(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int sender_seq, int unicast)
{

View File

@ -518,10 +518,6 @@ int overlay_packet_init_header(int encapsulation,
struct decode_context *context, struct overlay_buffer *buff,
struct subscriber *destination,
char unicast, char interface, int seq);
int overlay_frame_build_header(struct decode_context *context, struct overlay_buffer *buff,
int queue, int type, int modifiers, int ttl,
struct broadcast *broadcast, struct subscriber *next_hop,
struct subscriber *destination, struct subscriber *source);
int overlay_interface_args(const char *arg);
void overlay_rhizome_advertise(struct sched_ent *alarm);
int overlay_add_local_identity(unsigned char *s);
@ -829,6 +825,7 @@ extern long long bundles_available;
extern char crash_handler_clue[1024];
int link_received_duplicate(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int previous_seq, int unicast);
int link_received_packet(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int sender_seq, int unicode);
int link_receive(overlay_mdp_frame *mdp);
void link_explained(struct subscriber *subscriber);

View File

@ -363,6 +363,7 @@ test_multi_interface() {
wait_until multi_has_link $SIDA
}
# TODO assert that all packets arrive? assert that no duplicates arrive?
doc_ping_unreliable="Ping over a 1-hop unreliable link"
setup_ping_unreliable() {
setup_servald