From e28deeb6d54677b56049813436722921c3cf2283 Mon Sep 17 00:00:00 2001 From: Jeremy Lakeman Date: Tue, 9 Oct 2012 15:44:37 +1030 Subject: [PATCH] Move requested payload queue into frame structure --- overlay_address.c | 3 ++- overlay_mdp.c | 6 +++--- overlay_packet.h | 1 + overlay_packetformats.c | 6 +++--- overlay_payload.c | 29 +++++++++++++++-------------- overlay_route.c | 3 ++- serval.h | 2 +- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/overlay_address.c b/overlay_address.c index 74c03fd6..630f303f 100644 --- a/overlay_address.c +++ b/overlay_address.c @@ -549,7 +549,8 @@ int send_please_explain(struct decode_context *context, struct subscriber *sourc } DEBUGF("Queued please explain"); - if (!overlay_payload_enqueue(OQ_MESH_MANAGEMENT, context->please_explain)) + context->please_explain->queue=OQ_MESH_MANAGEMENT; + if (!overlay_payload_enqueue(context->please_explain)) return 0; op_free(context->please_explain); return 0; diff --git a/overlay_mdp.c b/overlay_mdp.c index 9fb5fd60..1304123c 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -911,16 +911,16 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP, } // TODO include priority in packet header - int qn=OQ_ORDINARY; + frame->queue=OQ_ORDINARY; /* Make sure voice traffic gets priority */ if ((frame->type&OF_TYPE_BITS)==OF_TYPE_DATA_VOICE) { - qn=OQ_ISOCHRONOUS_VOICE; + frame->queue=OQ_ISOCHRONOUS_VOICE; rhizome_saw_voice_traffic(); } frame->send_copies = mdp->out.send_copies; - if (overlay_payload_enqueue(qn, frame)) + if (overlay_payload_enqueue(frame)) op_free(frame); RETURN(0); } diff --git a/overlay_packet.h b/overlay_packet.h index fdfe6198..b889939d 100644 --- a/overlay_packet.h +++ b/overlay_packet.h @@ -31,6 +31,7 @@ struct overlay_frame { unsigned int modifiers; unsigned char ttl; + unsigned char queue; // temporary hack to improve reliability before implementing per-packet nack's int send_copies; diff --git a/overlay_packetformats.c b/overlay_packetformats.c index ad49b92c..8268881f 100644 --- a/overlay_packetformats.c +++ b/overlay_packetformats.c @@ -93,14 +93,14 @@ int overlay_forward_payload(struct overlay_frame *f){ return WHY("Could not clone frame for queuing"); // TODO include priority in packet header - int qn=OQ_ORDINARY; + qf->queue=OQ_ORDINARY; /* Make sure voice traffic gets priority */ if ((qf->type&OF_TYPE_BITS)==OF_TYPE_DATA_VOICE) { - qn=OQ_ISOCHRONOUS_VOICE; + qf->queue=OQ_ISOCHRONOUS_VOICE; rhizome_saw_voice_traffic(); } - if (overlay_payload_enqueue(qn,qf)) { + if (overlay_payload_enqueue(qf)) { op_free(qf); return WHY("failed to enqueue forwarded payload"); } diff --git a/overlay_payload.c b/overlay_payload.c index 4f92531c..89c1f343 100644 --- a/overlay_payload.c +++ b/overlay_payload.c @@ -177,7 +177,7 @@ int dump_payload(struct overlay_frame *p, char *message) return 0; } -int overlay_payload_enqueue(int q, struct overlay_frame *p) +int overlay_payload_enqueue(struct overlay_frame *p) { /* Add payload p to queue q. @@ -195,14 +195,15 @@ int overlay_payload_enqueue(int q, struct overlay_frame *p) return WHYF("Destination %s is unreachable (%d)", alloca_tohex_sid(p->destination->sid), r); } + if (p->queue<0||p->queue>=OQ_MAX) + return WHY("Invalid queue specified"); + + overlay_txqueue *queue = &overlay_tx[p->queue]; + if (debug&DEBUG_PACKETTX) DEBUGF("Enqueuing packet for %s* (q[%d]length = %d)", p->destination?alloca_tohex(p->destination->sid, 7): alloca_tohex(p->broadcast_id.id,BROADCAST_LEN), - q,overlay_tx[q].length); - - if (q<0||q>=OQ_MAX) - return WHY("Invalid queue specified"); - + p->queue, queue->length); if (p->payload && p->payload->position > p->payload->sizeLimit){ // HACK, maybe should be done in each caller @@ -210,8 +211,8 @@ int overlay_payload_enqueue(int q, struct overlay_frame *p) p->payload->sizeLimit=p->payload->position; } - if (overlay_tx[q].length>=overlay_tx[q].maxLength) - return WHYF("Queue #%d congested (size = %d)",q,overlay_tx[q].maxLength); + if (queue->length>=queue->maxLength) + return WHYF("Queue #%d congested (size = %d)",p->queue,queue->maxLength); if (p->send_copies<=0) p->send_copies=1; @@ -242,19 +243,19 @@ int overlay_payload_enqueue(int q, struct overlay_frame *p) p->sendBroadcast=1; } - struct overlay_frame *l=overlay_tx[q].last; + struct overlay_frame *l=queue->last; if (l) l->next=p; p->prev=l; p->next=NULL; p->enqueued_at=gettime_ms(); - overlay_tx[q].last=p; - if (!overlay_tx[q].first) overlay_tx[q].first=p; - overlay_tx[q].length++; + queue->last=p; + if (!queue->first) queue->first=p; + queue->length++; - overlay_update_queue_schedule(&overlay_tx[q], p); + overlay_update_queue_schedule(queue, p); - if (0) dump_queue("after",q); + if (0) dump_queue("after",p->queue); return 0; } diff --git a/overlay_route.c b/overlay_route.c index 7392371b..9418cd7d 100644 --- a/overlay_route.c +++ b/overlay_route.c @@ -303,7 +303,8 @@ int overlay_route_ack_selfannounce(struct overlay_frame *f, /* Add to queue. Keep broadcast status that we have assigned here if required to get ack back to sender before we have a route. */ - if (overlay_payload_enqueue(OQ_MESH_MANAGEMENT,out)) + out->queue=OQ_MESH_MANAGEMENT; + if (overlay_payload_enqueue(out)) { op_free(out); return WHY("overlay_payload_enqueue(self-announce ack) failed"); diff --git a/serval.h b/serval.h index 2402592a..c9be22f7 100644 --- a/serval.h +++ b/serval.h @@ -640,7 +640,7 @@ unsigned int overlay_route_hash_sid(const unsigned char *sid); int packetEncipher(unsigned char *packet,int maxlen,int *len,int cryptoflags); int overlayServerMode(); -int overlay_payload_enqueue(int q, struct overlay_frame *p); +int overlay_payload_enqueue(struct overlay_frame *p); int overlay_route_record_link( time_ms_t now,unsigned char *to, unsigned char *via,int sender_interface, unsigned int s1,unsigned int s2,int score,int gateways_en_route);