diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-16 16:24:32 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-16 16:24:32 +0000 |
commit | 27a6cee72d7c479853acbeed0047534fd4566deb (patch) | |
tree | d932da0e35e14abb83480b508874fcc9d0efdab2 /src/core/core_api_iterate_peers.c | |
parent | e054285d845aad88df678b60ee532d71d5115f4b (diff) | |
download | gnunet-27a6cee72d7c479853acbeed0047534fd4566deb.tar.gz gnunet-27a6cee72d7c479853acbeed0047534fd4566deb.zip |
remove double connect notify, add is connected optimization for peer iterate call
Diffstat (limited to 'src/core/core_api_iterate_peers.c')
-rw-r--r-- | src/core/core_api_iterate_peers.c | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c index fb9c01fee..8175b70c6 100644 --- a/src/core/core_api_iterate_peers.c +++ b/src/core/core_api_iterate_peers.c | |||
@@ -31,7 +31,6 @@ | |||
31 | 31 | ||
32 | struct GNUNET_CORE_RequestContext | 32 | struct GNUNET_CORE_RequestContext |
33 | { | 33 | { |
34 | |||
35 | /** | 34 | /** |
36 | * Our connection to the service. | 35 | * Our connection to the service. |
37 | */ | 36 | */ |
@@ -48,6 +47,11 @@ struct GNUNET_CORE_RequestContext | |||
48 | GNUNET_CORE_ConnectEventHandler peer_cb; | 47 | GNUNET_CORE_ConnectEventHandler peer_cb; |
49 | 48 | ||
50 | /** | 49 | /** |
50 | * Peer to check for. | ||
51 | */ | ||
52 | struct GNUNET_PeerIdentity *peer; | ||
53 | |||
54 | /** | ||
51 | * Closure for peer_cb. | 55 | * Closure for peer_cb. |
52 | */ | 56 | */ |
53 | void *cb_cls; | 57 | void *cb_cls; |
@@ -136,21 +140,78 @@ transmit_request(void *cls, | |||
136 | size_t size, void *buf) | 140 | size_t size, void *buf) |
137 | { | 141 | { |
138 | struct GNUNET_MessageHeader *msg; | 142 | struct GNUNET_MessageHeader *msg; |
139 | if ((size < sizeof(struct GNUNET_MessageHeader)) || (buf == NULL)) | 143 | struct GNUNET_PeerIdentity *peer = cls; |
144 | int msize; | ||
145 | |||
146 | if (peer == NULL) | ||
147 | msize = sizeof(struct GNUNET_MessageHeader); | ||
148 | else | ||
149 | msize = sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity); | ||
150 | |||
151 | if ((size < msize) || (buf == NULL)) | ||
140 | return 0; | 152 | return 0; |
141 | 153 | ||
142 | msg = (struct GNUNET_MessageHeader *)buf; | 154 | msg = (struct GNUNET_MessageHeader *)buf; |
143 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 155 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
144 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS); | 156 | msg->type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS); |
145 | return sizeof(struct GNUNET_MessageHeader); | 157 | memcpy(&msg[1], peer, sizeof(struct GNUNET_PeerIdentity)); |
158 | |||
159 | return msize; | ||
146 | } | 160 | } |
147 | 161 | ||
148 | /** | 162 | /** |
149 | * Obtain statistics and/or change preferences for the given peer. | 163 | * Iterate over all currently connected peers. |
164 | * Calls peer_cb with each connected peer, and then | ||
165 | * once with NULL to indicate that all peers have | ||
166 | * been handled. | ||
150 | * | 167 | * |
151 | * @param cfg configuration to use | 168 | * @param cfg configuration to use |
169 | * @param peer the specific peer to check for | ||
152 | * @param peer_cb function to call with the peer information | 170 | * @param peer_cb function to call with the peer information |
153 | * @param cb_cls closure for peer_cb | 171 | * @param cb_cls closure for peer_cb |
172 | * | ||
173 | * @return GNUNET_OK if iterating, GNUNET_SYSERR on error | ||
174 | */ | ||
175 | int | ||
176 | GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
177 | struct GNUNET_PeerIdentity *peer, | ||
178 | GNUNET_CORE_ConnectEventHandler peer_cb, | ||
179 | void *cb_cls) | ||
180 | { | ||
181 | struct GNUNET_CORE_RequestContext *request_context; | ||
182 | struct GNUNET_CLIENT_Connection *client; | ||
183 | |||
184 | client = GNUNET_CLIENT_connect ("core", cfg); | ||
185 | if (client == NULL) | ||
186 | return GNUNET_SYSERR; | ||
187 | GNUNET_assert(peer != NULL); | ||
188 | request_context = GNUNET_malloc (sizeof (struct GNUNET_CORE_RequestContext)); | ||
189 | request_context->client = client; | ||
190 | request_context->peer_cb = peer_cb; | ||
191 | request_context->cb_cls = cb_cls; | ||
192 | request_context->peer = peer; | ||
193 | |||
194 | request_context->th = GNUNET_CLIENT_notify_transmit_ready(client, | ||
195 | sizeof(struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity), | ||
196 | GNUNET_TIME_relative_get_forever(), | ||
197 | GNUNET_YES, | ||
198 | &transmit_request, | ||
199 | peer); | ||
200 | |||
201 | GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever()); | ||
202 | return GNUNET_OK; | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * Iterate over all currently connected peers. | ||
207 | * Calls peer_cb with each connected peer, and then | ||
208 | * once with NULL to indicate that all peers have | ||
209 | * been handled. | ||
210 | * | ||
211 | * @param cfg configuration to use | ||
212 | * @param peer_cb function to call with the peer information | ||
213 | * @param cb_cls closure for peer_cb | ||
214 | * | ||
154 | * @return GNUNET_OK if iterating, GNUNET_SYSERR on error | 215 | * @return GNUNET_OK if iterating, GNUNET_SYSERR on error |
155 | */ | 216 | */ |
156 | int | 217 | int |