diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-04 15:08:12 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-04 15:08:12 +0000 |
commit | 32c6b50f5c00042069e563ca238080ac4b6f309e (patch) | |
tree | e2dc4226df6446fce55e8e5babcab51ffc0fa310 /src/mesh/gnunet-service-mesh_connection.c | |
parent | ed9c614f78b9a53d1c0a928a47e6f07f8470adfa (diff) | |
download | gnunet-32c6b50f5c00042069e563ca238080ac4b6f309e.tar.gz gnunet-32c6b50f5c00042069e563ca238080ac4b6f309e.zip |
- sync
Diffstat (limited to 'src/mesh/gnunet-service-mesh_connection.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index b4bb8b279..dfe4fa953 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | #include "gnunet-service-mesh_connection.h" | 32 | #include "gnunet-service-mesh_connection.h" |
33 | #include "gnunet-service-mesh_peer.h" | 33 | #include "gnunet-service-mesh_peer.h" |
34 | #include "gnunet-service-mesh_local.h" | ||
34 | #include "mesh_protocol_enc.h" | 35 | #include "mesh_protocol_enc.h" |
35 | #include "mesh_path.h" | 36 | #include "mesh_path.h" |
36 | 37 | ||
@@ -286,6 +287,34 @@ static struct GNUNET_TIME_Relative refresh_connection_time; | |||
286 | static struct GNUNET_CORE_Handle *core_handle; | 287 | static struct GNUNET_CORE_Handle *core_handle; |
287 | 288 | ||
288 | 289 | ||
290 | |||
291 | /** | ||
292 | * Get string description for tunnel state. | ||
293 | * | ||
294 | * @param s Tunnel state. | ||
295 | * | ||
296 | * @return String representation. | ||
297 | */ | ||
298 | static const char * | ||
299 | GMC_DEBUG_state2s (enum MeshTunnelState s) | ||
300 | { | ||
301 | switch (s) | ||
302 | { | ||
303 | case MESH_CONNECTION_NEW: | ||
304 | return "MESH_CONNECTION_NEW"; | ||
305 | case MESH_CONNECTION_SENT: | ||
306 | return "MESH_CONNECTION_SENT"; | ||
307 | case MESH_CONNECTION_ACK: | ||
308 | return "MESH_CONNECTION_ACK"; | ||
309 | case MESH_CONNECTION_READY: | ||
310 | return "MESH_CONNECTION_READY"; | ||
311 | default: | ||
312 | return "MESH_CONNECTION_STATE_ERROR"; | ||
313 | } | ||
314 | } | ||
315 | |||
316 | |||
317 | |||
289 | /** | 318 | /** |
290 | * Initialize a Flow Control structure to the initial state. | 319 | * Initialize a Flow Control structure to the initial state. |
291 | * | 320 | * |
@@ -1483,6 +1512,130 @@ connection_reset_timeout (struct MeshConnection *c, int fwd) | |||
1483 | 1512 | ||
1484 | 1513 | ||
1485 | 1514 | ||
1515 | |||
1516 | |||
1517 | /** | ||
1518 | * Method called whenever a given peer connects. | ||
1519 | * | ||
1520 | * @param cls closure | ||
1521 | * @param peer peer identity this notification is about | ||
1522 | */ | ||
1523 | static void | ||
1524 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
1525 | { | ||
1526 | struct MeshPeer *pi; | ||
1527 | struct MeshPeerPath *path; | ||
1528 | |||
1529 | DEBUG_CONN ("Peer connected\n"); | ||
1530 | DEBUG_CONN (" %s\n", GNUNET_i2s (&my_full_id)); | ||
1531 | pi = peer_get (peer); | ||
1532 | if (myid == pi->id) | ||
1533 | { | ||
1534 | DEBUG_CONN (" (self)\n"); | ||
1535 | path = path_new (1); | ||
1536 | } | ||
1537 | else | ||
1538 | { | ||
1539 | DEBUG_CONN (" %s\n", GNUNET_i2s (peer)); | ||
1540 | path = path_new (2); | ||
1541 | path->peers[1] = pi->id; | ||
1542 | GNUNET_PEER_change_rc (pi->id, 1); | ||
1543 | GNUNET_STATISTICS_update (stats, "# peers", 1, GNUNET_NO); | ||
1544 | } | ||
1545 | path->peers[0] = myid; | ||
1546 | GNUNET_PEER_change_rc (myid, 1); | ||
1547 | peer_add_path (pi, path, GNUNET_YES); | ||
1548 | |||
1549 | pi->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); | ||
1550 | return; | ||
1551 | } | ||
1552 | |||
1553 | |||
1554 | /** | ||
1555 | * Method called whenever a peer disconnects. | ||
1556 | * | ||
1557 | * @param cls closure | ||
1558 | * @param peer peer identity this notification is about | ||
1559 | */ | ||
1560 | static void | ||
1561 | core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
1562 | { | ||
1563 | struct MeshPeer *pi; | ||
1564 | |||
1565 | DEBUG_CONN ("Peer disconnected\n"); | ||
1566 | pi = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
1567 | if (NULL == pi) | ||
1568 | { | ||
1569 | GNUNET_break (0); | ||
1570 | return; | ||
1571 | } | ||
1572 | |||
1573 | GNUNET_CONTAINER_multihashmap_iterate (pi->connections, | ||
1574 | GMC_notify_broken, | ||
1575 | pi); | ||
1576 | GNUNET_CONTAINER_multihashmap_destroy (pi->connections); | ||
1577 | pi->connections = NULL; | ||
1578 | if (NULL != pi->core_transmit) | ||
1579 | { | ||
1580 | GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit); | ||
1581 | pi->core_transmit = NULL; | ||
1582 | } | ||
1583 | if (myid == pi->id) | ||
1584 | { | ||
1585 | DEBUG_CONN (" (self)\n"); | ||
1586 | } | ||
1587 | GNUNET_STATISTICS_update (stats, "# peers", -1, GNUNET_NO); | ||
1588 | |||
1589 | return; | ||
1590 | } | ||
1591 | |||
1592 | |||
1593 | |||
1594 | /** | ||
1595 | * To be called on core init/fail. | ||
1596 | * | ||
1597 | * @param cls Closure (config) | ||
1598 | * @param identity the public identity of this peer | ||
1599 | */ | ||
1600 | static void | ||
1601 | core_init (void *cls, | ||
1602 | const struct GNUNET_PeerIdentity *identity) | ||
1603 | { | ||
1604 | const struct GNUNET_CONFIGURATION_Handle *c = cls; | ||
1605 | static int i = 0; | ||
1606 | |||
1607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n"); | ||
1608 | if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id))) | ||
1609 | { | ||
1610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n")); | ||
1611 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1612 | " core id %s\n", | ||
1613 | GNUNET_i2s (identity)); | ||
1614 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1615 | " my id %s\n", | ||
1616 | GNUNET_i2s (&my_full_id)); | ||
1617 | GNUNET_CORE_disconnect (core_handle); | ||
1618 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | ||
1619 | NULL, /* Closure passed to MESH functions */ | ||
1620 | &core_init, /* Call core_init once connected */ | ||
1621 | &core_connect, /* Handle connects */ | ||
1622 | &core_disconnect, /* remove peers on disconnects */ | ||
1623 | NULL, /* Don't notify about all incoming messages */ | ||
1624 | GNUNET_NO, /* For header only in notification */ | ||
1625 | NULL, /* Don't notify about all outbound messages */ | ||
1626 | GNUNET_NO, /* For header-only out notification */ | ||
1627 | core_handlers); /* Register these handlers */ | ||
1628 | if (10 < i++) | ||
1629 | GNUNET_abort(); | ||
1630 | } | ||
1631 | GML_start (); | ||
1632 | return; | ||
1633 | } | ||
1634 | |||
1635 | |||
1636 | |||
1637 | |||
1638 | |||
1486 | /** | 1639 | /** |
1487 | * Core handler for connection creation. | 1640 | * Core handler for connection creation. |
1488 | * | 1641 | * |