aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh-new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/gnunet-service-mesh-new.c')
-rw-r--r--src/mesh/gnunet-service-mesh-new.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index ccd7aceb4..32ae6998f 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -467,6 +467,7 @@ mesh_debug (void *cls, int success)
467} 467}
468#endif 468#endif
469 469
470/* FIXME */
470unsigned int debug_fwd_ack; 471unsigned int debug_fwd_ack;
471unsigned int debug_bck_ack; 472unsigned int debug_bck_ack;
472 473
@@ -1504,16 +1505,20 @@ tunnel_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1504 msg.header.size = htons (sizeof (msg)); 1505 msg.header.size = htons (sizeof (msg));
1505 msg.tid = htonl (t->id.tid); 1506 msg.tid = htonl (t->id.tid);
1506 GNUNET_PEER_resolve (t->id.oid, &msg.oid); 1507 GNUNET_PEER_resolve (t->id.oid, &msg.oid);
1507 msg.last_ack = htonl (fc->last_ack_recv);
1508 1508
1509 if (fc == &t->prev_fc) 1509 if (fc == &t->prev_fc)
1510 { 1510 {
1511 peer = t->prev_hop; 1511 peer = t->prev_hop;
1512 } 1512 }
1513 else 1513 else if (fc == &t->next_fc)
1514 { 1514 {
1515 peer = t->next_hop; 1515 peer = t->next_hop;
1516 } 1516 }
1517 else
1518 {
1519 GNUNET_break (0);
1520 return;
1521 }
1517 send_prebuilt_message (&msg.header, peer, t); 1522 send_prebuilt_message (&msg.header, peer, t);
1518 fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time); 1523 fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
1519 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time, 1524 fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
@@ -1980,6 +1985,8 @@ tunnel_send_bck_ack (struct MeshTunnel *t, uint16_t type)
1980 GNUNET_break (0); 1985 GNUNET_break (0);
1981 } 1986 }
1982 1987
1988 /* TODO: Check if we need to transmit the ACK (as in fwd) */
1989
1983 ack = t->next_fc.last_pid_recv + t->queue_max - t->prev_fc.queue_n; 1990 ack = t->next_fc.last_pid_recv + t->queue_max - t->prev_fc.queue_n;
1984 1991
1985 if (t->next_fc.last_ack_sent == ack && GNUNET_NO == t->force_ack) 1992 if (t->next_fc.last_ack_sent == ack && GNUNET_NO == t->force_ack)
@@ -2710,9 +2717,11 @@ queue_send (void *cls, size_t size, void *buf)
2710 switch (type) 2717 switch (type)
2711 { 2718 {
2712 case GNUNET_MESSAGE_TYPE_MESH_UNICAST: 2719 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
2720 t->next_fc.last_pid_sent = ((struct GNUNET_MESH_Unicast *) buf)->pid;
2713 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST); 2721 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_UNICAST);
2714 break; 2722 break;
2715 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 2723 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
2724 t->prev_fc.last_pid_sent = ((struct GNUNET_MESH_ToOrigin *) buf)->pid;
2716 tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); 2725 tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
2717 break; 2726 break;
2718 default: 2727 default:
@@ -2916,13 +2925,10 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
2916 { 2925 {
2917 t->nobuffer = GNUNET_YES; 2926 t->nobuffer = GNUNET_YES;
2918 t->prev_fc.last_ack_sent = t->prev_fc.last_pid_recv + 1; 2927 t->prev_fc.last_ack_sent = t->prev_fc.last_pid_recv + 1;
2919 } 2928 t->next_fc.last_ack_sent = t->next_fc.last_pid_recv + 1;
2920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " nobuffer:%d\n", t->nobuffer);
2921
2922 if (GNUNET_YES == t->nobuffer)
2923 {
2924 t->queue_max = 1; 2929 t->queue_max = 1;
2925 } 2930 }
2931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " nobuffer:%d\n", t->nobuffer);
2926 2932
2927 tunnel_reset_timeout (t); 2933 tunnel_reset_timeout (t);
2928 GMC_hash32 (t->local_tid_dest, &hash); 2934 GMC_hash32 (t->local_tid_dest, &hash);
@@ -3186,7 +3192,7 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
3186 * GNUNET_SYSERR to close it (signal serious error) 3192 * GNUNET_SYSERR to close it (signal serious error)
3187 */ 3193 */
3188static int 3194static int
3189handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, 3195handle_mesh_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
3190 const struct GNUNET_MessageHeader *message) 3196 const struct GNUNET_MessageHeader *message)
3191{ 3197{
3192 struct GNUNET_MESH_Unicast *msg; 3198 struct GNUNET_MESH_Unicast *msg;
@@ -3232,8 +3238,6 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
3232 " pid %u not seen yet, forwarding\n", pid); 3238 " pid %u not seen yet, forwarding\n", pid);
3233 } 3239 }
3234 3240
3235 t->prev_fc.last_pid_recv = pid;
3236
3237 if (GMC_is_pid_bigger (pid, t->prev_fc.last_ack_sent)) 3241 if (GMC_is_pid_bigger (pid, t->prev_fc.last_ack_sent))
3238 { 3242 {
3239 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO); 3243 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
@@ -3241,8 +3245,10 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
3241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3242 "Received PID %u, ACK %u\n", 3246 "Received PID %u, ACK %u\n",
3243 pid, t->prev_fc.last_ack_sent); 3247 pid, t->prev_fc.last_ack_sent);
3248 tunnel_send_fwd_ack(t, GNUNET_MESSAGE_TYPE_MESH_POLL);
3244 return GNUNET_OK; 3249 return GNUNET_OK;
3245 } 3250 }
3251 t->prev_fc.last_pid_recv = pid;
3246 3252
3247 tunnel_reset_timeout (t); 3253 tunnel_reset_timeout (t);
3248 if (t->dest == myid) 3254 if (t->dest == myid)
@@ -3277,15 +3283,6 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
3277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3278 " not for us, retransmitting...\n"); 3284 " not for us, retransmitting...\n");
3279 3285
3280 if (GNUNET_YES == t->nobuffer &&
3281 GNUNET_YES == GMC_is_pid_bigger (pid, t->next_fc.last_ack_recv))
3282 {
3283 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
3284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u > %u\n",
3285 pid, t->next_fc.last_ack_recv);
3286 GNUNET_break_op (0);
3287 return GNUNET_OK;
3288 }
3289 send_prebuilt_message (message, t->next_hop, t); 3286 send_prebuilt_message (message, t->next_hop, t);
3290 GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO); 3287 GNUNET_STATISTICS_update (stats, "# unicast forwarded", 1, GNUNET_NO);
3291 return GNUNET_OK; 3288 return GNUNET_OK;
@@ -3303,11 +3300,10 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
3303 * GNUNET_SYSERR to close it (signal serious error) 3300 * GNUNET_SYSERR to close it (signal serious error)
3304 */ 3301 */
3305static int 3302static int
3306handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, 3303handle_mesh_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3307 const struct GNUNET_MessageHeader *message) 3304 const struct GNUNET_MessageHeader *message)
3308{ 3305{
3309 struct GNUNET_MESH_ToOrigin *msg; 3306 struct GNUNET_MESH_ToOrigin *msg;
3310 struct MeshPeerInfo *peer_info;
3311 struct MeshTunnel *t; 3307 struct MeshTunnel *t;
3312 size_t size; 3308 size_t size;
3313 uint32_t pid; 3309 uint32_t pid;
@@ -3337,7 +3333,6 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3337 return GNUNET_OK; 3333 return GNUNET_OK;
3338 } 3334 }
3339 3335
3340
3341 if (t->next_fc.last_pid_recv == pid) 3336 if (t->next_fc.last_pid_recv == pid)
3342 { 3337 {
3343 /* already seen this packet, drop */ 3338 /* already seen this packet, drop */
@@ -3348,9 +3343,19 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3348 return GNUNET_OK; 3343 return GNUNET_OK;
3349 } 3344 }
3350 3345
3346 if (GMC_is_pid_bigger (pid, t->next_fc.last_ack_sent))
3347 {
3348 GNUNET_STATISTICS_update (stats, "# unsolicited to_orig", 1, GNUNET_NO);
3349 GNUNET_break_op (0);
3350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3351 "Received PID %u, ACK %u\n",
3352 pid, t->next_fc.last_ack_sent);
3353 tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_POLL);
3354 return GNUNET_OK;
3355 }
3356 t->next_fc.last_pid_recv = pid;
3351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3352 " pid %u not seen yet, forwarding\n", pid); 3358 " pid %u not seen yet, forwarding\n", pid);
3353 t->next_fc.last_pid_recv = pid;
3354 3359
3355 if (NULL != t->owner) 3360 if (NULL != t->owner)
3356 { 3361 {
@@ -3372,13 +3377,6 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3373 " not for us, retransmitting...\n"); 3378 " not for us, retransmitting...\n");
3374 3379
3375 peer_info = peer_get (&msg->oid);
3376 if (NULL == peer_info)
3377 {
3378 /* unknown origin of tunnel */
3379 GNUNET_break (0);
3380 return GNUNET_OK;
3381 }
3382 if (0 == t->prev_hop) /* No owner AND no prev hop */ 3380 if (0 == t->prev_hop) /* No owner AND no prev hop */
3383 { 3381 {
3384 if (GNUNET_YES == t->destroy) 3382 if (GNUNET_YES == t->destroy)
@@ -3395,7 +3393,7 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
3395 "from peer %s\n", 3393 "from peer %s\n",
3396 GNUNET_i2s (peer)); 3394 GNUNET_i2s (peer));
3397 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3398 "for tunnel %s [%X]\n", 3396 "on tunnel %s [%X]\n",
3399 GNUNET_i2s (&msg->oid), ntohl(msg->tid)); 3397 GNUNET_i2s (&msg->oid), ntohl(msg->tid));
3400 return GNUNET_OK; 3398 return GNUNET_OK;
3401 } 3399 }
@@ -3422,6 +3420,7 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3422{ 3420{
3423 struct GNUNET_MESH_ACK *msg; 3421 struct GNUNET_MESH_ACK *msg;
3424 struct MeshTunnel *t; 3422 struct MeshTunnel *t;
3423 GNUNET_PEER_Id id;
3425 uint32_t ack; 3424 uint32_t ack;
3426 3425
3427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n", 3426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
@@ -3440,9 +3439,10 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack); 3439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ACK %u\n", ack);
3441 3440
3442 /* Is this a forward or backward ACK? */ 3441 /* Is this a forward or backward ACK? */
3443 if (t->prev_hop != GNUNET_PEER_search (peer)) 3442 id = GNUNET_PEER_search (peer);
3443 if (t->next_hop == id)
3444 { 3444 {
3445 debug_bck_ack++; 3445 debug_fwd_ack++;
3446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); 3446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
3447 if (GNUNET_SCHEDULER_NO_TASK != t->next_fc.poll_task && 3447 if (GNUNET_SCHEDULER_NO_TASK != t->next_fc.poll_task &&
3448 GMC_is_pid_bigger (ack, t->next_fc.last_ack_recv)) 3448 GMC_is_pid_bigger (ack, t->next_fc.last_ack_recv))
@@ -3455,8 +3455,9 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3455 peer_unlock_queue (t->next_hop); 3455 peer_unlock_queue (t->next_hop);
3456 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK); 3456 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
3457 } 3457 }
3458 else 3458 else if (t->prev_hop == id)
3459 { 3459 {
3460 debug_bck_ack++;
3460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); 3461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
3461 if (GNUNET_SCHEDULER_NO_TASK != t->prev_fc.poll_task && 3462 if (GNUNET_SCHEDULER_NO_TASK != t->prev_fc.poll_task &&
3462 GMC_is_pid_bigger (ack, t->prev_fc.last_ack_recv)) 3463 GMC_is_pid_bigger (ack, t->prev_fc.last_ack_recv))
@@ -3469,6 +3470,8 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
3469 peer_unlock_queue (t->prev_hop); 3470 peer_unlock_queue (t->prev_hop);
3470 tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK); 3471 tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
3471 } 3472 }
3473 else
3474 GNUNET_break_op (0);
3472 return GNUNET_OK; 3475 return GNUNET_OK;
3473} 3476}
3474 3477
@@ -3652,10 +3655,10 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
3652 sizeof (struct GNUNET_MESH_PathBroken)}, 3655 sizeof (struct GNUNET_MESH_PathBroken)},
3653 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 3656 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY,
3654 sizeof (struct GNUNET_MESH_TunnelDestroy)}, 3657 sizeof (struct GNUNET_MESH_TunnelDestroy)},
3655 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 3658 {&handle_mesh_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
3656 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE, 3659 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE,
3657 sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, 3660 sizeof (struct GNUNET_MESH_TunnelKeepAlive)},
3658 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 3661 {&handle_mesh_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
3659 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK, 3662 {&handle_mesh_ack, GNUNET_MESSAGE_TYPE_MESH_ACK,
3660 sizeof (struct GNUNET_MESH_ACK)}, 3663 sizeof (struct GNUNET_MESH_ACK)},
3661 {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL, 3664 {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL,
@@ -4212,7 +4215,7 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
4212 copy->ttl = htonl (default_ttl); 4215 copy->ttl = htonl (default_ttl);
4213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4214 " calling generic handler...\n"); 4217 " calling generic handler...\n");
4215 handle_mesh_data_unicast (NULL, &my_full_id, &copy->header); 4218 handle_mesh_unicast (NULL, &my_full_id, &copy->header);
4216 } 4219 }
4217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); 4220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
4218 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4221 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -4301,7 +4304,6 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
4301 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 4304 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
4302 return; 4305 return;
4303 } 4306 }
4304 fc->last_pid_recv++;
4305 4307
4306 /* Ok, everything is correct, send the message 4308 /* Ok, everything is correct, send the message
4307 * (pretend we got it from a mesh peer) 4309 * (pretend we got it from a mesh peer)
@@ -4316,11 +4318,10 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
4316 GNUNET_PEER_resolve (t->id.oid, &copy->oid); 4318 GNUNET_PEER_resolve (t->id.oid, &copy->oid);
4317 copy->tid = htonl (t->id.tid); 4319 copy->tid = htonl (t->id.tid);
4318 copy->ttl = htonl (default_ttl); 4320 copy->ttl = htonl (default_ttl);
4319 copy->pid = htonl (t->prev_fc.last_pid_sent + 1);
4320 4321
4321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4322 " calling generic handler...\n"); 4323 " calling generic handler...\n");
4323 handle_mesh_data_to_orig (NULL, &my_full_id, &copy->header); 4324 handle_mesh_to_orig (NULL, &my_full_id, &copy->header);
4324 } 4325 }
4325 GNUNET_SERVER_receive_done (client, GNUNET_OK); 4326 GNUNET_SERVER_receive_done (client, GNUNET_OK);
4326 4327