diff options
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index e78445a0a..3d6ac4d23 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -530,9 +530,6 @@ lookup_session (struct Plugin *plugin, | |||
530 | { | 530 | { |
531 | struct LookupCtx lctx; | 531 | struct LookupCtx lctx; |
532 | 532 | ||
533 | GNUNET_assert (NULL != plugin); | ||
534 | GNUNET_assert (NULL != sender); | ||
535 | GNUNET_assert (NULL != ua); | ||
536 | lctx.s = NULL; | 533 | lctx.s = NULL; |
537 | lctx.ua = ua; | 534 | lctx.ua = ua; |
538 | lctx.ua_len = ua_len; | 535 | lctx.ua_len = ua_len; |
@@ -548,12 +545,15 @@ lookup_session (struct Plugin *plugin, | |||
548 | * to close a session due to a disconnect or failure to | 545 | * to close a session due to a disconnect or failure to |
549 | * establish a connection. | 546 | * establish a connection. |
550 | * | 547 | * |
548 | * @param cls closure with the `struct Plugin` | ||
551 | * @param s session to close down | 549 | * @param s session to close down |
550 | * @return #GNUNET_OK on success | ||
552 | */ | 551 | */ |
553 | static void | 552 | static int |
554 | disconnect_session (struct Session *s) | 553 | unix_session_disconnect (void *cls, |
554 | struct Session *s) | ||
555 | { | 555 | { |
556 | struct Plugin *plugin = s->plugin; | 556 | struct Plugin *plugin = cls; |
557 | struct UNIXMessageWrapper *msgw; | 557 | struct UNIXMessageWrapper *msgw; |
558 | struct UNIXMessageWrapper *next; | 558 | struct UNIXMessageWrapper *next; |
559 | int removed; | 559 | int removed; |
@@ -595,6 +595,7 @@ disconnect_session (struct Session *s) | |||
595 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 595 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
596 | } | 596 | } |
597 | GNUNET_free (s); | 597 | GNUNET_free (s); |
598 | return GNUNET_OK; | ||
598 | } | 599 | } |
599 | 600 | ||
600 | 601 | ||
@@ -610,13 +611,13 @@ disconnect_session (struct Session *s) | |||
610 | * @param priority how important is the message (ignored by UNIX) | 611 | * @param priority how important is the message (ignored by UNIX) |
611 | * @param timeout when should we time out (give up) if we can not transmit? | 612 | * @param timeout when should we time out (give up) if we can not transmit? |
612 | * @param addr the addr to send the message to, needs to be a sockaddr for us | 613 | * @param addr the addr to send the message to, needs to be a sockaddr for us |
613 | * @param addrlen the len of addr | 614 | * @param addrlen the len of @a addr |
614 | * @param payload bytes payload to send | 615 | * @param payload bytes payload to send |
615 | * @param cont continuation to call once the message has | 616 | * @param cont continuation to call once the message has |
616 | * been transmitted (or if the transport is ready | 617 | * been transmitted (or if the transport is ready |
617 | * for the next transmission call; or if the | 618 | * for the next transmission call; or if the |
618 | * peer disconnected...) | 619 | * peer disconnected...) |
619 | * @param cont_cls closure for cont | 620 | * @param cont_cls closure for @a cont |
620 | * @return on success the number of bytes written, RETRY for retry, -1 on errors | 621 | * @return on success the number of bytes written, RETRY for retry, -1 on errors |
621 | */ | 622 | */ |
622 | static ssize_t | 623 | static ssize_t |
@@ -637,7 +638,6 @@ unix_real_send (void *cls, | |||
637 | socklen_t un_len; | 638 | socklen_t un_len; |
638 | const char *unixpath; | 639 | const char *unixpath; |
639 | 640 | ||
640 | |||
641 | GNUNET_assert (NULL != plugin); | 641 | GNUNET_assert (NULL != plugin); |
642 | if (NULL == send_handle) | 642 | if (NULL == send_handle) |
643 | { | 643 | { |
@@ -734,7 +734,7 @@ struct GetSessionIteratorContext | |||
734 | const char *address; | 734 | const char *address; |
735 | 735 | ||
736 | /** | 736 | /** |
737 | * Number of bytes in 'address' | 737 | * Number of bytes in @e address |
738 | */ | 738 | */ |
739 | size_t addrlen; | 739 | size_t addrlen; |
740 | }; | 740 | }; |
@@ -784,7 +784,7 @@ session_timeout (void *cls, | |||
784 | s, | 784 | s, |
785 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 785 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
786 | GNUNET_YES)); | 786 | GNUNET_YES)); |
787 | disconnect_session (s); | 787 | unix_session_disconnect (s->plugin, s); |
788 | } | 788 | } |
789 | 789 | ||
790 | 790 | ||
@@ -903,7 +903,7 @@ unix_plugin_get_session (void *cls, | |||
903 | * @param cls closure | 903 | * @param cls closure |
904 | * @param session which session must be used | 904 | * @param session which session must be used |
905 | * @param msgbuf the message to transmit | 905 | * @param msgbuf the message to transmit |
906 | * @param msgbuf_size number of bytes in 'msgbuf' | 906 | * @param msgbuf_size number of bytes in @a msgbuf |
907 | * @param priority how important is the message (most plugins will | 907 | * @param priority how important is the message (most plugins will |
908 | * ignore message priority and just FIFO) | 908 | * ignore message priority and just FIFO) |
909 | * @param to how long to wait at most for the transmission (does not | 909 | * @param to how long to wait at most for the transmission (does not |
@@ -914,7 +914,7 @@ unix_plugin_get_session (void *cls, | |||
914 | * been transmitted (or if the transport is ready | 914 | * been transmitted (or if the transport is ready |
915 | * for the next transmission call; or if the | 915 | * for the next transmission call; or if the |
916 | * peer disconnected...); can be NULL | 916 | * peer disconnected...); can be NULL |
917 | * @param cont_cls closure for cont | 917 | * @param cont_cls closure for @a cont |
918 | * @return number of bytes used (on the physical network, with overheads); | 918 | * @return number of bytes used (on the physical network, with overheads); |
919 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 919 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
920 | * and does NOT mean that the message was not transmitted (DV) | 920 | * and does NOT mean that the message was not transmitted (DV) |
@@ -932,9 +932,6 @@ unix_plugin_send (void *cls, | |||
932 | struct UNIXMessage *message; | 932 | struct UNIXMessage *message; |
933 | int ssize; | 933 | int ssize; |
934 | 934 | ||
935 | GNUNET_assert (NULL != plugin); | ||
936 | GNUNET_assert (NULL != session); | ||
937 | |||
938 | if (GNUNET_OK != | 935 | if (GNUNET_OK != |
939 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 936 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, |
940 | &session->target, | 937 | &session->target, |
@@ -960,7 +957,7 @@ unix_plugin_send (void *cls, | |||
960 | sizeof (struct GNUNET_PeerIdentity)); | 957 | sizeof (struct GNUNET_PeerIdentity)); |
961 | memcpy (&message[1], msgbuf, msgbuf_size); | 958 | memcpy (&message[1], msgbuf, msgbuf_size); |
962 | reschedule_session_timeout (session); | 959 | reschedule_session_timeout (session); |
963 | wrapper = GNUNET_malloc (sizeof (struct UNIXMessageWrapper)); | 960 | wrapper = GNUNET_new (struct UNIXMessageWrapper); |
964 | wrapper->msg = message; | 961 | wrapper->msg = message; |
965 | wrapper->msgsize = ssize; | 962 | wrapper->msgsize = ssize; |
966 | wrapper->payload = msgbuf_size; | 963 | wrapper->payload = msgbuf_size; |
@@ -1001,9 +998,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1001 | struct GNUNET_HELLO_Address * addr; | 998 | struct GNUNET_HELLO_Address * addr; |
1002 | 999 | ||
1003 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); | 1000 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); |
1004 | |||
1005 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); | 1001 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); |
1006 | |||
1007 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1002 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1008 | "Received message from %s\n", | 1003 | "Received message from %s\n", |
1009 | unix_address_to_string(NULL, ua, ua_len)); | 1004 | unix_address_to_string(NULL, ua, ua_len)); |
@@ -1329,10 +1324,10 @@ unix_transport_server_start (void *cls) | |||
1329 | static int | 1324 | static int |
1330 | unix_check_address (void *cls, const void *addr, size_t addrlen) | 1325 | unix_check_address (void *cls, const void *addr, size_t addrlen) |
1331 | { | 1326 | { |
1332 | struct Plugin* plugin = cls; | 1327 | struct Plugin* plugin = cls; |
1333 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 1328 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
1334 | char *addrstr; | 1329 | char *addrstr; |
1335 | size_t addr_str_len; | 1330 | size_t addr_str_len; |
1336 | 1331 | ||
1337 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) | 1332 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) |
1338 | { | 1333 | { |
@@ -1366,11 +1361,11 @@ unix_check_address (void *cls, const void *addr, size_t addrlen) | |||
1366 | * @param type name of the transport that generated the address | 1361 | * @param type name of the transport that generated the address |
1367 | * @param addr one of the addresses of the host, NULL for the last address | 1362 | * @param addr one of the addresses of the host, NULL for the last address |
1368 | * the specific address format depends on the transport | 1363 | * the specific address format depends on the transport |
1369 | * @param addrlen length of the address | 1364 | * @param addrlen length of the @a addr |
1370 | * @param numeric should (IP) addresses be displayed in numeric form? | 1365 | * @param numeric should (IP) addresses be displayed in numeric form? |
1371 | * @param timeout after how long should we give up? | 1366 | * @param timeout after how long should we give up? |
1372 | * @param asc function to call on each string | 1367 | * @param asc function to call on each string |
1373 | * @param asc_cls closure for asc | 1368 | * @param asc_cls closure for @a asc |
1374 | */ | 1369 | */ |
1375 | static void | 1370 | static void |
1376 | unix_plugin_address_pretty_printer (void *cls, const char *type, | 1371 | unix_plugin_address_pretty_printer (void *cls, const char *type, |
@@ -1403,15 +1398,16 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1403 | * | 1398 | * |
1404 | * @param cls closure ('struct Plugin*') | 1399 | * @param cls closure ('struct Plugin*') |
1405 | * @param addr string address | 1400 | * @param addr string address |
1406 | * @param addrlen length of the address (strlen(addr) + '\0') | 1401 | * @param addrlen length of the @a addr (strlen(addr) + '\0') |
1407 | * @param buf location to store the buffer | 1402 | * @param buf location to store the buffer |
1408 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 1403 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
1409 | * @param added length of created address | 1404 | * @param added length of created address |
1410 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1405 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1411 | */ | 1406 | */ |
1412 | static int | 1407 | static int |
1413 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 1408 | unix_string_to_address (void *cls, |
1414 | void **buf, size_t *added) | 1409 | const char *addr, uint16_t addrlen, |
1410 | void **buf, size_t *added) | ||
1415 | { | 1411 | { |
1416 | struct UnixAddress *ua; | 1412 | struct UnixAddress *ua; |
1417 | char *address; | 1413 | char *address; |
@@ -1532,19 +1528,20 @@ reschedule_session_timeout (struct Session *s) | |||
1532 | /** | 1528 | /** |
1533 | * Function called on sessions to disconnect | 1529 | * Function called on sessions to disconnect |
1534 | * | 1530 | * |
1535 | * @param cls the plugin (unused) | 1531 | * @param cls the plugin |
1536 | * @param key peer identity (unused) | 1532 | * @param key peer identity (unused) |
1537 | * @param value the 'struct Session' to disconnect | 1533 | * @param value the 'struct Session' to disconnect |
1538 | * @return GNUNET_YES (always, continue to iterate) | 1534 | * @return #GNUNET_YES (always, continue to iterate) |
1539 | */ | 1535 | */ |
1540 | static int | 1536 | static int |
1541 | get_session_delete_it (void *cls, | 1537 | get_session_delete_it (void *cls, |
1542 | const struct GNUNET_PeerIdentity *key, | 1538 | const struct GNUNET_PeerIdentity *key, |
1543 | void *value) | 1539 | void *value) |
1544 | { | 1540 | { |
1541 | struct Plugin *plugin = cls; | ||
1545 | struct Session *s = value; | 1542 | struct Session *s = value; |
1546 | 1543 | ||
1547 | disconnect_session (s); | 1544 | unix_session_disconnect (plugin, s); |
1548 | return GNUNET_YES; | 1545 | return GNUNET_YES; |
1549 | } | 1546 | } |
1550 | 1547 | ||
@@ -1557,8 +1554,8 @@ get_session_delete_it (void *cls, | |||
1557 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1554 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1558 | */ | 1555 | */ |
1559 | static void | 1556 | static void |
1560 | unix_disconnect (void *cls, | 1557 | unix_peer_disconnect (void *cls, |
1561 | const struct GNUNET_PeerIdentity *target) | 1558 | const struct GNUNET_PeerIdentity *target) |
1562 | { | 1559 | { |
1563 | struct Plugin *plugin = cls; | 1560 | struct Plugin *plugin = cls; |
1564 | 1561 | ||
@@ -1589,7 +1586,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1589 | { | 1586 | { |
1590 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 1587 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
1591 | initialze the plugin or the API */ | 1588 | initialze the plugin or the API */ |
1592 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1589 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1593 | api->cls = NULL; | 1590 | api->cls = NULL; |
1594 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; | 1591 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; |
1595 | api->address_to_string = &unix_address_to_string; | 1592 | api->address_to_string = &unix_address_to_string; |
@@ -1600,7 +1597,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1600 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", | 1597 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", |
1601 | &port)) | 1598 | &port)) |
1602 | port = UNIX_NAT_DEFAULT_PORT; | 1599 | port = UNIX_NAT_DEFAULT_PORT; |
1603 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 1600 | plugin = GNUNET_new (struct Plugin); |
1604 | plugin->port = port; | 1601 | plugin->port = port; |
1605 | plugin->env = env; | 1602 | plugin->env = env; |
1606 | GNUNET_asprintf (&plugin->unix_socket_path, | 1603 | GNUNET_asprintf (&plugin->unix_socket_path, |
@@ -1610,12 +1607,13 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1610 | /* Initialize my flags */ | 1607 | /* Initialize my flags */ |
1611 | myoptions = 0; | 1608 | myoptions = 0; |
1612 | 1609 | ||
1613 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1610 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1614 | api->cls = plugin; | 1611 | api->cls = plugin; |
1615 | 1612 | ||
1616 | api->get_session = &unix_plugin_get_session; | 1613 | api->get_session = &unix_plugin_get_session; |
1617 | api->send = &unix_plugin_send; | 1614 | api->send = &unix_plugin_send; |
1618 | api->disconnect = &unix_disconnect; | 1615 | api->disconnect_peer = &unix_peer_disconnect; |
1616 | api->disconnect_session = &unix_session_disconnect; | ||
1619 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; | 1617 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; |
1620 | api->address_to_string = &unix_address_to_string; | 1618 | api->address_to_string = &unix_address_to_string; |
1621 | api->check_address = &unix_check_address; | 1619 | api->check_address = &unix_check_address; |