diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-24 16:42:44 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-24 16:42:44 +0000 |
commit | 8ce2f3cca8c7d75db63f6e761e6747384249b5e7 (patch) | |
tree | 06c360f457e458249500033a43a48696cd3d3479 /src | |
parent | b80b3f490c8ebd76c4874bf612f0e7d41f296ea2 (diff) | |
download | gnunet-8ce2f3cca8c7d75db63f6e761e6747384249b5e7.tar.gz gnunet-8ce2f3cca8c7d75db63f6e761e6747384249b5e7.zip |
Added connection broken p2p notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 130 | ||||
-rw-r--r-- | src/mesh/mesh_protocol.h | 36 |
2 files changed, 138 insertions, 28 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index d8b41e6ea..cbe369cdf 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -718,6 +718,23 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid); | |||
718 | 718 | ||
719 | 719 | ||
720 | /** | 720 | /** |
721 | * Notify a tunnel that a connection has broken that affects at least | ||
722 | * some of its peers. | ||
723 | * | ||
724 | * @param t Tunnel affected. | ||
725 | * @param p1 Peer that got disconnected from p2. | ||
726 | * @param p2 Peer that got disconnected from p1. | ||
727 | * | ||
728 | * @return Short ID of the peer disconnected (either p1 or p2). | ||
729 | * 0 if the tunnel remained unaffected. | ||
730 | */ | ||
731 | static GNUNET_PEER_Id | ||
732 | tunnel_notify_connection_broken (struct MeshTunnel *t, | ||
733 | GNUNET_PEER_Id p1, | ||
734 | GNUNET_PEER_Id p2); | ||
735 | |||
736 | |||
737 | /** | ||
721 | * Send the message to all clients that have subscribed to its type | 738 | * Send the message to all clients that have subscribed to its type |
722 | * | 739 | * |
723 | * @param msg Pointer to the message itself | 740 | * @param msg Pointer to the message itself |
@@ -1309,24 +1326,6 @@ peer_info_destroy (struct MeshPeerInfo *pi) | |||
1309 | 1326 | ||
1310 | 1327 | ||
1311 | /** | 1328 | /** |
1312 | * Notify a tunnel that a connection has broken that affects at least | ||
1313 | * some of its peers. | ||
1314 | * | ||
1315 | * @param t Tunnel affected. | ||
1316 | * @param peer Peer that (at least) has been affected by the disconnection. | ||
1317 | * @param p1 Peer that got disconnected from p2. | ||
1318 | * @param p2 Peer that got disconnected from p1. | ||
1319 | * | ||
1320 | * @return Short ID of the peer disconnected (either p1 or p2). | ||
1321 | * 0 if the tunnel remained unaffected. | ||
1322 | */ | ||
1323 | static GNUNET_PEER_Id | ||
1324 | tunnel_notify_connection_broken (struct MeshTunnel *t, | ||
1325 | struct MeshPeerInfo *peer, GNUNET_PEER_Id p1, | ||
1326 | GNUNET_PEER_Id p2); | ||
1327 | |||
1328 | |||
1329 | /** | ||
1330 | * Remove all paths that rely on a direct connection between p1 and p2 | 1329 | * Remove all paths that rely on a direct connection between p1 and p2 |
1331 | * from the peer itself and notify all tunnels about it. | 1330 | * from the peer itself and notify all tunnels about it. |
1332 | * | 1331 | * |
@@ -1374,7 +1373,7 @@ path_remove_from_peer (struct MeshPeerInfo *peer, | |||
1374 | 1373 | ||
1375 | for (i = 0; i < peer->ntunnels; i++) | 1374 | for (i = 0; i < peer->ntunnels; i++) |
1376 | { | 1375 | { |
1377 | d = tunnel_notify_connection_broken (peer->tunnels[i], peer, p1, p2); | 1376 | d = tunnel_notify_connection_broken (peer->tunnels[i], p1, p2); |
1378 | /* TODO | 1377 | /* TODO |
1379 | * Problem: one or more peers have been deleted from the tunnel tree. | 1378 | * Problem: one or more peers have been deleted from the tunnel tree. |
1380 | * We don't know who they are to try to add them again. | 1379 | * We don't know who they are to try to add them again. |
@@ -1650,6 +1649,8 @@ tunnel_get (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | |||
1650 | * disconnected, most likely because of a path change. | 1649 | * disconnected, most likely because of a path change. |
1651 | * | 1650 | * |
1652 | * @param n Node in the tree representing the disconnected peer | 1651 | * @param n Node in the tree representing the disconnected peer |
1652 | * | ||
1653 | * FIXME: pass tunnel via cls, make param just a peer identity | ||
1653 | */ | 1654 | */ |
1654 | void | 1655 | void |
1655 | notify_peer_disconnected (const struct MeshTunnelTreeNode *n) | 1656 | notify_peer_disconnected (const struct MeshTunnelTreeNode *n) |
@@ -1757,11 +1758,12 @@ tunnel_add_path (struct MeshTunnel *t, | |||
1757 | 1758 | ||
1758 | 1759 | ||
1759 | /** | 1760 | /** |
1760 | * Notify a tunnel that a connection has broken that affects at least | 1761 | * Notifies a tunnel that a connection has broken that affects at least |
1761 | * some of its peers. | 1762 | * some of its peers. Sends a notification towards the root of the tree. |
1763 | * In case the peer is the owner of the tree, notifies the client that owns | ||
1764 | * the tunnel and tries to reconnect. | ||
1762 | * | 1765 | * |
1763 | * @param t Tunnel affected. | 1766 | * @param t Tunnel affected. |
1764 | * @param peer Peer that (at least) has been affected by the disconnection. | ||
1765 | * @param p1 Peer that got disconnected from p2. | 1767 | * @param p1 Peer that got disconnected from p2. |
1766 | * @param p2 Peer that got disconnected from p1. | 1768 | * @param p2 Peer that got disconnected from p1. |
1767 | * | 1769 | * |
@@ -1770,12 +1772,38 @@ tunnel_add_path (struct MeshTunnel *t, | |||
1770 | */ | 1772 | */ |
1771 | static GNUNET_PEER_Id | 1773 | static GNUNET_PEER_Id |
1772 | tunnel_notify_connection_broken (struct MeshTunnel *t, | 1774 | tunnel_notify_connection_broken (struct MeshTunnel *t, |
1773 | struct MeshPeerInfo *peer, | ||
1774 | GNUNET_PEER_Id p1, | 1775 | GNUNET_PEER_Id p1, |
1775 | GNUNET_PEER_Id p2) | 1776 | GNUNET_PEER_Id p2) |
1776 | { | 1777 | { |
1777 | return tree_notify_connection_broken (t->tree, p1, p2, | 1778 | GNUNET_PEER_Id pid; |
1778 | ¬ify_peer_disconnected); | 1779 | |
1780 | pid = tree_notify_connection_broken (t->tree, | ||
1781 | p1, | ||
1782 | p2, | ||
1783 | ¬ify_peer_disconnected); | ||
1784 | if (myid != p1 && myid != p2) | ||
1785 | { | ||
1786 | return pid; | ||
1787 | } | ||
1788 | if (pid != myid) | ||
1789 | { | ||
1790 | if (NULL != t->tree->me->parent) | ||
1791 | { | ||
1792 | /* We are the peer still connected, notify owner of the disconnection. */ | ||
1793 | struct GNUNET_MESH_PathBroken msg; | ||
1794 | struct GNUNET_PeerIdentity neighbor; | ||
1795 | |||
1796 | msg.header.size = htons (sizeof (msg)); | ||
1797 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN); | ||
1798 | GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
1799 | msg.tid = htonl (t->id.tid); | ||
1800 | msg.peer1 = my_full_id; | ||
1801 | GNUNET_PEER_resolve (pid, &msg.peer2); | ||
1802 | GNUNET_PEER_resolve (t->tree->me->parent->peer, &neighbor); | ||
1803 | send_message (&msg.header, &neighbor); | ||
1804 | } | ||
1805 | } | ||
1806 | return pid; | ||
1779 | } | 1807 | } |
1780 | 1808 | ||
1781 | 1809 | ||
@@ -2545,6 +2573,51 @@ handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2545 | 2573 | ||
2546 | 2574 | ||
2547 | /** | 2575 | /** |
2576 | * Core handler for notifications of broken paths | ||
2577 | * | ||
2578 | * @param cls closure | ||
2579 | * @param message message | ||
2580 | * @param peer peer identity this notification is about | ||
2581 | * @param atsi performance data | ||
2582 | * @param atsi_count number of records in 'atsi' | ||
2583 | * | ||
2584 | * @return GNUNET_OK to keep the connection open, | ||
2585 | * GNUNET_SYSERR to close it (signal serious error) | ||
2586 | */ | ||
2587 | static int | ||
2588 | handle_mesh_path_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
2589 | const struct GNUNET_MessageHeader *message, | ||
2590 | const struct GNUNET_ATS_Information *atsi, | ||
2591 | unsigned int atsi_count) | ||
2592 | { | ||
2593 | struct GNUNET_MESH_PathBroken *msg; | ||
2594 | struct MeshTunnel *t; | ||
2595 | |||
2596 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2597 | "MESH: Received a PATH BROKEN msg from %s\n", | ||
2598 | GNUNET_i2s(peer)); | ||
2599 | msg = (struct GNUNET_MESH_PathBroken *) message; | ||
2600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2601 | "MESH: regarding %s\n", | ||
2602 | GNUNET_i2s(&msg->peer1)); | ||
2603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2604 | "MESH: regarding %s\n", | ||
2605 | GNUNET_i2s(&msg->peer2)); | ||
2606 | t = tunnel_get(&msg->oid, ntohl (msg->tid)); | ||
2607 | if (NULL == t) | ||
2608 | { | ||
2609 | GNUNET_break_op (0); | ||
2610 | return GNUNET_OK; | ||
2611 | } | ||
2612 | tunnel_notify_connection_broken(t, | ||
2613 | GNUNET_PEER_search(&msg->peer1), | ||
2614 | GNUNET_PEER_search(&msg->peer2)); | ||
2615 | return GNUNET_OK; | ||
2616 | |||
2617 | } | ||
2618 | |||
2619 | |||
2620 | /** | ||
2548 | * Core handler for tunnel destruction | 2621 | * Core handler for tunnel destruction |
2549 | * | 2622 | * |
2550 | * @param cls closure | 2623 | * @param cls closure |
@@ -2882,12 +2955,14 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2882 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 2955 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { |
2883 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, | 2956 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, |
2884 | {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, | 2957 | {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, |
2958 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, | ||
2959 | sizeof (struct GNUNET_MESH_PathBroken)}, | ||
2885 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, | 2960 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 0}, |
2886 | {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, | 2961 | {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, |
2887 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, | 2962 | {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, |
2888 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, | 2963 | {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, |
2889 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, | 2964 | {&handle_mesh_path_ack, GNUNET_MESSAGE_TYPE_MESH_PATH_ACK, |
2890 | sizeof (struct GNUNET_MESH_PathACK)}, | 2965 | sizeof (struct GNUNET_MESH_PathACK)}, |
2891 | {NULL, 0, 0} | 2966 | {NULL, 0, 0} |
2892 | }; | 2967 | }; |
2893 | 2968 | ||
@@ -3981,7 +4056,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
3981 | static void | 4056 | static void |
3982 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 4057 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
3983 | const struct GNUNET_ATS_Information *atsi, | 4058 | const struct GNUNET_ATS_Information *atsi, |
3984 | unsigned int atsi_count) | 4059 | unsigned int atsi_count) |
3985 | { | 4060 | { |
3986 | struct MeshPeerInfo *peer_info; | 4061 | struct MeshPeerInfo *peer_info; |
3987 | struct MeshPeerPath *path; | 4062 | struct MeshPeerPath *path; |
@@ -4038,6 +4113,7 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
4038 | } | 4113 | } |
4039 | for (i = 0; i < CORE_QUEUE_SIZE; i++) | 4114 | for (i = 0; i < CORE_QUEUE_SIZE; i++) |
4040 | { | 4115 | { |
4116 | /* TODO: notify that the transmission failed */ | ||
4041 | peer_info_cancel_transmission(pi, i); | 4117 | peer_info_cancel_transmission(pi, i); |
4042 | } | 4118 | } |
4043 | path_remove_from_peer (pi, pi->id, myid); | 4119 | path_remove_from_peer (pi, pi->id, myid); |
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index d7e28af45..e16f32093 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h | |||
@@ -159,7 +159,7 @@ struct GNUNET_MESH_ToOrigin | |||
159 | struct GNUNET_MESH_PathACK | 159 | struct GNUNET_MESH_PathACK |
160 | { | 160 | { |
161 | /** | 161 | /** |
162 | * Type: GNUNET_MESSAGE_TYPE_PATH_ACK | 162 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_ACK |
163 | */ | 163 | */ |
164 | struct GNUNET_MessageHeader header; | 164 | struct GNUNET_MessageHeader header; |
165 | 165 | ||
@@ -183,6 +183,40 @@ struct GNUNET_MESH_PathACK | |||
183 | 183 | ||
184 | 184 | ||
185 | /** | 185 | /** |
186 | * Message for notifying a disconnection in a path | ||
187 | */ | ||
188 | struct GNUNET_MESH_PathBroken | ||
189 | { | ||
190 | /** | ||
191 | * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN | ||
192 | */ | ||
193 | struct GNUNET_MessageHeader header; | ||
194 | |||
195 | /** | ||
196 | * TID of the tunnel | ||
197 | */ | ||
198 | uint32_t tid GNUNET_PACKED; | ||
199 | |||
200 | /** | ||
201 | * OID of the tunnel | ||
202 | */ | ||
203 | struct GNUNET_PeerIdentity oid; | ||
204 | |||
205 | /** | ||
206 | * ID of the endpoint | ||
207 | */ | ||
208 | struct GNUNET_PeerIdentity peer1; | ||
209 | |||
210 | /** | ||
211 | * ID of the endpoint | ||
212 | */ | ||
213 | struct GNUNET_PeerIdentity peer2; | ||
214 | |||
215 | /* TODO: signature */ | ||
216 | }; | ||
217 | |||
218 | |||
219 | /** | ||
186 | * Message to destroy a tunnel | 220 | * Message to destroy a tunnel |
187 | */ | 221 | */ |
188 | struct GNUNET_MESH_TunnelDestroy | 222 | struct GNUNET_MESH_TunnelDestroy |