diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-28 12:32:52 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-28 12:32:52 +0000 |
commit | 7967991c0b46cd87c8da69448eed0dcc7e4f45e1 (patch) | |
tree | da9a90d90b3acbe8cd8d0d07e086dcbcb0068cbe /src/transport/plugin_transport_unix.c | |
parent | a97019931121ce990f4e114bf32f01bca0423b85 (diff) | |
download | gnunet-7967991c0b46cd87c8da69448eed0dcc7e4f45e1.tar.gz gnunet-7967991c0b46cd87c8da69448eed0dcc7e4f45e1.zip |
options support for unix
Diffstat (limited to 'src/transport/plugin_transport_unix.c')
-rw-r--r-- | src/transport/plugin_transport_unix.c | 309 |
1 files changed, 247 insertions, 62 deletions
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 064a91663..4418964bd 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -43,6 +43,8 @@ | |||
43 | */ | 43 | */ |
44 | #define RETRY 0 | 44 | #define RETRY 0 |
45 | 45 | ||
46 | #define PLUGIN_NAME "unix" | ||
47 | |||
46 | /** | 48 | /** |
47 | * How long until we give up on transmitting the welcome message? | 49 | * How long until we give up on transmitting the welcome message? |
48 | */ | 50 | */ |
@@ -60,6 +62,14 @@ | |||
60 | 62 | ||
61 | GNUNET_NETWORK_STRUCT_BEGIN | 63 | GNUNET_NETWORK_STRUCT_BEGIN |
62 | 64 | ||
65 | struct UnixAddress | ||
66 | { | ||
67 | uint32_t options GNUNET_PACKED; | ||
68 | |||
69 | uint32_t addrlen GNUNET_PACKED; | ||
70 | }; | ||
71 | |||
72 | |||
63 | /** | 73 | /** |
64 | * UNIX Message-Packet header. | 74 | * UNIX Message-Packet header. |
65 | */ | 75 | */ |
@@ -77,6 +87,12 @@ struct UNIXMessage | |||
77 | 87 | ||
78 | }; | 88 | }; |
79 | 89 | ||
90 | GNUNET_NETWORK_STRUCT_END | ||
91 | |||
92 | /** | ||
93 | * Address options | ||
94 | */ | ||
95 | static uint32_t myoptions; | ||
80 | 96 | ||
81 | /** | 97 | /** |
82 | * Handle for a session. | 98 | * Handle for a session. |
@@ -87,7 +103,7 @@ struct Session | |||
87 | 103 | ||
88 | struct Plugin * plugin; | 104 | struct Plugin * plugin; |
89 | 105 | ||
90 | void *addr; | 106 | struct UnixAddress *addr; |
91 | 107 | ||
92 | size_t addrlen; | 108 | size_t addrlen; |
93 | 109 | ||
@@ -330,6 +346,19 @@ reschedule_session_timeout (struct Session *s); | |||
330 | static void | 346 | static void |
331 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 347 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
332 | 348 | ||
349 | /** | ||
350 | * Function called for a quick conversion of the binary address to | ||
351 | * a numeric address. Note that the caller must not free the | ||
352 | * address and that the next call to this function is allowed | ||
353 | * to override the address again. | ||
354 | * | ||
355 | * @param cls closure | ||
356 | * @param addr binary address | ||
357 | * @param addrlen length of the address | ||
358 | * @return string representing the same address | ||
359 | */ | ||
360 | static const char * | ||
361 | unix_address_to_string (void *cls, const void *addr, size_t addrlen); | ||
333 | 362 | ||
334 | /** | 363 | /** |
335 | * Re-schedule the main 'select' callback (unix_plugin_select) | 364 | * Re-schedule the main 'select' callback (unix_plugin_select) |
@@ -381,7 +410,9 @@ struct LookupCtx | |||
381 | /** | 410 | /** |
382 | * Address we are looking for. | 411 | * Address we are looking for. |
383 | */ | 412 | */ |
384 | const struct sockaddr_un *addr; | 413 | const struct UnixAddress *ua; |
414 | |||
415 | size_t ua_len; | ||
385 | }; | 416 | }; |
386 | 417 | ||
387 | 418 | ||
@@ -401,7 +432,10 @@ lookup_session_it (void *cls, | |||
401 | struct LookupCtx *lctx = cls; | 432 | struct LookupCtx *lctx = cls; |
402 | struct Session *t = value; | 433 | struct Session *t = value; |
403 | 434 | ||
404 | if (0 == strcmp (t->addr, lctx->addr->sun_path)) | 435 | if (t->addrlen != lctx->ua_len) |
436 | return GNUNET_YES; | ||
437 | |||
438 | if (0 == memcmp (&t->addr, lctx->ua, lctx->ua_len)) | ||
405 | { | 439 | { |
406 | lctx->s = t; | 440 | lctx->s = t; |
407 | return GNUNET_NO; | 441 | return GNUNET_NO; |
@@ -421,15 +455,16 @@ lookup_session_it (void *cls, | |||
421 | static struct Session * | 455 | static struct Session * |
422 | lookup_session (struct Plugin *plugin, | 456 | lookup_session (struct Plugin *plugin, |
423 | const struct GNUNET_PeerIdentity *sender, | 457 | const struct GNUNET_PeerIdentity *sender, |
424 | const struct sockaddr_un *addr) | 458 | const struct UnixAddress *ua, size_t ua_len) |
425 | { | 459 | { |
426 | struct LookupCtx lctx; | 460 | struct LookupCtx lctx; |
427 | 461 | ||
428 | GNUNET_assert (NULL != plugin); | 462 | GNUNET_assert (NULL != plugin); |
429 | GNUNET_assert (NULL != sender); | 463 | GNUNET_assert (NULL != sender); |
430 | GNUNET_assert (NULL != addr); | 464 | GNUNET_assert (NULL != ua); |
431 | lctx.s = NULL; | 465 | lctx.s = NULL; |
432 | lctx.addr = addr; | 466 | lctx.ua = ua; |
467 | lctx.ua_len = ua_len; | ||
433 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, | 468 | GNUNET_CONTAINER_multihashmap_get_multiple (plugin->session_map, |
434 | &sender->hashPubKey, | 469 | &sender->hashPubKey, |
435 | &lookup_session_it, &lctx); | 470 | &lookup_session_it, &lctx); |
@@ -519,7 +554,7 @@ unix_real_send (void *cls, | |||
519 | const struct GNUNET_PeerIdentity *target, const char *msgbuf, | 554 | const struct GNUNET_PeerIdentity *target, const char *msgbuf, |
520 | size_t msgbuf_size, unsigned int priority, | 555 | size_t msgbuf_size, unsigned int priority, |
521 | struct GNUNET_TIME_Absolute timeout, | 556 | struct GNUNET_TIME_Absolute timeout, |
522 | const void *addr, | 557 | const struct UnixAddress *addr, |
523 | size_t addrlen, | 558 | size_t addrlen, |
524 | size_t payload, | 559 | size_t payload, |
525 | GNUNET_TRANSPORT_TransmitContinuation cont, | 560 | GNUNET_TRANSPORT_TransmitContinuation cont, |
@@ -531,6 +566,8 @@ unix_real_send (void *cls, | |||
531 | size_t sbs; | 566 | size_t sbs; |
532 | struct sockaddr_un un; | 567 | struct sockaddr_un un; |
533 | size_t slen; | 568 | size_t slen; |
569 | const char *unix_path; | ||
570 | |||
534 | 571 | ||
535 | GNUNET_assert (NULL != plugin); | 572 | GNUNET_assert (NULL != plugin); |
536 | if (NULL == send_handle) | 573 | if (NULL == send_handle) |
@@ -545,13 +582,14 @@ unix_real_send (void *cls, | |||
545 | } | 582 | } |
546 | 583 | ||
547 | /* Prepare address */ | 584 | /* Prepare address */ |
585 | unix_path = (const char *) &addr[1]; | ||
548 | memset (&un, 0, sizeof (un)); | 586 | memset (&un, 0, sizeof (un)); |
549 | un.sun_family = AF_UNIX; | 587 | un.sun_family = AF_UNIX; |
550 | slen = strlen (addr) + 1; | 588 | slen = strlen (unix_path); |
551 | if (slen >= sizeof (un.sun_path)) | 589 | if (slen >= sizeof (un.sun_path)) |
552 | slen = sizeof (un.sun_path) - 1; | 590 | slen = sizeof (un.sun_path) - 1; |
553 | GNUNET_assert (slen < sizeof (un.sun_path)); | 591 | GNUNET_assert (slen < sizeof (un.sun_path)); |
554 | memcpy (un.sun_path, addr, slen); | 592 | memcpy (un.sun_path, unix_path, slen); |
555 | un.sun_path[slen] = '\0'; | 593 | un.sun_path[slen] = '\0'; |
556 | slen = sizeof (struct sockaddr_un); | 594 | slen = sizeof (struct sockaddr_un); |
557 | #if LINUX | 595 | #if LINUX |
@@ -703,10 +741,39 @@ unix_plugin_get_session (void *cls, | |||
703 | struct Plugin *plugin = cls; | 741 | struct Plugin *plugin = cls; |
704 | struct Session *s; | 742 | struct Session *s; |
705 | struct GetSessionIteratorContext gsi; | 743 | struct GetSessionIteratorContext gsi; |
744 | struct UnixAddress *ua; | ||
745 | char * addrstr; | ||
746 | uint32_t addr_str_len; | ||
706 | 747 | ||
707 | GNUNET_assert (NULL != plugin); | 748 | GNUNET_assert (NULL != plugin); |
708 | GNUNET_assert (NULL != address); | 749 | GNUNET_assert (NULL != address); |
709 | 750 | ||
751 | ua = (struct UnixAddress *) address->address; | ||
752 | if ((NULL == address->address) || (0 == address->address_length) || | ||
753 | (sizeof (struct UnixAddress) > address->address_length)) | ||
754 | { | ||
755 | GNUNET_break (0); | ||
756 | return NULL; | ||
757 | } | ||
758 | addrstr = (char *) &ua[1]; | ||
759 | addr_str_len = ntohl (ua->addrlen); | ||
760 | if (addr_str_len != address->address_length - sizeof (struct UnixAddress *)) | ||
761 | { | ||
762 | /* This can be a legacy address */ | ||
763 | return NULL; | ||
764 | } | ||
765 | |||
766 | if ('\0' != addrstr[addr_str_len - 1]) | ||
767 | { | ||
768 | GNUNET_break (0); | ||
769 | return NULL; | ||
770 | } | ||
771 | if (strlen (addrstr) + 1 != addr_str_len) | ||
772 | { | ||
773 | GNUNET_break (0); | ||
774 | return NULL; | ||
775 | } | ||
776 | |||
710 | /* Check if already existing */ | 777 | /* Check if already existing */ |
711 | gsi.address = (const char *) address->address; | 778 | gsi.address = (const char *) address->address; |
712 | gsi.addrlen = address->address_length; | 779 | gsi.addrlen = address->address_length; |
@@ -723,21 +790,18 @@ unix_plugin_get_session (void *cls, | |||
723 | 790 | ||
724 | /* create a new session */ | 791 | /* create a new session */ |
725 | s = GNUNET_malloc (sizeof (struct Session) + address->address_length); | 792 | s = GNUNET_malloc (sizeof (struct Session) + address->address_length); |
726 | s->addr = &s[1]; | 793 | s->addr = (struct UnixAddress *) &s[1]; |
727 | s->addrlen = address->address_length; | 794 | s->addrlen = address->address_length; |
728 | s->plugin = plugin; | 795 | s->plugin = plugin; |
729 | memcpy (s->addr, address->address, s->addrlen); | 796 | memcpy (s->addr, address->address, address->address_length); |
730 | memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | 797 | memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); |
731 | |||
732 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | 798 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); |
733 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 799 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
734 | &session_timeout, | 800 | &session_timeout, |
735 | s); | 801 | s); |
736 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 802 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
737 | "Creating a new session %p with timeout set to %s\n", | 803 | "Creating a new session %p for address `%s'\n", |
738 | s, | 804 | s, unix_address_to_string (NULL, address->address, address->address_length)); |
739 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
740 | GNUNET_YES)); | ||
741 | (void) GNUNET_CONTAINER_multihashmap_put (plugin->session_map, | 805 | (void) GNUNET_CONTAINER_multihashmap_put (plugin->session_map, |
742 | &address->peer.hashPubKey, s, | 806 | &address->peer.hashPubKey, s, |
743 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 807 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -852,18 +916,18 @@ unix_plugin_send (void *cls, | |||
852 | static void | 916 | static void |
853 | unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | 917 | unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, |
854 | const struct GNUNET_MessageHeader *currhdr, | 918 | const struct GNUNET_MessageHeader *currhdr, |
855 | const struct sockaddr_un *un, size_t fromlen) | 919 | const struct UnixAddress *ua, size_t ua_len) |
856 | { | 920 | { |
857 | struct Session *s = NULL; | 921 | struct Session *s = NULL; |
858 | struct GNUNET_HELLO_Address * addr; | 922 | struct GNUNET_HELLO_Address * addr; |
859 | 923 | ||
860 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); | 924 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); |
861 | 925 | ||
862 | GNUNET_assert (fromlen >= sizeof (struct sockaddr_un)); | 926 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); |
863 | 927 | ||
864 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 928 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
865 | "Received message from %s\n", | 929 | "Received message from %s\n", |
866 | un->sun_path); | 930 | unix_address_to_string(NULL, ua, ua_len)); |
867 | GNUNET_STATISTICS_update (plugin->env->stats, | 931 | GNUNET_STATISTICS_update (plugin->env->stats, |
868 | "# bytes received via UNIX", | 932 | "# bytes received via UNIX", |
869 | ntohs (currhdr->size), | 933 | ntohs (currhdr->size), |
@@ -871,20 +935,19 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
871 | 935 | ||
872 | addr = GNUNET_HELLO_address_allocate (sender, | 936 | addr = GNUNET_HELLO_address_allocate (sender, |
873 | "unix", | 937 | "unix", |
874 | un->sun_path, | 938 | ua, |
875 | strlen (un->sun_path) + 1); | 939 | ua_len); |
876 | s = lookup_session (plugin, sender, un); | 940 | s = lookup_session (plugin, sender, ua, ua_len); |
877 | if (NULL == s) | 941 | if (NULL == s) |
878 | s = unix_plugin_get_session (plugin, addr); | 942 | s = unix_plugin_get_session (plugin, addr); |
879 | reschedule_session_timeout (s); | 943 | reschedule_session_timeout (s); |
880 | 944 | ||
881 | plugin->env->receive (plugin->env->cls, sender, currhdr, | 945 | plugin->env->receive (plugin->env->cls, sender, currhdr, |
882 | s, un->sun_path, strlen (un->sun_path) + 1); | 946 | s, (const char *) ua, ua_len); |
883 | 947 | ||
884 | plugin->env->update_address_metrics (plugin->env->cls, | 948 | plugin->env->update_address_metrics (plugin->env->cls, |
885 | sender, | 949 | sender, |
886 | un->sun_path, | 950 | (const char *) ua, ua_len, |
887 | strlen (un->sun_path) + 1, | ||
888 | s, | 951 | s, |
889 | &plugin->ats_network, 1); | 952 | &plugin->ats_network, 1); |
890 | 953 | ||
@@ -901,6 +964,7 @@ static void | |||
901 | unix_plugin_select_read (struct Plugin *plugin) | 964 | unix_plugin_select_read (struct Plugin *plugin) |
902 | { | 965 | { |
903 | char buf[65536] GNUNET_ALIGN; | 966 | char buf[65536] GNUNET_ALIGN; |
967 | struct UnixAddress *ua; | ||
904 | struct UNIXMessage *msg; | 968 | struct UNIXMessage *msg; |
905 | struct GNUNET_PeerIdentity sender; | 969 | struct GNUNET_PeerIdentity sender; |
906 | struct sockaddr_un un; | 970 | struct sockaddr_un un; |
@@ -911,6 +975,7 @@ unix_plugin_select_read (struct Plugin *plugin) | |||
911 | char *msgbuf; | 975 | char *msgbuf; |
912 | const struct GNUNET_MessageHeader *currhdr; | 976 | const struct GNUNET_MessageHeader *currhdr; |
913 | uint16_t csize; | 977 | uint16_t csize; |
978 | size_t ua_len; | ||
914 | 979 | ||
915 | addrlen = sizeof (un); | 980 | addrlen = sizeof (un); |
916 | memset (&un, 0, sizeof (un)); | 981 | memset (&un, 0, sizeof (un)); |
@@ -937,6 +1002,11 @@ unix_plugin_select_read (struct Plugin *plugin) | |||
937 | } | 1002 | } |
938 | 1003 | ||
939 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 1004 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
1005 | ua_len = sizeof (struct UnixAddress) + strlen (&un.sun_path[0]) +1; | ||
1006 | ua = GNUNET_malloc (ua_len); | ||
1007 | ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); | ||
1008 | ua->options = htonl (0); | ||
1009 | memcpy (&ua[1], &un.sun_path[0], strlen (&un.sun_path[0]) +1); | ||
940 | 1010 | ||
941 | msg = (struct UNIXMessage *) buf; | 1011 | msg = (struct UNIXMessage *) buf; |
942 | csize = ntohs (msg->header.size); | 1012 | csize = ntohs (msg->header.size); |
@@ -959,9 +1029,10 @@ unix_plugin_select_read (struct Plugin *plugin) | |||
959 | GNUNET_break_op (0); | 1029 | GNUNET_break_op (0); |
960 | break; | 1030 | break; |
961 | } | 1031 | } |
962 | unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un)); | 1032 | unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len); |
963 | offset += csize; | 1033 | offset += csize; |
964 | } | 1034 | } |
1035 | GNUNET_free (ua); | ||
965 | } | 1036 | } |
966 | 1037 | ||
967 | 1038 | ||
@@ -1173,6 +1244,57 @@ unix_transport_server_start (void *cls) | |||
1173 | 1244 | ||
1174 | 1245 | ||
1175 | /** | 1246 | /** |
1247 | * Function called for a quick conversion of the binary address to | ||
1248 | * a numeric address. Note that the caller must not free the | ||
1249 | * address and that the next call to this function is allowed | ||
1250 | * to override the address again. | ||
1251 | * | ||
1252 | * @param cls closure | ||
1253 | * @param addr binary address | ||
1254 | * @param addrlen length of the address | ||
1255 | * @return string representing the same address | ||
1256 | */ | ||
1257 | static const char * | ||
1258 | unix_address_to_string (void *cls, const void *addr, size_t addrlen) | ||
1259 | { | ||
1260 | static char rbuf[1024]; | ||
1261 | struct UnixAddress *ua = (struct UnixAddress *) addr; | ||
1262 | char *addrstr; | ||
1263 | char *tmp; | ||
1264 | size_t addr_str_len; | ||
1265 | |||
1266 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) | ||
1267 | { | ||
1268 | GNUNET_break (0); | ||
1269 | return NULL; | ||
1270 | } | ||
1271 | addrstr = (char *) &ua[1]; | ||
1272 | addr_str_len = ntohl (ua->addrlen); | ||
1273 | |||
1274 | if (addr_str_len != addrlen - sizeof (struct UnixAddress *)) | ||
1275 | { | ||
1276 | GNUNET_break (0); | ||
1277 | return NULL; | ||
1278 | } | ||
1279 | |||
1280 | if ('\0' != addrstr[addr_str_len - 1]) | ||
1281 | { | ||
1282 | GNUNET_break (0); | ||
1283 | return NULL; | ||
1284 | } | ||
1285 | if (strlen (addrstr) + 1 != addr_str_len) | ||
1286 | { | ||
1287 | GNUNET_break (0); | ||
1288 | return NULL; | ||
1289 | } | ||
1290 | |||
1291 | GNUNET_asprintf(&tmp, "%s.%u.%s", PLUGIN_NAME, ntohl (ua->options), addrstr); | ||
1292 | memcpy (rbuf, tmp, strlen (tmp) + 1); | ||
1293 | GNUNET_free (tmp); | ||
1294 | return rbuf; | ||
1295 | } | ||
1296 | |||
1297 | /** | ||
1176 | * Function that will be called to check if a binary address for this | 1298 | * Function that will be called to check if a binary address for this |
1177 | * plugin is well-formed and corresponds to an address for THIS peer | 1299 | * plugin is well-formed and corresponds to an address for THIS peer |
1178 | * (as per our configuration). Naturally, if absolutely necessary, | 1300 | * (as per our configuration). Naturally, if absolutely necessary, |
@@ -1191,10 +1313,32 @@ unix_transport_server_start (void *cls) | |||
1191 | static int | 1313 | static int |
1192 | unix_check_address (void *cls, const void *addr, size_t addrlen) | 1314 | unix_check_address (void *cls, const void *addr, size_t addrlen) |
1193 | { | 1315 | { |
1194 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1316 | struct Plugin* plugin = cls; |
1195 | "Informing transport service about my address `%s'\n", | 1317 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
1196 | (char *) addr); | 1318 | char *addrstr; |
1197 | return GNUNET_OK; | 1319 | size_t addr_str_len; |
1320 | |||
1321 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) | ||
1322 | { | ||
1323 | GNUNET_break (0); | ||
1324 | return GNUNET_SYSERR; | ||
1325 | } | ||
1326 | addrstr = (char *) &ua[1]; | ||
1327 | addr_str_len = ntohl (ua->addrlen); | ||
1328 | if ('\0' != addrstr[addr_str_len - 1]) | ||
1329 | { | ||
1330 | GNUNET_break (0); | ||
1331 | return GNUNET_SYSERR; | ||
1332 | } | ||
1333 | if (strlen (addrstr) + 1 != addr_str_len) | ||
1334 | { | ||
1335 | GNUNET_break (0); | ||
1336 | return GNUNET_SYSERR; | ||
1337 | } | ||
1338 | |||
1339 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) | ||
1340 | return GNUNET_OK; | ||
1341 | return GNUNET_SYSERR; | ||
1198 | } | 1342 | } |
1199 | 1343 | ||
1200 | 1344 | ||
@@ -1222,7 +1366,7 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1222 | { | 1366 | { |
1223 | if ((NULL != addr) && (addrlen > 0)) | 1367 | if ((NULL != addr) && (addrlen > 0)) |
1224 | { | 1368 | { |
1225 | asc (asc_cls, (const char *) addr); | 1369 | asc (asc_cls, unix_address_to_string (NULL, addr, addrlen)); |
1226 | } | 1370 | } |
1227 | else | 1371 | else |
1228 | { | 1372 | { |
@@ -1249,47 +1393,70 @@ static int | |||
1249 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 1393 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, |
1250 | void **buf, size_t *added) | 1394 | void **buf, size_t *added) |
1251 | { | 1395 | { |
1252 | if ((NULL == addr) || (0 == addrlen)) | 1396 | struct UnixAddress *ua; |
1397 | char *address; | ||
1398 | char *plugin; | ||
1399 | char *optionstr; | ||
1400 | uint32_t options; | ||
1401 | size_t ua_size; | ||
1402 | |||
1403 | /* Format unix.options.address */ | ||
1404 | address = NULL; | ||
1405 | plugin = NULL; | ||
1406 | optionstr = NULL; | ||
1407 | options = 0; | ||
1408 | if ((NULL == addr) || (addrlen == 0)) | ||
1253 | { | 1409 | { |
1254 | GNUNET_break (0); | 1410 | GNUNET_break (0); |
1255 | return GNUNET_SYSERR; | 1411 | return GNUNET_SYSERR; |
1256 | } | 1412 | } |
1257 | |||
1258 | if ('\0' != addr[addrlen - 1]) | 1413 | if ('\0' != addr[addrlen - 1]) |
1259 | { | 1414 | { |
1260 | GNUNET_break (0); | 1415 | GNUNET_break (0); |
1261 | return GNUNET_SYSERR; | 1416 | return GNUNET_SYSERR; |
1262 | } | 1417 | } |
1263 | |||
1264 | if (strlen (addr) != addrlen - 1) | 1418 | if (strlen (addr) != addrlen - 1) |
1265 | { | 1419 | { |
1266 | GNUNET_break (0); | 1420 | GNUNET_break (0); |
1267 | return GNUNET_SYSERR; | 1421 | return GNUNET_SYSERR; |
1268 | } | 1422 | } |
1423 | plugin = GNUNET_strdup (addr); | ||
1424 | optionstr = strchr (plugin, '.'); | ||
1425 | if (NULL == optionstr) | ||
1426 | { | ||
1427 | GNUNET_break (0); | ||
1428 | GNUNET_free (plugin); | ||
1429 | return GNUNET_SYSERR; | ||
1430 | } | ||
1431 | optionstr[0] = '\0'; | ||
1432 | optionstr ++; | ||
1433 | options = atol (optionstr); | ||
1434 | address = strchr (optionstr, '.'); | ||
1435 | if (NULL == address) | ||
1436 | { | ||
1437 | GNUNET_break (0); | ||
1438 | GNUNET_free (plugin); | ||
1439 | return GNUNET_SYSERR; | ||
1440 | } | ||
1441 | address[0] = '\0'; | ||
1442 | address ++; | ||
1443 | if (0 != strcmp(plugin, PLUGIN_NAME)) | ||
1444 | { | ||
1445 | GNUNET_break (0); | ||
1446 | GNUNET_free (plugin); | ||
1447 | return GNUNET_SYSERR; | ||
1448 | } | ||
1269 | 1449 | ||
1270 | (*buf) = strdup (addr); | 1450 | ua_size = sizeof (struct UnixAddress) + strlen (address) + 1; |
1271 | (*added) = strlen (addr) + 1; | 1451 | ua = GNUNET_malloc (ua_size); |
1272 | return GNUNET_OK; | 1452 | ua->options = htonl (options); |
1273 | } | 1453 | ua->addrlen = htonl (strlen (address) + 1); |
1274 | 1454 | memcpy (&ua[1], address, strlen (address) + 1); | |
1455 | GNUNET_free (plugin); | ||
1275 | 1456 | ||
1276 | /** | 1457 | (*buf) = ua; |
1277 | * Function called for a quick conversion of the binary address to | 1458 | (*added) = ua_size; |
1278 | * a numeric address. Note that the caller must not free the | 1459 | return GNUNET_OK; |
1279 | * address and that the next call to this function is allowed | ||
1280 | * to override the address again. | ||
1281 | * | ||
1282 | * @param cls closure | ||
1283 | * @param addr binary address | ||
1284 | * @param addrlen length of the address | ||
1285 | * @return string representing the same address | ||
1286 | */ | ||
1287 | static const char * | ||
1288 | unix_address_to_string (void *cls, const void *addr, size_t addrlen) | ||
1289 | { | ||
1290 | if ((addr != NULL) && (addrlen > 0)) | ||
1291 | return (const char *) addr; | ||
1292 | return NULL; | ||
1293 | } | 1460 | } |
1294 | 1461 | ||
1295 | 1462 | ||
@@ -1304,12 +1471,19 @@ address_notification (void *cls, | |||
1304 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1471 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1305 | { | 1472 | { |
1306 | struct Plugin *plugin = cls; | 1473 | struct Plugin *plugin = cls; |
1474 | size_t len; | ||
1475 | struct UnixAddress *ua; | ||
1476 | |||
1477 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | ||
1478 | ua = GNUNET_malloc (len); | ||
1479 | ua->options = htonl (myoptions); | ||
1480 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | ||
1481 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | ||
1307 | 1482 | ||
1308 | plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; | 1483 | plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; |
1309 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 1484 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, |
1310 | plugin->unix_socket_path, | 1485 | ua, len, "unix"); |
1311 | strlen (plugin->unix_socket_path) + 1, | 1486 | GNUNET_free (ua); |
1312 | "unix"); | ||
1313 | } | 1487 | } |
1314 | 1488 | ||
1315 | 1489 | ||
@@ -1411,6 +1585,9 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1411 | "/tmp/unix-plugin-sock.%d", | 1585 | "/tmp/unix-plugin-sock.%d", |
1412 | plugin->port); | 1586 | plugin->port); |
1413 | 1587 | ||
1588 | /* Initialize my flags */ | ||
1589 | myoptions = 0; | ||
1590 | |||
1414 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1591 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
1415 | api->cls = plugin; | 1592 | api->cls = plugin; |
1416 | 1593 | ||
@@ -1443,16 +1620,24 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1443 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1620 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1444 | struct Plugin *plugin = api->cls; | 1621 | struct Plugin *plugin = api->cls; |
1445 | struct UNIXMessageWrapper * msgw; | 1622 | struct UNIXMessageWrapper * msgw; |
1623 | struct UnixAddress *ua; | ||
1624 | size_t len; | ||
1446 | 1625 | ||
1447 | if (NULL == plugin) | 1626 | if (NULL == plugin) |
1448 | { | 1627 | { |
1449 | GNUNET_free (api); | 1628 | GNUNET_free (api); |
1450 | return NULL; | 1629 | return NULL; |
1451 | } | 1630 | } |
1631 | |||
1632 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | ||
1633 | ua = GNUNET_malloc (len); | ||
1634 | ua->options = htonl (myoptions); | ||
1635 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | ||
1636 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | ||
1637 | |||
1452 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1638 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, |
1453 | plugin->unix_socket_path, | 1639 | ua, len, "unix"); |
1454 | strlen (plugin->unix_socket_path) + 1, | 1640 | GNUNET_free (ua); |
1455 | "unix"); | ||
1456 | while (NULL != (msgw = plugin->msg_head)) | 1641 | while (NULL != (msgw = plugin->msg_head)) |
1457 | { | 1642 | { |
1458 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 1643 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |