diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-12-04 12:39:47 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-12-04 12:39:47 +0000 |
commit | c03182d1e7b55b18d9a66cf890effb11c5dc7a45 (patch) | |
tree | f06057344b1484a564209db897c530d8236d4886 /src | |
parent | 1947bc8ef4eb37738ffc1c566d9c6f96071b29f7 (diff) | |
download | gnunet-c03182d1e7b55b18d9a66cf890effb11c5dc7a45.tar.gz gnunet-c03182d1e7b55b18d9a66cf890effb11c5dc7a45.zip |
- changed mesh api for monitoring
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_protocols.h | 8 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 115 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 92 |
3 files changed, 142 insertions, 73 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 1c73dc74e..087f86ac5 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -891,14 +891,14 @@ extern "C" | |||
891 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK 286 | 891 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK 286 |
892 | 892 | ||
893 | /** | 893 | /** |
894 | * Local monitoring of service. | 894 | * Local information about all tunnels of service. |
895 | */ | 895 | */ |
896 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR 287 | 896 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS 287 |
897 | 897 | ||
898 | /** | 898 | /** |
899 | * Local monitoring of service of a specific tunnel. | 899 | * Local information of service about a specific tunnel. |
900 | */ | 900 | */ |
901 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR_TUNNEL 288 | 901 | #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL 288 |
902 | 902 | ||
903 | /** | 903 | /** |
904 | * 640kb should be enough for everybody | 904 | * 640kb should be enough for everybody |
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 01f30156e..b41d7e570 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -8093,7 +8093,7 @@ monitor_all_tunnels_iterator (void *cls, | |||
8093 | msg->tunnel_id = htonl (t->id.tid); | 8093 | msg->tunnel_id = htonl (t->id.tid); |
8094 | msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor) + | 8094 | msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor) + |
8095 | npeers * sizeof (struct GNUNET_PeerIdentity)); | 8095 | npeers * sizeof (struct GNUNET_PeerIdentity)); |
8096 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR); | 8096 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); |
8097 | msg->npeers = 0; | 8097 | msg->npeers = 0; |
8098 | (void) GNUNET_CONTAINER_multihashmap_iterate (t->peers, | 8098 | (void) GNUNET_CONTAINER_multihashmap_iterate (t->peers, |
8099 | monitor_peers_iterator, | 8099 | monitor_peers_iterator, |
@@ -8106,14 +8106,14 @@ monitor_all_tunnels_iterator (void *cls, | |||
8106 | if (msg->npeers != npeers) | 8106 | if (msg->npeers != npeers) |
8107 | { | 8107 | { |
8108 | GNUNET_break (0); | 8108 | GNUNET_break (0); |
8109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Monitor fail: size %u - iter %u\n", | 8109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
8110 | "Get tunnels fail: size %u - iter %u\n", | ||
8110 | npeers, msg->npeers); | 8111 | npeers, msg->npeers); |
8111 | } | 8112 | } |
8112 | 8113 | ||
8113 | msg->npeers = htonl (npeers); | 8114 | msg->npeers = htonl (npeers); |
8114 | GNUNET_SERVER_notification_context_unicast (nc, client, | 8115 | GNUNET_SERVER_notification_context_unicast (nc, client, |
8115 | &msg->header, | 8116 | &msg->header, GNUNET_NO); |
8116 | GNUNET_NO); | ||
8117 | return GNUNET_YES; | 8117 | return GNUNET_YES; |
8118 | } | 8118 | } |
8119 | 8119 | ||
@@ -8126,8 +8126,8 @@ monitor_all_tunnels_iterator (void *cls, | |||
8126 | * @param message The actual message. | 8126 | * @param message The actual message. |
8127 | */ | 8127 | */ |
8128 | static void | 8128 | static void |
8129 | handle_local_monitor (void *cls, struct GNUNET_SERVER_Client *client, | 8129 | handle_local_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, |
8130 | const struct GNUNET_MessageHeader *message) | 8130 | const struct GNUNET_MessageHeader *message) |
8131 | { | 8131 | { |
8132 | struct MeshClient *c; | 8132 | struct MeshClient *c; |
8133 | 8133 | ||
@@ -8140,13 +8140,13 @@ handle_local_monitor (void *cls, struct GNUNET_SERVER_Client *client, | |||
8140 | } | 8140 | } |
8141 | 8141 | ||
8142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 8142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
8143 | "Received monitor request from client %u\n", | 8143 | "Received get tunnels request from client %u\n", |
8144 | c->id); | 8144 | c->id); |
8145 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, | 8145 | GNUNET_CONTAINER_multihashmap_iterate (tunnels, |
8146 | monitor_all_tunnels_iterator, | 8146 | monitor_all_tunnels_iterator, |
8147 | client); | 8147 | client); |
8148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 8148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
8149 | "Monitor request from client %u completed\n", | 8149 | "Get tunnels request from client %u completed\n", |
8150 | c->id); | 8150 | c->id); |
8151 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 8151 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
8152 | } | 8152 | } |
@@ -8154,9 +8154,6 @@ handle_local_monitor (void *cls, struct GNUNET_SERVER_Client *client, | |||
8154 | 8154 | ||
8155 | /** | 8155 | /** |
8156 | * Data needed to build a Monitor_Tunnel message. | 8156 | * Data needed to build a Monitor_Tunnel message. |
8157 | * | ||
8158 | * Both arrays can be combined to look up the position of the parent of | ||
8159 | * a peer: lookup[parent[peer]]. | ||
8160 | */ | 8157 | */ |
8161 | struct MeshMonitorTunnelContext | 8158 | struct MeshMonitorTunnelContext |
8162 | { | 8159 | { |
@@ -8166,19 +8163,20 @@ struct MeshMonitorTunnelContext | |||
8166 | struct GNUNET_MESH_LocalMonitor *msg; | 8163 | struct GNUNET_MESH_LocalMonitor *msg; |
8167 | 8164 | ||
8168 | /** | 8165 | /** |
8169 | * Array with parents: peer->parent. | 8166 | * Hashmap with positions: peer->position. |
8170 | */ | 8167 | */ |
8171 | GNUNET_PEER_Id *parents; | 8168 | struct GNUNET_CONTAINER_MultiHashMap *lookup; |
8172 | 8169 | ||
8173 | /** | 8170 | /** |
8174 | * Array with positions: peer->position. | 8171 | * Index of the parent of each peer in the message, realtive to the absolute |
8172 | * order in the array (can be in a previous message). | ||
8175 | */ | 8173 | */ |
8176 | uint32_t *lookup; | 8174 | uint32_t parents[1024]; |
8177 | 8175 | ||
8178 | /** | 8176 | /** |
8179 | * Size of the message so far. | 8177 | * Peers visited so far in the tree, aka position of the current peer. |
8180 | */ | 8178 | */ |
8181 | size_t size; | 8179 | unsigned int npeers; |
8182 | 8180 | ||
8183 | /** | 8181 | /** |
8184 | * Client requesting the info. | 8182 | * Client requesting the info. |
@@ -8188,15 +8186,17 @@ struct MeshMonitorTunnelContext | |||
8188 | 8186 | ||
8189 | 8187 | ||
8190 | /** | 8188 | /** |
8191 | * Send a client a message about | 8189 | * Send a client a message about the structure of a tunnel. |
8190 | * | ||
8191 | * @param ctx Context of the tunnel iteration, with info regarding the state | ||
8192 | * of the execution and the number of peers visited for this message. | ||
8192 | */ | 8193 | */ |
8193 | static void | 8194 | static void |
8194 | send_client_monitor_tunnel (struct MeshMonitorTunnelContext *ctx) | 8195 | send_client_tunnel_info (struct MeshMonitorTunnelContext *ctx) |
8195 | { | 8196 | { |
8196 | struct GNUNET_MESH_LocalMonitor *resp = ctx->msg; | 8197 | struct GNUNET_MESH_LocalMonitor *resp = ctx->msg; |
8197 | struct GNUNET_PeerIdentity *pid; | 8198 | struct GNUNET_PeerIdentity *pid; |
8198 | unsigned int *parent; | 8199 | unsigned int *parent; |
8199 | unsigned int i; | ||
8200 | size_t size; | 8200 | size_t size; |
8201 | 8201 | ||
8202 | size = sizeof (struct GNUNET_MESH_LocalMonitor); | 8202 | size = sizeof (struct GNUNET_MESH_LocalMonitor); |
@@ -8204,8 +8204,7 @@ send_client_monitor_tunnel (struct MeshMonitorTunnelContext *ctx) | |||
8204 | resp->header.size = htons (size); | 8204 | resp->header.size = htons (size); |
8205 | pid = (struct GNUNET_PeerIdentity *) &resp[1]; | 8205 | pid = (struct GNUNET_PeerIdentity *) &resp[1]; |
8206 | parent = (unsigned int *) &pid[resp->npeers]; | 8206 | parent = (unsigned int *) &pid[resp->npeers]; |
8207 | for (i = 0; i < resp->npeers; i++) | 8207 | memcpy (parent, ctx->parents, sizeof(uint32_t) * resp->npeers); |
8208 | parent[i] = htonl (ctx->lookup[ctx->parents[i]]); | ||
8209 | GNUNET_SERVER_notification_context_unicast (nc, ctx->c->handle, | 8208 | GNUNET_SERVER_notification_context_unicast (nc, ctx->c->handle, |
8210 | &resp->header, GNUNET_NO); | 8209 | &resp->header, GNUNET_NO); |
8211 | } | 8210 | } |
@@ -8217,32 +8216,39 @@ send_client_monitor_tunnel (struct MeshMonitorTunnelContext *ctx) | |||
8217 | * @param cls Closure (pointer to pointer of message being built). | 8216 | * @param cls Closure (pointer to pointer of message being built). |
8218 | * @param peer Short ID of a peer. | 8217 | * @param peer Short ID of a peer. |
8219 | * @param parent Short ID of the @c peer 's parent. | 8218 | * @param parent Short ID of the @c peer 's parent. |
8220 | * | ||
8221 | * FIXME: limit iterating to a message size / split if necessary | ||
8222 | */ | 8219 | */ |
8223 | static void | 8220 | static void |
8224 | monitor_tunnel_iterator (void *cls, | 8221 | tunnel_tree_iterator (void *cls, |
8225 | GNUNET_PEER_Id peer, | 8222 | GNUNET_PEER_Id peer, |
8226 | GNUNET_PEER_Id parent) | 8223 | GNUNET_PEER_Id parent) |
8227 | { | 8224 | { |
8228 | struct MeshMonitorTunnelContext *ctx = cls; | 8225 | struct MeshMonitorTunnelContext *ctx = cls; |
8229 | struct GNUNET_MESH_LocalMonitor *msg = ctx->msg; | 8226 | struct GNUNET_MESH_LocalMonitor *msg; |
8230 | struct GNUNET_PeerIdentity *pid; | 8227 | struct GNUNET_PeerIdentity *pid; |
8228 | struct GNUNET_PeerIdentity ppid; | ||
8231 | 8229 | ||
8232 | msg = ctx->msg; | 8230 | msg = ctx->msg; |
8233 | pid = (struct GNUNET_PeerIdentity *) &msg[1]; | 8231 | pid = (struct GNUNET_PeerIdentity *) &msg[1]; |
8234 | GNUNET_PEER_resolve(peer, &pid[msg->npeers]); | 8232 | GNUNET_PEER_resolve (peer, &pid[msg->npeers]); |
8235 | ctx->parents[msg->npeers] = parent; | 8233 | GNUNET_CONTAINER_multihashmap_put (ctx->lookup, |
8236 | ctx->lookup[peer] = msg->npeers; | 8234 | &pid[msg->npeers].hashPubKey, |
8237 | ctx->size += sizeof (struct GNUNET_PeerIdentity) * sizeof (uint32_t); | 8235 | (void *) (long) ctx->npeers, |
8236 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
8237 | GNUNET_PEER_resolve (parent, &ppid); | ||
8238 | ctx->parents[msg->npeers] = | ||
8239 | htonl ((long) GNUNET_CONTAINER_multihashmap_get (ctx->lookup, | ||
8240 | &ppid.hashPubKey)); | ||
8241 | |||
8242 | ctx->npeers++; | ||
8238 | msg->npeers++; | 8243 | msg->npeers++; |
8239 | 8244 | ||
8240 | if ( (ctx->size + sizeof (struct GNUNET_PeerIdentity) * sizeof (uint32_t)) | 8245 | if (sizeof (struct GNUNET_MESH_LocalMonitor) + |
8241 | > USHRT_MAX ) | 8246 | (msg->npeers + 1) * |
8247 | (sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t)) | ||
8248 | > USHRT_MAX) | ||
8242 | { | 8249 | { |
8243 | send_client_monitor_tunnel (ctx); | 8250 | send_client_tunnel_info (ctx); |
8244 | ctx->size = sizeof (struct GNUNET_MESH_LocalMonitor); | 8251 | msg->npeers = 0; |
8245 | ctx->msg->npeers = 0; | ||
8246 | } | 8252 | } |
8247 | } | 8253 | } |
8248 | 8254 | ||
@@ -8255,8 +8261,8 @@ monitor_tunnel_iterator (void *cls, | |||
8255 | * @param message The actual message. | 8261 | * @param message The actual message. |
8256 | */ | 8262 | */ |
8257 | static void | 8263 | static void |
8258 | handle_local_monitor_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | 8264 | handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, |
8259 | const struct GNUNET_MessageHeader *message) | 8265 | const struct GNUNET_MessageHeader *message) |
8260 | { | 8266 | { |
8261 | const struct GNUNET_MESH_LocalMonitor *msg; | 8267 | const struct GNUNET_MESH_LocalMonitor *msg; |
8262 | struct GNUNET_MESH_LocalMonitor *resp; | 8268 | struct GNUNET_MESH_LocalMonitor *resp; |
@@ -8274,8 +8280,10 @@ handle_local_monitor_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
8274 | 8280 | ||
8275 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | 8281 | msg = (struct GNUNET_MESH_LocalMonitor *) message; |
8276 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 8282 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
8277 | "Received monitor tunnel request from client %u\n", | 8283 | "Received tunnel info request from client %u for tunnel %s[%X]\n", |
8278 | c->id); | 8284 | c->id, |
8285 | &msg->owner, | ||
8286 | ntohl (msg->tunnel_id)); | ||
8279 | t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id)); | 8287 | t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id)); |
8280 | if (NULL == t) | 8288 | if (NULL == t) |
8281 | { | 8289 | { |
@@ -8291,22 +8299,21 @@ handle_local_monitor_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
8291 | return; | 8299 | return; |
8292 | } | 8300 | } |
8293 | 8301 | ||
8302 | /* Initialize context */ | ||
8294 | resp = GNUNET_malloc (USHRT_MAX); /* avoid realloc'ing on each step */ | 8303 | resp = GNUNET_malloc (USHRT_MAX); /* avoid realloc'ing on each step */ |
8295 | *resp = *msg; | 8304 | *resp = *msg; |
8296 | resp->npeers = 0; | 8305 | resp->npeers = 0; |
8297 | ctx.msg = resp; | 8306 | ctx.msg = resp; |
8298 | ctx.parents = GNUNET_malloc (sizeof (GNUNET_PEER_Id) * 1024); /* hard limit anyway */ | 8307 | ctx.lookup = GNUNET_CONTAINER_multihashmap_create (4 * t->peers_total, |
8299 | ctx.lookup = GNUNET_malloc (sizeof (int) * 1024); | 8308 | GNUNET_YES); |
8300 | ctx.size = sizeof (struct GNUNET_MESH_LocalMonitor); | ||
8301 | ctx.c = c; | 8309 | ctx.c = c; |
8302 | 8310 | ||
8303 | tree_iterate_all (t->tree, | 8311 | /* Collect and send information */ |
8304 | monitor_tunnel_iterator, | 8312 | tree_iterate_all (t->tree, &tunnel_tree_iterator, &ctx); |
8305 | &ctx); | 8313 | send_client_tunnel_info (&ctx); |
8306 | send_client_monitor_tunnel (&ctx); | ||
8307 | 8314 | ||
8308 | GNUNET_free (ctx.parents); | 8315 | /* Free context */ |
8309 | GNUNET_free (ctx.lookup); | 8316 | GNUNET_CONTAINER_multihashmap_destroy (ctx.lookup); |
8310 | GNUNET_free (resp); | 8317 | GNUNET_free (resp); |
8311 | 8318 | ||
8312 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 8319 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -8368,11 +8375,11 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | |||
8368 | {&handle_local_ack, NULL, | 8375 | {&handle_local_ack, NULL, |
8369 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, | 8376 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, |
8370 | sizeof (struct GNUNET_MESH_LocalAck)}, | 8377 | sizeof (struct GNUNET_MESH_LocalAck)}, |
8371 | {&handle_local_monitor, NULL, | 8378 | {&handle_local_get_tunnels, NULL, |
8372 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR, | 8379 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS, |
8373 | sizeof (struct GNUNET_MessageHeader)}, | 8380 | sizeof (struct GNUNET_MessageHeader)}, |
8374 | {&handle_local_monitor_tunnel, NULL, | 8381 | {&handle_local_show_tunnel, NULL, |
8375 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR_TUNNEL, | 8382 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL, |
8376 | sizeof (struct GNUNET_MESH_LocalMonitor)}, | 8383 | sizeof (struct GNUNET_MESH_LocalMonitor)}, |
8377 | {NULL, NULL, 0, 0} | 8384 | {NULL, NULL, 0, 0} |
8378 | }; | 8385 | }; |
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 9ebc48536..0e49fd831 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -227,6 +227,16 @@ struct GNUNET_MESH_Handle | |||
227 | */ | 227 | */ |
228 | void *tunnel_cls; | 228 | void *tunnel_cls; |
229 | 229 | ||
230 | /** | ||
231 | * All the peer in the tunnel so far. | ||
232 | */ | ||
233 | struct GNUNET_PeerIdentity *peers; | ||
234 | |||
235 | /** | ||
236 | * How many peers we have in this tunnel so far. | ||
237 | */ | ||
238 | unsigned int tunnel_npeers; | ||
239 | |||
230 | #if DEBUG_ACK | 240 | #if DEBUG_ACK |
231 | unsigned int acks_sent; | 241 | unsigned int acks_sent; |
232 | unsigned int acks_recv; | 242 | unsigned int acks_recv; |
@@ -1262,19 +1272,19 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
1262 | 1272 | ||
1263 | 1273 | ||
1264 | /** | 1274 | /** |
1265 | * Process a local monitor reply, pass info to the user. | 1275 | * Process a local reply about info on all tunnels, pass info to the user. |
1266 | * | 1276 | * |
1267 | * @param h Mesh handle. | 1277 | * @param h Mesh handle. |
1268 | * @param message Message itself. | 1278 | * @param message Message itself. |
1269 | */ | 1279 | */ |
1270 | static void | 1280 | static void |
1271 | process_monitor (struct GNUNET_MESH_Handle *h, | 1281 | process_get_tunnels (struct GNUNET_MESH_Handle *h, |
1272 | const struct GNUNET_MessageHeader *message) | 1282 | const struct GNUNET_MessageHeader *message) |
1273 | { | 1283 | { |
1274 | struct GNUNET_MESH_LocalMonitor *msg; | 1284 | struct GNUNET_MESH_LocalMonitor *msg; |
1275 | uint32_t npeers; | 1285 | uint32_t npeers; |
1276 | 1286 | ||
1277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Monitor messasge received\n"); | 1287 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); |
1278 | 1288 | ||
1279 | if (NULL == h->tunnels_cb) | 1289 | if (NULL == h->tunnels_cb) |
1280 | { | 1290 | { |
@@ -1284,13 +1294,13 @@ process_monitor (struct GNUNET_MESH_Handle *h, | |||
1284 | 1294 | ||
1285 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | 1295 | msg = (struct GNUNET_MESH_LocalMonitor *) message; |
1286 | npeers = ntohl (msg->npeers); | 1296 | npeers = ntohl (msg->npeers); |
1287 | if (ntohs (message->size) != | 1297 | if (ntohs (message->size) != |
1288 | (sizeof (struct GNUNET_MESH_LocalMonitor) + | 1298 | (sizeof (struct GNUNET_MESH_LocalMonitor) + |
1289 | npeers * sizeof (struct GNUNET_PeerIdentity))) | 1299 | npeers * sizeof (struct GNUNET_PeerIdentity))) |
1290 | { | 1300 | { |
1291 | GNUNET_break_op (0); | 1301 | GNUNET_break_op (0); |
1292 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1302 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1293 | "Monitor message: size %hu - expected %u (%u peers)\n", | 1303 | "Get tunnels message: size %hu - expected %u (%u peers)\n", |
1294 | ntohs (message->size), | 1304 | ntohs (message->size), |
1295 | sizeof (struct GNUNET_MESH_LocalMonitor) + | 1305 | sizeof (struct GNUNET_MESH_LocalMonitor) + |
1296 | npeers * sizeof (struct GNUNET_PeerIdentity), | 1306 | npeers * sizeof (struct GNUNET_PeerIdentity), |
@@ -1313,9 +1323,60 @@ process_monitor (struct GNUNET_MESH_Handle *h, | |||
1313 | * @param message Message itself. | 1323 | * @param message Message itself. |
1314 | */ | 1324 | */ |
1315 | static void | 1325 | static void |
1316 | process_monitor_tunnel (struct GNUNET_MESH_Handle *h, | 1326 | process_show_tunnel (struct GNUNET_MESH_Handle *h, |
1317 | const struct GNUNET_MessageHeader *message) | 1327 | const struct GNUNET_MessageHeader *message) |
1318 | { | 1328 | { |
1329 | struct GNUNET_MESH_LocalMonitor *msg; | ||
1330 | struct GNUNET_PeerIdentity *new_peers; | ||
1331 | uint32_t *new_parents; | ||
1332 | size_t esize; | ||
1333 | uint32_t npeers; | ||
1334 | unsigned int i; | ||
1335 | |||
1336 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Tunnel messasge received\n"); | ||
1337 | |||
1338 | if (NULL == h->tunnel_cb) | ||
1339 | { | ||
1340 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | ||
1341 | return; | ||
1342 | } | ||
1343 | |||
1344 | /* Verify message sanity */ | ||
1345 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | ||
1346 | npeers = ntohl (msg->npeers); | ||
1347 | esize = sizeof (struct GNUNET_MESH_LocalMonitor); | ||
1348 | esize += npeers * (sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t)); | ||
1349 | if (ntohs (message->size) != esize) | ||
1350 | { | ||
1351 | GNUNET_break_op (0); | ||
1352 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1353 | "Show tunnel message: size %hu - expected %u (%u peers)\n", | ||
1354 | ntohs (message->size), | ||
1355 | esize, | ||
1356 | npeers); | ||
1357 | |||
1358 | h->tunnel_cb (h->tunnel_cls, NULL, NULL); | ||
1359 | h->tunnel_cb = NULL; | ||
1360 | h->tunnel_cls = NULL; | ||
1361 | h->tunnel_npeers = 0; | ||
1362 | GNUNET_free_non_null (h->peers); | ||
1363 | h->peers = NULL; | ||
1364 | |||
1365 | return; | ||
1366 | } | ||
1367 | |||
1368 | new_peers = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
1369 | new_parents = (uint32_t *) &new_peers[npeers]; | ||
1370 | |||
1371 | h->peers = GNUNET_realloc (h->peers, h->tunnel_npeers + npeers); | ||
1372 | memcpy (&h->peers[h->tunnel_npeers], | ||
1373 | new_peers, | ||
1374 | npeers * sizeof (struct GNUNET_PeerIdentity)); | ||
1375 | h->tunnel_npeers += npeers; | ||
1376 | for (i = 0; i < npeers; i++) | ||
1377 | h->tunnel_cb (h->tunnel_cls, | ||
1378 | &new_peers[i], | ||
1379 | &h->peers[new_parents[i]]); | ||
1319 | } | 1380 | } |
1320 | 1381 | ||
1321 | 1382 | ||
@@ -1366,11 +1427,11 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1366 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | 1427 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: |
1367 | process_ack (h, msg); | 1428 | process_ack (h, msg); |
1368 | break; | 1429 | break; |
1369 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR: | 1430 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: |
1370 | process_monitor (h, msg); | 1431 | process_get_tunnels (h, msg); |
1371 | break; | 1432 | break; |
1372 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR_TUNNEL: | 1433 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: |
1373 | process_monitor_tunnel (h, msg); | 1434 | process_show_tunnel (h, msg); |
1374 | break; | 1435 | break; |
1375 | default: | 1436 | default: |
1376 | /* We shouldn't get any other packages, log and ignore */ | 1437 | /* We shouldn't get any other packages, log and ignore */ |
@@ -1713,7 +1774,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1713 | { | 1774 | { |
1714 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: | 1775 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: |
1715 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: | 1776 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: |
1716 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR: | 1777 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: |
1778 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: | ||
1717 | break; | 1779 | break; |
1718 | default: | 1780 | default: |
1719 | GNUNET_break (0); | 1781 | GNUNET_break (0); |
@@ -2250,7 +2312,7 @@ GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, | |||
2250 | struct GNUNET_MessageHeader msg; | 2312 | struct GNUNET_MessageHeader msg; |
2251 | 2313 | ||
2252 | msg.size = htons (sizeof (msg)); | 2314 | msg.size = htons (sizeof (msg)); |
2253 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR); | 2315 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); |
2254 | send_packet (h, &msg, NULL); | 2316 | send_packet (h, &msg, NULL); |
2255 | h->tunnels_cb = callback; | 2317 | h->tunnels_cb = callback; |
2256 | h->tunnels_cls = callback_cls; | 2318 | h->tunnels_cls = callback_cls; |
@@ -2299,7 +2361,7 @@ GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, | |||
2299 | struct GNUNET_MESH_LocalMonitor msg; | 2361 | struct GNUNET_MESH_LocalMonitor msg; |
2300 | 2362 | ||
2301 | msg.header.size = htons (sizeof (msg)); | 2363 | msg.header.size = htons (sizeof (msg)); |
2302 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR_TUNNEL); | 2364 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); |
2303 | msg.npeers = htonl (0); | 2365 | msg.npeers = htonl (0); |
2304 | msg.owner = *initiator; | 2366 | msg.owner = *initiator; |
2305 | msg.tunnel_id = htonl (tunnel_number); | 2367 | msg.tunnel_id = htonl (tunnel_number); |