diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-28 14:30:51 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-28 14:30:51 +0000 |
commit | 4493d69b8625d799167e82edc1aca52617ba913d (patch) | |
tree | 288f4fc16c185c4d62b8680302014ab58badd90a /src | |
parent | c4cba40c252dd423fc4876c9def15f0f8efe51f3 (diff) | |
download | gnunet-4493d69b8625d799167e82edc1aca52617ba913d.tar.gz gnunet-4493d69b8625d799167e82edc1aca52617ba913d.zip |
- Add some of the tunnel introscpecion back
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.c | 4 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.h | 5 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_local.c | 87 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 18 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.h | 6 | ||||
-rw-r--r-- | src/mesh/mesh.h | 4 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 224 |
7 files changed, 289 insertions, 59 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index a11210a38..42d9bc1cf 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c | |||
@@ -1351,11 +1351,11 @@ GMCH_destroy (struct MeshChannel *ch) | |||
1351 | 1351 | ||
1352 | 1352 | ||
1353 | /** | 1353 | /** |
1354 | * Get channel ID. | 1354 | * Get the channel's public ID. |
1355 | * | 1355 | * |
1356 | * @param ch Channel. | 1356 | * @param ch Channel. |
1357 | * | 1357 | * |
1358 | * @return ID | 1358 | * @return ID used to identify the channel with the remote peer. |
1359 | */ | 1359 | */ |
1360 | MESH_ChannelNumber | 1360 | MESH_ChannelNumber |
1361 | GMCH_get_id (const struct MeshChannel *ch) | 1361 | GMCH_get_id (const struct MeshChannel *ch) |
diff --git a/src/mesh/gnunet-service-mesh_channel.h b/src/mesh/gnunet-service-mesh_channel.h index 504754148..e1d5d4876 100644 --- a/src/mesh/gnunet-service-mesh_channel.h +++ b/src/mesh/gnunet-service-mesh_channel.h | |||
@@ -61,12 +61,13 @@ struct MeshChannel; | |||
61 | void | 61 | void |
62 | GMCH_destroy (struct MeshChannel *ch); | 62 | GMCH_destroy (struct MeshChannel *ch); |
63 | 63 | ||
64 | |||
64 | /** | 65 | /** |
65 | * Get channel ID. | 66 | * Get the channel's public ID. |
66 | * | 67 | * |
67 | * @param ch Channel. | 68 | * @param ch Channel. |
68 | * | 69 | * |
69 | * @return ID | 70 | * @return ID used to identify the channel with the remote peer. |
70 | */ | 71 | */ |
71 | MESH_ChannelNumber | 72 | MESH_ChannelNumber |
72 | GMCH_get_id (const struct MeshChannel *ch); | 73 | GMCH_get_id (const struct MeshChannel *ch); |
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c index fa54fafa6..82743c892 100644 --- a/src/mesh/gnunet-service-mesh_local.c +++ b/src/mesh/gnunet-service-mesh_local.c | |||
@@ -30,6 +30,9 @@ | |||
30 | #include "gnunet-service-mesh_local.h" | 30 | #include "gnunet-service-mesh_local.h" |
31 | #include "gnunet-service-mesh_channel.h" | 31 | #include "gnunet-service-mesh_channel.h" |
32 | 32 | ||
33 | /* INFO DEBUG */ | ||
34 | #include "gnunet-service-mesh_tunnel.h" | ||
35 | |||
33 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) | 36 | #define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) |
34 | 37 | ||
35 | /******************************************************************************/ | 38 | /******************************************************************************/ |
@@ -575,41 +578,41 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client, | |||
575 | } | 578 | } |
576 | 579 | ||
577 | 580 | ||
578 | /* | 581 | /** |
579 | * Iterator over all tunnels to send a monitoring client info about each tunnel. | 582 | * Iterator over all tunnels to send a monitoring client info about each tunnel. |
580 | * | 583 | * |
581 | * @param cls Closure (client handle). | 584 | * @param cls Closure (client handle). |
582 | * @param key Key (hashed tunnel ID, unused). | 585 | * @param peer Peer ID (tunnel remote peer). |
583 | * @param value Tunnel info. | 586 | * @param value Tunnel info. |
584 | * | 587 | * |
585 | * @return #GNUNET_YES, to keep iterating. | 588 | * @return #GNUNET_YES, to keep iterating. |
586 | */ | 589 | */ |
587 | // static int | 590 | static int |
588 | // monitor_all_tunnels_iterator (void *cls, | 591 | monitor_all_tunnels_iterator (void *cls, |
589 | // const struct GNUNET_HashCode * key, | 592 | const struct GNUNET_PeerIdentity * peer, |
590 | // void *value) | 593 | void *value) |
591 | // { | 594 | { |
592 | // struct GNUNET_SERVER_Client *client = cls; | 595 | struct GNUNET_SERVER_Client *client = cls; |
593 | // struct MeshChannel *ch = value; | 596 | struct MeshChannel *ch = value; |
594 | // struct GNUNET_MESH_LocalMonitor *msg; | 597 | struct GNUNET_MESH_LocalInfo *msg; |
595 | // | 598 | |
596 | // msg = GNUNET_new (struct GNUNET_MESH_LocalMonitor); | 599 | msg = GNUNET_new (struct GNUNET_MESH_LocalInfo); |
597 | // msg->channel_id = htonl (ch->gid); | 600 | msg->channel_id = htonl (GMCH_get_id (ch)); |
598 | // msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor)); | 601 | msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalInfo)); |
599 | // msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); | 602 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); |
600 | // | 603 | |
601 | // LOG (GNUNET_ERROR_TYPE_INFO, | 604 | LOG (GNUNET_ERROR_TYPE_INFO, |
602 | // "* sending info about tunnel %s\n", | 605 | "* sending info about tunnel %s\n", |
603 | // GNUNET_i2s (&msg->owner)); | 606 | GNUNET_i2s (&msg->owner)); |
604 | // | 607 | |
605 | // GNUNET_SERVER_notification_context_unicast (nc, client, | 608 | GNUNET_SERVER_notification_context_unicast (nc, client, |
606 | // &msg->header, GNUNET_NO); | 609 | &msg->header, GNUNET_NO); |
607 | // return GNUNET_YES; | 610 | return GNUNET_YES; |
608 | // } | 611 | } |
609 | 612 | ||
610 | 613 | ||
611 | /** | 614 | /** |
612 | * Handler for client's MONITOR request. | 615 | * Handler for client's INFO TUNNELS request. |
613 | * | 616 | * |
614 | * @param cls Closure (unused). | 617 | * @param cls Closure (unused). |
615 | * @param client Identification of the client. | 618 | * @param client Identification of the client. |
@@ -620,6 +623,8 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, | |||
620 | const struct GNUNET_MessageHeader *message) | 623 | const struct GNUNET_MessageHeader *message) |
621 | { | 624 | { |
622 | struct MeshClient *c; | 625 | struct MeshClient *c; |
626 | size_t size; | ||
627 | struct GNUNET_MessageHeader *reply; | ||
623 | 628 | ||
624 | /* Sanity check for client registration */ | 629 | /* Sanity check for client registration */ |
625 | if (NULL == (c = GML_client_get (client))) | 630 | if (NULL == (c = GML_client_get (client))) |
@@ -629,12 +634,18 @@ handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client, | |||
629 | return; | 634 | return; |
630 | } | 635 | } |
631 | 636 | ||
632 | LOG (GNUNET_ERROR_TYPE_INFO, | 637 | LOG (GNUNET_ERROR_TYPE_INFO, "Received get tunnels request from client %u\n", |
633 | "Received get tunnels request from client %u\n", | 638 | c->id); |
634 | c->id); | 639 | |
635 | // GNUNET_CONTAINER_multihashmap_iterate (tunnels, | 640 | size = GMT_count_all () + 1; /* Last one is all \0 to mark 'end' */ |
636 | // monitor_all_tunnels_iterator, | 641 | size *= sizeof (struct GNUNET_PeerIdentity); |
637 | // client); | 642 | size += sizeof (*reply); |
643 | reply = GNUNET_malloc (size); | ||
644 | GMT_iterate_all (reply, monitor_all_tunnels_iterator); | ||
645 | reply->size = htons (size); | ||
646 | reply->type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); | ||
647 | GNUNET_SERVER_notification_context_unicast (nc, client, reply, GNUNET_NO); | ||
648 | |||
638 | LOG (GNUNET_ERROR_TYPE_INFO, | 649 | LOG (GNUNET_ERROR_TYPE_INFO, |
639 | "Get tunnels request from client %u completed\n", | 650 | "Get tunnels request from client %u completed\n", |
640 | c->id); | 651 | c->id); |
@@ -653,8 +664,8 @@ void | |||
653 | handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | 664 | handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, |
654 | const struct GNUNET_MessageHeader *message) | 665 | const struct GNUNET_MessageHeader *message) |
655 | { | 666 | { |
656 | const struct GNUNET_MESH_LocalMonitor *msg; | 667 | const struct GNUNET_MESH_LocalInfo *msg; |
657 | struct GNUNET_MESH_LocalMonitor *resp; | 668 | struct GNUNET_MESH_LocalInfo *resp; |
658 | struct MeshClient *c; | 669 | struct MeshClient *c; |
659 | struct MeshChannel *ch; | 670 | struct MeshChannel *ch; |
660 | 671 | ||
@@ -666,7 +677,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
666 | return; | 677 | return; |
667 | } | 678 | } |
668 | 679 | ||
669 | msg = (struct GNUNET_MESH_LocalMonitor *) message; | 680 | msg = (struct GNUNET_MESH_LocalInfo *) message; |
670 | LOG (GNUNET_ERROR_TYPE_INFO, | 681 | LOG (GNUNET_ERROR_TYPE_INFO, |
671 | "Received tunnel info request from client %u for tunnel %s[%X]\n", | 682 | "Received tunnel info request from client %u for tunnel %s[%X]\n", |
672 | c->id, | 683 | c->id, |
@@ -677,7 +688,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
677 | if (NULL == ch) | 688 | if (NULL == ch) |
678 | { | 689 | { |
679 | /* We don't know the tunnel */ | 690 | /* We don't know the tunnel */ |
680 | struct GNUNET_MESH_LocalMonitor warn; | 691 | struct GNUNET_MESH_LocalInfo warn; |
681 | 692 | ||
682 | warn = *msg; | 693 | warn = *msg; |
683 | GNUNET_SERVER_notification_context_unicast (nc, client, | 694 | GNUNET_SERVER_notification_context_unicast (nc, client, |
@@ -688,9 +699,9 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client, | |||
688 | } | 699 | } |
689 | 700 | ||
690 | /* Initialize context */ | 701 | /* Initialize context */ |
691 | resp = GNUNET_new (struct GNUNET_MESH_LocalMonitor); | 702 | resp = GNUNET_new (struct GNUNET_MESH_LocalInfo); |
692 | *resp = *msg; | 703 | *resp = *msg; |
693 | resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor)); | 704 | resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalInfo)); |
694 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, | 705 | GNUNET_SERVER_notification_context_unicast (nc, c->handle, |
695 | &resp->header, GNUNET_NO); | 706 | &resp->header, GNUNET_NO); |
696 | GNUNET_free (resp); | 707 | GNUNET_free (resp); |
@@ -717,7 +728,7 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { | |||
717 | {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS, | 728 | {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS, |
718 | sizeof (struct GNUNET_MessageHeader)}, | 729 | sizeof (struct GNUNET_MessageHeader)}, |
719 | {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL, | 730 | {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL, |
720 | sizeof (struct GNUNET_MESH_LocalMonitor)}, | 731 | sizeof (struct GNUNET_MESH_LocalInfo)}, |
721 | {NULL, NULL, 0, 0} | 732 | {NULL, NULL, 0, 0} |
722 | }; | 733 | }; |
723 | 734 | ||
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 6976d576d..61a66a7b2 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -2542,6 +2542,11 @@ GMT_2s (const struct MeshTunnel3 *t) | |||
2542 | } | 2542 | } |
2543 | 2543 | ||
2544 | 2544 | ||
2545 | /******************************************************************************/ | ||
2546 | /***************************** INFO/DEBUG *******************************/ | ||
2547 | /******************************************************************************/ | ||
2548 | |||
2549 | |||
2545 | /** | 2550 | /** |
2546 | * Log all possible info about the tunnel state. | 2551 | * Log all possible info about the tunnel state. |
2547 | * | 2552 | * |
@@ -2581,3 +2586,16 @@ GMT_debug (const struct MeshTunnel3 *t) | |||
2581 | 2586 | ||
2582 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DEBUG TUNNEL END\n"); | 2587 | LOG (GNUNET_ERROR_TYPE_DEBUG, "DEBUG TUNNEL END\n"); |
2583 | } | 2588 | } |
2589 | |||
2590 | |||
2591 | void | ||
2592 | GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter) | ||
2593 | { | ||
2594 | GNUNET_CONTAINER_multipeermap_iterate (tunnels, iter, cls); | ||
2595 | } | ||
2596 | |||
2597 | unsigned int | ||
2598 | GMT_count_all (void) | ||
2599 | { | ||
2600 | return GNUNET_CONTAINER_multipeermap_size (tunnels); | ||
2601 | } | ||
diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index 04d429063..19431e346 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h | |||
@@ -463,6 +463,12 @@ GMT_2s (const struct MeshTunnel3 *t); | |||
463 | void | 463 | void |
464 | GMT_debug (const struct MeshTunnel3 *t); | 464 | GMT_debug (const struct MeshTunnel3 *t); |
465 | 465 | ||
466 | void | ||
467 | GMT_iterate_all (void *cls, GNUNET_CONTAINER_PeerMapIterator iter); | ||
468 | |||
469 | unsigned int | ||
470 | GMT_count_all (void); | ||
471 | |||
466 | #if 0 /* keep Emacsens' auto-indent happy */ | 472 | #if 0 /* keep Emacsens' auto-indent happy */ |
467 | { | 473 | { |
468 | #endif | 474 | #endif |
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 1211f7ebc..0113f7855 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -166,10 +166,10 @@ struct GNUNET_MESH_LocalAck | |||
166 | /** | 166 | /** |
167 | * Message to inform the client about channels in the service. | 167 | * Message to inform the client about channels in the service. |
168 | */ | 168 | */ |
169 | struct GNUNET_MESH_LocalMonitor | 169 | struct GNUNET_MESH_LocalInfo |
170 | { | 170 | { |
171 | /** | 171 | /** |
172 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR[_TUNNEL] | 172 | * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO[_TUNNEL] |
173 | */ | 173 | */ |
174 | struct GNUNET_MessageHeader header; | 174 | struct GNUNET_MessageHeader header; |
175 | 175 | ||
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index cd68e253e..926feb8af 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -203,6 +203,26 @@ struct GNUNET_MESH_Handle | |||
203 | * Channel callback closure. | 203 | * Channel callback closure. |
204 | */ | 204 | */ |
205 | void *channel_cls; | 205 | void *channel_cls; |
206 | |||
207 | /** | ||
208 | * Monitor callback | ||
209 | */ | ||
210 | GNUNET_MESH_TunnelsCB tunnels_cb; | ||
211 | |||
212 | /** | ||
213 | * Monitor callback closure. | ||
214 | */ | ||
215 | void *tunnels_cls; | ||
216 | |||
217 | /** | ||
218 | * Tunnel callback. | ||
219 | */ | ||
220 | GNUNET_MESH_TunnelCB tunnel_cb; | ||
221 | |||
222 | /** | ||
223 | * Tunnel callback closure. | ||
224 | */ | ||
225 | void *tunnel_cls; | ||
206 | }; | 226 | }; |
207 | 227 | ||
208 | 228 | ||
@@ -927,7 +947,7 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
927 | // process_get_channels (struct GNUNET_MESH_Handle *h, | 947 | // process_get_channels (struct GNUNET_MESH_Handle *h, |
928 | // const struct GNUNET_MessageHeader *message) | 948 | // const struct GNUNET_MessageHeader *message) |
929 | // { | 949 | // { |
930 | // struct GNUNET_MESH_LocalMonitor *msg; | 950 | // struct GNUNET_MESH_LocalInfo *msg; |
931 | // | 951 | // |
932 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n"); | 952 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n"); |
933 | // | 953 | // |
@@ -937,16 +957,16 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
937 | // return; | 957 | // return; |
938 | // } | 958 | // } |
939 | // | 959 | // |
940 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; | 960 | // msg = (struct GNUNET_MESH_LocalInfo *) message; |
941 | // if (ntohs (message->size) != | 961 | // if (ntohs (message->size) != |
942 | // (sizeof (struct GNUNET_MESH_LocalMonitor) + | 962 | // (sizeof (struct GNUNET_MESH_LocalInfo) + |
943 | // sizeof (struct GNUNET_PeerIdentity))) | 963 | // sizeof (struct GNUNET_PeerIdentity))) |
944 | // { | 964 | // { |
945 | // GNUNET_break_op (0); | 965 | // GNUNET_break_op (0); |
946 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 966 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
947 | // "Get channels message: size %hu - expected %u\n", | 967 | // "Get channels message: size %hu - expected %u\n", |
948 | // ntohs (message->size), | 968 | // ntohs (message->size), |
949 | // sizeof (struct GNUNET_MESH_LocalMonitor)); | 969 | // sizeof (struct GNUNET_MESH_LocalInfo)); |
950 | // return; | 970 | // return; |
951 | // } | 971 | // } |
952 | // h->channels_cb (h->channels_cls, | 972 | // h->channels_cb (h->channels_cls, |
@@ -967,7 +987,7 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
967 | // process_show_channel (struct GNUNET_MESH_Handle *h, | 987 | // process_show_channel (struct GNUNET_MESH_Handle *h, |
968 | // const struct GNUNET_MessageHeader *message) | 988 | // const struct GNUNET_MessageHeader *message) |
969 | // { | 989 | // { |
970 | // struct GNUNET_MESH_LocalMonitor *msg; | 990 | // struct GNUNET_MESH_LocalInfo *msg; |
971 | // size_t esize; | 991 | // size_t esize; |
972 | // | 992 | // |
973 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); | 993 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); |
@@ -979,8 +999,8 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
979 | // } | 999 | // } |
980 | // | 1000 | // |
981 | // /* Verify message sanity */ | 1001 | // /* Verify message sanity */ |
982 | // msg = (struct GNUNET_MESH_LocalMonitor *) message; | 1002 | // msg = (struct GNUNET_MESH_LocalInfo *) message; |
983 | // esize = sizeof (struct GNUNET_MESH_LocalMonitor); | 1003 | // esize = sizeof (struct GNUNET_MESH_LocalInfo); |
984 | // if (ntohs (message->size) != esize) | 1004 | // if (ntohs (message->size) != esize) |
985 | // { | 1005 | // { |
986 | // GNUNET_break_op (0); | 1006 | // GNUNET_break_op (0); |
@@ -1002,6 +1022,88 @@ process_ack (struct GNUNET_MESH_Handle *h, | |||
1002 | // } | 1022 | // } |
1003 | 1023 | ||
1004 | 1024 | ||
1025 | |||
1026 | |||
1027 | /* | ||
1028 | * Process a local reply about info on all tunnels, pass info to the user. | ||
1029 | * | ||
1030 | * @param h Mesh handle. | ||
1031 | * @param message Message itself. | ||
1032 | */ | ||
1033 | static void | ||
1034 | process_get_tunnels (struct GNUNET_MESH_Handle *h, | ||
1035 | const struct GNUNET_MessageHeader *message) | ||
1036 | { | ||
1037 | struct GNUNET_PeerIdentity *id; | ||
1038 | uint16_t size; | ||
1039 | unsigned int i; | ||
1040 | |||
1041 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); | ||
1042 | |||
1043 | if (NULL == h->tunnels_cb) | ||
1044 | { | ||
1045 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | ||
1046 | return; | ||
1047 | } | ||
1048 | |||
1049 | size = ntohs (message->size); | ||
1050 | size /= sizeof (struct GNUNET_PeerIdentity); | ||
1051 | id = (struct GNUNET_PeerIdentity *) &message[1]; | ||
1052 | |||
1053 | for (i = 0; i < size; i++) | ||
1054 | h->tunnels_cb (h->tunnels_cls, &id[i]); | ||
1055 | h->tunnels_cb (h->tunnels_cls, NULL); | ||
1056 | |||
1057 | h->tunnels_cb = NULL; | ||
1058 | h->tunnels_cls = NULL; | ||
1059 | } | ||
1060 | |||
1061 | |||
1062 | |||
1063 | /* | ||
1064 | * Process a local monitor_channel reply, pass info to the user. | ||
1065 | * | ||
1066 | * @param h Mesh handle. | ||
1067 | * @param message Message itself. | ||
1068 | */ | ||
1069 | // static void | ||
1070 | // process_show_channel (struct GNUNET_MESH_Handle *h, | ||
1071 | // const struct GNUNET_MessageHeader *message) | ||
1072 | // { | ||
1073 | // struct GNUNET_MESH_LocalInfo *msg; | ||
1074 | // size_t esize; | ||
1075 | // | ||
1076 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n"); | ||
1077 | // | ||
1078 | // if (NULL == h->channel_cb) | ||
1079 | // { | ||
1080 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); | ||
1081 | // return; | ||
1082 | // } | ||
1083 | // | ||
1084 | // /* Verify message sanity */ | ||
1085 | // msg = (struct GNUNET_MESH_LocalInfo *) message; | ||
1086 | // esize = sizeof (struct GNUNET_MESH_LocalInfo); | ||
1087 | // if (ntohs (message->size) != esize) | ||
1088 | // { | ||
1089 | // GNUNET_break_op (0); | ||
1090 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1091 | // "Show channel message: size %hu - expected %u\n", | ||
1092 | // ntohs (message->size), | ||
1093 | // esize); | ||
1094 | // | ||
1095 | // h->channel_cb (h->channel_cls, NULL, NULL); | ||
1096 | // h->channel_cb = NULL; | ||
1097 | // h->channel_cls = NULL; | ||
1098 | // | ||
1099 | // return; | ||
1100 | // } | ||
1101 | // | ||
1102 | // h->channel_cb (h->channel_cls, | ||
1103 | // &msg->destination, | ||
1104 | // &msg->owner); | ||
1105 | // } | ||
1106 | |||
1005 | /** | 1107 | /** |
1006 | * Function to process all messages received from the service | 1108 | * Function to process all messages received from the service |
1007 | * | 1109 | * |
@@ -1042,10 +1144,16 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1042 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: | 1144 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: |
1043 | process_ack (h, msg); | 1145 | process_ack (h, msg); |
1044 | break; | 1146 | break; |
1045 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED | 1147 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: |
1046 | // process_get_channels (h, msg); | 1148 | // process_get_channels (h, msg); |
1047 | // break; | 1149 | // break; |
1048 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED | 1150 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: |
1151 | // process_show_channel (h, msg); | ||
1152 | // break; | ||
1153 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: | ||
1154 | process_get_tunnels (h, msg); | ||
1155 | break; | ||
1156 | // case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: | ||
1049 | // process_show_channel (h, msg); | 1157 | // process_show_channel (h, msg); |
1050 | // break; | 1158 | // break; |
1051 | default: | 1159 | default: |
@@ -1550,6 +1658,16 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel) | |||
1550 | } | 1658 | } |
1551 | 1659 | ||
1552 | 1660 | ||
1661 | static void | ||
1662 | send_info_request (struct GNUNET_MESH_Handle *h, uint16_t type) | ||
1663 | { | ||
1664 | struct GNUNET_MessageHeader msg; | ||
1665 | |||
1666 | msg.size = htons (sizeof (msg)); | ||
1667 | msg.type = htons (type); | ||
1668 | send_packet (h, &msg, NULL); | ||
1669 | } | ||
1670 | |||
1553 | /** | 1671 | /** |
1554 | * Request information about the running mesh peer. | 1672 | * Request information about the running mesh peer. |
1555 | * The callback will be called for every channel known to the service, | 1673 | * The callback will be called for every channel known to the service, |
@@ -1570,11 +1688,7 @@ GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, | |||
1570 | GNUNET_MESH_ChannelsCB callback, | 1688 | GNUNET_MESH_ChannelsCB callback, |
1571 | void *callback_cls) | 1689 | void *callback_cls) |
1572 | { | 1690 | { |
1573 | struct GNUNET_MessageHeader msg; | 1691 | send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS); |
1574 | |||
1575 | msg.size = htons (sizeof (msg)); | ||
1576 | msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS); | ||
1577 | send_packet (h, &msg, NULL); | ||
1578 | h->channels_cb = callback; | 1692 | h->channels_cb = callback; |
1579 | h->channels_cls = callback_cls; | 1693 | h->channels_cls = callback_cls; |
1580 | } | 1694 | } |
@@ -1583,6 +1697,8 @@ GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h, | |||
1583 | /** | 1697 | /** |
1584 | * Cancel a monitor request. The monitor callback will not be called. | 1698 | * Cancel a monitor request. The monitor callback will not be called. |
1585 | * | 1699 | * |
1700 | * WARNING: unstable API, likely to change in the future! | ||
1701 | * | ||
1586 | * @param h Mesh handle. | 1702 | * @param h Mesh handle. |
1587 | * | 1703 | * |
1588 | * @return Closure given to GNUNET_MESH_monitor, if any. | 1704 | * @return Closure given to GNUNET_MESH_monitor, if any. |
@@ -1600,6 +1716,84 @@ GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h) | |||
1600 | 1716 | ||
1601 | 1717 | ||
1602 | /** | 1718 | /** |
1719 | * Request information about the running mesh peer. | ||
1720 | * The callback will be called for every channel known to the service, | ||
1721 | * listing all active peers that blong to the channel. | ||
1722 | * | ||
1723 | * If called again on the same handle, it will overwrite the previous | ||
1724 | * callback and cls. To retrieve the cls, monitor_cancel must be | ||
1725 | * called first. | ||
1726 | * | ||
1727 | * WARNING: unstable API, likely to change in the future! | ||
1728 | * | ||
1729 | * @param h Handle to the mesh peer. | ||
1730 | * @param callback Function to call with the requested data. | ||
1731 | * @param callback_cls Closure for @c callback. | ||
1732 | */ | ||
1733 | void | ||
1734 | GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, | ||
1735 | GNUNET_MESH_TunnelsCB callback, | ||
1736 | void *callback_cls) | ||
1737 | { | ||
1738 | send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); | ||
1739 | h->tunnels_cb = callback; | ||
1740 | h->tunnels_cls = callback_cls; | ||
1741 | } | ||
1742 | |||
1743 | |||
1744 | /** | ||
1745 | * Cancel a monitor request. The monitor callback will not be called. | ||
1746 | * | ||
1747 | * @param h Mesh handle. | ||
1748 | * | ||
1749 | * @return Closure given to GNUNET_MESH_monitor, if any. | ||
1750 | */ | ||
1751 | void * | ||
1752 | GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) | ||
1753 | { | ||
1754 | void *cls; | ||
1755 | |||
1756 | h->tunnels_cb = NULL; | ||
1757 | cls = h->tunnels_cls; | ||
1758 | h->tunnels_cls = NULL; | ||
1759 | |||
1760 | return cls; | ||
1761 | } | ||
1762 | |||
1763 | |||
1764 | |||
1765 | /** | ||
1766 | * Request information about the running mesh peer. | ||
1767 | * The callback will be called for every channel known to the service, | ||
1768 | * listing all active peers that blong to the channel. | ||
1769 | * | ||
1770 | * If called again on the same handle, it will overwrite the previous | ||
1771 | * callback and cls. To retrieve the cls, monitor_cancel must be | ||
1772 | * called first. | ||
1773 | * | ||
1774 | * WARNING: unstable API, likely to change in the future! | ||
1775 | * | ||
1776 | * @param h Handle to the mesh peer. | ||
1777 | * @param callback Function to call with the requested data. | ||
1778 | * @param callback_cls Closure for @c callback. | ||
1779 | */ | ||
1780 | void | ||
1781 | GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h, | ||
1782 | const struct GNUNET_PeerIdentity *id, | ||
1783 | GNUNET_MESH_TunnelsCB callback, | ||
1784 | void *callback_cls) | ||
1785 | { | ||
1786 | struct GNUNET_MESH_LocalInfo msg; | ||
1787 | |||
1788 | memset (&msg, 0, sizeof (msg)); | ||
1789 | msg.header.size = htons (sizeof (msg)); | ||
1790 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); | ||
1791 | msg.destination = *id; | ||
1792 | send_packet (h, &msg.header, NULL); | ||
1793 | } | ||
1794 | |||
1795 | |||
1796 | /** | ||
1603 | * Request information about a specific channel of the running mesh peer. | 1797 | * Request information about a specific channel of the running mesh peer. |
1604 | * | 1798 | * |
1605 | * WARNING: unstable API, likely to change in the future! | 1799 | * WARNING: unstable API, likely to change in the future! |
@@ -1618,7 +1812,7 @@ GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h, | |||
1618 | GNUNET_MESH_ChannelCB callback, | 1812 | GNUNET_MESH_ChannelCB callback, |
1619 | void *callback_cls) | 1813 | void *callback_cls) |
1620 | { | 1814 | { |
1621 | struct GNUNET_MESH_LocalMonitor msg; | 1815 | struct GNUNET_MESH_LocalInfo msg; |
1622 | 1816 | ||
1623 | msg.header.size = htons (sizeof (msg)); | 1817 | msg.header.size = htons (sizeof (msg)); |
1624 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); | 1818 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL); |