diff options
author | Bart Polot <bart@net.in.tum.de> | 2016-10-26 04:20:49 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2016-10-26 04:20:49 +0000 |
commit | 7a5b94705d47b9dccc3b35dfb7d08dc646fe5a33 (patch) | |
tree | dabd80abc1183063853e6a08a75e9952d83a38cd /src | |
parent | 2f3bf5f8f2f80ead818e514ab2f69052cc201a78 (diff) | |
download | gnunet-7a5b94705d47b9dccc3b35dfb7d08dc646fe5a33.tar.gz gnunet-7a5b94705d47b9dccc3b35dfb7d08dc646fe5a33.zip |
- simplify connection-level processing of messages to be sent
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 58 |
1 files changed, 19 insertions, 39 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 11f7fd9eb..47d841f04 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -1079,6 +1079,7 @@ send_broken (struct CadetConnection *c, | |||
1079 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); | 1079 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); |
1080 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 1080 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
1081 | msg.cid = c->id; | 1081 | msg.cid = c->id; |
1082 | msg.reserved = htonl (0); | ||
1082 | msg.peer1 = *id1; | 1083 | msg.peer1 = *id1; |
1083 | msg.peer2 = *id2; | 1084 | msg.peer2 = *id2; |
1084 | GNUNET_assert (NULL == | 1085 | GNUNET_assert (NULL == |
@@ -1112,6 +1113,7 @@ send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id, | |||
1112 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); | 1113 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); |
1113 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 1114 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
1114 | msg.cid = *connection_id; | 1115 | msg.cid = *connection_id; |
1116 | msg.reserved = htonl (0); | ||
1115 | msg.peer1 = *id1; | 1117 | msg.peer1 = *id1; |
1116 | if (NULL != id2) | 1118 | if (NULL != id2) |
1117 | msg.peer2 = *id2; | 1119 | msg.peer2 = *id2; |
@@ -1412,7 +1414,7 @@ connection_cancel_queues (struct CadetConnection *c, | |||
1412 | * @param cls Closure (poll ctx). | 1414 | * @param cls Closure (poll ctx). |
1413 | */ | 1415 | */ |
1414 | static void | 1416 | static void |
1415 | connection_poll (void *cls); | 1417 | send_connection_poll (void *cls); |
1416 | 1418 | ||
1417 | 1419 | ||
1418 | /** | 1420 | /** |
@@ -1450,7 +1452,7 @@ poll_sent (void *cls, | |||
1450 | GNUNET_assert (NULL == fc->poll_task); | 1452 | GNUNET_assert (NULL == fc->poll_task); |
1451 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); | 1453 | fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); |
1452 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | 1454 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, |
1453 | &connection_poll, | 1455 | &send_connection_poll, |
1454 | fc); | 1456 | fc); |
1455 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); | 1457 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); |
1456 | } | 1458 | } |
@@ -1463,7 +1465,7 @@ poll_sent (void *cls, | |||
1463 | * @param cls Closure (poll ctx). | 1465 | * @param cls Closure (poll ctx). |
1464 | */ | 1466 | */ |
1465 | static void | 1467 | static void |
1466 | connection_poll (void *cls) | 1468 | send_connection_poll (void *cls) |
1467 | { | 1469 | { |
1468 | struct CadetFlowControl *fc = cls; | 1470 | struct CadetFlowControl *fc = cls; |
1469 | struct GNUNET_CADET_Poll msg; | 1471 | struct GNUNET_CADET_Poll msg; |
@@ -1479,6 +1481,7 @@ connection_poll (void *cls) | |||
1479 | 1481 | ||
1480 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_POLL); | 1482 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_POLL); |
1481 | msg.header.size = htons (sizeof (msg)); | 1483 | msg.header.size = htons (sizeof (msg)); |
1484 | msg.cid = c->id; | ||
1482 | msg.pid = htonl (fc->last_pid_sent); | 1485 | msg.pid = htonl (fc->last_pid_sent); |
1483 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); | 1486 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); |
1484 | fc->poll_msg = | 1487 | fc->poll_msg = |
@@ -3259,15 +3262,10 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3259 | { | 3262 | { |
3260 | struct GNUNET_CADET_AX *axmsg; | 3263 | struct GNUNET_CADET_AX *axmsg; |
3261 | struct GNUNET_CADET_KX *kmsg; | 3264 | struct GNUNET_CADET_KX *kmsg; |
3262 | struct GNUNET_CADET_ACK *amsg; | ||
3263 | struct GNUNET_CADET_Poll *pmsg; | ||
3264 | struct GNUNET_CADET_ConnectionDestroy *dmsg; | ||
3265 | struct GNUNET_CADET_ConnectionBroken *bmsg; | ||
3266 | struct CadetFlowControl *fc; | 3265 | struct CadetFlowControl *fc; |
3267 | struct CadetConnectionQueue *q; | 3266 | struct CadetConnectionQueue *q; |
3268 | size_t size; | 3267 | size_t size; |
3269 | uint16_t type; | 3268 | uint16_t type; |
3270 | int droppable; | ||
3271 | 3269 | ||
3272 | GCC_check_connections (); | 3270 | GCC_check_connections (); |
3273 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3271 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
@@ -3283,7 +3281,6 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3283 | "--> %s (%s %4u) on conn %s (%p) %s [%5u]\n", | 3281 | "--> %s (%s %4u) on conn %s (%p) %s [%5u]\n", |
3284 | GC_m2s (type), GC_m2s (payload_type), payload_id, GCC_2s (c), c, | 3282 | GC_m2s (type), GC_m2s (payload_type), payload_id, GCC_2s (c), c, |
3285 | GC_f2s(fwd), size); | 3283 | GC_f2s(fwd), size); |
3286 | droppable = (GNUNET_NO == force); | ||
3287 | switch (type) | 3284 | switch (type) |
3288 | { | 3285 | { |
3289 | case GNUNET_MESSAGE_TYPE_CADET_AX: | 3286 | case GNUNET_MESSAGE_TYPE_CADET_AX: |
@@ -3293,13 +3290,13 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3293 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n); | 3290 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n); |
3294 | LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); | 3291 | LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); |
3295 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); | 3292 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); |
3296 | if (GNUNET_YES == droppable) | 3293 | if (GNUNET_NO == force) |
3297 | { | 3294 | { |
3298 | fc->queue_n++; | 3295 | fc->queue_n++; |
3299 | } | 3296 | } |
3300 | else | 3297 | else |
3301 | { | 3298 | { |
3302 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not droppable, Q_N stays the same\n"); | 3299 | LOG (GNUNET_ERROR_TYPE_DEBUG, " forced msg, Q_N stays the same\n"); |
3303 | } | 3300 | } |
3304 | break; | 3301 | break; |
3305 | 3302 | ||
@@ -3309,35 +3306,16 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3309 | kmsg->cid = c->id; | 3306 | kmsg->cid = c->id; |
3310 | break; | 3307 | break; |
3311 | 3308 | ||
3312 | case GNUNET_MESSAGE_TYPE_CADET_ACK: | 3309 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: |
3313 | amsg = (struct GNUNET_CADET_ACK *) message; | 3310 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK: |
3314 | amsg->cid = c->id; | 3311 | GNUNET_break (0); /* Should've used specific functions. */ |
3315 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ntohl (amsg->ack)); | ||
3316 | droppable = GNUNET_NO; | ||
3317 | break; | 3312 | break; |
3318 | 3313 | ||
3314 | case GNUNET_MESSAGE_TYPE_CADET_ACK: | ||
3319 | case GNUNET_MESSAGE_TYPE_CADET_POLL: | 3315 | case GNUNET_MESSAGE_TYPE_CADET_POLL: |
3320 | pmsg = (struct GNUNET_CADET_Poll *) message; | ||
3321 | pmsg->cid = c->id; | ||
3322 | LOG (GNUNET_ERROR_TYPE_DEBUG, " POLL %u\n", ntohl (pmsg->pid)); | ||
3323 | droppable = GNUNET_NO; | ||
3324 | break; | ||
3325 | |||
3326 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: | 3316 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: |
3327 | dmsg = (struct GNUNET_CADET_ConnectionDestroy *) message; | ||
3328 | dmsg->reserved = htonl (0); | ||
3329 | dmsg->cid = c->id; | ||
3330 | break; | ||
3331 | |||
3332 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: | 3317 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: |
3333 | bmsg = (struct GNUNET_CADET_ConnectionBroken *) message; | 3318 | GNUNET_assert (GNUNET_YES == force); |
3334 | bmsg->reserved = htonl (0); | ||
3335 | bmsg->cid = c->id; | ||
3336 | break; | ||
3337 | |||
3338 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: | ||
3339 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK: | ||
3340 | GNUNET_break (0); /* Should've used specific functions. */ | ||
3341 | break; | 3319 | break; |
3342 | 3320 | ||
3343 | default: | 3321 | default: |
@@ -3345,7 +3323,7 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3345 | return NULL; | 3323 | return NULL; |
3346 | } | 3324 | } |
3347 | 3325 | ||
3348 | if (fc->queue_n > fc->queue_max && droppable) | 3326 | if (fc->queue_n > fc->queue_max && GNUNET_NO == force) |
3349 | { | 3327 | { |
3350 | GNUNET_STATISTICS_update (stats, "# messages dropped (buffer full)", | 3328 | GNUNET_STATISTICS_update (stats, "# messages dropped (buffer full)", |
3351 | 1, GNUNET_NO); | 3329 | 1, GNUNET_NO); |
@@ -3364,7 +3342,7 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message, | |||
3364 | c->pending_messages++; | 3342 | c->pending_messages++; |
3365 | 3343 | ||
3366 | q = GNUNET_new (struct CadetConnectionQueue); | 3344 | q = GNUNET_new (struct CadetConnectionQueue); |
3367 | q->forced = !droppable; | 3345 | q->forced = force; |
3368 | q->peer_q = GCP_send (get_hop (c, fwd), message, | 3346 | q->peer_q = GCP_send (get_hop (c, fwd), message, |
3369 | payload_type, payload_id, | 3347 | payload_type, payload_id, |
3370 | c, fwd, | 3348 | c, fwd, |
@@ -3410,7 +3388,8 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3410 | uint16_t size; | 3388 | uint16_t size; |
3411 | 3389 | ||
3412 | /* Allocate a copy of the message on the stack, so we can modify it as needed, | 3390 | /* Allocate a copy of the message on the stack, so we can modify it as needed, |
3413 | * adding the Connection ID. | 3391 | * adding the Connection ID, PID, and other data the Tunnel layer doesn't |
3392 | * have access to. | ||
3414 | */ | 3393 | */ |
3415 | size = ntohs (message->size); | 3394 | size = ntohs (message->size); |
3416 | { | 3395 | { |
@@ -3585,6 +3564,7 @@ GCC_send_destroy (struct CadetConnection *c) | |||
3585 | msg.header.size = htons (sizeof (msg)); | 3564 | msg.header.size = htons (sizeof (msg)); |
3586 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); | 3565 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY); |
3587 | msg.cid = c->id; | 3566 | msg.cid = c->id; |
3567 | msg.reserved = htonl (0); | ||
3588 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3568 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3589 | " sending connection destroy for connection %s\n", | 3569 | " sending connection destroy for connection %s\n", |
3590 | GCC_2s (c)); | 3570 | GCC_2s (c)); |
@@ -3635,7 +3615,7 @@ GCC_start_poll (struct CadetConnection *c, int fwd) | |||
3635 | } | 3615 | } |
3636 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL started on request\n"); | 3616 | LOG (GNUNET_ERROR_TYPE_DEBUG, "POLL started on request\n"); |
3637 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, | 3617 | fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, |
3638 | &connection_poll, | 3618 | &send_connection_poll, |
3639 | fc); | 3619 | fc); |
3640 | } | 3620 | } |
3641 | 3621 | ||