aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-08-03 11:34:36 +0000
committerChristian Grothoff <christian@grothoff.org>2015-08-03 11:34:36 +0000
commite71c17ad3aebd7a8f444a08744288dec1415980c (patch)
tree51e7f3781f95e9afd22ba49e15b730f8f711464a /src/core/gnunet-service-core_neighbours.c
parent1e7bd3002f10aef6bd760e7caf13fb22a5f06345 (diff)
downloadgnunet-e71c17ad3aebd7a8f444a08744288dec1415980c.tar.gz
gnunet-e71c17ad3aebd7a8f444a08744288dec1415980c.zip
-improve indentation, reduce duplication of PIDs in core's neighbour map
Diffstat (limited to 'src/core/gnunet-service-core_neighbours.c')
-rw-r--r--src/core/gnunet-service-core_neighbours.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c
index f69f99870..5e5ed4db3 100644
--- a/src/core/gnunet-service-core_neighbours.c
+++ b/src/core/gnunet-service-core_neighbours.c
@@ -141,7 +141,8 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer)
141{ 141{
142 if (NULL == neighbours) 142 if (NULL == neighbours)
143 return NULL; 143 return NULL;
144 return GNUNET_CONTAINER_multipeermap_get (neighbours, peer); 144 return GNUNET_CONTAINER_multipeermap_get (neighbours,
145 peer);
145} 146}
146 147
147 148
@@ -218,7 +219,9 @@ process_queue (struct Neighbour *n);
218 * @return number of bytes transmitted 219 * @return number of bytes transmitted
219 */ 220 */
220static size_t 221static size_t
221transmit_ready (void *cls, size_t size, void *buf) 222transmit_ready (void *cls,
223 size_t size,
224 void *buf)
222{ 225{
223 struct Neighbour *n = cls; 226 struct Neighbour *n = cls;
224 struct NeighbourMessageEntry *m; 227 struct NeighbourMessageEntry *m;
@@ -249,13 +252,16 @@ transmit_ready (void *cls, size_t size, void *buf)
249 } 252 }
250 cbuf = buf; 253 cbuf = buf;
251 GNUNET_assert (size >= m->size); 254 GNUNET_assert (size >= m->size);
252 memcpy (cbuf, &m[1], m->size); 255 memcpy (cbuf,
256 &m[1],
257 m->size);
253 ret = m->size; 258 ret = m->size;
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Copied message of type %u and size %u into transport buffer for `%4s'\n", 260 "Copied message of type %u and size %u into transport buffer for `%4s'\n",
256 (unsigned int) 261 (unsigned int)
257 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 262 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
258 (unsigned int) ret, GNUNET_i2s (&n->peer)); 263 (unsigned int) ret,
264 GNUNET_i2s (&n->peer));
259 GNUNET_free (m); 265 GNUNET_free (m);
260 n->has_excess_bandwidth = GNUNET_NO; 266 n->has_excess_bandwidth = GNUNET_NO;
261 process_queue (n); 267 process_queue (n);
@@ -336,20 +342,21 @@ handle_transport_notify_connect (void *cls,
336 return; 342 return;
337 } 343 }
338 n = find_neighbour (peer); 344 n = find_neighbour (peer);
339 if (n != NULL) 345 if (NULL != n)
340 { 346 {
341 /* duplicate connect notification!? */ 347 /* duplicate connect notification!? */
342 GNUNET_break (0); 348 GNUNET_break (0);
343 return; 349 return;
344 } 350 }
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346 "Received connection from `%4s'.\n", 352 "Received connection from `%s'.\n",
347 GNUNET_i2s (peer)); 353 GNUNET_i2s (peer));
348 n = GNUNET_new (struct Neighbour); 354 n = GNUNET_new (struct Neighbour);
349 n->peer = *peer; 355 n->peer = *peer;
350 GNUNET_assert (GNUNET_OK == 356 GNUNET_assert (GNUNET_OK ==
351 GNUNET_CONTAINER_multipeermap_put (neighbours, 357 GNUNET_CONTAINER_multipeermap_put (neighbours,
352 &n->peer, n, 358 &n->peer,
359 n,
353 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 360 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
354 GNUNET_STATISTICS_set (GSC_stats, 361 GNUNET_STATISTICS_set (GSC_stats,
355 gettext_noop ("# neighbour entries allocated"), 362 gettext_noop ("# neighbour entries allocated"),
@@ -373,7 +380,7 @@ handle_transport_notify_disconnect (void *cls,
373 struct Neighbour *n; 380 struct Neighbour *n;
374 381
375 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 "Peer `%4s' disconnected from us; received notification from transport.\n", 383 "Peer `%s' disconnected from us; received notification from transport.\n",
377 GNUNET_i2s (peer)); 384 GNUNET_i2s (peer));
378 n = find_neighbour (peer); 385 n = find_neighbour (peer);
379 if (NULL == n) 386 if (NULL == n)
@@ -401,15 +408,18 @@ handle_transport_receive (void *cls,
401 uint16_t type; 408 uint16_t type;
402 409
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Received message of type %u from `%4s', demultiplexing.\n", 411 "Received message of type %u from `%s', demultiplexing.\n",
405 (unsigned int) ntohs (message->type), GNUNET_i2s (peer)); 412 (unsigned int) ntohs (message->type),
406 if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 413 GNUNET_i2s (peer));
414 if (0 == memcmp (peer,
415 &GSC_my_identity,
416 sizeof (struct GNUNET_PeerIdentity)))
407 { 417 {
408 GNUNET_break (0); 418 GNUNET_break (0);
409 return; 419 return;
410 } 420 }
411 n = find_neighbour (peer); 421 n = find_neighbour (peer);
412 if (n == NULL) 422 if (NULL == n)
413 { 423 {
414 /* received message from peer that is not connected!? */ 424 /* received message from peer that is not connected!? */
415 GNUNET_break (0); 425 GNUNET_break (0);
@@ -556,9 +566,12 @@ GSC_NEIGHBOURS_check_excess_bandwidth (const struct GNUNET_PeerIdentity *target)
556int 566int
557GSC_NEIGHBOURS_init () 567GSC_NEIGHBOURS_init ()
558{ 568{
559 neighbours = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 569 neighbours = GNUNET_CONTAINER_multipeermap_create (128,
570 GNUNET_YES);
560 transport = 571 transport =
561 GNUNET_TRANSPORT_connect2 (GSC_cfg, &GSC_my_identity, NULL, 572 GNUNET_TRANSPORT_connect2 (GSC_cfg,
573 &GSC_my_identity,
574 NULL,
562 &handle_transport_receive, 575 &handle_transport_receive,
563 &handle_transport_notify_connect, 576 &handle_transport_notify_connect,
564 &handle_transport_notify_disconnect, 577 &handle_transport_notify_disconnect,
@@ -574,7 +587,7 @@ GSC_NEIGHBOURS_init ()
574 587
575 588
576/** 589/**
577 * Wrapper around 'free_neighbour'. 590 * Wrapper around #free_neighbour().
578 * 591 *
579 * @param cls unused 592 * @param cls unused
580 * @param key peer identity 593 * @param key peer identity