diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:21:27 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-01-27 04:21:27 +0100 |
commit | f0b35049f6d9e743d2bc5fcf11664633d130d6fc (patch) | |
tree | bee27beb5d8a25ca043e483a40400fef783056c9 | |
parent | d3f013aba71486c121800d279cd1d3af4425c412 (diff) | |
download | gnunet-f0b35049f6d9e743d2bc5fcf11664633d130d6fc.tar.gz gnunet-f0b35049f6d9e743d2bc5fcf11664633d130d6fc.zip |
more work towards fixing #5385
-rw-r--r-- | src/cadet/cadet_api_list_tunnels.c | 81 | ||||
-rw-r--r-- | src/cadet/gnunet-cadet.c | 45 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet.c | 8 | ||||
-rw-r--r-- | src/include/gnunet_cadet_service.h | 44 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 9 |
5 files changed, 103 insertions, 84 deletions
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c index 631b321b7..a2ba65993 100644 --- a/src/cadet/cadet_api_list_tunnels.c +++ b/src/cadet/cadet_api_list_tunnels.c | |||
@@ -71,26 +71,25 @@ struct GNUNET_CADET_ListTunnels | |||
71 | 71 | ||
72 | 72 | ||
73 | /** | 73 | /** |
74 | * Check that message received from CADET service is well-formed. | 74 | * Process a local reply about info on all tunnels, pass info to the user. |
75 | * | 75 | * |
76 | * @param cls the `struct GNUNET_CADET_Handle` | 76 | * @param cls a `struct GNUNET_CADET_ListTunnels *` |
77 | * @param message the message we got | 77 | * @param info Message itself. |
78 | * @return #GNUNET_OK if the message is well-formed, | ||
79 | * #GNUNET_SYSERR otherwise | ||
80 | */ | 78 | */ |
81 | static int | 79 | static void |
82 | check_get_tunnels (void *cls, | 80 | handle_get_tunnels (void *cls, |
83 | const struct GNUNET_MessageHeader *message) | 81 | const struct GNUNET_CADET_LocalInfoTunnel *info) |
84 | { | 82 | { |
85 | size_t esize; | 83 | struct GNUNET_CADET_ListTunnels *lt = cls; |
86 | 84 | struct GNUNET_CADET_TunnelDetails td; | |
87 | (void) cls; | 85 | |
88 | esize = ntohs (message->size); | 86 | td.peer = info->destination; |
89 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == esize) | 87 | td.channels = ntohl (info->channels); |
90 | return GNUNET_OK; | 88 | td.connections = ntohl (info->connections); |
91 | if (sizeof (struct GNUNET_MessageHeader) == esize) | 89 | td.estate = ntohs (info->estate); |
92 | return GNUNET_OK; | 90 | td.cstate = ntohs (info->cstate); |
93 | return GNUNET_SYSERR; | 91 | lt->tunnels_cb (lt->tunnels_cb_cls, |
92 | &td); | ||
94 | } | 93 | } |
95 | 94 | ||
96 | 95 | ||
@@ -101,31 +100,15 @@ check_get_tunnels (void *cls, | |||
101 | * @param message Message itself. | 100 | * @param message Message itself. |
102 | */ | 101 | */ |
103 | static void | 102 | static void |
104 | handle_get_tunnels (void *cls, | 103 | handle_get_tunnels_end (void *cls, |
105 | const struct GNUNET_MessageHeader *msg) | 104 | const struct GNUNET_MessageHeader *msg) |
106 | { | 105 | { |
107 | struct GNUNET_CADET_ListTunnels *lt = cls; | 106 | struct GNUNET_CADET_ListTunnels *lt = cls; |
108 | const struct GNUNET_CADET_LocalInfoTunnel *info = | 107 | (void) msg; |
109 | (const struct GNUNET_CADET_LocalInfoTunnel *) msg; | 108 | |
110 | 109 | lt->tunnels_cb (lt->tunnels_cb_cls, | |
111 | // FIXME: use two message types! | 110 | NULL); |
112 | if (sizeof (struct GNUNET_CADET_LocalInfoTunnel) == ntohs (msg->size)) | 111 | GNUNET_CADET_list_tunnels_cancel (lt); |
113 | lt->tunnels_cb (lt->tunnels_cb_cls, | ||
114 | &info->destination, | ||
115 | ntohl (info->channels), | ||
116 | ntohl (info->connections), | ||
117 | ntohs (info->estate), | ||
118 | ntohs (info->cstate)); | ||
119 | else | ||
120 | { | ||
121 | lt->tunnels_cb (lt->tunnels_cb_cls, | ||
122 | NULL, | ||
123 | 0, | ||
124 | 0, | ||
125 | 0, | ||
126 | 0); | ||
127 | GNUNET_CADET_list_tunnels_cancel (lt); | ||
128 | } | ||
129 | } | 112 | } |
130 | 113 | ||
131 | 114 | ||
@@ -170,10 +153,14 @@ reconnect (void *cls) | |||
170 | { | 153 | { |
171 | struct GNUNET_CADET_ListTunnels *lt = cls; | 154 | struct GNUNET_CADET_ListTunnels *lt = cls; |
172 | struct GNUNET_MQ_MessageHandler handlers[] = { | 155 | struct GNUNET_MQ_MessageHandler handlers[] = { |
173 | GNUNET_MQ_hd_var_size (get_tunnels, | 156 | GNUNET_MQ_hd_fixed_size (get_tunnels, |
174 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | 157 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, |
175 | struct GNUNET_MessageHeader, | 158 | struct GNUNET_CADET_LocalInfoTunnel, |
176 | lt), | 159 | lt), |
160 | GNUNET_MQ_hd_fixed_size (get_tunnels_end, | ||
161 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END, | ||
162 | struct GNUNET_MessageHeader, | ||
163 | lt), | ||
177 | GNUNET_MQ_handler_end () | 164 | GNUNET_MQ_handler_end () |
178 | }; | 165 | }; |
179 | struct GNUNET_MessageHeader *msg; | 166 | struct GNUNET_MessageHeader *msg; |
@@ -188,7 +175,7 @@ reconnect (void *cls) | |||
188 | if (NULL == lt->mq) | 175 | if (NULL == lt->mq) |
189 | return; | 176 | return; |
190 | env = GNUNET_MQ_msg (msg, | 177 | env = GNUNET_MQ_msg (msg, |
191 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); | 178 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS); |
192 | GNUNET_MQ_send (lt->mq, | 179 | GNUNET_MQ_send (lt->mq, |
193 | env); | 180 | env); |
194 | } | 181 | } |
@@ -199,9 +186,7 @@ reconnect (void *cls) | |||
199 | * The callback will be called for every tunnel of the service. | 186 | * The callback will be called for every tunnel of the service. |
200 | * Only one info request (of any kind) can be active at once. | 187 | * Only one info request (of any kind) can be active at once. |
201 | * | 188 | * |
202 | * WARNING: unstable API, likely to change in the future! | 189 | * @param cfg configuration to use |
203 | * | ||
204 | * @param h Handle to the cadet peer. | ||
205 | * @param callback Function to call with the requested data. | 190 | * @param callback Function to call with the requested data. |
206 | * @param callback_cls Closure for @c callback. | 191 | * @param callback_cls Closure for @c callback. |
207 | * @return NULL on error | 192 | * @return NULL on error |
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c index 3386f7464..9e2d105b3 100644 --- a/src/cadet/gnunet-cadet.c +++ b/src/cadet/gnunet-cadet.c | |||
@@ -109,7 +109,12 @@ static struct GNUNET_CADET_GetPath *gpo; | |||
109 | /** | 109 | /** |
110 | * Active peer listing operation. | 110 | * Active peer listing operation. |
111 | */ | 111 | */ |
112 | struct GNUNET_CADET_PeersLister *plo; | 112 | static struct GNUNET_CADET_PeersLister *plo; |
113 | |||
114 | /** | ||
115 | * Active tunnel listing operation. | ||
116 | */ | ||
117 | static struct GNUNET_CADET_ListTunnels *tio; | ||
113 | 118 | ||
114 | /** | 119 | /** |
115 | * Channel handle. | 120 | * Channel handle. |
@@ -231,6 +236,11 @@ shutdown_task (void *cls) | |||
231 | GNUNET_CADET_list_peers_cancel (plo); | 236 | GNUNET_CADET_list_peers_cancel (plo); |
232 | plo = NULL; | 237 | plo = NULL; |
233 | } | 238 | } |
239 | if (NULL != tio) | ||
240 | { | ||
241 | GNUNET_CADET_list_tunnels_cancel (tio); | ||
242 | tio = NULL; | ||
243 | } | ||
234 | if (NULL != mh) | 244 | if (NULL != mh) |
235 | { | 245 | { |
236 | GNUNET_CADET_disconnect (mh); | 246 | GNUNET_CADET_disconnect (mh); |
@@ -569,32 +579,25 @@ path_callback (void *cls, | |||
569 | * Method called to retrieve information about all tunnels in CADET. | 579 | * Method called to retrieve information about all tunnels in CADET. |
570 | * | 580 | * |
571 | * @param cls Closure. | 581 | * @param cls Closure. |
572 | * @param peer Destination peer. | 582 | * @param td tunnel details |
573 | * @param channels Number of channels. | ||
574 | * @param connections Number of connections. | ||
575 | * @param estate Encryption state. | ||
576 | * @param cstate Connectivity state. | ||
577 | */ | 583 | */ |
578 | static void | 584 | static void |
579 | tunnels_callback (void *cls, | 585 | tunnels_callback (void *cls, |
580 | const struct GNUNET_PeerIdentity *peer, | 586 | const struct GNUNET_CADET_TunnelDetails *td) |
581 | unsigned int channels, | ||
582 | unsigned int connections, | ||
583 | uint16_t estate, | ||
584 | uint16_t cstate) | ||
585 | { | 587 | { |
586 | if (NULL == peer) | 588 | if (NULL == td) |
587 | { | 589 | { |
590 | tio = NULL; | ||
588 | GNUNET_SCHEDULER_shutdown(); | 591 | GNUNET_SCHEDULER_shutdown(); |
589 | return; | 592 | return; |
590 | } | 593 | } |
591 | FPRINTF (stdout, | 594 | FPRINTF (stdout, |
592 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", | 595 | "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n", |
593 | GNUNET_i2s_full (peer), | 596 | GNUNET_i2s_full (&td->peer), |
594 | enc_2s (estate), | 597 | enc_2s (td->estate), |
595 | conn_2s (cstate), | 598 | conn_2s (td->cstate), |
596 | channels, | 599 | td->channels, |
597 | connections); | 600 | td->connections); |
598 | } | 601 | } |
599 | 602 | ||
600 | 603 | ||
@@ -692,11 +695,9 @@ static void | |||
692 | get_tunnels (void *cls) | 695 | get_tunnels (void *cls) |
693 | { | 696 | { |
694 | job = NULL; | 697 | job = NULL; |
695 | #if FIXME5385 | 698 | tio = GNUNET_CADET_list_tunnels (my_cfg, |
696 | GNUNET_CADET_list_tunnels (my_cfg, | 699 | &tunnels_callback, |
697 | &tunnels_callback, | 700 | NULL); |
698 | NULL); | ||
699 | #endif | ||
700 | } | 701 | } |
701 | 702 | ||
702 | 703 | ||
diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index a62ce4cb0..ef5fa6d7e 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c | |||
@@ -974,7 +974,7 @@ get_all_tunnels_iterator (void *cls, | |||
974 | 974 | ||
975 | 975 | ||
976 | /** | 976 | /** |
977 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS request. | 977 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS request. |
978 | * | 978 | * |
979 | * @param cls client Identification of the client. | 979 | * @param cls client Identification of the client. |
980 | * @param message The actual message. | 980 | * @param message The actual message. |
@@ -990,7 +990,7 @@ handle_info_tunnels (void *cls, | |||
990 | GCP_iterate_all (&get_all_tunnels_iterator, | 990 | GCP_iterate_all (&get_all_tunnels_iterator, |
991 | c); | 991 | c); |
992 | env = GNUNET_MQ_msg (reply, | 992 | env = GNUNET_MQ_msg (reply, |
993 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS); | 993 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END); |
994 | GNUNET_MQ_send (c->mq, | 994 | GNUNET_MQ_send (c->mq, |
995 | env); | 995 | env); |
996 | GNUNET_SERVICE_client_continue (c->client); | 996 | GNUNET_SERVICE_client_continue (c->client); |
@@ -1036,7 +1036,7 @@ iter_channel (void *cls, | |||
1036 | 1036 | ||
1037 | 1037 | ||
1038 | /** | 1038 | /** |
1039 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL request. | 1039 | * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNEL request. |
1040 | * | 1040 | * |
1041 | * @param cls Identification of the client. | 1041 | * @param cls Identification of the client. |
1042 | * @param msg The actual message. | 1042 | * @param msg The actual message. |
@@ -1435,7 +1435,7 @@ GNUNET_SERVICE_MAIN | |||
1435 | struct GNUNET_CADET_RequestPathInfoMessage, | 1435 | struct GNUNET_CADET_RequestPathInfoMessage, |
1436 | NULL), | 1436 | NULL), |
1437 | GNUNET_MQ_hd_fixed_size (info_tunnels, | 1437 | GNUNET_MQ_hd_fixed_size (info_tunnels, |
1438 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, | 1438 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS, |
1439 | struct GNUNET_MessageHeader, | 1439 | struct GNUNET_MessageHeader, |
1440 | NULL), | 1440 | NULL), |
1441 | GNUNET_MQ_hd_fixed_size (info_tunnel, | 1441 | GNUNET_MQ_hd_fixed_size (info_tunnel, |
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h index ce44be88a..82350ed32 100644 --- a/src/include/gnunet_cadet_service.h +++ b/src/include/gnunet_cadet_service.h | |||
@@ -572,25 +572,49 @@ GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp); | |||
572 | 572 | ||
573 | 573 | ||
574 | /** | 574 | /** |
575 | * Details about a tunnel managed by CADET. | ||
576 | */ | ||
577 | struct GNUNET_CADET_TunnelDetails | ||
578 | { | ||
579 | /** | ||
580 | * Target of the tunnel. | ||
581 | */ | ||
582 | struct GNUNET_PeerIdentity peer; | ||
583 | |||
584 | /** | ||
585 | * How many channels use the tunnel. | ||
586 | */ | ||
587 | uint32_t channels; | ||
588 | |||
589 | /** | ||
590 | * How many connections support the tunnel. | ||
591 | */ | ||
592 | uint32_t connections; | ||
593 | |||
594 | /** | ||
595 | * What is our encryption state? | ||
596 | */ | ||
597 | uint16_t estate; | ||
598 | |||
599 | /** | ||
600 | * What is our connectivity state? | ||
601 | */ | ||
602 | uint16_t cstate; | ||
603 | }; | ||
604 | |||
605 | |||
606 | /** | ||
575 | * Method called to retrieve information about all tunnels in CADET, called | 607 | * Method called to retrieve information about all tunnels in CADET, called |
576 | * once per tunnel. | 608 | * once per tunnel. |
577 | * | 609 | * |
578 | * After last tunnel has been reported, an additional call with NULL is done. | 610 | * After last tunnel has been reported, an additional call with NULL is done. |
579 | * | 611 | * |
580 | * @param cls Closure. | 612 | * @param cls Closure. |
581 | * @param peer Destination peer, or NULL on "EOF". | 613 | * @param td tunnel details, NULL for end of list |
582 | * @param channels Number of channels. | ||
583 | * @param connections Number of connections. | ||
584 | * @param estate Encryption state. | ||
585 | * @param cstate Connectivity state. | ||
586 | */ | 614 | */ |
587 | typedef void | 615 | typedef void |
588 | (*GNUNET_CADET_TunnelsCB) (void *cls, | 616 | (*GNUNET_CADET_TunnelsCB) (void *cls, |
589 | const struct GNUNET_PeerIdentity *peer, | 617 | const struct GNUNET_CADET_TunnelDetails *td); |
590 | unsigned int channels, | ||
591 | unsigned int connections, | ||
592 | uint16_t estate, | ||
593 | uint16_t cstate); | ||
594 | 618 | ||
595 | 619 | ||
596 | /** | 620 | /** |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 1b1bdc099..9d3280d36 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2916,6 +2916,15 @@ extern "C" | |||
2916 | */ | 2916 | */ |
2917 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH 1042 | 2917 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH 1042 |
2918 | 2918 | ||
2919 | /** | ||
2920 | * End of local information about all tunnels of service. | ||
2921 | */ | ||
2922 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END 1043 | ||
2923 | |||
2924 | /** | ||
2925 | * Request local information about all tunnels of service. | ||
2926 | */ | ||
2927 | #define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS 1044 | ||
2919 | 2928 | ||
2920 | /******************************** Application *******************************/ | 2929 | /******************************** Application *******************************/ |
2921 | 2930 | ||