summaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api_list_tunnels.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_api_list_tunnels.c')
-rw-r--r--src/cadet/cadet_api_list_tunnels.c121
1 files changed, 61 insertions, 60 deletions
diff --git a/src/cadet/cadet_api_list_tunnels.c b/src/cadet/cadet_api_list_tunnels.c
index 2ea8cf26c..e9ae069bb 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -34,7 +34,8 @@
34/** 34/**
35 * Operation handle. 35 * Operation handle.
36 */ 36 */
37struct GNUNET_CADET_ListTunnels { 37struct GNUNET_CADET_ListTunnels
38{
38 /** 39 /**
39 * Monitor callback 40 * Monitor callback
40 */ 41 */
@@ -74,19 +75,19 @@ struct GNUNET_CADET_ListTunnels {
74 * @param info Message itself. 75 * @param info Message itself.
75 */ 76 */
76static void 77static void
77handle_get_tunnels(void *cls, 78handle_get_tunnels (void *cls,
78 const struct GNUNET_CADET_LocalInfoTunnel *info) 79 const struct GNUNET_CADET_LocalInfoTunnel *info)
79{ 80{
80 struct GNUNET_CADET_ListTunnels *lt = cls; 81 struct GNUNET_CADET_ListTunnels *lt = cls;
81 struct GNUNET_CADET_TunnelDetails td; 82 struct GNUNET_CADET_TunnelDetails td;
82 83
83 td.peer = info->destination; 84 td.peer = info->destination;
84 td.channels = ntohl(info->channels); 85 td.channels = ntohl (info->channels);
85 td.connections = ntohl(info->connections); 86 td.connections = ntohl (info->connections);
86 td.estate = ntohs(info->estate); 87 td.estate = ntohs (info->estate);
87 td.cstate = ntohs(info->cstate); 88 td.cstate = ntohs (info->cstate);
88 lt->tunnels_cb(lt->tunnels_cb_cls, 89 lt->tunnels_cb (lt->tunnels_cb_cls,
89 &td); 90 &td);
90} 91}
91 92
92 93
@@ -97,16 +98,16 @@ handle_get_tunnels(void *cls,
97 * @param message Message itself. 98 * @param message Message itself.
98 */ 99 */
99static void 100static void
100handle_get_tunnels_end(void *cls, 101handle_get_tunnels_end (void *cls,
101 const struct GNUNET_MessageHeader *msg) 102 const struct GNUNET_MessageHeader *msg)
102{ 103{
103 struct GNUNET_CADET_ListTunnels *lt = cls; 104 struct GNUNET_CADET_ListTunnels *lt = cls;
104 105
105 (void)msg; 106 (void) msg;
106 107
107 lt->tunnels_cb(lt->tunnels_cb_cls, 108 lt->tunnels_cb (lt->tunnels_cb_cls,
108 NULL); 109 NULL);
109 GNUNET_CADET_list_tunnels_cancel(lt); 110 GNUNET_CADET_list_tunnels_cancel (lt);
110} 111}
111 112
112 113
@@ -116,7 +117,7 @@ handle_get_tunnels_end(void *cls,
116 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 117 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
117 */ 118 */
118static void 119static void
119reconnect(void *cls); 120reconnect (void *cls);
120 121
121 122
122/** 123/**
@@ -126,18 +127,18 @@ reconnect(void *cls);
126 * @param error error code from MQ 127 * @param error error code from MQ
127 */ 128 */
128static void 129static void
129error_handler(void *cls, 130error_handler (void *cls,
130 enum GNUNET_MQ_Error error) 131 enum GNUNET_MQ_Error error)
131{ 132{
132 struct GNUNET_CADET_ListTunnels *lt = cls; 133 struct GNUNET_CADET_ListTunnels *lt = cls;
133 134
134 GNUNET_MQ_destroy(lt->mq); 135 GNUNET_MQ_destroy (lt->mq);
135 lt->mq = NULL; 136 lt->mq = NULL;
136 lt->backoff = GNUNET_TIME_randomized_backoff(lt->backoff, 137 lt->backoff = GNUNET_TIME_randomized_backoff (lt->backoff,
137 GNUNET_TIME_UNIT_MINUTES); 138 GNUNET_TIME_UNIT_MINUTES);
138 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed(lt->backoff, 139 lt->reconnect_task = GNUNET_SCHEDULER_add_delayed (lt->backoff,
139 &reconnect, 140 &reconnect,
140 lt); 141 lt);
141} 142}
142 143
143 144
@@ -147,35 +148,35 @@ error_handler(void *cls,
147 * @param cls a `struct GNUNET_CADET_ListTunnels` operation 148 * @param cls a `struct GNUNET_CADET_ListTunnels` operation
148 */ 149 */
149static void 150static void
150reconnect(void *cls) 151reconnect (void *cls)
151{ 152{
152 struct GNUNET_CADET_ListTunnels *lt = cls; 153 struct GNUNET_CADET_ListTunnels *lt = cls;
153 struct GNUNET_MQ_MessageHandler handlers[] = { 154 struct GNUNET_MQ_MessageHandler handlers[] = {
154 GNUNET_MQ_hd_fixed_size(get_tunnels, 155 GNUNET_MQ_hd_fixed_size (get_tunnels,
155 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 156 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
156 struct GNUNET_CADET_LocalInfoTunnel, 157 struct GNUNET_CADET_LocalInfoTunnel,
157 lt), 158 lt),
158 GNUNET_MQ_hd_fixed_size(get_tunnels_end, 159 GNUNET_MQ_hd_fixed_size (get_tunnels_end,
159 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END, 160 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS_END,
160 struct GNUNET_MessageHeader, 161 struct GNUNET_MessageHeader,
161 lt), 162 lt),
162 GNUNET_MQ_handler_end() 163 GNUNET_MQ_handler_end ()
163 }; 164 };
164 struct GNUNET_MessageHeader *msg; 165 struct GNUNET_MessageHeader *msg;
165 struct GNUNET_MQ_Envelope *env; 166 struct GNUNET_MQ_Envelope *env;
166 167
167 lt->reconnect_task = NULL; 168 lt->reconnect_task = NULL;
168 lt->mq = GNUNET_CLIENT_connect(lt->cfg, 169 lt->mq = GNUNET_CLIENT_connect (lt->cfg,
169 "cadet", 170 "cadet",
170 handlers, 171 handlers,
171 &error_handler, 172 &error_handler,
172 lt); 173 lt);
173 if (NULL == lt->mq) 174 if (NULL == lt->mq)
174 return; 175 return;
175 env = GNUNET_MQ_msg(msg, 176 env = GNUNET_MQ_msg (msg,
176 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS); 177 GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_TUNNELS);
177 GNUNET_MQ_send(lt->mq, 178 GNUNET_MQ_send (lt->mq,
178 env); 179 env);
179} 180}
180 181
181 182
@@ -190,27 +191,27 @@ reconnect(void *cls)
190 * @return NULL on error 191 * @return NULL on error
191 */ 192 */
192struct GNUNET_CADET_ListTunnels * 193struct GNUNET_CADET_ListTunnels *
193GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg, 194GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
194 GNUNET_CADET_TunnelsCB callback, 195 GNUNET_CADET_TunnelsCB callback,
195 void *callback_cls) 196 void *callback_cls)
196{ 197{
197 struct GNUNET_CADET_ListTunnels *lt; 198 struct GNUNET_CADET_ListTunnels *lt;
198 199
199 if (NULL == callback) 200 if (NULL == callback)
200 { 201 {
201 GNUNET_break(0); 202 GNUNET_break (0);
202 return NULL; 203 return NULL;
203 } 204 }
204 lt = GNUNET_new(struct GNUNET_CADET_ListTunnels); 205 lt = GNUNET_new (struct GNUNET_CADET_ListTunnels);
205 lt->tunnels_cb = callback; 206 lt->tunnels_cb = callback;
206 lt->tunnels_cb_cls = callback_cls; 207 lt->tunnels_cb_cls = callback_cls;
207 lt->cfg = cfg; 208 lt->cfg = cfg;
208 reconnect(lt); 209 reconnect (lt);
209 if (NULL == lt->mq) 210 if (NULL == lt->mq)
210 { 211 {
211 GNUNET_free(lt); 212 GNUNET_free (lt);
212 return NULL; 213 return NULL;
213 } 214 }
214 return lt; 215 return lt;
215} 216}
216 217
@@ -222,15 +223,15 @@ GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg,
222 * @return Closure given to GNUNET_CADET_list_tunnels(). 223 * @return Closure given to GNUNET_CADET_list_tunnels().
223 */ 224 */
224void * 225void *
225GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt) 226GNUNET_CADET_list_tunnels_cancel (struct GNUNET_CADET_ListTunnels *lt)
226{ 227{
227 void *ret = lt->tunnels_cb_cls; 228 void *ret = lt->tunnels_cb_cls;
228 229
229 if (NULL != lt->mq) 230 if (NULL != lt->mq)
230 GNUNET_MQ_destroy(lt->mq); 231 GNUNET_MQ_destroy (lt->mq);
231 if (NULL != lt->reconnect_task) 232 if (NULL != lt->reconnect_task)
232 GNUNET_SCHEDULER_cancel(lt->reconnect_task); 233 GNUNET_SCHEDULER_cancel (lt->reconnect_task);
233 GNUNET_free(lt); 234 GNUNET_free (lt);
234 return ret; 235 return ret;
235} 236}
236 237