diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-02 08:21:39 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-02 08:21:39 +0000 |
commit | e7cbe5448a9c6d7b858a989271e696b5c623741a (patch) | |
tree | 05b2b7ee661cdad703412c08d20f4a02bc539119 /src | |
parent | cd91050ff520c04dde0a15473649379929eb35f1 (diff) | |
download | gnunet-e7cbe5448a9c6d7b858a989271e696b5c623741a.tar.gz gnunet-e7cbe5448a9c6d7b858a989271e696b5c623741a.zip |
- connection ack
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index e2b6cf0ce..1c655c3b9 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -1365,6 +1365,25 @@ send_local_ack (struct MeshChannel *ch, | |||
1365 | 1365 | ||
1366 | 1366 | ||
1367 | /** | 1367 | /** |
1368 | * Count established (ready) connections of a tunnel. | ||
1369 | * | ||
1370 | * @param t Tunnel on which to send the message. | ||
1371 | * | ||
1372 | * @return Number of connections. | ||
1373 | */ | ||
1374 | static unsigned int | ||
1375 | tunnel_count_connections (struct MeshTunnel2 *t) | ||
1376 | { | ||
1377 | struct MeshConnection *c; | ||
1378 | unsigned int i; | ||
1379 | |||
1380 | for (c = t->connection_head, i = 0; NULL != c; c = c->next, i++); | ||
1381 | |||
1382 | return i; | ||
1383 | } | ||
1384 | |||
1385 | |||
1386 | /** | ||
1368 | * Pick a connection on which send the next data message. | 1387 | * Pick a connection on which send the next data message. |
1369 | * | 1388 | * |
1370 | * @param t Tunnel on which to send the message. | 1389 | * @param t Tunnel on which to send the message. |
@@ -4259,7 +4278,7 @@ handle_mesh_connection_create (void *cls, | |||
4259 | 4278 | ||
4260 | /* Remember peers */ | 4279 | /* Remember peers */ |
4261 | dest_peer = peer_get (&id[size - 1]); | 4280 | dest_peer = peer_get (&id[size - 1]); |
4262 | orig_peer = peer_get (&id[0]7); | 4281 | orig_peer = peer_get (&id[0]); |
4263 | 4282 | ||
4264 | /* Create path */ | 4283 | /* Create path */ |
4265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | 4284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); |
@@ -4320,37 +4339,33 @@ handle_mesh_connection_create (void *cls, | |||
4320 | * GNUNET_SYSERR to close it (signal serious error) | 4339 | * GNUNET_SYSERR to close it (signal serious error) |
4321 | */ | 4340 | */ |
4322 | static int | 4341 | static int |
4323 | handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | 4342 | handle_mesh_connection_ack (void *cls, const struct GNUNET_PeerIdentity *peer, |
4324 | const struct GNUNET_MessageHeader *message) | 4343 | const struct GNUNET_MessageHeader *message) |
4325 | { | 4344 | { |
4326 | struct GNUNET_MESH_PathACK *msg; | 4345 | struct GNUNET_MESH_ConnectionACK *msg; |
4327 | struct MeshPeer *peer_info; | ||
4328 | struct MeshPeerPath *p; | 4346 | struct MeshPeerPath *p; |
4329 | struct MeshTunnel *t; | 4347 | struct MeshConnection *c; |
4348 | uint32_t cid; | ||
4330 | 4349 | ||
4331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a path ACK msg [%s]\n", | 4350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a connection ACK msg\n"); |
4332 | GNUNET_i2s (&my_full_id)); | 4351 | msg = (struct GNUNET_MESH_ConnectionACK *) message; |
4333 | msg = (struct GNUNET_MESH_PathACK *) message; | 4352 | cid = ntohl(msg->cid); |
4334 | t = channel_get (&msg->oid, ntohl(msg->tid)); | 4353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on connection %s[%X]\n", |
4335 | if (NULL == t) | 4354 | GNUNET_h2s (&msg->tid), cid); |
4355 | c = connection_get (&msg->tid, cid); | ||
4356 | if (NULL == c) | ||
4336 | { | 4357 | { |
4337 | /* TODO notify that we don't know the tunnel */ | 4358 | GNUNET_STATISTICS_update (stats, "# control on unknown connection", |
4338 | GNUNET_STATISTICS_update (stats, "# control on unknown tunnel", 1, GNUNET_NO); | 4359 | 1, GNUNET_NO); |
4339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " don't know the tunnel %s [%X]!\n", | 4360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " don't know the connection!\n"); |
4340 | GNUNET_i2s (&msg->oid), ntohl(msg->tid)); | ||
4341 | return GNUNET_OK; | 4361 | return GNUNET_OK; |
4342 | } | 4362 | } |
4343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %s [%X]\n", | ||
4344 | GNUNET_i2s (&msg->oid), ntohl(msg->tid)); | ||
4345 | 4363 | ||
4346 | peer_info = peer_get (&msg->peer_id); | ||
4347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by peer %s\n", | ||
4348 | GNUNET_i2s (&msg->peer_id)); | ||
4349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n", | 4364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n", |
4350 | GNUNET_i2s (peer)); | 4365 | GNUNET_i2s (peer)); |
4351 | 4366 | ||
4352 | /* Add path to peers? */ | 4367 | /* Add path to peers? */ |
4353 | p = t->path; | 4368 | p = c->path; |
4354 | if (NULL != p) | 4369 | if (NULL != p) |
4355 | { | 4370 | { |
4356 | path_add_to_peers (p, GNUNET_YES); | 4371 | path_add_to_peers (p, GNUNET_YES); |
@@ -4359,33 +4374,24 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4359 | { | 4374 | { |
4360 | GNUNET_break (0); | 4375 | GNUNET_break (0); |
4361 | } | 4376 | } |
4362 | tunnel_change_state (t, MESH_TUNNEL_READY); | 4377 | connection_change_state (c, MESH_CONNECTION_READY); |
4363 | tunnel_reset_timeout (t, GNUNET_NO); | 4378 | connection_reset_timeout (c, GNUNET_NO); |
4364 | t->next_fc.last_ack_recv = (NULL == t->client) ? ntohl (msg->ack) : 0; | ||
4365 | t->prev_fc.last_ack_sent = ntohl (msg->ack); | ||
4366 | 4379 | ||
4367 | /* Message for us? */ | 4380 | /* Message for us? */ |
4368 | if (0 == memcmp (&msg->oid, &my_full_id, sizeof (struct GNUNET_PeerIdentity))) | 4381 | if (NULL != c->t->channel_head) |
4369 | { | 4382 | { |
4370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); | 4383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); |
4371 | if (NULL == t->owner) | 4384 | if (3 <= tunnel_count_connections(c->t) && NULL != c->t->peer->dhtget) |
4372 | { | 4385 | { |
4373 | GNUNET_break_op (0); | 4386 | GNUNET_DHT_get_stop (c->t->peer->dhtget); |
4374 | return GNUNET_OK; | 4387 | c->t->peer->dhtget = NULL; |
4375 | } | 4388 | } |
4376 | if (NULL != peer_info->dhtget) | 4389 | connection_send_ack (c, GNUNET_NO); /* FIXME */ |
4377 | { | ||
4378 | GNUNET_DHT_get_stop (peer_info->dhtget); | ||
4379 | peer_info->dhtget = NULL; | ||
4380 | } | ||
4381 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, GNUNET_YES); | ||
4382 | tunnel_send_ack (t, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, GNUNET_NO); | ||
4383 | return GNUNET_OK; | 4390 | return GNUNET_OK; |
4384 | } | 4391 | } |
4385 | 4392 | ||
4386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
4387 | " not for us, retransmitting...\n"); | 4394 | send_prebuilt_message_connection (message, c, NULL, GNUNET_NO); |
4388 | send_prebuilt_message (message, t->prev_hop, t); | ||
4389 | return GNUNET_OK; | 4395 | return GNUNET_OK; |
4390 | } | 4396 | } |
4391 | 4397 | ||
@@ -4998,7 +5004,10 @@ handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4998 | * Functions to handle messages from core | 5004 | * Functions to handle messages from core |
4999 | */ | 5005 | */ |
5000 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 5006 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { |
5001 | {&handle_mesh_connection_create, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, 0}, | 5007 | {&handle_mesh_connection_create, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE, |
5008 | 0}, | ||
5009 | {&handle_mesh_connection_ack, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, | ||
5010 | sizeof (struct GNUNET_MESH_ConnectionACK)}, | ||
5002 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, | 5011 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, |
5003 | sizeof (struct GNUNET_MESH_PathBroken)}, | 5012 | sizeof (struct GNUNET_MESH_PathBroken)}, |
5004 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, | 5013 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, |
@@ -5017,8 +5026,6 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
5017 | sizeof (struct GNUNET_MESH_ACK)}, | 5026 | sizeof (struct GNUNET_MESH_ACK)}, |
5018 | {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL, | 5027 | {&handle_mesh_poll, GNUNET_MESSAGE_TYPE_MESH_POLL, |
5019 | sizeof (struct GNUNET_MESH_Poll)}, | 5028 | sizeof (struct GNUNET_MESH_Poll)}, |
5020 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK, | ||
5021 | sizeof (struct GNUNET_MESH_PathACK)}, | ||
5022 | {NULL, 0, 0} | 5029 | {NULL, 0, 0} |
5023 | }; | 5030 | }; |
5024 | 5031 | ||