diff options
Diffstat (limited to 'src/mesh/gnunet-service-mesh-new.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh-new.c | 100 |
1 files changed, 16 insertions, 84 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 32ae6998f..49b70319a 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c | |||
@@ -294,6 +294,11 @@ struct MeshTunnel | |||
294 | struct MESH_TunnelID id; | 294 | struct MESH_TunnelID id; |
295 | 295 | ||
296 | /** | 296 | /** |
297 | * Port of the tunnel. | ||
298 | */ | ||
299 | uint32_t port; | ||
300 | |||
301 | /** | ||
297 | * State of the tunnel. | 302 | * State of the tunnel. |
298 | */ | 303 | */ |
299 | enum MeshTunnelState state; | 304 | enum MeshTunnelState state; |
@@ -1196,7 +1201,7 @@ send_create_path (struct MeshTunnel *t) | |||
1196 | neighbor = peer_get_short (t->next_hop); | 1201 | neighbor = peer_get_short (t->next_hop); |
1197 | queue_add (t, | 1202 | queue_add (t, |
1198 | GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, | 1203 | GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, |
1199 | sizeof (struct GNUNET_MESH_ManipulatePath) + | 1204 | sizeof (struct GNUNET_MESH_CreateTunnel) + |
1200 | (t->path->length * sizeof (struct GNUNET_PeerIdentity)), | 1205 | (t->path->length * sizeof (struct GNUNET_PeerIdentity)), |
1201 | neighbor, | 1206 | neighbor, |
1202 | t); | 1207 | t); |
@@ -2419,7 +2424,7 @@ static size_t | |||
2419 | send_core_path_create (void *cls, size_t size, void *buf) | 2424 | send_core_path_create (void *cls, size_t size, void *buf) |
2420 | { | 2425 | { |
2421 | struct MeshTunnel *t = cls; | 2426 | struct MeshTunnel *t = cls; |
2422 | struct GNUNET_MESH_ManipulatePath *msg; | 2427 | struct GNUNET_MESH_CreateTunnel *msg; |
2423 | struct GNUNET_PeerIdentity *peer_ptr; | 2428 | struct GNUNET_PeerIdentity *peer_ptr; |
2424 | struct MeshPeerPath *p = t->path; | 2429 | struct MeshPeerPath *p = t->path; |
2425 | size_t size_needed; | 2430 | size_t size_needed; |
@@ -2428,7 +2433,7 @@ send_core_path_create (void *cls, size_t size, void *buf) | |||
2428 | 2433 | ||
2429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATE PATH sending...\n"); | 2434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATE PATH sending...\n"); |
2430 | size_needed = | 2435 | size_needed = |
2431 | sizeof (struct GNUNET_MESH_ManipulatePath) + | 2436 | sizeof (struct GNUNET_MESH_CreateTunnel) + |
2432 | p->length * sizeof (struct GNUNET_PeerIdentity); | 2437 | p->length * sizeof (struct GNUNET_PeerIdentity); |
2433 | 2438 | ||
2434 | if (size < size_needed || NULL == buf) | 2439 | if (size < size_needed || NULL == buf) |
@@ -2436,7 +2441,7 @@ send_core_path_create (void *cls, size_t size, void *buf) | |||
2436 | GNUNET_break (0); | 2441 | GNUNET_break (0); |
2437 | return 0; | 2442 | return 0; |
2438 | } | 2443 | } |
2439 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; | 2444 | msg = (struct GNUNET_MESH_CreateTunnel *) buf; |
2440 | msg->header.size = htons (size_needed); | 2445 | msg->header.size = htons (size_needed); |
2441 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); | 2446 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); |
2442 | msg->tid = ntohl (t->id.tid); | 2447 | msg->tid = ntohl (t->id.tid); |
@@ -2444,8 +2449,8 @@ send_core_path_create (void *cls, size_t size, void *buf) | |||
2444 | opt = 0; | 2449 | opt = 0; |
2445 | if (GNUNET_YES == t->nobuffer) | 2450 | if (GNUNET_YES == t->nobuffer) |
2446 | opt |= MESH_TUNNEL_OPT_NOBUFFER; | 2451 | opt |= MESH_TUNNEL_OPT_NOBUFFER; |
2447 | msg->opt = htonl(opt); | 2452 | msg->opt = htonl (opt); |
2448 | msg->reserved = 0; | 2453 | msg->port = htonl (t->port); |
2449 | 2454 | ||
2450 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; | 2455 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; |
2451 | for (i = 0; i < p->length; i++) | 2456 | for (i = 0; i < p->length; i++) |
@@ -2871,7 +2876,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2871 | uint16_t size; | 2876 | uint16_t size; |
2872 | uint16_t i; | 2877 | uint16_t i; |
2873 | MESH_TunnelNumber tid; | 2878 | MESH_TunnelNumber tid; |
2874 | struct GNUNET_MESH_ManipulatePath *msg; | 2879 | struct GNUNET_MESH_CreateTunnel *msg; |
2875 | struct GNUNET_PeerIdentity *pi; | 2880 | struct GNUNET_PeerIdentity *pi; |
2876 | struct GNUNET_HashCode hash; | 2881 | struct GNUNET_HashCode hash; |
2877 | struct MeshPeerPath *path; | 2882 | struct MeshPeerPath *path; |
@@ -2883,13 +2888,13 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2883 | "Received a path create msg [%s]\n", | 2888 | "Received a path create msg [%s]\n", |
2884 | GNUNET_i2s (&my_full_id)); | 2889 | GNUNET_i2s (&my_full_id)); |
2885 | size = ntohs (message->size); | 2890 | size = ntohs (message->size); |
2886 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | 2891 | if (size < sizeof (struct GNUNET_MESH_CreateTunnel)) |
2887 | { | 2892 | { |
2888 | GNUNET_break_op (0); | 2893 | GNUNET_break_op (0); |
2889 | return GNUNET_OK; | 2894 | return GNUNET_OK; |
2890 | } | 2895 | } |
2891 | 2896 | ||
2892 | size -= sizeof (struct GNUNET_MESH_ManipulatePath); | 2897 | size -= sizeof (struct GNUNET_MESH_CreateTunnel); |
2893 | if (size % sizeof (struct GNUNET_PeerIdentity)) | 2898 | if (size % sizeof (struct GNUNET_PeerIdentity)) |
2894 | { | 2899 | { |
2895 | GNUNET_break_op (0); | 2900 | GNUNET_break_op (0); |
@@ -2902,7 +2907,7 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2902 | return GNUNET_OK; | 2907 | return GNUNET_OK; |
2903 | } | 2908 | } |
2904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size); | 2909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size); |
2905 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | 2910 | msg = (struct GNUNET_MESH_CreateTunnel *) message; |
2906 | 2911 | ||
2907 | tid = ntohl (msg->tid); | 2912 | tid = ntohl (msg->tid); |
2908 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | 2913 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; |
@@ -3023,79 +3028,6 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3023 | 3028 | ||
3024 | 3029 | ||
3025 | /** | 3030 | /** |
3026 | * Core handler for path destruction | ||
3027 | * | ||
3028 | * @param cls closure | ||
3029 | * @param message message | ||
3030 | * @param peer peer identity this notification is about | ||
3031 | * | ||
3032 | * @return GNUNET_OK to keep the connection open, | ||
3033 | * GNUNET_SYSERR to close it (signal serious error) | ||
3034 | */ | ||
3035 | static int | ||
3036 | handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
3037 | const struct GNUNET_MessageHeader *message) | ||
3038 | { | ||
3039 | struct GNUNET_MESH_ManipulatePath *msg; | ||
3040 | struct GNUNET_PeerIdentity *pi; | ||
3041 | struct MeshTunnel *t; | ||
3042 | unsigned int own_pos; | ||
3043 | unsigned int i; | ||
3044 | size_t size; | ||
3045 | |||
3046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3047 | "Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer)); | ||
3048 | size = ntohs (message->size); | ||
3049 | if (size < sizeof (struct GNUNET_MESH_ManipulatePath)) | ||
3050 | { | ||
3051 | GNUNET_break_op (0); | ||
3052 | return GNUNET_OK; | ||
3053 | } | ||
3054 | |||
3055 | size -= sizeof (struct GNUNET_MESH_ManipulatePath); | ||
3056 | if (size % sizeof (struct GNUNET_PeerIdentity)) | ||
3057 | { | ||
3058 | GNUNET_break_op (0); | ||
3059 | return GNUNET_OK; | ||
3060 | } | ||
3061 | size /= sizeof (struct GNUNET_PeerIdentity); | ||
3062 | if (size < 2) | ||
3063 | { | ||
3064 | GNUNET_break_op (0); | ||
3065 | return GNUNET_OK; | ||
3066 | } | ||
3067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " path has %u hops.\n", size); | ||
3068 | |||
3069 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | ||
3070 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
3071 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3072 | " path is for tunnel %s [%X].\n", GNUNET_i2s (pi), | ||
3073 | msg->tid); | ||
3074 | t = tunnel_get (pi, ntohl (msg->tid)); | ||
3075 | if (NULL == t) | ||
3076 | { | ||
3077 | /* TODO notify back: we don't know this tunnel */ | ||
3078 | GNUNET_break_op (0); | ||
3079 | return GNUNET_OK; | ||
3080 | } | ||
3081 | own_pos = 0; | ||
3082 | for (i = 0; i < size; i++) | ||
3083 | { | ||
3084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %u: %s\n", i, GNUNET_i2s (&pi[i])); | ||
3085 | if (GNUNET_PEER_search (&pi[i]) == myid) | ||
3086 | own_pos = i; | ||
3087 | } | ||
3088 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | ||
3089 | if (own_pos < size - 1) | ||
3090 | send_prebuilt_message (message, t->next_hop, t); | ||
3091 | else | ||
3092 | send_client_tunnel_destroy (t); | ||
3093 | |||
3094 | return GNUNET_OK; | ||
3095 | } | ||
3096 | |||
3097 | |||
3098 | /** | ||
3099 | * Core handler for notifications of broken paths | 3031 | * Core handler for notifications of broken paths |
3100 | * | 3032 | * |
3101 | * @param cls closure | 3033 | * @param cls closure |
@@ -3650,7 +3582,6 @@ handle_mesh_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
3650 | */ | 3582 | */ |
3651 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { | 3583 | static struct GNUNET_CORE_MessageHandler core_handlers[] = { |
3652 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, | 3584 | {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0}, |
3653 | {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0}, | ||
3654 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, | 3585 | {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN, |
3655 | sizeof (struct GNUNET_MESH_PathBroken)}, | 3586 | sizeof (struct GNUNET_MESH_PathBroken)}, |
3656 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, | 3587 | {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, |
@@ -3994,6 +3925,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
3994 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 3925 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3995 | return; | 3926 | return; |
3996 | } | 3927 | } |
3928 | t->port = ntohl (t->port); | ||
3997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", | 3929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", |
3998 | GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); | 3930 | GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); |
3999 | 3931 | ||