diff options
Diffstat (limited to 'src/cadet/cadet_api_list_tunnels.c')
-rw-r--r-- | src/cadet/cadet_api_list_tunnels.c | 81 |
1 files changed, 33 insertions, 48 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 |