aboutsummaryrefslogtreecommitdiff
path: root/src/util/server_nc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
commitd9d94d0e53d26af75ec8241383d166544ebd79f3 (patch)
tree9080b73624389403a198257fe0547bb4634e64d2 /src/util/server_nc.c
parent2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff)
downloadgnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz
gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/server_nc.c')
-rw-r--r--src/util/server_nc.c221
1 files changed, 113 insertions, 108 deletions
diff --git a/src/util/server_nc.c b/src/util/server_nc.c
index dc7a27c8b..cbe98a014 100644
--- a/src/util/server_nc.c
+++ b/src/util/server_nc.c
@@ -33,6 +33,8 @@
33#include "gnunet_server_lib.h" 33#include "gnunet_server_lib.h"
34#include "gnunet_time_lib.h" 34#include "gnunet_time_lib.h"
35 35
36#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
37
36 38
37#define DEBUG_SERVER_NC GNUNET_EXTRA_LOGGING 39#define DEBUG_SERVER_NC GNUNET_EXTRA_LOGGING
38 40
@@ -154,40 +156,40 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
154 struct PendingMessageList *pml; 156 struct PendingMessageList *pml;
155 157
156 if (client == NULL) 158 if (client == NULL)
157 { 159 {
158 nc->server = NULL; 160 nc->server = NULL;
159 return; 161 return;
160 } 162 }
161 prev = NULL; 163 prev = NULL;
162 pos = nc->clients; 164 pos = nc->clients;
163 while (NULL != pos) 165 while (NULL != pos)
164 { 166 {
165 if (pos->client == client) 167 if (pos->client == client)
166 break; 168 break;
167 prev = pos; 169 prev = pos;
168 pos = pos->next; 170 pos = pos->next;
169 } 171 }
170 if (pos == NULL) 172 if (pos == NULL)
171 return; 173 return;
172#if DEBUG_SERVER_NC 174#if DEBUG_SERVER_NC
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 175 LOG (GNUNET_ERROR_TYPE_DEBUG,
174 "Client disconnected, cleaning up %u messages in NC queue\n", 176 "Client disconnected, cleaning up %u messages in NC queue\n",
175 pos->num_pending); 177 pos->num_pending);
176#endif 178#endif
177 if (prev == NULL) 179 if (prev == NULL)
178 nc->clients = pos->next; 180 nc->clients = pos->next;
179 else 181 else
180 prev->next = pos->next; 182 prev->next = pos->next;
181 while (NULL != (pml = pos->pending_head)) 183 while (NULL != (pml = pos->pending_head))
182 { 184 {
183 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); 185 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml);
184 GNUNET_free (pml); 186 GNUNET_free (pml);
185 } 187 }
186 if (pos->th != NULL) 188 if (pos->th != NULL)
187 { 189 {
188 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); 190 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
189 pos->th = NULL; 191 pos->th = NULL;
190 } 192 }
191 GNUNET_SERVER_client_drop (client); 193 GNUNET_SERVER_client_drop (client);
192 GNUNET_free (pos); 194 GNUNET_free (pos);
193} 195}
@@ -203,8 +205,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
203 * @return handle to the notification context 205 * @return handle to the notification context
204 */ 206 */
205struct GNUNET_SERVER_NotificationContext * 207struct GNUNET_SERVER_NotificationContext *
206GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, 208GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle
207 unsigned int queue_length) 209 *server, unsigned int queue_length)
208{ 210{
209 struct GNUNET_SERVER_NotificationContext *ret; 211 struct GNUNET_SERVER_NotificationContext *ret;
210 212
@@ -223,26 +225,27 @@ GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
223 */ 225 */
224void 226void
225GNUNET_SERVER_notification_context_destroy (struct 227GNUNET_SERVER_notification_context_destroy (struct
226 GNUNET_SERVER_NotificationContext 228 GNUNET_SERVER_NotificationContext
227 *nc) 229 *nc)
228{ 230{
229 struct ClientList *pos; 231 struct ClientList *pos;
230 struct PendingMessageList *pml; 232 struct PendingMessageList *pml;
231 233
232 while (NULL != (pos = nc->clients)) 234 while (NULL != (pos = nc->clients))
233 {
234 nc->clients = pos->next;
235 GNUNET_SERVER_client_drop (pos->client);
236 while (NULL != (pml = pos->pending_head))
237 { 235 {
238 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail, pml); 236 nc->clients = pos->next;
239 GNUNET_free (pml); 237 GNUNET_SERVER_client_drop (pos->client);
238 while (NULL != (pml = pos->pending_head))
239 {
240 GNUNET_CONTAINER_DLL_remove (pos->pending_head, pos->pending_tail,
241 pml);
242 GNUNET_free (pml);
243 }
244 GNUNET_free (pos);
240 } 245 }
241 GNUNET_free (pos);
242 }
243 if (nc->server != NULL) 246 if (nc->server != NULL)
244 GNUNET_SERVER_disconnect_notify_cancel (nc->server, 247 GNUNET_SERVER_disconnect_notify_cancel (nc->server,
245 &handle_client_disconnect, nc); 248 &handle_client_disconnect, nc);
246 GNUNET_free (nc); 249 GNUNET_free (nc);
247} 250}
248 251
@@ -254,9 +257,9 @@ GNUNET_SERVER_notification_context_destroy (struct
254 * @param client client to add 257 * @param client client to add
255 */ 258 */
256void 259void
257GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext 260GNUNET_SERVER_notification_context_add (struct
258 *nc, 261 GNUNET_SERVER_NotificationContext *nc,
259 struct GNUNET_SERVER_Client *client) 262 struct GNUNET_SERVER_Client *client)
260{ 263{
261 struct ClientList *cl; 264 struct ClientList *cl;
262 265
@@ -290,44 +293,45 @@ transmit_message (void *cls, size_t size, void *buf)
290 293
291 cl->th = NULL; 294 cl->th = NULL;
292 if (buf == NULL) 295 if (buf == NULL)
293 { 296 {
294 /* 'cl' should be freed via disconnect notification shortly */ 297 /* 'cl' should be freed via disconnect notification shortly */
295#if DEBUG_SERVER_NC 298#if DEBUG_SERVER_NC
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 299 LOG (GNUNET_ERROR_TYPE_DEBUG,
297 "Failed to transmit message from NC queue to client\n"); 300 "Failed to transmit message from NC queue to client\n");
298#endif 301#endif
299 return 0; 302 return 0;
300 } 303 }
301 ret = 0; 304 ret = 0;
302 while (NULL != (pml = cl->pending_head)) 305 while (NULL != (pml = cl->pending_head))
303 { 306 {
304 msize = ntohs (pml->msg->size); 307 msize = ntohs (pml->msg->size);
305 if (size < msize) 308 if (size < msize)
306 break; 309 break;
307 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml); 310 GNUNET_CONTAINER_DLL_remove (cl->pending_head, cl->pending_tail, pml);
308#if DEBUG_SERVER_NC 311#if DEBUG_SERVER_NC
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 312 LOG (GNUNET_ERROR_TYPE_DEBUG,
310 "Copying message of type %u and size %u from pending queue to transmission buffer\n", 313 "Copying message of type %u and size %u from pending queue to transmission buffer\n",
311 ntohs (pml->msg->type), msize); 314 ntohs (pml->msg->type), msize);
312#endif 315#endif
313 memcpy (&cbuf[ret], pml->msg, msize); 316 memcpy (&cbuf[ret], pml->msg, msize);
314 ret += msize; 317 ret += msize;
315 size -= msize; 318 size -= msize;
316 GNUNET_free (pml); 319 GNUNET_free (pml);
317 cl->num_pending--; 320 cl->num_pending--;
318 } 321 }
319 if (pml != NULL) 322 if (pml != NULL)
320 { 323 {
321#if DEBUG_SERVER_NC 324#if DEBUG_SERVER_NC
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 325 LOG (GNUNET_ERROR_TYPE_DEBUG,
323 "Have %u messages left in NC queue, will try transmission again\n", 326 "Have %u messages left in NC queue, will try transmission again\n",
324 cl->num_pending); 327 cl->num_pending);
325#endif 328#endif
326 cl->th = 329 cl->th =
327 GNUNET_SERVER_notify_transmit_ready (cl->client, ntohs (pml->msg->size), 330 GNUNET_SERVER_notify_transmit_ready (cl->client,
328 GNUNET_TIME_UNIT_FOREVER_REL, 331 ntohs (pml->msg->size),
329 &transmit_message, cl); 332 GNUNET_TIME_UNIT_FOREVER_REL,
330 } 333 &transmit_message, cl);
334 }
331 else 335 else
332 GNUNET_assert (cl->num_pending == 0); 336 GNUNET_assert (cl->num_pending == 0);
333 return ret; 337 return ret;
@@ -344,47 +348,46 @@ transmit_message (void *cls, size_t size, void *buf)
344 */ 348 */
345static void 349static void
346do_unicast (struct GNUNET_SERVER_NotificationContext *nc, 350do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
347 struct ClientList *client, const struct GNUNET_MessageHeader *msg, 351 struct ClientList *client, const struct GNUNET_MessageHeader *msg,
348 int can_drop) 352 int can_drop)
349{ 353{
350 struct PendingMessageList *pml; 354 struct PendingMessageList *pml;
351 uint16_t size; 355 uint16_t size;
352 356
353 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop)) 357 if ((client->num_pending > nc->queue_length) && (GNUNET_YES == can_drop))
354 { 358 {
355 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 359 LOG (GNUNET_ERROR_TYPE_INFO,
356 "Dropping message of type %u and size %u due to full queue (%u entries)\n", 360 "Dropping message of type %u and size %u due to full queue (%u entries)\n",
357 ntohs (msg->type), ntohs (msg->size), 361 ntohs (msg->type), ntohs (msg->size),
358 (unsigned int) nc->queue_length); 362 (unsigned int) nc->queue_length);
359 return; /* drop! */ 363 return; /* drop! */
360 } 364 }
361 if (client->num_pending > nc->queue_length) 365 if (client->num_pending > nc->queue_length)
362 { 366 {
363 /* FIXME: consider checking for other messages in the 367 /* FIXME: consider checking for other messages in the
364 * queue that are 'droppable' */ 368 * queue that are 'droppable' */
365 } 369 }
366 client->num_pending++; 370 client->num_pending++;
367 size = ntohs (msg->size); 371 size = ntohs (msg->size);
368 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size); 372 pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size);
369 pml->msg = (const struct GNUNET_MessageHeader *) &pml[1]; 373 pml->msg = (const struct GNUNET_MessageHeader *) &pml[1];
370 pml->can_drop = can_drop; 374 pml->can_drop = can_drop;
371#if DEBUG_SERVER_NC 375#if DEBUG_SERVER_NC
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 LOG (GNUNET_ERROR_TYPE_DEBUG,
373 "Adding message of type %u and size %u to pending queue (which has %u entries)\n", 377 "Adding message of type %u and size %u to pending queue (which has %u entries)\n",
374 ntohs (msg->type), ntohs (msg->size), 378 ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length);
375 (unsigned int) nc->queue_length);
376#endif 379#endif
377 memcpy (&pml[1], msg, size); 380 memcpy (&pml[1], msg, size);
378 /* append */ 381 /* append */
379 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head, client->pending_tail, 382 GNUNET_CONTAINER_DLL_insert_tail (client->pending_head,
380 pml); 383 client->pending_tail, pml);
381 if (client->th == NULL) 384 if (client->th == NULL)
382 client->th = 385 client->th =
383 GNUNET_SERVER_notify_transmit_ready (client->client, 386 GNUNET_SERVER_notify_transmit_ready (client->client,
384 ntohs (client->pending_head-> 387 ntohs (client->pending_head->
385 msg->size), 388 msg->size),
386 GNUNET_TIME_UNIT_FOREVER_REL, 389 GNUNET_TIME_UNIT_FOREVER_REL,
387 &transmit_message, client); 390 &transmit_message, client);
388} 391}
389 392
390 393
@@ -399,21 +402,22 @@ do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
399 */ 402 */
400void 403void
401GNUNET_SERVER_notification_context_unicast (struct 404GNUNET_SERVER_notification_context_unicast (struct
402 GNUNET_SERVER_NotificationContext 405 GNUNET_SERVER_NotificationContext
403 *nc, 406 *nc,
404 struct GNUNET_SERVER_Client *client, 407 struct GNUNET_SERVER_Client
405 const struct GNUNET_MessageHeader 408 *client,
406 *msg, int can_drop) 409 const struct GNUNET_MessageHeader
410 *msg, int can_drop)
407{ 411{
408 struct ClientList *pos; 412 struct ClientList *pos;
409 413
410 pos = nc->clients; 414 pos = nc->clients;
411 while (NULL != pos) 415 while (NULL != pos)
412 { 416 {
413 if (pos->client == client) 417 if (pos->client == client)
414 break; 418 break;
415 pos = pos->next; 419 pos = pos->next;
416 } 420 }
417 GNUNET_assert (pos != NULL); 421 GNUNET_assert (pos != NULL);
418 do_unicast (nc, pos, msg, can_drop); 422 do_unicast (nc, pos, msg, can_drop);
419} 423}
@@ -428,19 +432,20 @@ GNUNET_SERVER_notification_context_unicast (struct
428 */ 432 */
429void 433void
430GNUNET_SERVER_notification_context_broadcast (struct 434GNUNET_SERVER_notification_context_broadcast (struct
431 GNUNET_SERVER_NotificationContext 435 GNUNET_SERVER_NotificationContext
432 *nc, 436 *nc,
433 const struct GNUNET_MessageHeader 437 const struct
434 *msg, int can_drop) 438 GNUNET_MessageHeader *msg,
439 int can_drop)
435{ 440{
436 struct ClientList *pos; 441 struct ClientList *pos;
437 442
438 pos = nc->clients; 443 pos = nc->clients;
439 while (NULL != pos) 444 while (NULL != pos)
440 { 445 {
441 do_unicast (nc, pos, msg, can_drop); 446 do_unicast (nc, pos, msg, can_drop);
442 pos = pos->next; 447 pos = pos->next;
443 } 448 }
444} 449}
445 450
446 451