diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-14 09:54:04 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-14 09:54:04 +0000 |
commit | fd5dc253ee8bb65127fd4180b0458b952ad6f877 (patch) | |
tree | cf0eaa8f7aa2e9684fc94b6c612e52bc97aaa871 /src/mesh | |
parent | 80aa2dac8b2f8ab7fad3a4c951eb1ee3da4de59c (diff) | |
download | gnunet-fd5dc253ee8bb65127fd4180b0458b952ad6f877.tar.gz gnunet-fd5dc253ee8bb65127fd4180b0458b952ad6f877.zip |
Expanded test to include traffic to origin, fixed bugs, separated unicast traffic handling from traffic to origin
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 115 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 30 | ||||
-rw-r--r-- | src/mesh/test_mesh_small_unicast.c | 18 |
3 files changed, 149 insertions, 14 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index bbf5679fe..1c636443b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -2295,7 +2295,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2295 | 2295 | ||
2296 | 2296 | ||
2297 | /** | 2297 | /** |
2298 | * Core handler for mesh network traffic | 2298 | * Core handler for mesh network traffic toward the owner of a tunnel |
2299 | * | 2299 | * |
2300 | * @param cls closure | 2300 | * @param cls closure |
2301 | * @param message message | 2301 | * @param message message |
@@ -2316,6 +2316,9 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2316 | struct MeshTunnel *t; | 2316 | struct MeshTunnel *t; |
2317 | size_t size; | 2317 | size_t size; |
2318 | 2318 | ||
2319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2320 | "MESH: got a ToOrigin packet from %s\n", | ||
2321 | GNUNET_i2s (peer)); | ||
2319 | size = ntohs (message->size); | 2322 | size = ntohs (message->size); |
2320 | if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ | 2323 | if (size < sizeof (struct GNUNET_MESH_ToOrigin) + /* Payload must be */ |
2321 | sizeof (struct GNUNET_MessageHeader)) /* at least a header */ | 2324 | sizeof (struct GNUNET_MessageHeader)) /* at least a header */ |
@@ -2324,27 +2327,46 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2324 | return GNUNET_OK; | 2327 | return GNUNET_OK; |
2325 | } | 2328 | } |
2326 | msg = (struct GNUNET_MESH_ToOrigin *) message; | 2329 | msg = (struct GNUNET_MESH_ToOrigin *) message; |
2330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2331 | "MESH: of type %u\n", | ||
2332 | ntohs (msg[1].header.type)); | ||
2327 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); | 2333 | t = tunnel_get (&msg->oid, ntohl (msg->tid)); |
2328 | 2334 | ||
2329 | if (NULL == t) | 2335 | if (NULL == t) |
2330 | { | 2336 | { |
2331 | /* TODO notify that we dont know this tunnel (whom)? */ | 2337 | /* TODO notify that we dont know this tunnel (whom)? */ |
2338 | GNUNET_break_op (0); | ||
2332 | return GNUNET_OK; | 2339 | return GNUNET_OK; |
2333 | } | 2340 | } |
2334 | 2341 | ||
2335 | if (t->id.oid == myid) | 2342 | if (t->id.oid == myid) |
2336 | { | 2343 | { |
2344 | char cbuf[size]; | ||
2345 | struct GNUNET_MESH_ToOrigin *copy; | ||
2346 | |||
2347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2348 | "MESH: it's for us! sending to clients...\n"); | ||
2337 | if (NULL == t->client) | 2349 | if (NULL == t->client) |
2338 | { | 2350 | { |
2339 | /* got data packet for ownerless tunnel */ | 2351 | /* got data packet for ownerless tunnel */ |
2352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2353 | "MESH: no clients!\n"); | ||
2340 | GNUNET_break_op (0); | 2354 | GNUNET_break_op (0); |
2341 | return GNUNET_OK; | 2355 | return GNUNET_OK; |
2342 | } | 2356 | } |
2343 | /* TODO signature verification */ | 2357 | /* TODO signature verification */ |
2344 | GNUNET_SERVER_notification_context_unicast (nc, t->client->handle, message, | 2358 | memcpy (cbuf, message, size); |
2359 | copy = (struct GNUNET_MESH_ToOrigin *) cbuf; | ||
2360 | copy->tid = htonl (t->local_tid); | ||
2361 | GNUNET_SERVER_notification_context_unicast (nc, | ||
2362 | t->client->handle, | ||
2363 | ©->header, | ||
2345 | GNUNET_YES); | 2364 | GNUNET_YES); |
2346 | return GNUNET_OK; | 2365 | return GNUNET_OK; |
2347 | } | 2366 | } |
2367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2368 | "MESH: not for us, retransmitting...\n"); | ||
2369 | |||
2348 | peer_info = peer_info_get (&msg->oid); | 2370 | peer_info = peer_info_get (&msg->oid); |
2349 | if (NULL == peer_info) | 2371 | if (NULL == peer_info) |
2350 | { | 2372 | { |
@@ -3322,6 +3344,93 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
3322 | return; | 3344 | return; |
3323 | } | 3345 | } |
3324 | 3346 | ||
3347 | |||
3348 | /** | ||
3349 | * Handler for client traffic directed to the origin | ||
3350 | * | ||
3351 | * @param cls closure | ||
3352 | * @param client identification of the client | ||
3353 | * @param message the actual message | ||
3354 | */ | ||
3355 | static void | ||
3356 | handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client, | ||
3357 | const struct GNUNET_MessageHeader *message) | ||
3358 | { | ||
3359 | struct GNUNET_MESH_ToOrigin *data_msg; | ||
3360 | struct GNUNET_PeerIdentity id; | ||
3361 | struct MeshClient *c; | ||
3362 | struct MeshTunnel *t; | ||
3363 | MESH_TunnelNumber tid; | ||
3364 | size_t size; | ||
3365 | |||
3366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3367 | "MESH: Got a ToOrigin request from a client!\n"); | ||
3368 | |||
3369 | /* Sanity check for client registration */ | ||
3370 | if (NULL == (c = client_get (client))) | ||
3371 | { | ||
3372 | GNUNET_break (0); | ||
3373 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3374 | return; | ||
3375 | } | ||
3376 | data_msg = (struct GNUNET_MESH_ToOrigin *) message; | ||
3377 | /* Sanity check for message size */ | ||
3378 | size = ntohs (message->size); | ||
3379 | if (sizeof (struct GNUNET_MESH_ToOrigin) + | ||
3380 | sizeof (struct GNUNET_MessageHeader) > size) | ||
3381 | { | ||
3382 | GNUNET_break (0); | ||
3383 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3384 | return; | ||
3385 | } | ||
3386 | |||
3387 | /* Tunnel exists? */ | ||
3388 | tid = ntohl (data_msg->tid); | ||
3389 | if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) | ||
3390 | { | ||
3391 | GNUNET_break (0); | ||
3392 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3393 | return; | ||
3394 | } | ||
3395 | t = tunnel_get_by_local_id (c, tid); | ||
3396 | if (NULL == t) | ||
3397 | { | ||
3398 | GNUNET_break (0); | ||
3399 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3400 | return; | ||
3401 | } | ||
3402 | |||
3403 | /* It shouldn't be a local tunnel. */ | ||
3404 | if (NULL != t->client) | ||
3405 | { | ||
3406 | GNUNET_break (0); | ||
3407 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3408 | return; | ||
3409 | } | ||
3410 | GNUNET_PEER_resolve(t->id.oid, &id); | ||
3411 | |||
3412 | /* Ok, everything is correct, send the message | ||
3413 | * (pretend we got it from a mesh peer) | ||
3414 | */ | ||
3415 | { | ||
3416 | char buf[ntohs (message->size)]; | ||
3417 | struct GNUNET_MESH_ToOrigin *copy; | ||
3418 | |||
3419 | /* Work around const limitation */ | ||
3420 | copy = (struct GNUNET_MESH_ToOrigin *) buf; | ||
3421 | memcpy (buf, data_msg, size); | ||
3422 | copy->oid = id; | ||
3423 | copy->tid = htonl (t->id.tid); | ||
3424 | copy->sender = my_full_id; | ||
3425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3426 | "MESH: calling generic handler...\n"); | ||
3427 | handle_mesh_data_to_orig (NULL, &my_full_id, ©->header, NULL); | ||
3428 | } | ||
3429 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
3430 | return; | ||
3431 | } | ||
3432 | |||
3433 | |||
3325 | /** | 3434 | /** |
3326 | * Handler for client traffic directed to all peers in a tunnel | 3435 | * Handler for client traffic directed to all peers in a tunnel |
3327 | * | 3436 | * |
@@ -3409,7 +3518,7 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | |||
3409 | sizeof (struct GNUNET_MESH_ConnectPeerByType)}, | 3518 | sizeof (struct GNUNET_MESH_ConnectPeerByType)}, |
3410 | {&handle_local_unicast, NULL, | 3519 | {&handle_local_unicast, NULL, |
3411 | GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, | 3520 | GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, |
3412 | {&handle_local_unicast, NULL, | 3521 | {&handle_local_to_origin, NULL, |
3413 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, | 3522 | GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, |
3414 | {&handle_local_multicast, NULL, | 3523 | {&handle_local_multicast, NULL, |
3415 | GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, | 3524 | GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0}, |
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index dfa60837d..a85173e54 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -1044,7 +1044,31 @@ send_callback (void *cls, size_t size, void *buf) | |||
1044 | #endif | 1044 | #endif |
1045 | if (NULL != th->notify) | 1045 | if (NULL != th->notify) |
1046 | { | 1046 | { |
1047 | if (th->target == 0) | 1047 | if (th->tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) |
1048 | { | ||
1049 | /* traffic to origin */ | ||
1050 | struct GNUNET_MESH_ToOrigin to; | ||
1051 | struct GNUNET_MessageHeader *mh; | ||
1052 | |||
1053 | GNUNET_assert (size >= th->size); | ||
1054 | mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; | ||
1055 | psize = | ||
1056 | th->notify (th->notify_cls, size - sizeof (to), mh); | ||
1057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1058 | "mesh: to origin, type %u\n", | ||
1059 | ntohs (mh->type)); | ||
1060 | if (psize > 0) | ||
1061 | { | ||
1062 | to.header.size = htons (th->size); | ||
1063 | to.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN); | ||
1064 | to.tid = htonl (th->tunnel->tid); | ||
1065 | memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity)); | ||
1066 | memset (&to.sender, 0, sizeof (struct GNUNET_PeerIdentity)); | ||
1067 | memcpy (cbuf, &to, sizeof (to)); | ||
1068 | psize += sizeof (to); | ||
1069 | } | ||
1070 | } | ||
1071 | else if (th->target == 0) | ||
1048 | { | 1072 | { |
1049 | /* multicast */ | 1073 | /* multicast */ |
1050 | struct GNUNET_MESH_Multicast mc; | 1074 | struct GNUNET_MESH_Multicast mc; |
@@ -1489,7 +1513,9 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, | |||
1489 | th->priority = priority; | 1513 | th->priority = priority; |
1490 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); | 1514 | th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); |
1491 | th->target = GNUNET_PEER_intern (target); | 1515 | th->target = GNUNET_PEER_intern (target); |
1492 | if (NULL == target) | 1516 | if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) |
1517 | overhead = sizeof (struct GNUNET_MESH_ToOrigin); | ||
1518 | else if (NULL == target) | ||
1493 | overhead = sizeof (struct GNUNET_MESH_Multicast); | 1519 | overhead = sizeof (struct GNUNET_MESH_Multicast); |
1494 | else | 1520 | else |
1495 | overhead = sizeof (struct GNUNET_MESH_Unicast); | 1521 | overhead = sizeof (struct GNUNET_MESH_Unicast); |
diff --git a/src/mesh/test_mesh_small_unicast.c b/src/mesh/test_mesh_small_unicast.c index f4ba307cb..24db46d49 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 3 | 60 | #define OK_GOAL 4 |
61 | 61 | ||
62 | static int ok; | 62 | static int ok; |
63 | 63 | ||
@@ -249,14 +249,14 @@ data_callback (void *cls, | |||
249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
250 | "test: Destination client got a message \n"); | 250 | "test: Destination client got a message \n"); |
251 | ok++; | 251 | ok++; |
252 | // GNUNET_MESH_notify_transmit_ready(incoming_t, | 252 | GNUNET_MESH_notify_transmit_ready(incoming_t, |
253 | // GNUNET_NO, | 253 | GNUNET_NO, |
254 | // 0, | 254 | 0, |
255 | // GNUNET_TIME_UNIT_FOREVER_REL, | 255 | GNUNET_TIME_UNIT_FOREVER_REL, |
256 | // sender, | 256 | sender, |
257 | // sizeof(struct GNUNET_MessageHeader), | 257 | sizeof(struct GNUNET_MessageHeader), |
258 | // &tmt_rdy, | 258 | &tmt_rdy, |
259 | // (void *) 1L); | 259 | (void *) 1L); |
260 | GNUNET_SCHEDULER_cancel (disconnect_task); | 260 | GNUNET_SCHEDULER_cancel (disconnect_task); |
261 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, | 261 | disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME, |
262 | &disconnect_mesh_peers, | 262 | &disconnect_mesh_peers, |