diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-11 10:59:32 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-11 10:59:32 +0000 |
commit | ef2231cf7c1b83ac45c6fbe75f2ef73280815024 (patch) | |
tree | 4f3aa6d15bc26ded2de7c983c9df689000b354a6 /src/mesh | |
parent | 23cd779d3db3edd280ca9f760f1a98efa49e6653 (diff) | |
download | gnunet-ef2231cf7c1b83ac45c6fbe75f2ef73280815024.tar.gz gnunet-ef2231cf7c1b83ac45c6fbe75f2ef73280815024.zip |
- sync
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.c | 75 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.h | 12 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_local.c | 68 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_peer.c | 14 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_peer.h | 10 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 1 |
6 files changed, 113 insertions, 67 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index e44d52ff6..aa89730c3 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "gnunet-service-mesh_channel.h" | 30 | #include "gnunet-service-mesh_channel.h" |
31 | #include "gnunet-service-mesh_local.h" | 31 | #include "gnunet-service-mesh_local.h" |
32 | #include "gnunet-service-mesh_tunnel.h" | 32 | #include "gnunet-service-mesh_tunnel.h" |
33 | #include "gnunet-service-mesh_peer.h" | ||
33 | 34 | ||
34 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-chn",__VA_ARGS__) | 35 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-chn",__VA_ARGS__) |
35 | 36 | ||
@@ -1305,6 +1306,80 @@ GMCH_handle_local_destroy (struct MeshChannel *ch, | |||
1305 | 1306 | ||
1306 | 1307 | ||
1307 | /** | 1308 | /** |
1309 | * Handle a channel create requested by a client. | ||
1310 | * | ||
1311 | * Create the channel and the tunnel in case this was the first0 channel. | ||
1312 | * | ||
1313 | * @param c Client that requested the creation (will be the root). | ||
1314 | * @param msg Create Channel message. | ||
1315 | */ | ||
1316 | void | ||
1317 | GMCH_handle_local_create (struct MeshClient *c, | ||
1318 | struct GNUNET_MESH_ChannelMessage *msg) | ||
1319 | { | ||
1320 | struct MeshChannel *ch; | ||
1321 | struct MeshTunnel3 *t; | ||
1322 | struct MeshPeer *peer; | ||
1323 | MESH_ChannelNumber chid; | ||
1324 | |||
1325 | LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", | ||
1326 | GNUNET_i2s (&msg->peer), ntohl (msg->port)); | ||
1327 | chid = ntohl (msg->channel_id); | ||
1328 | |||
1329 | /* Sanity check for duplicate channel IDs */ | ||
1330 | if (NULL != GML_channel_get (c, chid)) | ||
1331 | { | ||
1332 | GNUNET_break (0); | ||
1333 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1334 | return; | ||
1335 | } | ||
1336 | |||
1337 | peer = GMP_get (&msg->peer); | ||
1338 | GMP_add_tunnel (peer); | ||
1339 | t = GMP_get_tunnel(peer); | ||
1340 | |||
1341 | if (GMP_get_short_id(peer) == myid) | ||
1342 | { | ||
1343 | GMT_change_state (t, MESH_TUNNEL3_READY); | ||
1344 | } | ||
1345 | else | ||
1346 | { | ||
1347 | GMP_connect (peer); | ||
1348 | } | ||
1349 | |||
1350 | /* Create channel */ | ||
1351 | ch = channel_new (t, c, chid); | ||
1352 | if (NULL == ch) | ||
1353 | { | ||
1354 | GNUNET_break (0); | ||
1355 | return; | ||
1356 | } | ||
1357 | ch->port = ntohl (msg->port); | ||
1358 | channel_set_options (ch, ntohl (msg->opt)); | ||
1359 | |||
1360 | /* In unreliable channels, we'll use the DLL to buffer BCK data */ | ||
1361 | ch->root_rel = GNUNET_new (struct MeshChannelReliability); | ||
1362 | ch->root_rel->ch = ch; | ||
1363 | ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME; | ||
1364 | |||
1365 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", | ||
1366 | peer2s (t->peer), ch->gid, ch->port, ch->lid_root); | ||
1367 | |||
1368 | /* Send create channel */ | ||
1369 | { | ||
1370 | struct GNUNET_MESH_ChannelCreate msgcc; | ||
1371 | |||
1372 | msgcc.header.size = htons (sizeof (msgcc)); | ||
1373 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); | ||
1374 | msgcc.chid = htonl (ch->gid); | ||
1375 | msgcc.port = msg->port; | ||
1376 | msgcc.opt = msg->opt; | ||
1377 | |||
1378 | GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES); | ||
1379 | } | ||
1380 | } | ||
1381 | |||
1382 | /** | ||
1308 | * Handler for mesh network payload traffic. | 1383 | * Handler for mesh network payload traffic. |
1309 | * | 1384 | * |
1310 | * @param ch Channel for the message. | 1385 | * @param ch Channel for the message. |
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index e8d10255a..09f5fd3f0 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h | |||
@@ -200,6 +200,18 @@ GMCH_handle_local_destroy (struct MeshChannel *ch, | |||
200 | MESH_ChannelNumber chid); | 200 | MESH_ChannelNumber chid); |
201 | 201 | ||
202 | /** | 202 | /** |
203 | * Handle a channel create requested by a client. | ||
204 | * | ||
205 | * Create the channel and the tunnel in case this was the first0 channel. | ||
206 | * | ||
207 | * @param c Client that requested the creation (will be the root). | ||
208 | * @param msg Create Channel message. | ||
209 | */ | ||
210 | void | ||
211 | GMCH_handle_local_create (struct MeshClient *c, | ||
212 | struct GNUNET_MESH_ChannelMessage *msg); | ||
213 | |||
214 | /** | ||
203 | * Handler for mesh network payload traffic. | 215 | * Handler for mesh network payload traffic. |
204 | * | 216 | * |
205 | * @param ch Channel for the message. | 217 | * @param ch Channel for the message. |
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index 6ee23e6e0..b77b7be8d 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c | |||
@@ -328,17 +328,12 @@ static void | |||
328 | handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client, | 328 | handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client, |
329 | const struct GNUNET_MessageHeader *message) | 329 | const struct GNUNET_MessageHeader *message) |
330 | { | 330 | { |
331 | struct GNUNET_MESH_ChannelMessage *msg; | ||
332 | struct MeshPeer *peer; | ||
333 | struct MeshTunnel2 *t; | ||
334 | struct MeshChannel *ch; | ||
335 | struct MeshClient *c; | 331 | struct MeshClient *c; |
336 | MESH_ChannelNumber chid; | ||
337 | 332 | ||
338 | LOG (GNUNET_ERROR_TYPE_DEBUG, "new channel requested\n"); | 333 | LOG (GNUNET_ERROR_TYPE_DEBUG, "new channel requested\n"); |
339 | 334 | ||
340 | /* Sanity check for client registration */ | 335 | /* Sanity check for client registration */ |
341 | if (NULL == (c = client_get (client))) | 336 | if (NULL == (c = GML_client_get (client))) |
342 | { | 337 | { |
343 | GNUNET_break (0); | 338 | GNUNET_break (0); |
344 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 339 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -354,66 +349,7 @@ handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
354 | return; | 349 | return; |
355 | } | 350 | } |
356 | 351 | ||
357 | msg = (struct GNUNET_MESH_ChannelMessage *) message; | 352 | GMCH_handle_local_create (c, (struct GNUNET_MESH_ChannelMessage *) message); |
358 | LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", | ||
359 | GNUNET_i2s (&msg->peer), ntohl (msg->port)); | ||
360 | chid = ntohl (msg->channel_id); | ||
361 | |||
362 | /* Sanity check for duplicate channel IDs */ | ||
363 | if (NULL != channel_get_by_local_id (c, chid)) | ||
364 | { | ||
365 | GNUNET_break (0); | ||
366 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | peer = peer_get (&msg->peer); | ||
371 | if (NULL == peer->tunnel) | ||
372 | { | ||
373 | peer->tunnel = tunnel_new (); | ||
374 | peer->tunnel->peer = peer; | ||
375 | if (peer->id == myid) | ||
376 | { | ||
377 | tunnel_change_state (peer->tunnel, MESH_TUNNEL_READY); | ||
378 | } | ||
379 | else | ||
380 | { | ||
381 | peer_connect (peer); | ||
382 | } | ||
383 | } | ||
384 | t = peer->tunnel; | ||
385 | |||
386 | /* Create channel */ | ||
387 | ch = channel_new (t, c, chid); | ||
388 | if (NULL == ch) | ||
389 | { | ||
390 | GNUNET_break (0); | ||
391 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
392 | return; | ||
393 | } | ||
394 | ch->port = ntohl (msg->port); | ||
395 | channel_set_options (ch, ntohl (msg->opt)); | ||
396 | |||
397 | /* In unreliable channels, we'll use the DLL to buffer BCK data */ | ||
398 | ch->root_rel = GNUNET_new (struct MeshChannelReliability); | ||
399 | ch->root_rel->ch = ch; | ||
400 | ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME; | ||
401 | |||
402 | LOG (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n", | ||
403 | peer2s (t->peer), ch->gid, ch->port, ch->lid_root); | ||
404 | |||
405 | /* Send create channel */ | ||
406 | { | ||
407 | struct GNUNET_MESH_ChannelCreate msgcc; | ||
408 | |||
409 | msgcc.header.size = htons (sizeof (msgcc)); | ||
410 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE); | ||
411 | msgcc.chid = htonl (ch->gid); | ||
412 | msgcc.port = msg->port; | ||
413 | msgcc.opt = msg->opt; | ||
414 | |||
415 | GMT_queue_data (t, ch, &msgcc.header, GNUNET_YES); | ||
416 | } | ||
417 | 353 | ||
418 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 354 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
419 | return; | 355 | return; |
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index bdc2fdd02..70b88afe3 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c | |||
@@ -1617,6 +1617,20 @@ GMP_get_short_id (const struct MeshPeer *peer) | |||
1617 | 1617 | ||
1618 | 1618 | ||
1619 | /** | 1619 | /** |
1620 | * Get the tunnel towards a peer. | ||
1621 | * | ||
1622 | * @param peer Peer to get from. | ||
1623 | * | ||
1624 | * @return Tunnel towards peer. | ||
1625 | */ | ||
1626 | struct MeshTunnel3 * | ||
1627 | GMP_get_tunnel (const struct MeshPeer *peer) | ||
1628 | { | ||
1629 | return peer->tunnel; | ||
1630 | } | ||
1631 | |||
1632 | |||
1633 | /** | ||
1620 | * Get the static string for a peer ID. | 1634 | * Get the static string for a peer ID. |
1621 | * | 1635 | * |
1622 | * @param peer Peer. | 1636 | * @param peer Peer. |
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index 57eb1c61d..97f928bfd 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h | |||
@@ -264,6 +264,16 @@ GNUNET_PEER_Id | |||
264 | GMP_get_short_id (const struct MeshPeer *peer); | 264 | GMP_get_short_id (const struct MeshPeer *peer); |
265 | 265 | ||
266 | /** | 266 | /** |
267 | * Get the tunnel towards a peer. | ||
268 | * | ||
269 | * @param peer Peer to get from. | ||
270 | * | ||
271 | * @return Tunnel towards peer. | ||
272 | */ | ||
273 | struct MeshTunnel3 * | ||
274 | GMP_get_tunnel (const struct MeshPeer *peer); | ||
275 | |||
276 | /** | ||
267 | * Get the static string for a peer ID. | 277 | * Get the static string for a peer ID. |
268 | * | 278 | * |
269 | * @param peer Peer. | 279 | * @param peer Peer. |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 8b8085658..a8cb883f6 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -611,7 +611,6 @@ GMT_new (struct MeshPeer *destination) | |||
611 | } | 611 | } |
612 | 612 | ||
613 | 613 | ||
614 | |||
615 | /** | 614 | /** |
616 | * Change the tunnel state. | 615 | * Change the tunnel state. |
617 | * | 616 | * |