diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-10-11 13:30:43 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-10-11 13:30:43 +0000 |
commit | 9a50e92d4a43f917b0cd1ed34d4932470cb3a3da (patch) | |
tree | fe5abe83a5f4fc15ede27eb5e13cd5702fcfadb3 /src/mesh | |
parent | b3a8bef570a61d01694bb68ad52a5e4e8b585c0f (diff) | |
download | gnunet-9a50e92d4a43f917b0cd1ed34d4932470cb3a3da.tar.gz gnunet-9a50e92d4a43f917b0cd1ed34d4932470cb3a3da.zip |
- fix "broken connection" notifications
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 109 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.h | 11 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_peer.c | 2 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 42 |
4 files changed, 92 insertions, 72 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 525bca61a..369704171 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -217,6 +217,11 @@ extern struct GNUNET_STATISTICS_Handle *stats; | |||
217 | extern GNUNET_PEER_Id myid; | 217 | extern GNUNET_PEER_Id myid; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * Local peer own ID (full value). | ||
221 | */ | ||
222 | extern struct GNUNET_PeerIdentity my_full_id; | ||
223 | |||
224 | /** | ||
220 | * Connections known, indexed by cid (MeshConnection). | 225 | * Connections known, indexed by cid (MeshConnection). |
221 | */ | 226 | */ |
222 | static struct GNUNET_CONTAINER_MultiHashMap *connections; | 227 | static struct GNUNET_CONTAINER_MultiHashMap *connections; |
@@ -1157,24 +1162,53 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1157 | 1162 | ||
1158 | 1163 | ||
1159 | /** | 1164 | /** |
1165 | * Is traffic coming from this sender 'FWD' traffic? | ||
1166 | * | ||
1167 | * @param c Connection to check. | ||
1168 | * @param sender Peer identity of neighbor. | ||
1169 | * | ||
1170 | * @return GNUNET_YES in case the sender is the 'prev' hop and therefore | ||
1171 | * the traffic is 'FWD'. GNUNET_NO for BCK. GNUNET_SYSERR for errors. | ||
1172 | */ | ||
1173 | int | ||
1174 | is_fwd (const struct MeshConnection *c, | ||
1175 | const struct GNUNET_PeerIdentity *sender) | ||
1176 | { | ||
1177 | GNUNET_PEER_Id id; | ||
1178 | |||
1179 | id = GNUNET_PEER_search (sender); | ||
1180 | if (GMP_get_short_id (get_prev_hop (c)) == id) | ||
1181 | return GNUNET_YES; | ||
1182 | |||
1183 | if (GMP_get_short_id (get_next_hop (c)) == id) | ||
1184 | return GNUNET_NO; | ||
1185 | |||
1186 | GNUNET_break (0); | ||
1187 | return GNUNET_SYSERR; | ||
1188 | } | ||
1189 | |||
1190 | |||
1191 | /** | ||
1160 | * Core handler for notifications of broken paths | 1192 | * Core handler for notifications of broken paths |
1161 | * | 1193 | * |
1162 | * @param cls Closure (unused). | 1194 | * @param cls Closure (unused). |
1163 | * @param peer Peer identity of sending neighbor. | 1195 | * @param id Peer identity of sending neighbor. |
1164 | * @param message Message. | 1196 | * @param message Message. |
1165 | * | 1197 | * |
1166 | * @return GNUNET_OK to keep the connection open, | 1198 | * @return GNUNET_OK to keep the connection open, |
1167 | * GNUNET_SYSERR to close it (signal serious error) | 1199 | * GNUNET_SYSERR to close it (signal serious error) |
1168 | */ | 1200 | */ |
1169 | int | 1201 | int |
1170 | GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | 1202 | GMC_handle_broken (void* cls, |
1171 | const struct GNUNET_MessageHeader *message) | 1203 | const struct GNUNET_PeerIdentity* id, |
1204 | const struct GNUNET_MessageHeader* message) | ||
1172 | { | 1205 | { |
1173 | struct GNUNET_MESH_ConnectionBroken *msg; | 1206 | struct GNUNET_MESH_ConnectionBroken *msg; |
1174 | struct MeshConnection *c; | 1207 | struct MeshConnection *c; |
1208 | int fwd; | ||
1175 | 1209 | ||
1176 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1210 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1177 | "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (peer)); | 1211 | "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (id)); |
1178 | msg = (struct GNUNET_MESH_ConnectionBroken *) message; | 1212 | msg = (struct GNUNET_MESH_ConnectionBroken *) message; |
1179 | LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n", | 1213 | LOG (GNUNET_ERROR_TYPE_DEBUG, " regarding %s\n", |
1180 | GNUNET_i2s (&msg->peer1)); | 1214 | GNUNET_i2s (&msg->peer1)); |
@@ -1186,8 +1220,22 @@ GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1186 | GNUNET_break_op (0); | 1220 | GNUNET_break_op (0); |
1187 | return GNUNET_OK; | 1221 | return GNUNET_OK; |
1188 | } | 1222 | } |
1189 | tunnel_notify_connection_broken (c->t, GNUNET_PEER_search (&msg->peer1), | 1223 | |
1190 | GNUNET_PEER_search (&msg->peer2)); | 1224 | fwd = is_fwd (c, id); |
1225 | connection_cancel_queues (c, !fwd); | ||
1226 | if (GMC_is_terminal (c, fwd)) | ||
1227 | { | ||
1228 | if (0 < c->pending_messages) | ||
1229 | c->destroy = GNUNET_YES; | ||
1230 | else | ||
1231 | GMC_destroy (c); | ||
1232 | } | ||
1233 | else | ||
1234 | { | ||
1235 | GMC_send_prebuilt_message (message, c, NULL, fwd); | ||
1236 | c->destroy = GNUNET_YES; | ||
1237 | } | ||
1238 | |||
1191 | return GNUNET_OK; | 1239 | return GNUNET_OK; |
1192 | 1240 | ||
1193 | } | 1241 | } |
@@ -1209,7 +1257,6 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1209 | { | 1257 | { |
1210 | struct GNUNET_MESH_ConnectionDestroy *msg; | 1258 | struct GNUNET_MESH_ConnectionDestroy *msg; |
1211 | struct MeshConnection *c; | 1259 | struct MeshConnection *c; |
1212 | GNUNET_PEER_Id id; | ||
1213 | int fwd; | 1260 | int fwd; |
1214 | 1261 | ||
1215 | msg = (struct GNUNET_MESH_ConnectionDestroy *) message; | 1262 | msg = (struct GNUNET_MESH_ConnectionDestroy *) message; |
@@ -1230,12 +1277,8 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1230 | 1, GNUNET_NO); | 1277 | 1, GNUNET_NO); |
1231 | return GNUNET_OK; | 1278 | return GNUNET_OK; |
1232 | } | 1279 | } |
1233 | id = GNUNET_PEER_search (peer); | 1280 | fwd = is_fwd (c, peer); |
1234 | if (id == GMP_get_short_id (get_prev_hop (c))) | 1281 | if (GNUNET_SYSERR == fwd) |
1235 | fwd = GNUNET_YES; | ||
1236 | else if (id == GMP_get_short_id (get_next_hop (c))) | ||
1237 | fwd = GNUNET_NO; | ||
1238 | else | ||
1239 | { | 1282 | { |
1240 | GNUNET_break_op (0); | 1283 | GNUNET_break_op (0); |
1241 | return GNUNET_OK; | 1284 | return GNUNET_OK; |
@@ -1875,19 +1918,40 @@ GMC_get_qn (struct MeshConnection *c, int fwd) | |||
1875 | 1918 | ||
1876 | 1919 | ||
1877 | /** | 1920 | /** |
1921 | * Send a notification that a connection is broken. | ||
1922 | * | ||
1923 | * @param c Connection that is broken. | ||
1924 | * @param id1 Peer that has disconnected. | ||
1925 | * @param id2 Peer that has disconnected. | ||
1926 | * @param fwd Direction towards which to send it. | ||
1927 | */ | ||
1928 | static void | ||
1929 | send_broken (struct MeshConnection *c, | ||
1930 | const struct GNUNET_PeerIdentity *id1, | ||
1931 | const struct GNUNET_PeerIdentity *id2, | ||
1932 | int fwd) | ||
1933 | { | ||
1934 | struct GNUNET_MESH_ConnectionBroken msg; | ||
1935 | |||
1936 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); | ||
1937 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN); | ||
1938 | msg.cid = c->id; | ||
1939 | msg.peer1 = *id1; | ||
1940 | msg.peer2 = *id2; | ||
1941 | GMC_send_prebuilt_message (&msg.header, c, NULL, fwd); | ||
1942 | } | ||
1943 | |||
1944 | /** | ||
1878 | * Notify other peers on a connection of a broken link. Mark connections | 1945 | * Notify other peers on a connection of a broken link. Mark connections |
1879 | * to destroy after all traffic has been sent. | 1946 | * to destroy after all traffic has been sent. |
1880 | * | 1947 | * |
1881 | * @param c Connection on which there has been a disconnection. | 1948 | * @param c Connection on which there has been a disconnection. |
1882 | * @param peer Peer that disconnected. | 1949 | * @param peer Peer that disconnected. |
1883 | * @param my_full_id My ID (to send to other peers). | ||
1884 | */ | 1950 | */ |
1885 | void | 1951 | void |
1886 | GMC_notify_broken (struct MeshConnection *c, | 1952 | GMC_notify_broken (struct MeshConnection *c, |
1887 | struct MeshPeer *peer, | 1953 | struct MeshPeer *peer) |
1888 | struct GNUNET_PeerIdentity *my_full_id) | ||
1889 | { | 1954 | { |
1890 | struct GNUNET_MESH_ConnectionBroken msg; | ||
1891 | int fwd; | 1955 | int fwd; |
1892 | 1956 | ||
1893 | fwd = peer == get_prev_hop (c); | 1957 | fwd = peer == get_prev_hop (c); |
@@ -1900,12 +1964,11 @@ GMC_notify_broken (struct MeshConnection *c, | |||
1900 | return; | 1964 | return; |
1901 | } | 1965 | } |
1902 | 1966 | ||
1903 | msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken)); | 1967 | send_broken (c, &my_full_id, GMP_get_id (peer), fwd); |
1904 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN); | 1968 | |
1905 | msg.cid = c->id; | 1969 | /* Connection will have at least one pending message |
1906 | msg.peer1 = *my_full_id; | 1970 | * (the one we just scheduled), so no point in checking whether to |
1907 | msg.peer2 = *GMP_get_id (peer); | 1971 | * destroy immediately. */ |
1908 | GMC_send_prebuilt_message (&msg.header, c, NULL, fwd); | ||
1909 | c->destroy = GNUNET_YES; | 1972 | c->destroy = GNUNET_YES; |
1910 | 1973 | ||
1911 | return; | 1974 | return; |
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index 9e9dec512..b55d55fe6 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h | |||
@@ -110,15 +110,16 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
110 | * Core handler for notifications of broken paths | 110 | * Core handler for notifications of broken paths |
111 | * | 111 | * |
112 | * @param cls Closure (unused). | 112 | * @param cls Closure (unused). |
113 | * @param peer Peer identity of sending neighbor. | 113 | * @param id Peer identity of sending neighbor. |
114 | * @param message Message. | 114 | * @param message Message. |
115 | * | 115 | * |
116 | * @return GNUNET_OK to keep the connection open, | 116 | * @return GNUNET_OK to keep the connection open, |
117 | * GNUNET_SYSERR to close it (signal serious error) | 117 | * GNUNET_SYSERR to close it (signal serious error) |
118 | */ | 118 | */ |
119 | int | 119 | int |
120 | GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer, | 120 | GMC_handle_broken (void* cls, |
121 | const struct GNUNET_MessageHeader *message); | 121 | const struct GNUNET_PeerIdentity* id, |
122 | const struct GNUNET_MessageHeader* message); | ||
122 | 123 | ||
123 | /** | 124 | /** |
124 | * Core handler for tunnel destruction | 125 | * Core handler for tunnel destruction |
@@ -340,12 +341,10 @@ GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
340 | * | 341 | * |
341 | * @param c Connection on which there has been a disconnection. | 342 | * @param c Connection on which there has been a disconnection. |
342 | * @param peer Peer that disconnected. | 343 | * @param peer Peer that disconnected. |
343 | * @param my_full_id My ID (to send to other peers). | ||
344 | */ | 344 | */ |
345 | void | 345 | void |
346 | GMC_notify_broken (struct MeshConnection *c, | 346 | GMC_notify_broken (struct MeshConnection *c, |
347 | struct MeshPeer *peer, | 347 | struct MeshPeer *peer); |
348 | struct GNUNET_PeerIdentity *my_full_id); | ||
349 | 348 | ||
350 | /** | 349 | /** |
351 | * Is this peer the first one on the connection? | 350 | * Is this peer the first one on the connection? |
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 3a38fc40a..75c34c55a 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c | |||
@@ -232,7 +232,7 @@ notify_broken (void *cls, | |||
232 | struct MeshPeer *peer = cls; | 232 | struct MeshPeer *peer = cls; |
233 | struct MeshConnection *c = value; | 233 | struct MeshConnection *c = value; |
234 | 234 | ||
235 | GMC_notify_broken (c, peer, &my_full_id); | 235 | GMC_notify_broken (c, peer); |
236 | 236 | ||
237 | return GNUNET_YES; | 237 | return GNUNET_YES; |
238 | } | 238 | } |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index e117a9481..634a4d7f1 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -827,48 +827,6 @@ GMT_destroy (struct MeshTunnel3 *t) | |||
827 | 827 | ||
828 | 828 | ||
829 | /** | 829 | /** |
830 | * Notifies a tunnel that a connection has broken that affects at least | ||
831 | * some of its peers. Sends a notification towards the root of the tree. | ||
832 | * In case the peer is the owner of the tree, notifies the client that owns | ||
833 | * the tunnel and tries to reconnect. | ||
834 | * | ||
835 | * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME | ||
836 | * | ||
837 | * @param t Tunnel affected. | ||
838 | * @param p1 Peer that got disconnected from p2. | ||
839 | * @param p2 Peer that got disconnected from p1. | ||
840 | * | ||
841 | * @return Short ID of the peer disconnected (either p1 or p2). | ||
842 | * 0 if the tunnel remained unaffected. | ||
843 | */ | ||
844 | GNUNET_PEER_Id | ||
845 | GMT_notify_connection_broken (struct MeshTunnel3* t, | ||
846 | GNUNET_PEER_Id p1, GNUNET_PEER_Id p2) | ||
847 | { | ||
848 | // if (myid != p1 && myid != p2) FIXME | ||
849 | // { | ||
850 | // return; | ||
851 | // } | ||
852 | // | ||
853 | // if (tree_get_predecessor (t->tree) != 0) | ||
854 | // { | ||
855 | // /* We are the peer still connected, notify owner of the disconnection. */ | ||
856 | // struct GNUNET_MESH_PathBroken msg; | ||
857 | // struct GNUNET_PeerIdentity neighbor; | ||
858 | // | ||
859 | // msg.header.size = htons (sizeof (msg)); | ||
860 | // msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN); | ||
861 | // GNUNET_PEER_resolve (t->id.oid, &msg.oid); | ||
862 | // msg.tid = htonl (t->id.tid); | ||
863 | // msg.peer1 = my_full_id; | ||
864 | // GNUNET_PEER_resolve (pid, &msg.peer2); | ||
865 | // GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &neighbor); | ||
866 | // send_prebuilt_message (&msg.header, &neighbor, t); | ||
867 | // } | ||
868 | return 0; | ||
869 | } | ||
870 | |||
871 | /** | ||
872 | * @brief Use the given path for the tunnel. | 830 | * @brief Use the given path for the tunnel. |
873 | * Update the next and prev hops (and RCs). | 831 | * Update the next and prev hops (and RCs). |
874 | * (Re)start the path refresh in case the tunnel is locally owned. | 832 | * (Re)start the path refresh in case the tunnel is locally owned. |