diff options
author | t3sserakt <t3ss@posteo.de> | 2021-11-19 15:18:32 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-11-19 15:29:43 +0100 |
commit | 7e5fdf07515b4a921de564adc67b2808e6ad28e2 (patch) | |
tree | 6bc8cfcdf54016b3f904c91f186c5654dd20738e /src | |
parent | 6a043a9228022fcce97fd50739db74abdabde055 (diff) | |
parent | cdd9c0cb797aa349eb3147d0db3fd1224df10c04 (diff) | |
download | gnunet-7e5fdf07515b4a921de564adc67b2808e6ad28e2.tar.gz gnunet-7e5fdf07515b4a921de564adc67b2808e6ad28e2.zip |
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r-- | src/curl/curl.c | 118 | ||||
-rw-r--r-- | src/identity/identity_api.c | 6 | ||||
-rw-r--r-- | src/include/gnu_name_system_record_types.h | 10 | ||||
-rw-r--r-- | src/include/gnunet_messenger_service.h | 21 | ||||
-rw-r--r-- | src/include/gnunet_network_lib.h | 16 | ||||
-rw-r--r-- | src/messenger/Makefile.am | 13 | ||||
-rw-r--r-- | src/messenger/gnunet-service-messenger.c | 8 | ||||
-rw-r--r-- | src/messenger/gnunet-service-messenger_tunnel.c | 8 | ||||
-rw-r--r-- | src/messenger/messenger.conf.in | 1 | ||||
-rw-r--r-- | src/messenger/messenger_api.c | 7 | ||||
-rw-r--r-- | src/messenger/messenger_api_message.c | 8 | ||||
-rw-r--r-- | src/messenger/messenger_api_message.h | 8 | ||||
-rw-r--r-- | src/messenger/plugin_gnsrecord_messenger.c | 243 | ||||
-rw-r--r-- | src/pq/pq_event.c | 20 | ||||
-rw-r--r-- | src/util/network.c | 61 |
15 files changed, 426 insertions, 122 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c index 71672c780..30c2f8c01 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -368,7 +368,8 @@ download_cb (char *bufptr, | |||
368 | db->eno = ENOMEM; | 368 | db->eno = ENOMEM; |
369 | return 0; /* signals an error to curl */ | 369 | return 0; /* signals an error to curl */ |
370 | } | 370 | } |
371 | db->buf = GNUNET_realloc (db->buf, db->buf_size + msize); | 371 | db->buf = GNUNET_realloc (db->buf, |
372 | db->buf_size + msize); | ||
372 | buf = db->buf + db->buf_size; | 373 | buf = db->buf + db->buf_size; |
373 | GNUNET_memcpy (buf, bufptr, msize); | 374 | GNUNET_memcpy (buf, bufptr, msize); |
374 | db->buf_size += msize; | 375 | db->buf_size += msize; |
@@ -421,7 +422,8 @@ setup_job_headers (struct GNUNET_CURL_Context *ctx, | |||
421 | &scope.scope_id, | 422 | &scope.scope_id, |
422 | sizeof(struct GNUNET_AsyncScopeId)); | 423 | sizeof(struct GNUNET_AsyncScopeId)); |
423 | GNUNET_assert (NULL != aid_header); | 424 | GNUNET_assert (NULL != aid_header); |
424 | GNUNET_assert (NULL != curl_slist_append (all_headers, aid_header)); | 425 | GNUNET_assert (NULL != curl_slist_append (all_headers, |
426 | aid_header)); | ||
425 | GNUNET_free (aid_header); | 427 | GNUNET_free (aid_header); |
426 | } | 428 | } |
427 | } | 429 | } |
@@ -455,12 +457,25 @@ setup_job (CURL *eh, | |||
455 | job = GNUNET_new (struct GNUNET_CURL_Job); | 457 | job = GNUNET_new (struct GNUNET_CURL_Job); |
456 | job->job_headers = all_headers; | 458 | job->job_headers = all_headers; |
457 | 459 | ||
458 | if ((CURLE_OK != curl_easy_setopt (eh, CURLOPT_PRIVATE, job)) || | 460 | if ( (CURLE_OK != |
459 | (CURLE_OK != | 461 | curl_easy_setopt (eh, |
460 | curl_easy_setopt (eh, CURLOPT_WRITEFUNCTION, &download_cb)) || | 462 | CURLOPT_PRIVATE, |
461 | (CURLE_OK != curl_easy_setopt (eh, CURLOPT_WRITEDATA, &job->db)) || | 463 | job)) || |
462 | (CURLE_OK != curl_easy_setopt (eh, CURLOPT_SHARE, ctx->share)) || | 464 | (CURLE_OK != |
463 | (CURLM_OK != curl_multi_add_handle (ctx->multi, eh))) | 465 | curl_easy_setopt (eh, |
466 | CURLOPT_WRITEFUNCTION, | ||
467 | &download_cb)) || | ||
468 | (CURLE_OK != | ||
469 | curl_easy_setopt (eh, | ||
470 | CURLOPT_WRITEDATA, | ||
471 | &job->db)) || | ||
472 | (CURLE_OK != | ||
473 | curl_easy_setopt (eh, | ||
474 | CURLOPT_SHARE, | ||
475 | ctx->share)) || | ||
476 | (CURLM_OK != | ||
477 | curl_multi_add_handle (ctx->multi, | ||
478 | eh)) ) | ||
464 | { | 479 | { |
465 | GNUNET_break (0); | 480 | GNUNET_break (0); |
466 | GNUNET_free (job); | 481 | GNUNET_free (job); |
@@ -683,9 +698,12 @@ GNUNET_CURL_job_cancel (struct GNUNET_CURL_Job *job) | |||
683 | { | 698 | { |
684 | struct GNUNET_CURL_Context *ctx = job->ctx; | 699 | struct GNUNET_CURL_Context *ctx = job->ctx; |
685 | 700 | ||
686 | GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, ctx->jobs_tail, job); | 701 | GNUNET_CONTAINER_DLL_remove (ctx->jobs_head, |
702 | ctx->jobs_tail, | ||
703 | job); | ||
687 | GNUNET_break (CURLM_OK == | 704 | GNUNET_break (CURLM_OK == |
688 | curl_multi_remove_handle (ctx->multi, job->easy_handle)); | 705 | curl_multi_remove_handle (ctx->multi, |
706 | job->easy_handle)); | ||
689 | curl_easy_cleanup (job->easy_handle); | 707 | curl_easy_cleanup (job->easy_handle); |
690 | GNUNET_free (job->db.buf); | 708 | GNUNET_free (job->db.buf); |
691 | curl_slist_free_all (job->job_headers); | 709 | curl_slist_free_all (job->job_headers); |
@@ -831,7 +849,8 @@ enum GNUNET_GenericReturnValue | |||
831 | GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, | 849 | GNUNET_CURL_append_header (struct GNUNET_CURL_Context *ctx, |
832 | const char *header) | 850 | const char *header) |
833 | { | 851 | { |
834 | ctx->common_headers = curl_slist_append (ctx->common_headers, header); | 852 | ctx->common_headers = curl_slist_append (ctx->common_headers, |
853 | header); | ||
835 | if (NULL == ctx->common_headers) | 854 | if (NULL == ctx->common_headers) |
836 | return GNUNET_SYSERR; | 855 | return GNUNET_SYSERR; |
837 | 856 | ||
@@ -854,40 +873,46 @@ do_benchmark (CURLMsg *cmsg) | |||
854 | uint64_t bytes_sent = 0; | 873 | uint64_t bytes_sent = 0; |
855 | uint64_t bytes_received = 0; | 874 | uint64_t bytes_received = 0; |
856 | 875 | ||
857 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 876 | GNUNET_break (CURLE_OK == |
858 | CURLINFO_TOTAL_TIME, | 877 | curl_easy_getinfo (cmsg->easy_handle, |
859 | &total_as_double)); | 878 | CURLINFO_TOTAL_TIME, |
879 | &total_as_double)); | ||
860 | total.rel_value_us = total_as_double * 1000 * 1000; | 880 | total.rel_value_us = total_as_double * 1000 * 1000; |
861 | 881 | ||
862 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 882 | GNUNET_break (CURLE_OK == |
863 | CURLINFO_EFFECTIVE_URL, | 883 | curl_easy_getinfo (cmsg->easy_handle, |
864 | &url)); | 884 | CURLINFO_EFFECTIVE_URL, |
885 | &url)); | ||
865 | 886 | ||
866 | /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total | 887 | /* HEADER_SIZE + SIZE_DOWNLOAD_T is hopefully the total |
867 | number of bytes received, not clear from curl docs. */ | 888 | number of bytes received, not clear from curl docs. */ |
868 | 889 | ||
869 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 890 | GNUNET_break (CURLE_OK == |
870 | CURLINFO_HEADER_SIZE, | 891 | curl_easy_getinfo (cmsg->easy_handle, |
871 | &size_long)); | 892 | CURLINFO_HEADER_SIZE, |
893 | &size_long)); | ||
872 | bytes_received += size_long; | 894 | bytes_received += size_long; |
873 | 895 | ||
874 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 896 | GNUNET_break (CURLE_OK == |
875 | CURLINFO_SIZE_DOWNLOAD_T, | 897 | curl_easy_getinfo (cmsg->easy_handle, |
876 | &size_curl)); | 898 | CURLINFO_SIZE_DOWNLOAD_T, |
899 | &size_curl)); | ||
877 | bytes_received += size_curl; | 900 | bytes_received += size_curl; |
878 | 901 | ||
879 | /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes | 902 | /* REQUEST_SIZE + SIZE_UPLOAD_T is hopefully the total number of bytes |
880 | sent, again docs are not completely clear. */ | 903 | sent, again docs are not completely clear. */ |
881 | 904 | ||
882 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 905 | GNUNET_break (CURLE_OK == |
883 | CURLINFO_REQUEST_SIZE, | 906 | curl_easy_getinfo (cmsg->easy_handle, |
884 | &size_long)); | 907 | CURLINFO_REQUEST_SIZE, |
908 | &size_long)); | ||
885 | bytes_sent += size_long; | 909 | bytes_sent += size_long; |
886 | 910 | ||
887 | /* We obtain this value to check an invariant, but never use it otherwise. */ | 911 | /* We obtain this value to check an invariant, but never use it otherwise. */ |
888 | GNUNET_break (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 912 | GNUNET_break (CURLE_OK == |
889 | CURLINFO_SIZE_UPLOAD_T, | 913 | curl_easy_getinfo (cmsg->easy_handle, |
890 | &size_curl)); | 914 | CURLINFO_SIZE_UPLOAD_T, |
915 | &size_curl)); | ||
891 | 916 | ||
892 | /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should | 917 | /* CURLINFO_SIZE_UPLOAD_T <= CURLINFO_REQUEST_SIZE should |
893 | be an invariant. | 918 | be an invariant. |
@@ -900,8 +925,10 @@ do_benchmark (CURLMsg *cmsg) | |||
900 | 925 | ||
901 | urd = get_url_benchmark_data (url, (unsigned int) response_code); | 926 | urd = get_url_benchmark_data (url, (unsigned int) response_code); |
902 | urd->count++; | 927 | urd->count++; |
903 | urd->time = GNUNET_TIME_relative_add (urd->time, total); | 928 | urd->time = GNUNET_TIME_relative_add (urd->time, |
904 | urd->time_max = GNUNET_TIME_relative_max (total, urd->time_max); | 929 | total); |
930 | urd->time_max = GNUNET_TIME_relative_max (total, | ||
931 | urd->time_max); | ||
905 | urd->bytes_sent += bytes_sent; | 932 | urd->bytes_sent += bytes_sent; |
906 | urd->bytes_received += bytes_received; | 933 | urd->bytes_received += bytes_received; |
907 | } | 934 | } |
@@ -929,7 +956,8 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, | |||
929 | 956 | ||
930 | (void) curl_multi_perform (ctx->multi, | 957 | (void) curl_multi_perform (ctx->multi, |
931 | &n_running); | 958 | &n_running); |
932 | while (NULL != (cmsg = curl_multi_info_read (ctx->multi, &n_completed))) | 959 | while (NULL != (cmsg = curl_multi_info_read (ctx->multi, |
960 | &n_completed))) | ||
933 | { | 961 | { |
934 | struct GNUNET_CURL_Job *job; | 962 | struct GNUNET_CURL_Job *job; |
935 | long response_code; | 963 | long response_code; |
@@ -937,9 +965,10 @@ GNUNET_CURL_perform2 (struct GNUNET_CURL_Context *ctx, | |||
937 | 965 | ||
938 | /* Only documented return value is CURLMSG_DONE */ | 966 | /* Only documented return value is CURLMSG_DONE */ |
939 | GNUNET_break (CURLMSG_DONE == cmsg->msg); | 967 | GNUNET_break (CURLMSG_DONE == cmsg->msg); |
940 | GNUNET_assert (CURLE_OK == curl_easy_getinfo (cmsg->easy_handle, | 968 | GNUNET_assert (CURLE_OK == |
941 | CURLINFO_PRIVATE, | 969 | curl_easy_getinfo (cmsg->easy_handle, |
942 | (char **) &job)); | 970 | CURLINFO_PRIVATE, |
971 | (char **) &job)); | ||
943 | GNUNET_assert (job->ctx == ctx); | 972 | GNUNET_assert (job->ctx == ctx); |
944 | response_code = 0; | 973 | response_code = 0; |
945 | if (NULL != job->jcc_raw) | 974 | if (NULL != job->jcc_raw) |
@@ -1027,14 +1056,17 @@ GNUNET_CURL_get_select_info (struct GNUNET_CURL_Context *ctx, | |||
1027 | int m; | 1056 | int m; |
1028 | 1057 | ||
1029 | m = -1; | 1058 | m = -1; |
1030 | GNUNET_assert (CURLM_OK == curl_multi_fdset (ctx->multi, | 1059 | GNUNET_assert (CURLM_OK == |
1031 | read_fd_set, | 1060 | curl_multi_fdset (ctx->multi, |
1032 | write_fd_set, | 1061 | read_fd_set, |
1033 | except_fd_set, | 1062 | write_fd_set, |
1034 | &m)); | 1063 | except_fd_set, |
1064 | &m)); | ||
1035 | to = *timeout; | 1065 | to = *timeout; |
1036 | *max_fd = GNUNET_MAX (m, *max_fd); | 1066 | *max_fd = GNUNET_MAX (m, *max_fd); |
1037 | GNUNET_assert (CURLM_OK == curl_multi_timeout (ctx->multi, &to)); | 1067 | GNUNET_assert (CURLM_OK == |
1068 | curl_multi_timeout (ctx->multi, | ||
1069 | &to)); | ||
1038 | 1070 | ||
1039 | /* Only if what we got back from curl is smaller than what we | 1071 | /* Only if what we got back from curl is smaller than what we |
1040 | already had (-1 == infinity!), then update timeout */ | 1072 | already had (-1 == infinity!), then update timeout */ |
@@ -1079,7 +1111,9 @@ GNUNET_CURL_constructor__ (void) | |||
1079 | 1111 | ||
1080 | if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT))) | 1112 | if (CURLE_OK != (ret = curl_global_init (CURL_GLOBAL_DEFAULT))) |
1081 | { | 1113 | { |
1082 | CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, "curl_global_init", ret); | 1114 | CURL_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
1115 | "curl_global_init", | ||
1116 | ret); | ||
1083 | curl_fail = 1; | 1117 | curl_fail = 1; |
1084 | } | 1118 | } |
1085 | } | 1119 | } |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 22371f91a..08a975e65 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2013, 2016, 2021 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -1020,7 +1020,9 @@ GNUNET_IDENTITY_write_key_to_buffer (const struct | |||
1020 | return -1; | 1020 | return -1; |
1021 | if (length < 0) | 1021 | if (length < 0) |
1022 | return -2; | 1022 | return -2; |
1023 | GNUNET_memcpy (buffer, key, length); | 1023 | GNUNET_memcpy (buffer, &(key->type), sizeof (key->type)); |
1024 | GNUNET_memcpy (buffer + sizeof (key->type), &(key->ecdsa_key), length | ||
1025 | - sizeof (key->type)); | ||
1024 | return length; | 1026 | return length; |
1025 | } | 1027 | } |
1026 | 1028 | ||
diff --git a/src/include/gnu_name_system_record_types.h b/src/include/gnu_name_system_record_types.h index b2cf45dc8..22b2c472e 100644 --- a/src/include/gnu_name_system_record_types.h +++ b/src/include/gnu_name_system_record_types.h | |||
@@ -127,6 +127,16 @@ extern "C" { | |||
127 | */ | 127 | */ |
128 | #define GNUNET_GNSRECORD_TYPE_EDKEY 65556 | 128 | #define GNUNET_GNSRECORD_TYPE_EDKEY 65556 |
129 | 129 | ||
130 | /** | ||
131 | * Encoding for Robust Immutable Storage (ERIS) binary read capability | ||
132 | */ | ||
133 | #define GNUNET_GNSRECORD_TYPE_ERIS_READ_CAPABILITY 65557 | ||
134 | |||
135 | /** | ||
136 | * Record type to share an entry of a messenger room | ||
137 | */ | ||
138 | #define GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY 65558 | ||
139 | |||
130 | 140 | ||
131 | #if 0 /* keep Emacsens' auto-indent happy */ | 141 | #if 0 /* keep Emacsens' auto-indent happy */ |
132 | { | 142 | { |
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index b54567aa7..96d48b411 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -75,6 +75,27 @@ struct GNUNET_MESSENGER_Room; | |||
75 | */ | 75 | */ |
76 | struct GNUNET_MESSENGER_Contact; | 76 | struct GNUNET_MESSENGER_Contact; |
77 | 77 | ||
78 | GNUNET_NETWORK_STRUCT_BEGIN | ||
79 | |||
80 | /** | ||
81 | * A room entry record specifies which peer is hosting a given room and | ||
82 | * may also specify the key to enter it. | ||
83 | */ | ||
84 | struct GNUNET_MESSENGER_RoomEntryRecord | ||
85 | { | ||
86 | /** | ||
87 | * The peer identity of an open door to a room. | ||
88 | */ | ||
89 | struct GNUNET_PeerIdentity door; | ||
90 | |||
91 | /** | ||
92 | * The hash identifying the port of the room. | ||
93 | */ | ||
94 | struct GNUNET_HashCode key; | ||
95 | }; | ||
96 | |||
97 | GNUNET_NETWORK_STRUCT_END | ||
98 | |||
78 | /** | 99 | /** |
79 | * Enum for the different supported kinds of messages | 100 | * Enum for the different supported kinds of messages |
80 | */ | 101 | */ |
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 97ab64add..ff1e853f5 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -78,7 +78,7 @@ struct GNUNET_NETWORK_FDSet | |||
78 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) | 78 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) |
79 | * @return #GNUNET_OK if the PF is supported | 79 | * @return #GNUNET_OK if the PF is supported |
80 | */ | 80 | */ |
81 | int | 81 | enum GNUNET_GenericReturnValue |
82 | GNUNET_NETWORK_test_pf (int pf); | 82 | GNUNET_NETWORK_test_pf (int pf); |
83 | 83 | ||
84 | 84 | ||
@@ -154,7 +154,7 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | |||
154 | * @param address_len length of @a address | 154 | * @param address_len length of @a address |
155 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 155 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
156 | */ | 156 | */ |
157 | int | 157 | enum GNUNET_GenericReturnValue |
158 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 158 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
159 | const struct sockaddr *address, | 159 | const struct sockaddr *address, |
160 | socklen_t address_len); | 160 | socklen_t address_len); |
@@ -165,7 +165,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
165 | * @param desc socket to close | 165 | * @param desc socket to close |
166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 166 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
167 | */ | 167 | */ |
168 | int | 168 | enum GNUNET_GenericReturnValue |
169 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); | 169 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); |
170 | 170 | ||
171 | 171 | ||
@@ -186,7 +186,7 @@ GNUNET_NETWORK_socket_free_memory_only_ (struct GNUNET_NETWORK_Handle *desc); | |||
186 | * @param address_len of @a address | 186 | * @param address_len of @a address |
187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 187 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
188 | */ | 188 | */ |
189 | int | 189 | enum GNUNET_GenericReturnValue |
190 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | 190 | GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, |
191 | const struct sockaddr *address, | 191 | const struct sockaddr *address, |
192 | socklen_t address_len); | 192 | socklen_t address_len); |
@@ -202,7 +202,7 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
202 | * @param optlen length of optval | 202 | * @param optlen length of optval |
203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
204 | */ | 204 | */ |
205 | int | 205 | enum GNUNET_GenericReturnValue |
206 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | 206 | GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, |
207 | int level, | 207 | int level, |
208 | int optname, | 208 | int optname, |
@@ -217,7 +217,7 @@ GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, | |||
217 | * @param backlog length of the listen queue | 217 | * @param backlog length of the listen queue |
218 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 218 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
219 | */ | 219 | */ |
220 | int | 220 | enum GNUNET_GenericReturnValue |
221 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, | 221 | GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, |
222 | int backlog); | 222 | int backlog); |
223 | 223 | ||
@@ -339,7 +339,7 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, | |||
339 | * @param how type of shutdown | 339 | * @param how type of shutdown |
340 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 340 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
341 | */ | 341 | */ |
342 | int | 342 | enum GNUNET_GenericReturnValue |
343 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | 343 | GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, |
344 | int how); | 344 | int how); |
345 | 345 | ||
@@ -353,7 +353,7 @@ GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, | |||
353 | * @param desc socket | 353 | * @param desc socket |
354 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 354 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
355 | */ | 355 | */ |
356 | int | 356 | enum GNUNET_GenericReturnValue |
357 | GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc); | 357 | GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc); |
358 | 358 | ||
359 | 359 | ||
diff --git a/src/messenger/Makefile.am b/src/messenger/Makefile.am index 3fc532e7e..4be11f3aa 100644 --- a/src/messenger/Makefile.am +++ b/src/messenger/Makefile.am | |||
@@ -10,6 +10,19 @@ pkgcfgdir= $(pkgdatadir)/config.d/ | |||
10 | 10 | ||
11 | libexecdir= $(pkglibdir)/libexec/ | 11 | libexecdir= $(pkglibdir)/libexec/ |
12 | 12 | ||
13 | plugin_LTLIBRARIES = \ | ||
14 | libgnunet_plugin_gnsrecord_messenger.la | ||
15 | |||
16 | |||
17 | libgnunet_plugin_gnsrecord_messenger_la_SOURCES = \ | ||
18 | plugin_gnsrecord_messenger.c | ||
19 | libgnunet_plugin_gnsrecord_messenger_la_LIBADD = \ | ||
20 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
21 | $(LTLIBINTL) | ||
22 | libgnunet_plugin_gnsrecord_messenger_la_LDFLAGS = \ | ||
23 | $(GN_PLUGIN_LDFLAGS) | ||
24 | |||
25 | |||
13 | pkgcfg_DATA = \ | 26 | pkgcfg_DATA = \ |
14 | messenger.conf | 27 | messenger.conf |
15 | 28 | ||
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c index 989157ceb..a994e16ee 100644 --- a/src/messenger/gnunet-service-messenger.c +++ b/src/messenger/gnunet-service-messenger.c | |||
@@ -227,10 +227,10 @@ check_for_message: | |||
227 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, GNUNET_NO, NULL)) | 227 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, GNUNET_NO, NULL)) |
228 | return GNUNET_NO; | 228 | return GNUNET_NO; |
229 | 229 | ||
230 | if (GNUNET_YES != filter_message_sending(&message)) | 230 | const int allowed = filter_message_sending(&message); |
231 | return GNUNET_NO; | ||
232 | 231 | ||
233 | return GNUNET_OK; | 232 | cleanup_message(&message); |
233 | return GNUNET_YES == allowed? GNUNET_OK : GNUNET_NO; | ||
234 | } | 234 | } |
235 | 235 | ||
236 | static void | 236 | static void |
@@ -278,6 +278,8 @@ handle_send_message (void *cls, | |||
278 | GNUNET_MESSENGER_name_of_kind (message.header.kind), GNUNET_h2s (key)); | 278 | GNUNET_MESSENGER_name_of_kind (message.header.kind), GNUNET_h2s (key)); |
279 | 279 | ||
280 | end_handling: | 280 | end_handling: |
281 | cleanup_message(&message); | ||
282 | |||
281 | GNUNET_SERVICE_client_continue (msg_client->client); | 283 | GNUNET_SERVICE_client_continue (msg_client->client); |
282 | } | 284 | } |
283 | 285 | ||
diff --git a/src/messenger/gnunet-service-messenger_tunnel.c b/src/messenger/gnunet-service-messenger_tunnel.c index fdd6429e6..c21f298b3 100644 --- a/src/messenger/gnunet-service-messenger_tunnel.c +++ b/src/messenger/gnunet-service-messenger_tunnel.c | |||
@@ -176,6 +176,9 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
176 | { | 176 | { |
177 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | 177 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; |
178 | 178 | ||
179 | if (!tunnel) | ||
180 | return; | ||
181 | |||
179 | const uint16_t length = ntohs (header->size) - sizeof(*header); | 182 | const uint16_t length = ntohs (header->size) - sizeof(*header); |
180 | const char *buffer = (const char*) &header[1]; | 183 | const char *buffer = (const char*) &header[1]; |
181 | 184 | ||
@@ -190,9 +193,6 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n", | 193 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n", |
191 | GNUNET_MESSENGER_name_of_kind(message.header.kind)); | 194 | GNUNET_MESSENGER_name_of_kind(message.header.kind)); |
192 | 195 | ||
193 | if (!tunnel) | ||
194 | return; | ||
195 | |||
196 | const int new_message = update_room_message ( | 196 | const int new_message = update_room_message ( |
197 | tunnel->room, copy_message (&message), &hash | 197 | tunnel->room, copy_message (&message), &hash |
198 | ); | 198 | ); |
@@ -226,6 +226,8 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
226 | } | 226 | } |
227 | 227 | ||
228 | receive_done: | 228 | receive_done: |
229 | cleanup_message(&message); | ||
230 | |||
229 | GNUNET_CADET_receive_done (tunnel->channel); | 231 | GNUNET_CADET_receive_done (tunnel->channel); |
230 | } | 232 | } |
231 | 233 | ||
diff --git a/src/messenger/messenger.conf.in b/src/messenger/messenger.conf.in index 59e11b166..6b54550ea 100644 --- a/src/messenger/messenger.conf.in +++ b/src/messenger/messenger.conf.in | |||
@@ -1,5 +1,6 @@ | |||
1 | [messenger] | 1 | [messenger] |
2 | START_ON_DEMAND = YES | 2 | START_ON_DEMAND = YES |
3 | RUN_PER_USER = YES | ||
3 | PORT = 2097 | 4 | PORT = 2097 |
4 | HOSTNAME = localhost | 5 | HOSTNAME = localhost |
5 | BINARY = gnunet-service-messenger | 6 | BINARY = gnunet-service-messenger |
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c index ef6244e19..81a02e858 100644 --- a/src/messenger/messenger_api.c +++ b/src/messenger/messenger_api.c | |||
@@ -214,6 +214,7 @@ check_recv_message (void *cls, | |||
214 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL)) | 214 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL)) |
215 | return GNUNET_NO; | 215 | return GNUNET_NO; |
216 | 216 | ||
217 | cleanup_message(&message); | ||
217 | return GNUNET_OK; | 218 | return GNUNET_OK; |
218 | } | 219 | } |
219 | 220 | ||
@@ -254,11 +255,15 @@ handle_recv_message (void *cls, | |||
254 | 255 | ||
255 | handle_room_message (room, contact, &message, hash); | 256 | handle_room_message (room, contact, &message, hash); |
256 | 257 | ||
258 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message(room, hash); | ||
259 | |||
257 | if (handle->msg_callback) | 260 | if (handle->msg_callback) |
258 | handle->msg_callback (handle->msg_cls, room, contact, &message, hash, flags); | 261 | handle->msg_callback (handle->msg_cls, room, contact, stored_message, hash, flags); |
259 | } | 262 | } |
260 | else | 263 | else |
261 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Room not found\n"); | 264 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Room not found\n"); |
265 | |||
266 | cleanup_message(&message); | ||
262 | } | 267 | } |
263 | 268 | ||
264 | static void | 269 | static void |
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index 05bf654fb..4e64cc22f 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c | |||
@@ -126,6 +126,14 @@ destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
126 | } | 126 | } |
127 | 127 | ||
128 | void | 128 | void |
129 | cleanup_message (struct GNUNET_MESSENGER_Message *message) | ||
130 | { | ||
131 | GNUNET_assert(message); | ||
132 | |||
133 | destroy_message_body (message->header.kind, &(message->body)); | ||
134 | } | ||
135 | |||
136 | void | ||
129 | destroy_message (struct GNUNET_MESSENGER_Message *message) | 137 | destroy_message (struct GNUNET_MESSENGER_Message *message) |
130 | { | 138 | { |
131 | GNUNET_assert(message); | 139 | GNUNET_assert(message); |
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h index 6aebf4014..21161c134 100644 --- a/src/messenger/messenger_api_message.h +++ b/src/messenger/messenger_api_message.h | |||
@@ -62,6 +62,14 @@ struct GNUNET_MESSENGER_Message* | |||
62 | copy_message (const struct GNUNET_MESSENGER_Message *message); | 62 | copy_message (const struct GNUNET_MESSENGER_Message *message); |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Frees the messages body memory. | ||
66 | * | ||
67 | * @param[in/out] message Message | ||
68 | */ | ||
69 | void | ||
70 | cleanup_message (struct GNUNET_MESSENGER_Message *message); | ||
71 | |||
72 | /** | ||
65 | * Destroys a message and frees its memory fully. | 73 | * Destroys a message and frees its memory fully. |
66 | * | 74 | * |
67 | * @param[in/out] message Message | 75 | * @param[in/out] message Message |
diff --git a/src/messenger/plugin_gnsrecord_messenger.c b/src/messenger/plugin_gnsrecord_messenger.c new file mode 100644 index 000000000..2219f0bde --- /dev/null +++ b/src/messenger/plugin_gnsrecord_messenger.c | |||
@@ -0,0 +1,243 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/plugin_gnsrecord_messenger.c | ||
23 | * @brief Plugin to provide the API for useful GNS records to improve | ||
24 | * the usability of the messenger service. | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_gnsrecord_lib.h" | ||
30 | #include "gnunet_messenger_service.h" | ||
31 | #include "gnunet_gnsrecord_plugin.h" | ||
32 | |||
33 | |||
34 | /** | ||
35 | * Convert the 'value' of a record to a string. | ||
36 | * | ||
37 | * @param cls closure, unused | ||
38 | * @param type type of the record | ||
39 | * @param data value in binary encoding | ||
40 | * @param data_size number of bytes in @a data | ||
41 | * @return NULL on error, otherwise human-readable representation of the value | ||
42 | */ | ||
43 | static char * | ||
44 | messenger_value_to_string (void *cls, | ||
45 | uint32_t type, | ||
46 | const void *data, | ||
47 | size_t data_size) | ||
48 | { | ||
49 | (void) cls; | ||
50 | switch (type) | ||
51 | { | ||
52 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY: | ||
53 | { | ||
54 | if (data_size != sizeof(struct GNUNET_MESSENGER_RoomEntryRecord)) | ||
55 | { | ||
56 | GNUNET_break_op (0); | ||
57 | return NULL; | ||
58 | } | ||
59 | |||
60 | const struct GNUNET_MESSENGER_RoomEntryRecord *record = data; | ||
61 | |||
62 | char *door = GNUNET_CRYPTO_eddsa_public_key_to_string (&(record->door.public_key)); | ||
63 | char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode)); | ||
64 | |||
65 | char *ret; | ||
66 | GNUNET_asprintf (&ret, "%s-%s", door, key); | ||
67 | GNUNET_free (key); | ||
68 | GNUNET_free (door); | ||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | default: | ||
73 | return NULL; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Convert human-readable version of a 'value' of a record to the binary | ||
80 | * representation. | ||
81 | * | ||
82 | * @param cls closure, unused | ||
83 | * @param type type of the record | ||
84 | * @param s human-readable string | ||
85 | * @param data set to value in binary encoding (will be allocated) | ||
86 | * @param data_size set to number of bytes in @a data | ||
87 | * @return #GNUNET_OK on success | ||
88 | */ | ||
89 | static int | ||
90 | messenger_string_to_value (void *cls, | ||
91 | uint32_t type, | ||
92 | const char *s, | ||
93 | void **data, | ||
94 | size_t *data_size) | ||
95 | { | ||
96 | (void) cls; | ||
97 | if (NULL == s) | ||
98 | { | ||
99 | GNUNET_break (0); | ||
100 | return GNUNET_SYSERR; | ||
101 | } | ||
102 | |||
103 | switch (type) | ||
104 | { | ||
105 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY: | ||
106 | { | ||
107 | char key [103]; | ||
108 | const char *dash; | ||
109 | struct GNUNET_PeerIdentity door; | ||
110 | |||
111 | if ((NULL == (dash = strchr (s, '-'))) || | ||
112 | (1 != sscanf (s, "%103s-", key)) || | ||
113 | (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, | ||
114 | strlen (dash + 1), | ||
115 | &(door.public_key)))) | ||
116 | { | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
118 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), | ||
119 | s); | ||
120 | return GNUNET_SYSERR; | ||
121 | } | ||
122 | |||
123 | struct GNUNET_MESSENGER_RoomEntryRecord *record = GNUNET_new ( | ||
124 | struct GNUNET_MESSENGER_RoomEntryRecord | ||
125 | ); | ||
126 | |||
127 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (key, | ||
128 | strlen (key), | ||
129 | &(record->key), | ||
130 | sizeof(struct GNUNET_HashCode))) | ||
131 | { | ||
132 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
133 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), | ||
134 | s); | ||
135 | GNUNET_free (record); | ||
136 | return GNUNET_SYSERR; | ||
137 | } | ||
138 | |||
139 | record->door = door; | ||
140 | *data = record; | ||
141 | *data_size = sizeof(struct GNUNET_MESSENGER_RoomEntryRecord); | ||
142 | return GNUNET_OK; | ||
143 | } | ||
144 | |||
145 | default: | ||
146 | return GNUNET_SYSERR; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | |||
151 | /** | ||
152 | * Mapping of record type numbers to human-readable | ||
153 | * record type names. | ||
154 | */ | ||
155 | static struct | ||
156 | { | ||
157 | const char *name; | ||
158 | uint32_t number; | ||
159 | } name_map[] = { | ||
160 | { "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY }, | ||
161 | { NULL, UINT32_MAX } | ||
162 | }; | ||
163 | |||
164 | |||
165 | /** | ||
166 | * Convert a type name (e.g. "AAAA") to the corresponding number. | ||
167 | * | ||
168 | * @param cls closure, unused | ||
169 | * @param gns_typename name to convert | ||
170 | * @return corresponding number, UINT32_MAX on error | ||
171 | */ | ||
172 | static uint32_t | ||
173 | messenger_typename_to_number (void *cls, | ||
174 | const char *gns_typename) | ||
175 | { | ||
176 | unsigned int i; | ||
177 | |||
178 | (void) cls; | ||
179 | i = 0; | ||
180 | while ((name_map[i].name != NULL) && | ||
181 | (0 != strcasecmp (gns_typename, name_map[i].name))) | ||
182 | i++; | ||
183 | return name_map[i].number; | ||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Convert a type number to the corresponding type string (e.g. 1 to "A") | ||
189 | * | ||
190 | * @param cls closure, unused | ||
191 | * @param type number of a type to convert | ||
192 | * @return corresponding typestring, NULL on error | ||
193 | */ | ||
194 | static const char * | ||
195 | messenger_number_to_typename (void *cls, | ||
196 | uint32_t type) | ||
197 | { | ||
198 | unsigned int i; | ||
199 | |||
200 | (void) cls; | ||
201 | i = 0; | ||
202 | while ((name_map[i].name != NULL) && | ||
203 | (type != name_map[i].number)) | ||
204 | i++; | ||
205 | return name_map[i].name; | ||
206 | } | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Entry point for the plugin. | ||
211 | * | ||
212 | * @param cls NULL | ||
213 | * @return the exported block API | ||
214 | */ | ||
215 | void * | ||
216 | libgnunet_plugin_gnsrecord_messenger_init (void *cls) | ||
217 | { | ||
218 | struct GNUNET_GNSRECORD_PluginFunctions *api; | ||
219 | |||
220 | (void) cls; | ||
221 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); | ||
222 | api->value_to_string = &messenger_value_to_string; | ||
223 | api->string_to_value = &messenger_string_to_value; | ||
224 | api->typename_to_number = &messenger_typename_to_number; | ||
225 | api->number_to_typename = &messenger_number_to_typename; | ||
226 | return api; | ||
227 | } | ||
228 | |||
229 | |||
230 | /** | ||
231 | * Exit point from the plugin. | ||
232 | * | ||
233 | * @param cls the return value from #libgnunet_plugin_block_test_init | ||
234 | * @return NULL | ||
235 | */ | ||
236 | void * | ||
237 | libgnunet_plugin_gnsrecord_messenger_done (void *cls) | ||
238 | { | ||
239 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | ||
240 | |||
241 | GNUNET_free (api); | ||
242 | return NULL; | ||
243 | } | ||
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index 79a2e80c6..283e4569c 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c | |||
@@ -420,6 +420,7 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
420 | void *cb_cls) | 420 | void *cb_cls) |
421 | { | 421 | { |
422 | struct GNUNET_DB_EventHandler *eh; | 422 | struct GNUNET_DB_EventHandler *eh; |
423 | bool sub; | ||
423 | 424 | ||
424 | eh = GNUNET_new (struct GNUNET_DB_EventHandler); | 425 | eh = GNUNET_new (struct GNUNET_DB_EventHandler); |
425 | eh->db = db; | 426 | eh->db = db; |
@@ -427,6 +428,9 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
427 | &eh->sh); | 428 | &eh->sh); |
428 | eh->cb = cb; | 429 | eh->cb = cb; |
429 | eh->cb_cls = cb_cls; | 430 | eh->cb_cls = cb_cls; |
431 | sub = (NULL == | ||
432 | GNUNET_CONTAINER_multishortmap_get (db->channel_map, | ||
433 | &eh->sh)); | ||
430 | GNUNET_assert (GNUNET_OK == | 434 | GNUNET_assert (GNUNET_OK == |
431 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, | 435 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, |
432 | &eh->sh, | 436 | &eh->sh, |
@@ -439,9 +443,10 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
439 | scheduler_fd_cb (db, | 443 | scheduler_fd_cb (db, |
440 | PQsocket (db->conn)); | 444 | PQsocket (db->conn)); |
441 | } | 445 | } |
442 | manage_subscribe (db, | 446 | if (sub) |
443 | "LISTEN X", | 447 | manage_subscribe (db, |
444 | eh); | 448 | "LISTEN X", |
449 | eh); | ||
445 | eh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 450 | eh->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
446 | &event_timeout, | 451 | &event_timeout, |
447 | eh); | 452 | eh); |
@@ -458,9 +463,12 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) | |||
458 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, | 463 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, |
459 | &eh->sh, | 464 | &eh->sh, |
460 | eh)); | 465 | eh)); |
461 | manage_subscribe (db, | 466 | if (NULL == |
462 | "UNLISTEN X", | 467 | GNUNET_CONTAINER_multishortmap_get (db->channel_map, |
463 | eh); | 468 | &eh->sh)) |
469 | manage_subscribe (db, | ||
470 | "UNLISTEN X", | ||
471 | eh); | ||
464 | if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)) | 472 | if (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)) |
465 | { | 473 | { |
466 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 474 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
diff --git a/src/util/network.c b/src/util/network.c index 014701e02..688c37665 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -75,13 +75,7 @@ struct GNUNET_NETWORK_Handle | |||
75 | }; | 75 | }; |
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | enum GNUNET_GenericReturnValue |
79 | * Test if the given protocol family is supported by this system. | ||
80 | * | ||
81 | * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) | ||
82 | * @return #GNUNET_OK if the PF is supported | ||
83 | */ | ||
84 | int | ||
85 | GNUNET_NETWORK_test_pf (int pf) | 79 | GNUNET_NETWORK_test_pf (int pf) |
86 | { | 80 | { |
87 | static int cache_v4 = -1; | 81 | static int cache_v4 = -1; |
@@ -145,15 +139,6 @@ GNUNET_NETWORK_test_pf (int pf) | |||
145 | } | 139 | } |
146 | 140 | ||
147 | 141 | ||
148 | /** | ||
149 | * Given a unixpath that is too long (larger than UNIX_PATH_MAX), | ||
150 | * shorten it to an acceptable length while keeping it unique | ||
151 | * and making sure it remains a valid filename (if possible). | ||
152 | * | ||
153 | * @param unixpath long path, will be freed (or same pointer returned | ||
154 | * with moved 0-termination). | ||
155 | * @return shortened unixpath, NULL on error | ||
156 | */ | ||
157 | char * | 142 | char * |
158 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) | 143 | GNUNET_NETWORK_shorten_unixpath (char *unixpath) |
159 | { | 144 | { |
@@ -189,15 +174,6 @@ GNUNET_NETWORK_shorten_unixpath (char *unixpath) | |||
189 | } | 174 | } |
190 | 175 | ||
191 | 176 | ||
192 | /** | ||
193 | * If services crash, they can leave a unix domain socket file on the | ||
194 | * disk. This needs to be manually removed, because otherwise both | ||
195 | * bind() and connect() for the respective address will fail. In this | ||
196 | * function, we test if such a left-over file exists, and if so, | ||
197 | * remove it (unless there is a listening service at the address). | ||
198 | * | ||
199 | * @param un unix domain socket address to check | ||
200 | */ | ||
201 | void | 177 | void |
202 | GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) | 178 | GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) |
203 | { | 179 | { |
@@ -244,14 +220,7 @@ GNUNET_NETWORK_unix_precheck (const struct sockaddr_un *un) | |||
244 | #endif | 220 | #endif |
245 | 221 | ||
246 | 222 | ||
247 | /** | 223 | enum GNUNET_GenericReturnValue |
248 | * Set if a socket should use blocking or non-blocking IO. | ||
249 | * | ||
250 | * @param fd socket | ||
251 | * @param doBlock blocking mode | ||
252 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
253 | */ | ||
254 | int | ||
255 | GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | 224 | GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, |
256 | int doBlock) | 225 | int doBlock) |
257 | { | 226 | { |
@@ -418,14 +387,6 @@ initialize_network_handle (struct GNUNET_NETWORK_Handle *h, | |||
418 | } | 387 | } |
419 | 388 | ||
420 | 389 | ||
421 | /** | ||
422 | * accept a new connection on a socket | ||
423 | * | ||
424 | * @param desc bound socket | ||
425 | * @param address address of the connecting peer, may be NULL | ||
426 | * @param address_len length of @a address | ||
427 | * @return client socket | ||
428 | */ | ||
429 | struct GNUNET_NETWORK_Handle * | 390 | struct GNUNET_NETWORK_Handle * |
430 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | 391 | GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, |
431 | struct sockaddr *address, | 392 | struct sockaddr *address, |
@@ -473,15 +434,7 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
473 | } | 434 | } |
474 | 435 | ||
475 | 436 | ||
476 | /** | 437 | enum GNUNET_GenericReturnValue |
477 | * Bind a socket to a particular address. | ||
478 | * | ||
479 | * @param desc socket to bind | ||
480 | * @param address address to be bound | ||
481 | * @param address_len length of @a address | ||
482 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
483 | */ | ||
484 | int | ||
485 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 438 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
486 | const struct sockaddr *address, | 439 | const struct sockaddr *address, |
487 | socklen_t address_len) | 440 | socklen_t address_len) |
@@ -550,13 +503,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
550 | } | 503 | } |
551 | 504 | ||
552 | 505 | ||
553 | /** | 506 | enum GNUNET_GenericReturnValue |
554 | * Close a socket | ||
555 | * | ||
556 | * @param desc socket | ||
557 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
558 | */ | ||
559 | int | ||
560 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | 507 | GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) |
561 | { | 508 | { |
562 | int ret; | 509 | int ret; |