aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api_list_peers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-01-26 21:18:06 +0100
committerChristian Grothoff <christian@grothoff.org>2019-01-26 21:18:06 +0100
commit8f884f001a70fee622fff0c0ac8c38a0634df789 (patch)
treecd8b0c45ab3209d73db6396dc2956cf569625b54 /src/cadet/cadet_api_list_peers.c
parent7fc78674a6d3f2edb41e32cea59200908d0b344b (diff)
downloadgnunet-8f884f001a70fee622fff0c0ac8c38a0634df789.tar.gz
gnunet-8f884f001a70fee622fff0c0ac8c38a0634df789.zip
more work on 5385
Diffstat (limited to 'src/cadet/cadet_api_list_peers.c')
-rw-r--r--src/cadet/cadet_api_list_peers.c125
1 files changed, 76 insertions, 49 deletions
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index 4bdc8b961..f6563a290 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.c
@@ -71,55 +71,6 @@ send_info_request (struct GNUNET_CADET_Handle *h,
71 71
72 72
73/** 73/**
74 * Request information about peers known to the running cadet service.
75 * The callback will be called for every peer known to the service.
76 * Only one info request (of any kind) can be active at once.
77 *
78 * WARNING: unstable API, likely to change in the future!
79 *
80 * @param h Handle to the cadet peer.
81 * @param callback Function to call with the requested data.
82 * @param callback_cls Closure for @c callback.
83 * @return #GNUNET_OK / #GNUNET_SYSERR
84 */
85int
86GNUNET_CADET_list_peers (struct GNUNET_CADET_Handle *h,
87 GNUNET_CADET_PeersCB callback,
88 void *callback_cls)
89{
90 if (NULL != h->info_cb.peers_cb)
91 {
92 GNUNET_break (0);
93 return GNUNET_SYSERR;
94 }
95 send_info_request (h,
96 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
97 h->info_cb.peers_cb = callback;
98 h->info_cls = callback_cls;
99 return GNUNET_OK;
100}
101
102
103/**
104 * Cancel a peer info request. The callback will not be called (anymore).
105 *
106 * WARNING: unstable API, likely to change in the future!
107 *
108 * @param h Cadet handle.
109 * @return Closure given to GNUNET_CADET_get_peers().
110 */
111void *
112GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_Handle *h)
113{
114 void *cls = h->info_cls;
115
116 h->info_cb.peers_cb = NULL;
117 h->info_cls = NULL;
118 return cls;
119}
120
121
122/**
123 * Check that message received from CADET service is well-formed. 74 * Check that message received from CADET service is well-formed.
124 * 75 *
125 * @param cls the `struct GNUNET_CADET_Handle` 76 * @param cls the `struct GNUNET_CADET_Handle`
@@ -174,6 +125,82 @@ handle_get_peers (void *cls,
174} 125}
175 126
176 127
128static void
129reconnect (void *cls)
130{
131 struct GNUNET_CADET_ListTunnels *lt = cls;
132 struct GNUNET_MQ_MessageHandler *handlers[] = {
133 GNUNET_MQ_hd_var_size (get_peers,
134 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
135 struct GNUNET_MessageHeader,
136 h),
137 GNUNET_MQ_handler_end ()
138 }
139 struct GNUNET_MessageHeader *msg;
140 struct GNUNET_MQ_Envelope *env;
141
142 cm->mq = GNUNET_CLIENT_connect (cm->cfg,
143 "cadet",
144 handlers,
145 &error_handler,
146 cm);
147
148 env = GNUNET_MQ_msg (msg,
149 type);
150 GNUNET_MQ_send (cm->mq,
151 env);
152}
153
154
155/**
156 * Request information about peers known to the running cadet service.
157 * The callback will be called for every peer known to the service.
158 * Only one info request (of any kind) can be active at once.
159 *
160 * WARNING: unstable API, likely to change in the future!
161 *
162 * @param h Handle to the cadet peer.
163 * @param callback Function to call with the requested data.
164 * @param callback_cls Closure for @c callback.
165 * @return #GNUNET_OK / #GNUNET_SYSERR
166 */
167struct GNUNET_CADET_PeersLister *
168GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
169 GNUNET_CADET_PeersCB callback,
170 void *callback_cls)
171{
172 if (NULL != h->info_cb.peers_cb)
173 {
174 GNUNET_break (0);
175 return GNUNET_SYSERR;
176 }
177 send_info_request (h,
178 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
179 h->info_cb.peers_cb = callback;
180 h->info_cls = callback_cls;
181 return GNUNET_OK;
182}
183
184
185/**
186 * Cancel a peer info request. The callback will not be called (anymore).
187 *
188 * WARNING: unstable API, likely to change in the future!
189 *
190 * @param h Cadet handle.
191 * @return Closure given to GNUNET_CADET_get_peers().
192 */
193void *
194GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
195{
196 void *cls = h->info_cls;
197
198 h->info_cb.peers_cb = NULL;
199 h->info_cls = NULL;
200 return cls;
201}
202
203
177 204
178 205
179 206