diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-11-08 14:40:01 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-11-08 14:40:01 +0100 |
commit | 6dc4bacb0197e96d5d9c6e5f881a104ab054a1f0 (patch) | |
tree | 9050589ac3ba2731f3d8dd1d8456b2e78794aeef /src/transport | |
parent | 304bfc5d18d5613a38b5d927925dbfa00adfc82a (diff) | |
download | gnunet-6dc4bacb0197e96d5d9c6e5f881a104ab054a1f0.tar.gz gnunet-6dc4bacb0197e96d5d9c6e5f881a104ab054a1f0.zip |
send NEW_COMMUNICATOR message on startup
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 30 | ||||
-rw-r--r-- | src/transport/transport.h | 16 | ||||
-rw-r--r-- | src/transport/transport_api2_communication.c | 34 |
3 files changed, 61 insertions, 19 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 2879b1738..cd3ae5dce 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -41,9 +41,14 @@ | |||
41 | #define DEFAULT_MAX_QUEUE_LENGTH 8 | 41 | #define DEFAULT_MAX_QUEUE_LENGTH 8 |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Name of the communicator. | 44 | * Address prefix used by the communicator. |
45 | */ | 45 | */ |
46 | #define COMMUNICATOR_NAME "unix" | 46 | #define COMMUNICATOR_ADDRESS_PREFIX "unix" |
47 | |||
48 | /** | ||
49 | * Configuration section used by the communicator. | ||
50 | */ | ||
51 | #define COMMUNICATOR_CONFIG_SECTION "communicator-unix" | ||
47 | 52 | ||
48 | 53 | ||
49 | GNUNET_NETWORK_STRUCT_BEGIN | 54 | GNUNET_NETWORK_STRUCT_BEGIN |
@@ -656,12 +661,12 @@ setup_queue (const struct GNUNET_PeerIdentity *target, | |||
656 | if ('\0' == un->sun_path[0]) | 661 | if ('\0' == un->sun_path[0]) |
657 | GNUNET_asprintf (&foreign_addr, | 662 | GNUNET_asprintf (&foreign_addr, |
658 | "%s-@%s", | 663 | "%s-@%s", |
659 | COMMUNICATOR_NAME, | 664 | COMMUNICATOR_ADDRESS_PREFIX, |
660 | &un->sun_path[1]); | 665 | &un->sun_path[1]); |
661 | else | 666 | else |
662 | GNUNET_asprintf (&foreign_addr, | 667 | GNUNET_asprintf (&foreign_addr, |
663 | "%s-%s", | 668 | "%s-%s", |
664 | COMMUNICATOR_NAME, | 669 | COMMUNICATOR_ADDRESS_PREFIX, |
665 | un->sun_path); | 670 | un->sun_path); |
666 | queue->qh | 671 | queue->qh |
667 | = GNUNET_TRANSPORT_communicator_mq_add (ch, | 672 | = GNUNET_TRANSPORT_communicator_mq_add (ch, |
@@ -855,13 +860,13 @@ mq_init (void *cls, | |||
855 | socklen_t un_len; | 860 | socklen_t un_len; |
856 | 861 | ||
857 | if (0 != strncmp (address, | 862 | if (0 != strncmp (address, |
858 | COMMUNICATOR_NAME "-", | 863 | COMMUNICATOR_ADDRESS_PREFIX "-", |
859 | strlen (COMMUNICATOR_NAME "-"))) | 864 | strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) |
860 | { | 865 | { |
861 | GNUNET_break_op (0); | 866 | GNUNET_break_op (0); |
862 | return GNUNET_SYSERR; | 867 | return GNUNET_SYSERR; |
863 | } | 868 | } |
864 | path = &address[strlen (COMMUNICATOR_NAME "-")]; | 869 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; |
865 | un = unix_address_to_sockaddr (path, | 870 | un = unix_address_to_sockaddr (path, |
866 | &un_len); | 871 | &un_len); |
867 | queue = lookup_queue (peer, | 872 | queue = lookup_queue (peer, |
@@ -983,18 +988,18 @@ run (void *cls, | |||
983 | 988 | ||
984 | if (GNUNET_OK != | 989 | if (GNUNET_OK != |
985 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 990 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
986 | "communicator-unix", | 991 | COMMUNICATOR_CONFIG_SECTION, |
987 | "UNIXPATH", | 992 | "UNIXPATH", |
988 | &unix_socket_path)) | 993 | &unix_socket_path)) |
989 | { | 994 | { |
990 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 995 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
991 | "communicator-unix", | 996 | COMMUNICATOR_CONFIG_SECTION, |
992 | "UNIXPATH"); | 997 | "UNIXPATH"); |
993 | return; | 998 | return; |
994 | } | 999 | } |
995 | if (GNUNET_OK != | 1000 | if (GNUNET_OK != |
996 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1001 | GNUNET_CONFIGURATION_get_value_number (cfg, |
997 | "communicator-unix", | 1002 | COMMUNICATOR_CONFIG_SECTION, |
998 | "MAX_QUEUE_LENGTH", | 1003 | "MAX_QUEUE_LENGTH", |
999 | &max_queue_length)) | 1004 | &max_queue_length)) |
1000 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | 1005 | max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; |
@@ -1062,7 +1067,8 @@ run (void *cls, | |||
1062 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, | 1067 | queue_map = GNUNET_CONTAINER_multipeermap_create (10, |
1063 | GNUNET_NO); | 1068 | GNUNET_NO); |
1064 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | 1069 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, |
1065 | COMMUNICATOR_NAME, | 1070 | COMMUNICATOR_CONFIG_SECTION, |
1071 | COMMUNICATOR_ADDRESS_PREFIX, | ||
1066 | 65535, | 1072 | 65535, |
1067 | &mq_init, | 1073 | &mq_init, |
1068 | NULL); | 1074 | NULL); |
@@ -1075,7 +1081,7 @@ run (void *cls, | |||
1075 | } | 1081 | } |
1076 | GNUNET_asprintf (&my_addr, | 1082 | GNUNET_asprintf (&my_addr, |
1077 | "%s-%s", | 1083 | "%s-%s", |
1078 | COMMUNICATOR_NAME, | 1084 | COMMUNICATOR_ADDRESS_PREFIX, |
1079 | unix_socket_path); | 1085 | unix_socket_path); |
1080 | ai = GNUNET_TRANSPORT_communicator_address_add (ch, | 1086 | ai = GNUNET_TRANSPORT_communicator_address_add (ch, |
1081 | my_addr, | 1087 | my_addr, |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 5662d6c4d..f21863aef 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -654,6 +654,22 @@ struct TransportPluginMonitorMessage | |||
654 | /* *********************** TNG messages ***************** */ | 654 | /* *********************** TNG messages ***************** */ |
655 | 655 | ||
656 | /** | 656 | /** |
657 | * Communicator goes online. Note which addresses it can | ||
658 | * work with. | ||
659 | */ | ||
660 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage | ||
661 | { | ||
662 | |||
663 | /** | ||
664 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR. | ||
665 | */ | ||
666 | struct GNUNET_MessageHeader header; | ||
667 | |||
668 | /* Followed by the address prefix of the communicator */ | ||
669 | }; | ||
670 | |||
671 | |||
672 | /** | ||
657 | * Add address to the list. | 673 | * Add address to the list. |
658 | */ | 674 | */ |
659 | struct GNUNET_TRANSPORT_AddAddressMessage | 675 | struct GNUNET_TRANSPORT_AddAddressMessage |
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index 434138e19..3a68c6eba 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c | |||
@@ -157,9 +157,14 @@ struct GNUNET_TRANSPORT_CommunicatorHandle | |||
157 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 157 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
158 | 158 | ||
159 | /** | 159 | /** |
160 | * Name of the communicator. | 160 | * Config section to use. |
161 | */ | 161 | */ |
162 | const char *name; | 162 | const char *config_section; |
163 | |||
164 | /** | ||
165 | * Address prefix to use. | ||
166 | */ | ||
167 | const char *addr_prefix; | ||
163 | 168 | ||
164 | /** | 169 | /** |
165 | * Function to call when the transport service wants us to initiate | 170 | * Function to call when the transport service wants us to initiate |
@@ -723,13 +728,24 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) | |||
723 | ch), | 728 | ch), |
724 | GNUNET_MQ_handler_end() | 729 | GNUNET_MQ_handler_end() |
725 | }; | 730 | }; |
731 | struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; | ||
732 | struct GNUNET_MQ_Envelope *env; | ||
726 | 733 | ||
727 | ch->mq = GNUNET_CLIENT_connect (ch->cfg, | 734 | ch->mq = GNUNET_CLIENT_connect (ch->cfg, |
728 | "transport", | 735 | "transport", |
729 | handlers, | 736 | handlers, |
730 | &error_handler, | 737 | &error_handler, |
731 | ch); | 738 | ch); |
732 | // FIXME: must notify transport that we are responsible for 'ch->name' addresses!!! | 739 | if (NULL == ch->mq) |
740 | return; | ||
741 | env = GNUNET_MQ_msg_extra (cam, | ||
742 | strlen (ch->addr_prefix) + 1, | ||
743 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); | ||
744 | memcpy (&cam[1], | ||
745 | ch->addr_prefix, | ||
746 | strlen (ch->addr_prefix) + 1); | ||
747 | GNUNET_MQ_send (ch->mq, | ||
748 | env); | ||
733 | for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; | 749 | for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; |
734 | NULL != ai; | 750 | NULL != ai; |
735 | ai = ai->next) | 751 | ai = ai->next) |
@@ -745,7 +761,9 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) | |||
745 | * Connect to the transport service. | 761 | * Connect to the transport service. |
746 | * | 762 | * |
747 | * @param cfg configuration to use | 763 | * @param cfg configuration to use |
748 | * @param name name of the communicator that is connecting | 764 | * @param config_section section of the configuration to use for options |
765 | * @param addr_prefix address prefix for addresses supported by this | ||
766 | * communicator, could be NULL for incoming-only communicators | ||
749 | * @param mtu maximum message size supported by communicator, 0 if | 767 | * @param mtu maximum message size supported by communicator, 0 if |
750 | * sending is not supported, SIZE_MAX for no MTU | 768 | * sending is not supported, SIZE_MAX for no MTU |
751 | * @param mq_init function to call to initialize a message queue given | 769 | * @param mq_init function to call to initialize a message queue given |
@@ -756,7 +774,8 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) | |||
756 | */ | 774 | */ |
757 | struct GNUNET_TRANSPORT_CommunicatorHandle * | 775 | struct GNUNET_TRANSPORT_CommunicatorHandle * |
758 | GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 776 | GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
759 | const char *name, | 777 | const char *config_section, |
778 | const char *addr_prefix, | ||
760 | size_t mtu, | 779 | size_t mtu, |
761 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, | 780 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, |
762 | void *mq_init_cls) | 781 | void *mq_init_cls) |
@@ -765,14 +784,15 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle | |||
765 | 784 | ||
766 | ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle); | 785 | ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle); |
767 | ch->cfg = cfg; | 786 | ch->cfg = cfg; |
768 | ch->name = name; | 787 | ch->config_section = config_section; |
788 | ch->addr_prefix = addr_prefix; | ||
769 | ch->mtu = mtu; | 789 | ch->mtu = mtu; |
770 | ch->mq_init = mq_init; | 790 | ch->mq_init = mq_init; |
771 | ch->mq_init_cls = mq_init_cls; | 791 | ch->mq_init_cls = mq_init_cls; |
772 | reconnect (ch); | 792 | reconnect (ch); |
773 | if (GNUNET_OK != | 793 | if (GNUNET_OK != |
774 | GNUNET_CONFIGURATION_get_value_number (cfg, | 794 | GNUNET_CONFIGURATION_get_value_number (cfg, |
775 | name, | 795 | config_section, |
776 | "MAX_QUEUE_LENGTH", | 796 | "MAX_QUEUE_LENGTH", |
777 | &ch->max_queue_length)) | 797 | &ch->max_queue_length)) |
778 | ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; | 798 | ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; |