diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-09 22:04:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-09 22:04:11 +0000 |
commit | 1dd22b0d681848af9980e5202e38b1a307cf2094 (patch) | |
tree | e013a7f735f2e967222890d87136bd5b76c1f803 /src/transport/plugin_transport_unix.c | |
parent | c9f75566447fd3a9c5c304dbc8e31fd68b6aa3ed (diff) | |
download | gnunet-1dd22b0d681848af9980e5202e38b1a307cf2094.tar.gz gnunet-1dd22b0d681848af9980e5202e38b1a307cf2094.zip |
clarify prettyprinter API and protocols, make sure implementations are consistent in their implemenation, doxygen fixes, indentation fixes, subtle semantic fixes
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 792d7718e..03c38f4e1 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -64,9 +64,9 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
64 | 64 | ||
65 | struct UnixAddress | 65 | struct UnixAddress |
66 | { | 66 | { |
67 | uint32_t options GNUNET_PACKED; | 67 | uint32_t options GNUNET_PACKED; |
68 | 68 | ||
69 | uint32_t addrlen GNUNET_PACKED; | 69 | uint32_t addrlen GNUNET_PACKED; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
@@ -340,6 +340,7 @@ reschedule_session_timeout (struct Session *s); | |||
340 | static void | 340 | static void |
341 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 341 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
342 | 342 | ||
343 | |||
343 | static struct sockaddr_un * | 344 | static struct sockaddr_un * |
344 | unix_address_to_sockaddr (const char *unixpath, | 345 | unix_address_to_sockaddr (const char *unixpath, |
345 | socklen_t *sock_len) | 346 | socklen_t *sock_len) |
@@ -372,11 +373,13 @@ unix_address_to_sockaddr (const char *unixpath, | |||
372 | * | 373 | * |
373 | * @param cls closure | 374 | * @param cls closure |
374 | * @param addr binary address | 375 | * @param addr binary address |
375 | * @param addrlen length of the address | 376 | * @param addrlen length of the @a addr |
376 | * @return string representing the same address | 377 | * @return string representing the same address |
377 | */ | 378 | */ |
378 | static const char * | 379 | static const char * |
379 | unix_address_to_string (void *cls, const void *addr, size_t addrlen) | 380 | unix_address_to_string (void *cls, |
381 | const void *addr, | ||
382 | size_t addrlen) | ||
380 | { | 383 | { |
381 | static char rbuf[1024]; | 384 | static char rbuf[1024]; |
382 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 385 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
@@ -387,7 +390,7 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
387 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | 390 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) |
388 | { | 391 | { |
389 | GNUNET_break(0); | 392 | GNUNET_break(0); |
390 | return NULL ; | 393 | return NULL; |
391 | } | 394 | } |
392 | addrstr = (char *) &ua[1]; | 395 | addrstr = (char *) &ua[1]; |
393 | addr_str_len = ntohl (ua->addrlen); | 396 | addr_str_len = ntohl (ua->addrlen); |
@@ -395,39 +398,36 @@ unix_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
395 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) | 398 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) |
396 | { | 399 | { |
397 | GNUNET_break(0); | 400 | GNUNET_break(0); |
398 | return NULL ; | 401 | return NULL; |
399 | } | 402 | } |
400 | 403 | ||
401 | if ('\0' != addrstr[addr_str_len - 1]) | 404 | if ('\0' != addrstr[addr_str_len - 1]) |
402 | { | 405 | { |
403 | GNUNET_break(0); | 406 | GNUNET_break(0); |
404 | return NULL ; | 407 | return NULL; |
405 | } | 408 | } |
406 | if (strlen (addrstr) + 1 != addr_str_len) | 409 | if (strlen (addrstr) + 1 != addr_str_len) |
407 | { | 410 | { |
408 | GNUNET_break(0); | 411 | GNUNET_break(0); |
409 | return NULL ; | 412 | return NULL; |
410 | } | 413 | } |
411 | 414 | ||
412 | off = 0; | 415 | off = 0; |
413 | if ('\0' == addrstr[0]) | 416 | if ('\0' == addrstr[0]) |
414 | off++; | 417 | off++; |
415 | memset (rbuf, 0, sizeof (rbuf)); | 418 | memset (rbuf, 0, sizeof (rbuf)); |
416 | GNUNET_snprintf (rbuf, sizeof (rbuf) - 1, "%s.%u.%s%.*s", | 419 | GNUNET_snprintf (rbuf, |
417 | PLUGIN_NAME, | 420 | sizeof (rbuf) - 1, |
418 | ntohl (ua->options), | 421 | "%s.%u.%s%.*s", |
419 | (off == 1) ? "@" : "", | 422 | PLUGIN_NAME, |
420 | (int) (addr_str_len - off), | 423 | ntohl (ua->options), |
421 | &addrstr[off]); | 424 | (off == 1) ? "@" : "", |
422 | /* | 425 | (int) (addr_str_len - off), |
423 | GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, | 426 | &addrstr[off]); |
424 | ntohl (ua->options), addrstr);*/ | ||
425 | return rbuf; | 427 | return rbuf; |
426 | } | 428 | } |
427 | 429 | ||
428 | 430 | ||
429 | |||
430 | |||
431 | /** | 431 | /** |
432 | * Re-schedule the main 'select' callback (unix_plugin_select) | 432 | * Re-schedule the main 'select' callback (unix_plugin_select) |
433 | * for this plugin. | 433 | * for this plugin. |
@@ -547,7 +547,9 @@ unix_session_disconnect (void *cls, | |||
547 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 547 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
548 | "Disconnecting session for peer `%s' `%s'\n", | 548 | "Disconnecting session for peer `%s' `%s'\n", |
549 | GNUNET_i2s (&s->target), | 549 | GNUNET_i2s (&s->target), |
550 | unix_address_to_string (NULL, s->address->address, s->address->address_length) ); | 550 | unix_address_to_string (NULL, |
551 | s->address->address, | ||
552 | s->address->address_length)); | ||
551 | plugin->env->session_end (plugin->env->cls, s->address, s); | 553 | plugin->env->session_end (plugin->env->cls, s->address, s); |
552 | removed = GNUNET_NO; | 554 | removed = GNUNET_NO; |
553 | next = plugin->msg_head; | 555 | next = plugin->msg_head; |
@@ -870,7 +872,8 @@ unix_plugin_get_session (void *cls, | |||
870 | &get_session_it, &gsi); | 872 | &get_session_it, &gsi); |
871 | if (NULL != gsi.res) | 873 | if (NULL != gsi.res) |
872 | { | 874 | { |
873 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n", | 875 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
876 | "Found existing session %p for address `%s'\n", | ||
874 | gsi.res, | 877 | gsi.res, |
875 | unix_address_to_string (NULL, address->address, address->address_length)); | 878 | unix_address_to_string (NULL, address->address, address->address_length)); |
876 | return gsi.res; | 879 | return gsi.res; |
@@ -887,7 +890,10 @@ unix_plugin_get_session (void *cls, | |||
887 | s); | 890 | s); |
888 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 891 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
889 | "Creating a new session %p for address `%s'\n", | 892 | "Creating a new session %p for address `%s'\n", |
890 | s, unix_address_to_string (NULL, address->address, address->address_length)); | 893 | s, |
894 | unix_address_to_string (NULL, | ||
895 | address->address, | ||
896 | address->address_length)); | ||
891 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, | 897 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, |
892 | &address->peer, s, | 898 | &address->peer, s, |
893 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 899 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -961,8 +967,9 @@ unix_plugin_send (void *cls, | |||
961 | LOG (GNUNET_ERROR_TYPE_ERROR, | 967 | LOG (GNUNET_ERROR_TYPE_ERROR, |
962 | "Invalid session for peer `%s' `%s'\n", | 968 | "Invalid session for peer `%s' `%s'\n", |
963 | GNUNET_i2s (&session->target), | 969 | GNUNET_i2s (&session->target), |
964 | unix_address_to_string(NULL, session->address->address, | 970 | unix_address_to_string(NULL, |
965 | session->address->address_length)); | 971 | session->address->address, |
972 | session->address->address_length)); | ||
966 | GNUNET_break (0); | 973 | GNUNET_break (0); |
967 | return GNUNET_SYSERR; | 974 | return GNUNET_SYSERR; |
968 | } | 975 | } |
@@ -970,8 +977,9 @@ unix_plugin_send (void *cls, | |||
970 | "Sending %u bytes with session for peer `%s' `%s'\n", | 977 | "Sending %u bytes with session for peer `%s' `%s'\n", |
971 | msgbuf_size, | 978 | msgbuf_size, |
972 | GNUNET_i2s (&session->target), | 979 | GNUNET_i2s (&session->target), |
973 | unix_address_to_string(NULL, session->address->address, | 980 | unix_address_to_string (NULL, |
974 | session->address->address_length)); | 981 | session->address->address, |
982 | session->address->address_length)); | ||
975 | ssize = sizeof (struct UNIXMessage) + msgbuf_size; | 983 | ssize = sizeof (struct UNIXMessage) + msgbuf_size; |
976 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); | 984 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); |
977 | message->header.size = htons (ssize); | 985 | message->header.size = htons (ssize); |
@@ -1024,7 +1032,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1024 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); | 1032 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); |
1025 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1033 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1026 | "Received message from %s\n", | 1034 | "Received message from %s\n", |
1027 | unix_address_to_string(NULL, ua, ua_len)); | 1035 | unix_address_to_string (NULL, ua, ua_len)); |
1028 | GNUNET_STATISTICS_update (plugin->env->stats, | 1036 | GNUNET_STATISTICS_update (plugin->env->stats, |
1029 | "# bytes received via UNIX", | 1037 | "# bytes received via UNIX", |
1030 | ntohs (currhdr->size), | 1038 | ntohs (currhdr->size), |
@@ -1419,12 +1427,17 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1419 | GNUNET_TRANSPORT_AddressStringCallback asc, | 1427 | GNUNET_TRANSPORT_AddressStringCallback asc, |
1420 | void *asc_cls) | 1428 | void *asc_cls) |
1421 | { | 1429 | { |
1422 | if ((NULL != addr) && (addrlen > 0)) | 1430 | const char *ret; |
1423 | { | 1431 | |
1424 | asc (asc_cls, unix_address_to_string (NULL, addr, addrlen), GNUNET_OK); | 1432 | if ( (NULL != addr) && (addrlen > 0)) |
1425 | } | 1433 | ret = unix_address_to_string (NULL, |
1434 | addr, | ||
1435 | addrlen); | ||
1426 | else | 1436 | else |
1427 | asc (asc_cls, NULL, GNUNET_SYSERR); | 1437 | ret = NULL; |
1438 | asc (asc_cls, | ||
1439 | ret, | ||
1440 | (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | ||
1428 | asc (asc_cls, NULL, GNUNET_OK); | 1441 | asc (asc_cls, NULL, GNUNET_OK); |
1429 | } | 1442 | } |
1430 | 1443 | ||
@@ -1433,7 +1446,7 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1433 | * Function called to convert a string address to | 1446 | * Function called to convert a string address to |
1434 | * a binary address. | 1447 | * a binary address. |
1435 | * | 1448 | * |
1436 | * @param cls closure ('struct Plugin*') | 1449 | * @param cls closure (`struct Plugin *`) |
1437 | * @param addr string address | 1450 | * @param addr string address |
1438 | * @param addrlen length of the @a addr (strlen(addr) + '\0') | 1451 | * @param addrlen length of the @a addr (strlen(addr) + '\0') |
1439 | * @param buf location to store the buffer | 1452 | * @param buf location to store the buffer |
@@ -1573,7 +1586,7 @@ reschedule_session_timeout (struct Session *s) | |||
1573 | * | 1586 | * |
1574 | * @param cls the plugin | 1587 | * @param cls the plugin |
1575 | * @param key peer identity (unused) | 1588 | * @param key peer identity (unused) |
1576 | * @param value the 'struct Session' to disconnect | 1589 | * @param value the `struct Session *` to disconnect |
1577 | * @return #GNUNET_YES (always, continue to iterate) | 1590 | * @return #GNUNET_YES (always, continue to iterate) |
1578 | */ | 1591 | */ |
1579 | static int | 1592 | static int |