aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api_iterate_peers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-02 11:10:12 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-02 11:10:12 +0000
commitb734ef1365245bbaf42fbdb1861baeaa95327f67 (patch)
tree6f65f4ce7e052244c5523bdcc89724820ca41d56 /src/core/core_api_iterate_peers.c
parent45063a766d9a922d7f2b762ede305679e728cbfc (diff)
downloadgnunet-b734ef1365245bbaf42fbdb1861baeaa95327f67.tar.gz
gnunet-b734ef1365245bbaf42fbdb1861baeaa95327f67.zip
-fixing #2293
Diffstat (limited to 'src/core/core_api_iterate_peers.c')
-rw-r--r--src/core/core_api_iterate_peers.c46
1 files changed, 1 insertions, 45 deletions
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 0ecd98ed7..8e6904480 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -119,6 +119,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
119 request_context, GNUNET_TIME_UNIT_FOREVER_REL); 119 request_context, GNUNET_TIME_UNIT_FOREVER_REL);
120} 120}
121 121
122
122/** 123/**
123 * Function called to notify a client about the socket 124 * Function called to notify a client about the socket
124 * begin ready to queue more data. "buf" will be 125 * begin ready to queue more data. "buf" will be
@@ -143,10 +144,8 @@ transmit_request (void *cls, size_t size, void *buf)
143 msize = 144 msize =
144 sizeof (struct GNUNET_MessageHeader) + 145 sizeof (struct GNUNET_MessageHeader) +
145 sizeof (struct GNUNET_PeerIdentity); 146 sizeof (struct GNUNET_PeerIdentity);
146
147 if ((size < msize) || (buf == NULL)) 147 if ((size < msize) || (buf == NULL))
148 return 0; 148 return 0;
149
150 msg = (struct GNUNET_MessageHeader *) buf; 149 msg = (struct GNUNET_MessageHeader *) buf;
151 msg->size = htons (msize); 150 msg->size = htons (msize);
152 if (peer != NULL) 151 if (peer != NULL)
@@ -160,50 +159,7 @@ transmit_request (void *cls, size_t size, void *buf)
160 return msize; 159 return msize;
161} 160}
162 161
163/**
164 * Iterate over all currently connected peers.
165 * Calls peer_cb with each connected peer, and then
166 * once with NULL to indicate that all peers have
167 * been handled.
168 *
169 * @param cfg configuration to use
170 * @param peer the specific peer to check for
171 * @param peer_cb function to call with the peer information
172 * @param cb_cls closure for peer_cb
173 *
174 * @return GNUNET_OK if iterating, GNUNET_SYSERR on error
175 */
176int
177GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg,
178 struct GNUNET_PeerIdentity *peer,
179 GNUNET_CORE_ConnectEventHandler peer_cb,
180 void *cb_cls)
181{
182 struct GNUNET_CORE_RequestContext *request_context;
183 struct GNUNET_CLIENT_Connection *client;
184
185 client = GNUNET_CLIENT_connect ("core", cfg);
186 if (client == NULL)
187 return GNUNET_SYSERR;
188 GNUNET_assert (peer != NULL);
189 request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext));
190 request_context->client = client;
191 request_context->peer_cb = peer_cb;
192 request_context->cb_cls = cb_cls;
193 request_context->peer = peer;
194 162
195 request_context->th =
196 GNUNET_CLIENT_notify_transmit_ready (client,
197 sizeof (struct GNUNET_MessageHeader)
198 +
199 sizeof (struct GNUNET_PeerIdentity),
200 GNUNET_TIME_relative_get_forever (),
201 GNUNET_YES, &transmit_request, peer);
202 GNUNET_assert (request_context->th != NULL);
203 GNUNET_CLIENT_receive (client, &receive_info, request_context,
204 GNUNET_TIME_relative_get_forever ());
205 return GNUNET_OK;
206}
207 163
208/** 164/**
209 * Iterate over all currently connected peers. 165 * Iterate over all currently connected peers.