diff options
Diffstat (limited to 'src/cadet/cadet_api_list_peers.c')
-rw-r--r-- | src/cadet/cadet_api_list_peers.c | 119 |
1 files changed, 60 insertions, 59 deletions
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c index 65e9ad4da..8865b6f57 100644 --- a/src/cadet/cadet_api_list_peers.c +++ b/src/cadet/cadet_api_list_peers.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Operation handle. | 35 | * Operation handle. |
36 | */ | 36 | */ |
37 | struct GNUNET_CADET_PeersLister { | 37 | struct GNUNET_CADET_PeersLister |
38 | { | ||
38 | /** | 39 | /** |
39 | * Monitor callback | 40 | * Monitor callback |
40 | */ | 41 | */ |
@@ -74,18 +75,18 @@ struct GNUNET_CADET_PeersLister { | |||
74 | * @param info Message itself. | 75 | * @param info Message itself. |
75 | */ | 76 | */ |
76 | static void | 77 | static void |
77 | handle_get_peers(void *cls, | 78 | handle_get_peers (void *cls, |
78 | const struct GNUNET_CADET_LocalInfoPeers *info) | 79 | const struct GNUNET_CADET_LocalInfoPeers *info) |
79 | { | 80 | { |
80 | struct GNUNET_CADET_PeersLister *pl = cls; | 81 | struct GNUNET_CADET_PeersLister *pl = cls; |
81 | struct GNUNET_CADET_PeerListEntry ple; | 82 | struct GNUNET_CADET_PeerListEntry ple; |
82 | 83 | ||
83 | ple.peer = info->destination; | 84 | ple.peer = info->destination; |
84 | ple.have_tunnel = (int)ntohs(info->tunnel); | 85 | ple.have_tunnel = (int) ntohs (info->tunnel); |
85 | ple.n_paths = (unsigned int)ntohs(info->paths); | 86 | ple.n_paths = (unsigned int) ntohs (info->paths); |
86 | ple.best_path_length = (unsigned int)ntohl(info->best_path_length); | 87 | ple.best_path_length = (unsigned int) ntohl (info->best_path_length); |
87 | pl->peers_cb(pl->peers_cb_cls, | 88 | pl->peers_cb (pl->peers_cb_cls, |
88 | &ple); | 89 | &ple); |
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
@@ -96,16 +97,16 @@ handle_get_peers(void *cls, | |||
96 | * @param msg Message itself. | 97 | * @param msg Message itself. |
97 | */ | 98 | */ |
98 | static void | 99 | static void |
99 | handle_get_peers_end(void *cls, | 100 | handle_get_peers_end (void *cls, |
100 | const struct GNUNET_MessageHeader *msg) | 101 | const struct GNUNET_MessageHeader *msg) |
101 | { | 102 | { |
102 | struct GNUNET_CADET_PeersLister *pl = cls; | 103 | struct GNUNET_CADET_PeersLister *pl = cls; |
103 | 104 | ||
104 | (void)msg; | 105 | (void) msg; |
105 | 106 | ||
106 | pl->peers_cb(pl->peers_cb_cls, | 107 | pl->peers_cb (pl->peers_cb_cls, |
107 | NULL); | 108 | NULL); |
108 | GNUNET_CADET_list_peers_cancel(pl); | 109 | GNUNET_CADET_list_peers_cancel (pl); |
109 | } | 110 | } |
110 | 111 | ||
111 | 112 | ||
@@ -115,7 +116,7 @@ handle_get_peers_end(void *cls, | |||
115 | * @param cls a `struct GNUNET_CADET_PeersLister` operation | 116 | * @param cls a `struct GNUNET_CADET_PeersLister` operation |
116 | */ | 117 | */ |
117 | static void | 118 | static void |
118 | reconnect(void *cls); | 119 | reconnect (void *cls); |
119 | 120 | ||
120 | 121 | ||
121 | /** | 122 | /** |
@@ -125,18 +126,18 @@ reconnect(void *cls); | |||
125 | * @param error error code from MQ | 126 | * @param error error code from MQ |
126 | */ | 127 | */ |
127 | static void | 128 | static void |
128 | error_handler(void *cls, | 129 | error_handler (void *cls, |
129 | enum GNUNET_MQ_Error error) | 130 | enum GNUNET_MQ_Error error) |
130 | { | 131 | { |
131 | struct GNUNET_CADET_PeersLister *pl = cls; | 132 | struct GNUNET_CADET_PeersLister *pl = cls; |
132 | 133 | ||
133 | GNUNET_MQ_destroy(pl->mq); | 134 | GNUNET_MQ_destroy (pl->mq); |
134 | pl->mq = NULL; | 135 | pl->mq = NULL; |
135 | pl->backoff = GNUNET_TIME_randomized_backoff(pl->backoff, | 136 | pl->backoff = GNUNET_TIME_randomized_backoff (pl->backoff, |
136 | GNUNET_TIME_UNIT_MINUTES); | 137 | GNUNET_TIME_UNIT_MINUTES); |
137 | pl->reconnect_task = GNUNET_SCHEDULER_add_delayed(pl->backoff, | 138 | pl->reconnect_task = GNUNET_SCHEDULER_add_delayed (pl->backoff, |
138 | &reconnect, | 139 | &reconnect, |
139 | pl); | 140 | pl); |
140 | } | 141 | } |
141 | 142 | ||
142 | 143 | ||
@@ -146,35 +147,35 @@ error_handler(void *cls, | |||
146 | * @param cls a `struct GNUNET_CADET_PeersLister` operation | 147 | * @param cls a `struct GNUNET_CADET_PeersLister` operation |
147 | */ | 148 | */ |
148 | static void | 149 | static void |
149 | reconnect(void *cls) | 150 | reconnect (void *cls) |
150 | { | 151 | { |
151 | struct GNUNET_CADET_PeersLister *pl = cls; | 152 | struct GNUNET_CADET_PeersLister *pl = cls; |
152 | struct GNUNET_MQ_MessageHandler handlers[] = { | 153 | struct GNUNET_MQ_MessageHandler handlers[] = { |
153 | GNUNET_MQ_hd_fixed_size(get_peers, | 154 | GNUNET_MQ_hd_fixed_size (get_peers, |
154 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, | 155 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, |
155 | struct GNUNET_CADET_LocalInfoPeers, | 156 | struct GNUNET_CADET_LocalInfoPeers, |
156 | pl), | 157 | pl), |
157 | GNUNET_MQ_hd_fixed_size(get_peers_end, | 158 | GNUNET_MQ_hd_fixed_size (get_peers_end, |
158 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, | 159 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, |
159 | struct GNUNET_MessageHeader, | 160 | struct GNUNET_MessageHeader, |
160 | pl), | 161 | pl), |
161 | GNUNET_MQ_handler_end() | 162 | GNUNET_MQ_handler_end () |
162 | }; | 163 | }; |
163 | struct GNUNET_MessageHeader *msg; | 164 | struct GNUNET_MessageHeader *msg; |
164 | struct GNUNET_MQ_Envelope *env; | 165 | struct GNUNET_MQ_Envelope *env; |
165 | 166 | ||
166 | pl->reconnect_task = NULL; | 167 | pl->reconnect_task = NULL; |
167 | pl->mq = GNUNET_CLIENT_connect(pl->cfg, | 168 | pl->mq = GNUNET_CLIENT_connect (pl->cfg, |
168 | "cadet", | 169 | "cadet", |
169 | handlers, | 170 | handlers, |
170 | &error_handler, | 171 | &error_handler, |
171 | pl); | 172 | pl); |
172 | if (NULL == pl->mq) | 173 | if (NULL == pl->mq) |
173 | return; | 174 | return; |
174 | env = GNUNET_MQ_msg(msg, | 175 | env = GNUNET_MQ_msg (msg, |
175 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); | 176 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS); |
176 | GNUNET_MQ_send(pl->mq, | 177 | GNUNET_MQ_send (pl->mq, |
177 | env); | 178 | env); |
178 | } | 179 | } |
179 | 180 | ||
180 | 181 | ||
@@ -189,27 +190,27 @@ reconnect(void *cls) | |||
189 | * @return NULL on error | 190 | * @return NULL on error |
190 | */ | 191 | */ |
191 | struct GNUNET_CADET_PeersLister * | 192 | struct GNUNET_CADET_PeersLister * |
192 | GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, | 193 | GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, |
193 | GNUNET_CADET_PeersCB callback, | 194 | GNUNET_CADET_PeersCB callback, |
194 | void *callback_cls) | 195 | void *callback_cls) |
195 | { | 196 | { |
196 | struct GNUNET_CADET_PeersLister *pl; | 197 | struct GNUNET_CADET_PeersLister *pl; |
197 | 198 | ||
198 | if (NULL == callback) | 199 | if (NULL == callback) |
199 | { | 200 | { |
200 | GNUNET_break(0); | 201 | GNUNET_break (0); |
201 | return NULL; | 202 | return NULL; |
202 | } | 203 | } |
203 | pl = GNUNET_new(struct GNUNET_CADET_PeersLister); | 204 | pl = GNUNET_new (struct GNUNET_CADET_PeersLister); |
204 | pl->peers_cb = callback; | 205 | pl->peers_cb = callback; |
205 | pl->peers_cb_cls = callback_cls; | 206 | pl->peers_cb_cls = callback_cls; |
206 | pl->cfg = cfg; | 207 | pl->cfg = cfg; |
207 | reconnect(pl); | 208 | reconnect (pl); |
208 | if (NULL == pl->mq) | 209 | if (NULL == pl->mq) |
209 | { | 210 | { |
210 | GNUNET_free(pl); | 211 | GNUNET_free (pl); |
211 | return NULL; | 212 | return NULL; |
212 | } | 213 | } |
213 | return pl; | 214 | return pl; |
214 | } | 215 | } |
215 | 216 | ||
@@ -221,15 +222,15 @@ GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
221 | * @return Closure given to GNUNET_CADET_get_peers(). | 222 | * @return Closure given to GNUNET_CADET_get_peers(). |
222 | */ | 223 | */ |
223 | void * | 224 | void * |
224 | GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl) | 225 | GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl) |
225 | { | 226 | { |
226 | void *ret = pl->peers_cb_cls; | 227 | void *ret = pl->peers_cb_cls; |
227 | 228 | ||
228 | if (NULL != pl->mq) | 229 | if (NULL != pl->mq) |
229 | GNUNET_MQ_destroy(pl->mq); | 230 | GNUNET_MQ_destroy (pl->mq); |
230 | if (NULL != pl->reconnect_task) | 231 | if (NULL != pl->reconnect_task) |
231 | GNUNET_SCHEDULER_cancel(pl->reconnect_task); | 232 | GNUNET_SCHEDULER_cancel (pl->reconnect_task); |
232 | GNUNET_free(pl); | 233 | GNUNET_free (pl); |
233 | return ret; | 234 | return ret; |
234 | } | 235 | } |
235 | 236 | ||