diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-13 13:44:18 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-13 13:44:18 +0000 |
commit | 2e9731ebda48bf2549aed64ca9cdfea5b298f9d7 (patch) | |
tree | 299c800975b74b4036dcda3168c352799e7c89e2 | |
parent | 8c61ac28c875a62ed8f3a51bfbd7359fdd581d0b (diff) | |
download | gnunet-2e9731ebda48bf2549aed64ca9cdfea5b298f9d7.tar.gz gnunet-2e9731ebda48bf2549aed64ca9cdfea5b298f9d7.zip |
Extended testcase, fixed bugs in client -> service data traffic handling
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 31 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 25 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.c | 22 | ||||
-rw-r--r-- | src/mesh/mesh_tunnel_tree.h | 13 | ||||
-rw-r--r-- | src/mesh/test_mesh_small_unicast.c | 109 |
5 files changed, 159 insertions, 41 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index cff27272c..a19aa268d 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -1427,10 +1427,14 @@ tunnel_add_path (struct MeshTunnel *t, | |||
1427 | struct MeshPeerPath *p, | 1427 | struct MeshPeerPath *p, |
1428 | unsigned int own_pos) | 1428 | unsigned int own_pos) |
1429 | { | 1429 | { |
1430 | struct GNUNET_PeerIdentity id; | ||
1431 | |||
1430 | GNUNET_assert (0 != own_pos); | 1432 | GNUNET_assert (0 != own_pos); |
1431 | tree_add_path(t->tree, p, NULL); | 1433 | tree_add_path(t->tree, p, NULL); |
1432 | if (NULL == t->tree->me) | 1434 | if (NULL == t->tree->me) |
1433 | t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]); | 1435 | t->tree->me = tree_find_peer(t->tree->root, p->peers[own_pos]); |
1436 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); | ||
1437 | tree_update_first_hops(t->tree, t->tree->me, &id); | ||
1434 | } | 1438 | } |
1435 | 1439 | ||
1436 | 1440 | ||
@@ -2028,9 +2032,12 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2028 | { | 2032 | { |
2029 | struct GNUNET_MESH_Unicast *msg; | 2033 | struct GNUNET_MESH_Unicast *msg; |
2030 | struct MeshTunnel *t; | 2034 | struct MeshTunnel *t; |
2031 | struct MeshPeerInfo *pi; | 2035 | GNUNET_PEER_Id pid; |
2032 | size_t size; | 2036 | size_t size; |
2033 | 2037 | ||
2038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2039 | "MESH: got a unicast packet from %s\n", | ||
2040 | GNUNET_i2s (peer)); | ||
2034 | size = ntohs (message->size); | 2041 | size = ntohs (message->size); |
2035 | if (size < | 2042 | if (size < |
2036 | sizeof (struct GNUNET_MESH_Unicast) + | 2043 | sizeof (struct GNUNET_MESH_Unicast) + |
@@ -2047,24 +2054,21 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2047 | GNUNET_break_op (0); | 2054 | GNUNET_break_op (0); |
2048 | return GNUNET_OK; | 2055 | return GNUNET_OK; |
2049 | } | 2056 | } |
2050 | pi = GNUNET_CONTAINER_multihashmap_get (t->peers, | 2057 | pid = GNUNET_PEER_search(&msg->destination); |
2051 | &msg->destination.hashPubKey); | 2058 | if (pid == myid) |
2052 | if (NULL == pi) | ||
2053 | { | ||
2054 | /* TODO maybe feedback, log to statistics */ | ||
2055 | GNUNET_break_op (0); | ||
2056 | return GNUNET_OK; | ||
2057 | } | ||
2058 | if (pi->id == myid) | ||
2059 | { | 2059 | { |
2060 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2061 | "MESH: it's for us! sending to clients...\n"); | ||
2060 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); | 2062 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); |
2061 | return GNUNET_OK; | 2063 | return GNUNET_OK; |
2062 | } | 2064 | } |
2065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2066 | "MESH: not for us, retransmitting...\n"); | ||
2063 | msg = GNUNET_malloc (size); | 2067 | msg = GNUNET_malloc (size); |
2064 | memcpy (msg, message, size); | 2068 | memcpy (msg, message, size); |
2065 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 2069 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
2066 | GNUNET_TIME_UNIT_FOREVER_REL, | 2070 | GNUNET_TIME_UNIT_FOREVER_REL, |
2067 | path_get_first_hop (t->tree, pi->id), | 2071 | path_get_first_hop (t->tree, pid), |
2068 | size, | 2072 | size, |
2069 | &send_core_data_raw, msg); | 2073 | &send_core_data_raw, msg); |
2070 | return GNUNET_OK; | 2074 | return GNUNET_OK; |
@@ -3125,6 +3129,9 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
3125 | MESH_TunnelNumber tid; | 3129 | MESH_TunnelNumber tid; |
3126 | size_t size; | 3130 | size_t size; |
3127 | 3131 | ||
3132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3133 | "MESH: Got a unicast request from a client!\n"); | ||
3134 | |||
3128 | /* Sanity check for client registration */ | 3135 | /* Sanity check for client registration */ |
3129 | if (NULL == (c = client_get (client))) | 3136 | if (NULL == (c = client_get (client))) |
3130 | { | 3137 | { |
@@ -3183,6 +3190,8 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
3183 | memcpy (buf, data_msg, size); | 3190 | memcpy (buf, data_msg, size); |
3184 | copy->oid = my_full_id; | 3191 | copy->oid = my_full_id; |
3185 | copy->tid = htonl (t->id.tid); | 3192 | copy->tid = htonl (t->id.tid); |
3193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3194 | "MESH: calling generic handler...\n"); | ||
3186 | handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL); | 3195 | handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL); |
3187 | } | 3196 | } |
3188 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3197 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index d3ce0b2ae..ff655166d 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -1044,7 +1044,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
1044 | /* multicast */ | 1044 | /* multicast */ |
1045 | struct GNUNET_MESH_Multicast mc; | 1045 | struct GNUNET_MESH_Multicast mc; |
1046 | 1046 | ||
1047 | GNUNET_assert (size >= sizeof (mc) + th->size); | 1047 | GNUNET_assert (size >= th->size); |
1048 | psize = | 1048 | psize = |
1049 | th->notify (th->notify_cls, size - sizeof (mc), &cbuf[sizeof (mc)]); | 1049 | th->notify (th->notify_cls, size - sizeof (mc), &cbuf[sizeof (mc)]); |
1050 | if (psize > 0) | 1050 | if (psize > 0) |
@@ -1054,7 +1054,7 @@ send_callback (void *cls, size_t size, void *buf) | |||
1054 | mc.tid = htonl (th->tunnel->tid); | 1054 | mc.tid = htonl (th->tunnel->tid); |
1055 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); | 1055 | memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); |
1056 | memcpy (cbuf, &mc, sizeof (mc)); | 1056 | memcpy (cbuf, &mc, sizeof (mc)); |
1057 | psize = th->size + sizeof (mc); | 1057 | psize += sizeof (mc); |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | else | 1060 | else |
@@ -1062,18 +1062,18 @@ send_callback (void *cls, size_t size, void *buf) | |||
1062 | /* unicast */ | 1062 | /* unicast */ |
1063 | struct GNUNET_MESH_Unicast uc; | 1063 | struct GNUNET_MESH_Unicast uc; |
1064 | 1064 | ||
1065 | GNUNET_assert (size >= sizeof (uc) + th->size); | 1065 | GNUNET_assert (size >= th->size); |
1066 | psize = | 1066 | psize = |
1067 | th->notify (th->notify_cls, size - sizeof (uc), &cbuf[sizeof (uc)]); | 1067 | th->notify (th->notify_cls, size - sizeof (uc), &cbuf[sizeof (uc)]); |
1068 | if (psize > 0) | 1068 | if (psize > 0) |
1069 | { | 1069 | { |
1070 | uc.header.size = htons (sizeof (uc) + th->size); | 1070 | uc.header.size = htons (th->size); |
1071 | uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); | 1071 | uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); |
1072 | uc.tid = htonl (th->tunnel->tid); | 1072 | uc.tid = htonl (th->tunnel->tid); |
1073 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); | 1073 | memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); |
1074 | GNUNET_PEER_resolve (th->target, &uc.destination); | 1074 | GNUNET_PEER_resolve (th->target, &uc.destination); |
1075 | memcpy (cbuf, &uc, sizeof (uc)); | 1075 | memcpy (cbuf, &uc, sizeof (uc)); |
1076 | psize = th->size + sizeof (uc); | 1076 | psize += sizeof (uc); |
1077 | } | 1077 | } |
1078 | } | 1078 | } |
1079 | } | 1079 | } |
@@ -1434,6 +1434,12 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1434 | uint32_t least_priority; | 1434 | uint32_t least_priority; |
1435 | size_t overhead; | 1435 | size_t overhead; |
1436 | 1436 | ||
1437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1438 | "mesh: mesh notify transmit ready called\n"); | ||
1439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1440 | "mesh: target %s\n", | ||
1441 | GNUNET_i2s (target)); | ||
1442 | |||
1437 | GNUNET_assert (NULL != notify); | 1443 | GNUNET_assert (NULL != notify); |
1438 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && | 1444 | if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size && |
1439 | tunnel->npackets > 0) | 1445 | tunnel->npackets > 0) |
@@ -1481,6 +1487,15 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1481 | th->notify = notify; | 1487 | th->notify = notify; |
1482 | th->notify_cls = notify_cls; | 1488 | th->notify_cls = notify_cls; |
1483 | add_to_queue (tunnel->mesh, th); | 1489 | add_to_queue (tunnel->mesh, th); |
1490 | if (NULL != tunnel->mesh->th) | ||
1491 | return th; | ||
1492 | tunnel->mesh->th = | ||
1493 | GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, | ||
1494 | th->size, | ||
1495 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1496 | GNUNET_YES, | ||
1497 | &send_callback, | ||
1498 | tunnel->mesh); | ||
1484 | return th; | 1499 | return th; |
1485 | } | 1500 | } |
1486 | 1501 | ||
diff --git a/src/mesh/mesh_tunnel_tree.c b/src/mesh/mesh_tunnel_tree.c index 7ad5bfbd7..b2c03247e 100644 --- a/src/mesh/mesh_tunnel_tree.c +++ b/src/mesh/mesh_tunnel_tree.c | |||
@@ -336,7 +336,7 @@ tree_mark_peers_disconnected (struct MeshTunnelTree *tree, | |||
336 | * @param hop If known, ID of the first hop. | 336 | * @param hop If known, ID of the first hop. |
337 | * If not known, NULL to find out and pass on children. | 337 | * If not known, NULL to find out and pass on children. |
338 | */ | 338 | */ |
339 | static void | 339 | void |
340 | tree_update_first_hops (struct MeshTunnelTree *tree, | 340 | tree_update_first_hops (struct MeshTunnelTree *tree, |
341 | struct MeshTunnelTreeNode *parent, | 341 | struct MeshTunnelTreeNode *parent, |
342 | struct GNUNET_PeerIdentity *hop) | 342 | struct GNUNET_PeerIdentity *hop) |
@@ -486,6 +486,7 @@ tree_get_path_to_peer(struct MeshTunnelTree *t, GNUNET_PEER_Id peer) | |||
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | |||
489 | /** | 490 | /** |
490 | * Integrate a stand alone path into the tunnel tree. | 491 | * Integrate a stand alone path into the tunnel tree. |
491 | * If the peer toward which the new path is already in the tree, the peer | 492 | * If the peer toward which the new path is already in the tree, the peer |
@@ -516,7 +517,6 @@ tree_add_path (struct MeshTunnelTree *t, | |||
516 | struct MeshTunnelTreeNode *n; | 517 | struct MeshTunnelTreeNode *n; |
517 | struct MeshTunnelTreeNode *c; | 518 | struct MeshTunnelTreeNode *c; |
518 | struct GNUNET_PeerIdentity id; | 519 | struct GNUNET_PeerIdentity id; |
519 | struct GNUNET_PeerIdentity *hop; | ||
520 | GNUNET_PEER_Id myid; | 520 | GNUNET_PEER_Id myid; |
521 | int me; | 521 | int me; |
522 | unsigned int i; | 522 | unsigned int i; |
@@ -604,20 +604,12 @@ tree_add_path (struct MeshTunnelTree *t, | |||
604 | n->status = MESH_PEER_SEARCHING; | 604 | n->status = MESH_PEER_SEARCHING; |
605 | 605 | ||
606 | /* Add info about first hop into hashmap. */ | 606 | /* Add info about first hop into hashmap. */ |
607 | if (me < p->length - 1) | 607 | if (-1 != me && me < p->length - 1) |
608 | { | 608 | { |
609 | GNUNET_PEER_resolve (p->peers[p->length - 1], &id); | 609 | GNUNET_PEER_resolve (p->peers[me + 1], &id); |
610 | hop = GNUNET_CONTAINER_multihashmap_get(t->first_hops, &id.hashPubKey); | 610 | tree_update_first_hops(t, |
611 | if (NULL != hop) | 611 | tree_find_peer(t->root, p->peers[p->length - 1]), |
612 | { | 612 | &id); |
613 | GNUNET_CONTAINER_multihashmap_remove_all(t->first_hops, &id.hashPubKey); | ||
614 | GNUNET_free(hop); | ||
615 | } | ||
616 | hop = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); | ||
617 | GNUNET_PEER_resolve (p->peers[me + 1], hop); | ||
618 | GNUNET_CONTAINER_multihashmap_put (t->first_hops, &id.hashPubKey, | ||
619 | hop, | ||
620 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
621 | } | 613 | } |
622 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); | 614 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "tree: New node added.\n"); |
623 | return GNUNET_OK; | 615 | return GNUNET_OK; |
diff --git a/src/mesh/mesh_tunnel_tree.h b/src/mesh/mesh_tunnel_tree.h index 509d254a1..82a1d1d1b 100644 --- a/src/mesh/mesh_tunnel_tree.h +++ b/src/mesh/mesh_tunnel_tree.h | |||
@@ -267,6 +267,19 @@ tree_find_peer (struct MeshTunnelTreeNode *parent, | |||
267 | 267 | ||
268 | 268 | ||
269 | /** | 269 | /** |
270 | * Recusively update the info about what is the first hop to reach the node | ||
271 | * | ||
272 | * @param tree Tree this nodes belongs to | ||
273 | * @param parent Node to be start updating | ||
274 | * @param hop If known, ID of the first hop. | ||
275 | * If not known, NULL to find out and pass on children. | ||
276 | */ | ||
277 | void | ||
278 | tree_update_first_hops (struct MeshTunnelTree *tree, | ||
279 | struct MeshTunnelTreeNode *parent, | ||
280 | struct GNUNET_PeerIdentity *hop); | ||
281 | |||
282 | /** | ||
270 | * Delete the current path to the peer, including all now unused relays. | 283 | * Delete the current path to the peer, including all now unused relays. |
271 | * The destination peer is NOT destroyed, it is returned in order to either set | 284 | * The destination peer is NOT destroyed, it is returned in order to either set |
272 | * a new path to it or destroy it explicitly, taking care of it's child nodes. | 285 | * a new path to it or destroy it explicitly, taking care of it's child nodes. |
diff --git a/src/mesh/test_mesh_small_unicast.c b/src/mesh/test_mesh_small_unicast.c index 5660dc0b0..2aee7ad6b 100644 --- a/src/mesh/test_mesh_small_unicast.c +++ b/src/mesh/test_mesh_small_unicast.c | |||
@@ -57,7 +57,7 @@ struct StatsContext | |||
57 | */ | 57 | */ |
58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 58 | #define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
59 | 59 | ||
60 | #define OK_GOAL 2 | 60 | #define OK_GOAL 4 |
61 | 61 | ||
62 | static int ok; | 62 | static int ok; |
63 | 63 | ||
@@ -137,6 +137,8 @@ static struct GNUNET_MESH_Handle *h2; | |||
137 | 137 | ||
138 | static struct GNUNET_MESH_Tunnel *t; | 138 | static struct GNUNET_MESH_Tunnel *t; |
139 | 139 | ||
140 | static struct GNUNET_MESH_Tunnel *incoming_t; | ||
141 | |||
140 | static uint16_t *mesh_peers; | 142 | static uint16_t *mesh_peers; |
141 | 143 | ||
142 | /** | 144 | /** |
@@ -182,10 +184,76 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
182 | 184 | ||
183 | 185 | ||
184 | /** | 186 | /** |
187 | * Transmit ready callback | ||
188 | */ | ||
189 | size_t | ||
190 | tmt_rdy (void *cls, size_t size, void *buf) | ||
191 | { | ||
192 | struct GNUNET_MessageHeader *msg = buf; | ||
193 | |||
194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tmt_rdy called\n"); | ||
195 | if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf) | ||
196 | return 0; | ||
197 | msg->size = htons (sizeof(struct GNUNET_MessageHeader)); | ||
198 | msg->type = htonl ((long) cls); | ||
199 | return sizeof(struct GNUNET_MessageHeader); | ||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Function is called whenever a message is received. | ||
205 | * | ||
206 | * @param cls closure (set from GNUNET_MESH_connect) | ||
207 | * @param tunnel connection to the other end | ||
208 | * @param tunnel_ctx place to store local state associated with the tunnel | ||
209 | * @param sender who sent the message | ||
210 | * @param message the actual message | ||
211 | * @param atsi performance data for the connection | ||
212 | * @return GNUNET_OK to keep the connection open, | ||
213 | * GNUNET_SYSERR to close it (signal serious error) | ||
214 | */ | ||
215 | int | ||
216 | data_callback (void *cls, | ||
217 | struct GNUNET_MESH_Tunnel * tunnel, | ||
218 | void **tunnel_ctx, | ||
219 | const struct GNUNET_PeerIdentity *sender, | ||
220 | const struct GNUNET_MessageHeader *message, | ||
221 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
222 | { | ||
223 | long client = (long) cls; | ||
224 | |||
225 | switch (client) | ||
226 | { | ||
227 | case 1L: | ||
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
229 | "test: Origin client got a response!\n"); | ||
230 | ok++; | ||
231 | break; | ||
232 | case 2L: | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
234 | "test: Destination client got a message \n"); | ||
235 | ok++; | ||
236 | GNUNET_MESH_notify_transmit_ready(incoming_t, | ||
237 | GNUNET_NO, | ||
238 | 0, | ||
239 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
240 | sender, | ||
241 | sizeof(struct GNUNET_MessageHeader), | ||
242 | &tmt_rdy, | ||
243 | (void *) 1L); | ||
244 | break; | ||
245 | default: | ||
246 | break; | ||
247 | } | ||
248 | return GNUNET_OK; | ||
249 | } | ||
250 | |||
251 | |||
252 | /** | ||
185 | * Handlers, for diverse services | 253 | * Handlers, for diverse services |
186 | */ | 254 | */ |
187 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 255 | static struct GNUNET_MESH_MessageHandler handlers[] = { |
188 | // {&callback, 1, 0}, | 256 | {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)}, |
189 | {NULL, 0, 0} | 257 | {NULL, 0, 0} |
190 | }; | 258 | }; |
191 | 259 | ||
@@ -224,6 +292,7 @@ incoming_tunnel (void *cls, | |||
224 | "test: Incoming tunnel from %s\n", | 292 | "test: Incoming tunnel from %s\n", |
225 | GNUNET_i2s(initiator)); | 293 | GNUNET_i2s(initiator)); |
226 | ok++; | 294 | ok++; |
295 | incoming_t = tunnel; | ||
227 | GNUNET_SCHEDULER_cancel (disconnect_task); | 296 | GNUNET_SCHEDULER_cancel (disconnect_task); |
228 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | 297 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, |
229 | &disconnect_mesh_peers, | 298 | &disconnect_mesh_peers, |
@@ -251,6 +320,7 @@ tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, | |||
251 | return; | 320 | return; |
252 | } | 321 | } |
253 | 322 | ||
323 | |||
254 | /** | 324 | /** |
255 | * Method called whenever a tunnel falls apart. | 325 | * Method called whenever a tunnel falls apart. |
256 | * | 326 | * |
@@ -263,8 +333,6 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
264 | "test: peer %s disconnected\n", | 334 | "test: peer %s disconnected\n", |
265 | GNUNET_i2s(peer)); | 335 | GNUNET_i2s(peer)); |
266 | if (memcmp(&d2->id, peer, sizeof(d2->id))) | ||
267 | ok++; | ||
268 | return; | 336 | return; |
269 | } | 337 | } |
270 | 338 | ||
@@ -283,6 +351,24 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
284 | "test: peer %s connected\n", | 352 | "test: peer %s connected\n", |
285 | GNUNET_i2s(peer)); | 353 | GNUNET_i2s(peer)); |
354 | if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L) | ||
355 | ok++; | ||
356 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | ||
357 | { | ||
358 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
359 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | ||
360 | &disconnect_mesh_peers, | ||
361 | NULL); | ||
362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Sending data unicast...\n"); | ||
363 | GNUNET_MESH_notify_transmit_ready(t, | ||
364 | GNUNET_NO, | ||
365 | 0, | ||
366 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
367 | &d2->id, | ||
368 | sizeof(struct GNUNET_MessageHeader), | ||
369 | &tmt_rdy, | ||
370 | (void *) 1L); | ||
371 | } | ||
286 | return; | 372 | return; |
287 | } | 373 | } |
288 | 374 | ||
@@ -388,14 +474,14 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
388 | #endif | 474 | #endif |
389 | h1 = GNUNET_MESH_connect (d1->cfg, | 475 | h1 = GNUNET_MESH_connect (d1->cfg, |
390 | 10, | 476 | 10, |
391 | NULL, | 477 | (void *) 1L, |
392 | NULL, | 478 | NULL, |
393 | &tunnel_cleaner, | 479 | &tunnel_cleaner, |
394 | handlers, | 480 | handlers, |
395 | &app); | 481 | &app); |
396 | h2 = GNUNET_MESH_connect (d2->cfg, | 482 | h2 = GNUNET_MESH_connect (d2->cfg, |
397 | 10, | 483 | 10, |
398 | NULL, | 484 | (void *) 2L, |
399 | &incoming_tunnel, | 485 | &incoming_tunnel, |
400 | &tunnel_cleaner, | 486 | &tunnel_cleaner, |
401 | handlers, | 487 | handlers, |
@@ -408,7 +494,7 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
408 | "test: connected to mesh service of peer %s\n", | 494 | "test: connected to mesh service of peer %s\n", |
409 | GNUNET_i2s (&d2->id)); | 495 | GNUNET_i2s (&d2->id)); |
410 | #endif | 496 | #endif |
411 | t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); | 497 | t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); |
412 | test_task = | 498 | test_task = |
413 | GNUNET_SCHEDULER_add_delayed( | 499 | GNUNET_SCHEDULER_add_delayed( |
414 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), | 500 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6), |
@@ -664,16 +750,19 @@ int | |||
664 | main (int argc, char *argv[]) | 750 | main (int argc, char *argv[]) |
665 | { | 751 | { |
666 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", | 752 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", |
667 | gettext_noop ("Test mesh unicast in a small network."), options, | 753 | gettext_noop ("Test mesh unicast in a small network."), |
668 | &run, NULL); | 754 | options, &run, NULL); |
669 | #if REMOVE_DIR | 755 | #if REMOVE_DIR |
670 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); | 756 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); |
671 | #endif | 757 | #endif |
672 | if (OK_GOAL != ok) | 758 | if (OK_GOAL != ok) |
673 | { | 759 | { |
674 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n"); | 760 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
761 | "test: FAILED! (%d/%d)\n", | ||
762 | ok, OK_GOAL); | ||
675 | return 1; | 763 | return 1; |
676 | } | 764 | } |
765 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n"); | ||
677 | return 0; | 766 | return 0; |
678 | } | 767 | } |
679 | 768 | ||