aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-07-11 11:58:09 +0000
committerBart Polot <bart@net.in.tum.de>2013-07-11 11:58:09 +0000
commiteadb185a411fe68d5bd08dc6526e49046e3bfc86 (patch)
treea73cfbdf476c82f9ee36ba2e7aab454dd3169670 /src/mesh/gnunet-service-mesh.c
parentd1bbc74bc202a18f898aa98524517a7c0791e682 (diff)
downloadgnunet-eadb185a411fe68d5bd08dc6526e49046e3bfc86.tar.gz
gnunet-eadb185a411fe68d5bd08dc6526e49046e3bfc86.zip
- avoid POLL messing with reliability counter
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c67
1 files changed, 53 insertions, 14 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 6ba811b52..d330fb42a 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -3181,31 +3181,67 @@ queue_add (void *cls, uint16_t type, size_t size,
3181{ 3181{
3182 struct MeshPeerQueue *queue; 3182 struct MeshPeerQueue *queue;
3183 struct GNUNET_PeerIdentity id; 3183 struct GNUNET_PeerIdentity id;
3184 unsigned int *n; 3184 struct MeshFlowControl *fc;
3185 uint32_t pid;
3186 uint32_t pid_q;
3187 int priority;
3185 3188
3186 n = NULL; 3189 fc = NULL;
3190 priority = GNUNET_NO;
3187 if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type) 3191 if (GNUNET_MESSAGE_TYPE_MESH_UNICAST == type)
3188 { 3192 {
3189 n = &t->next_fc.queue_n; 3193 fc = &t->next_fc;
3194 pid = ntohl (((struct GNUNET_MESH_Data *)cls)->pid);
3190 } 3195 }
3191 else if (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type) 3196 else if (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN == type)
3192 { 3197 {
3193 n = &t->prev_fc.queue_n; 3198 fc = &t->prev_fc;
3199 pid = ntohl (((struct GNUNET_MESH_Data *)cls)->pid);
3194 } 3200 }
3195 if (NULL != n) 3201 if (NULL != fc)
3196 { 3202 {
3197 if (*n >= t->queue_max) 3203 if (fc->queue_n >= t->queue_max)
3198 { 3204 {
3199 GNUNET_break(0); 3205 GNUNET_break (0);
3200 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3206 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3201 "queue full: %u/%u\n", 3207 "queue full: %u/%u\n",
3202 *n, t->queue_max); 3208 fc->queue_n, t->queue_max);
3203 GNUNET_STATISTICS_update(stats, 3209 GNUNET_STATISTICS_update (stats,
3204 "# messages dropped (buffer full)", 3210 "# messages dropped (buffer full)",
3205 1, GNUNET_NO); 3211 1, GNUNET_NO);
3206 return; /* Drop message */ 3212 /* Get the PID of the oldest message in the queue */
3213 for (queue = dst->queue_head; queue != NULL; queue = queue->next)
3214 if (queue->type == type && queue->tunnel == t)
3215 {
3216 pid_q = ntohl (((struct GNUNET_MESH_Data *)(queue->cls))->pid);
3217 break;
3218 }
3219 GNUNET_assert (NULL != queue);
3220
3221 /* If this is an earlier message that that, give it priority:
3222 * - drop the newest message in the queue
3223 * - instert current one at the end of the queue (first to get out)
3224 */
3225 if (GNUNET_YES == t->reliable && GMC_is_pid_bigger(pid_q, pid))
3226 {
3227 for (queue = dst->queue_tail; queue != NULL; queue = queue->prev)
3228 if (queue->type == type && queue->tunnel == t)
3229 {
3230 /* Drop message from queue */
3231 GNUNET_CONTAINER_DLL_remove (dst->queue_head,
3232 dst->queue_tail,
3233 queue);
3234 queue_destroy (queue, GNUNET_YES);
3235 fc->queue_n--;
3236 t->pending_messages--;
3237 priority = GNUNET_YES;
3238 break;
3239 }
3240 }
3241 else
3242 return; /* Drop this message */
3207 } 3243 }
3208 (*n)++; 3244 fc->queue_n++;
3209 } 3245 }
3210 queue = GNUNET_malloc (sizeof (struct MeshPeerQueue)); 3246 queue = GNUNET_malloc (sizeof (struct MeshPeerQueue));
3211 queue->cls = cls; 3247 queue->cls = cls;
@@ -3213,7 +3249,10 @@ queue_add (void *cls, uint16_t type, size_t size,
3213 queue->size = size; 3249 queue->size = size;
3214 queue->peer = dst; 3250 queue->peer = dst;
3215 queue->tunnel = t; 3251 queue->tunnel = t;
3216 GNUNET_CONTAINER_DLL_insert_tail (dst->queue_head, dst->queue_tail, queue); 3252 if (GNUNET_YES == priority)
3253 GNUNET_CONTAINER_DLL_insert (dst->queue_head, dst->queue_tail, queue);
3254 else
3255 GNUNET_CONTAINER_DLL_insert_tail (dst->queue_head, dst->queue_tail, queue);
3217 if (NULL == dst->core_transmit) 3256 if (NULL == dst->core_transmit)
3218 { 3257 {
3219 GNUNET_PEER_resolve (dst->id, &id); 3258 GNUNET_PEER_resolve (dst->id, &id);