diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2020-10-01 21:13:43 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2020-11-12 16:57:45 +0100 |
commit | 8bf864c25bda97c1448b709a76a168834753ff86 (patch) | |
tree | 6ffccc18a3c112e035235c596006f8b13aca1be7 /src | |
parent | 8fd7531e5841c9d9f80f821a3490a05934fee933 (diff) | |
download | gnunet-8bf864c25bda97c1448b709a76a168834753ff86.tar.gz gnunet-8bf864c25bda97c1448b709a76a168834753ff86.zip |
adding the messenger service and its client-side library
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src')
231 files changed, 13889 insertions, 1818 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 234a63389..c04d730be 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -12,7 +12,8 @@ endif | |||
12 | if HAVE_EXPERIMENTAL | 12 | if HAVE_EXPERIMENTAL |
13 | EXP_DIR = \ | 13 | EXP_DIR = \ |
14 | rps \ | 14 | rps \ |
15 | abd | 15 | #abd FTBFS |
16 | messenger | ||
16 | if HAVE_ABE | 17 | if HAVE_ABE |
17 | EXP_DIR += \ | 18 | EXP_DIR += \ |
18 | abe | 19 | abe |
@@ -51,7 +52,6 @@ SUBDIRS = \ | |||
51 | include $(INTLEMU_SUBDIRS) \ | 52 | include $(INTLEMU_SUBDIRS) \ |
52 | util \ | 53 | util \ |
53 | nt \ | 54 | nt \ |
54 | gnsrecord \ | ||
55 | hello \ | 55 | hello \ |
56 | block \ | 56 | block \ |
57 | statistics \ | 57 | statistics \ |
@@ -74,7 +74,6 @@ SUBDIRS = \ | |||
74 | fragmentation \ | 74 | fragmentation \ |
75 | transport \ | 75 | transport \ |
76 | ats-tool \ | 76 | ats-tool \ |
77 | peerinfo-tool \ | ||
78 | core \ | 77 | core \ |
79 | $(TESTBED) \ | 78 | $(TESTBED) \ |
80 | $(ATS_TESTS) \ | 79 | $(ATS_TESTS) \ |
@@ -85,8 +84,10 @@ SUBDIRS = \ | |||
85 | regex \ | 84 | regex \ |
86 | dns \ | 85 | dns \ |
87 | identity \ | 86 | identity \ |
87 | gnsrecord \ | ||
88 | namecache \ | 88 | namecache \ |
89 | namestore \ | 89 | namestore \ |
90 | peerinfo-tool \ | ||
90 | cadet \ | 91 | cadet \ |
91 | set \ | 92 | set \ |
92 | seti \ | 93 | seti \ |
diff --git a/src/ats-tests/ats-testing-log.c b/src/ats-tests/ats-testing-log.c index 38094a438..955401dd8 100644 --- a/src/ats-tests/ats-testing-log.c +++ b/src/ats-tests/ats-testing-log.c | |||
@@ -575,7 +575,7 @@ GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l, | |||
575 | 575 | ||
576 | /* Assembling slave string */ | 576 | /* Assembling slave string */ |
577 | GNUNET_asprintf (&data, | 577 | GNUNET_asprintf (&data, |
578 | "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n", | 578 | "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%llu;%u;%u;%u;%u;%.3f;%.3f\n", |
579 | (long long unsigned | 579 | (long long unsigned |
580 | int) cur_lt->timestamp.abs_value_us, | 580 | int) cur_lt->timestamp.abs_value_us, |
581 | (long long unsigned | 581 | (long long unsigned |
@@ -593,7 +593,7 @@ GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l, | |||
593 | (double) plt->app_rtt / 1000, | 593 | (double) plt->app_rtt / 1000, |
594 | plt->bandwidth_in, | 594 | plt->bandwidth_in, |
595 | plt->bandwidth_out, | 595 | plt->bandwidth_out, |
596 | plt->ats_delay, | 596 | plt->ats_delay.rel_value_us, |
597 | plt->ats_distance, | 597 | plt->ats_distance, |
598 | plt->ats_network_type, | 598 | plt->ats_network_type, |
599 | plt->ats_utilization_out, | 599 | plt->ats_utilization_out, |
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index dab53b8c4..ae6d21452 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c | |||
@@ -442,7 +442,7 @@ GCCH_2s (const struct CadetChannel *ch) | |||
442 | ? "loopback" | 442 | ? "loopback" |
443 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), | 443 | : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), |
444 | GNUNET_h2s (&ch->port), | 444 | GNUNET_h2s (&ch->port), |
445 | ch->ctn, | 445 | ch->ctn.cn, |
446 | (NULL == ch->owner) | 446 | (NULL == ch->owner) |
447 | ? 0 | 447 | ? 0 |
448 | : ntohl (ch->owner->ccn.channel_of_client), | 448 | : ntohl (ch->owner->ccn.channel_of_client), |
@@ -1899,10 +1899,10 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1899 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); | 1899 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); |
1900 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); | 1900 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); |
1901 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1901 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1902 | "Sending message %u from local client to %s with %u bytes\n", | 1902 | "Sending message %u from local client to %s with %lu bytes\n", |
1903 | ntohl (crm->data_message->mid.mid), | 1903 | ntohl (crm->data_message->mid.mid), |
1904 | GCCH_2s (ch), | 1904 | GCCH_2s (ch), |
1905 | buf_len); | 1905 | (unsigned long) buf_len); |
1906 | if (NULL != ch->retry_data_task) | 1906 | if (NULL != ch->retry_data_task) |
1907 | { | 1907 | { |
1908 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1908 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
@@ -2044,7 +2044,7 @@ GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) | |||
2044 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); | 2044 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); |
2045 | return; | 2045 | return; |
2046 | } | 2046 | } |
2047 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); | 2047 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn.cn, ch); |
2048 | if (NULL != ch->owner) | 2048 | if (NULL != ch->owner) |
2049 | { | 2049 | { |
2050 | LOG2 (level, | 2050 | LOG2 (level, |
@@ -2062,7 +2062,7 @@ GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) | |||
2062 | ntohl (ch->dest->ccn.channel_of_client)); | 2062 | ntohl (ch->dest->ccn.channel_of_client)); |
2063 | } | 2063 | } |
2064 | LOG2 (level, | 2064 | LOG2 (level, |
2065 | "CHN Message IDs recv: %d (%LLX), send: %d\n", | 2065 | "CHN Message IDs recv: %d (%llX), send: %d\n", |
2066 | ntohl (ch->mid_recv.mid), | 2066 | ntohl (ch->mid_recv.mid), |
2067 | (unsigned long long) ch->mid_futures, | 2067 | (unsigned long long) ch->mid_futures, |
2068 | ntohl (ch->mid_send.mid)); | 2068 | ntohl (ch->mid_send.mid)); |
diff --git a/src/cadet/gnunet-service-cadet_core.c b/src/cadet/gnunet-service-cadet_core.c index 9a83fa31d..95a5d3f63 100644 --- a/src/cadet/gnunet-service-cadet_core.c +++ b/src/cadet/gnunet-service-cadet_core.c | |||
@@ -296,7 +296,7 @@ discard_all_from_rung_tail () | |||
296 | while (NULL != (dir = tail->rd_head)) | 296 | while (NULL != (dir = tail->rd_head)) |
297 | { | 297 | { |
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 298 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
299 | "Queue full due new message %s on connection %s, dropping old message\n", | 299 | "Queue full due new message on connection %s, dropping old message\n", |
300 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); | 300 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); |
301 | GNUNET_STATISTICS_update (stats, | 301 | GNUNET_STATISTICS_update (stats, |
302 | "# messages dropped due to full buffer", | 302 | "# messages dropped due to full buffer", |
@@ -408,7 +408,7 @@ route_message (struct CadetPeer *prev, | |||
408 | { | 408 | { |
409 | /* We are in the highest rung, drop our own! */ | 409 | /* We are in the highest rung, drop our own! */ |
410 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 410 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
411 | "Queue full due new message %s on connection %s, dropping old message\n", | 411 | "Queue full due new message on connection %s, dropping old message\n", |
412 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); | 412 | GNUNET_sh2s (&dir->my_route->cid.connection_of_tunnel)); |
413 | GNUNET_STATISTICS_update (stats, | 413 | GNUNET_STATISTICS_update (stats, |
414 | "# messages dropped due to full buffer", | 414 | "# messages dropped due to full buffer", |
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c index 4e8ccbb08..e1bbeb2c3 100644 --- a/src/cadet/gnunet-service-cadet_dht.c +++ b/src/cadet/gnunet-service-cadet_dht.c | |||
@@ -195,8 +195,8 @@ announce_id (void *cls) | |||
195 | &my_full_id, | 195 | &my_full_id, |
196 | sizeof(my_full_id)); | 196 | sizeof(my_full_id)); |
197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 197 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
198 | "Announcing my HELLO (%u bytes) in the DHT\n", | 198 | "Announcing my HELLO (%lu bytes) in the DHT\n", |
199 | size); | 199 | (unsigned long) size); |
200 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | 200 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
201 | &phash, /* Key to use */ | 201 | &phash, /* Key to use */ |
202 | dht_replication_level, /* Replication level */ | 202 | dht_replication_level, /* Replication level */ |
diff --git a/src/cadet/gnunet-service-cadet_tunnels.c b/src/cadet/gnunet-service-cadet_tunnels.c index 2ca46b5aa..78bc54a5c 100644 --- a/src/cadet/gnunet-service-cadet_tunnels.c +++ b/src/cadet/gnunet-service-cadet_tunnels.c | |||
@@ -2431,7 +2431,7 @@ connection_ready_cb (void *cls, | |||
2431 | { | 2431 | { |
2432 | case CADET_TUNNEL_KEY_UNINITIALIZED: | 2432 | case CADET_TUNNEL_KEY_UNINITIALIZED: |
2433 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2433 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2434 | "Do not begin KX for %s if WE have no channels waiting. Retrying after %d\n", | 2434 | "Do not begin KX for %s if WE have no channels waiting. Retrying after %llu\n", |
2435 | GCT_2s (t), | 2435 | GCT_2s (t), |
2436 | GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us); | 2436 | GNUNET_TIME_absolute_get_remaining (t->next_kx_attempt).rel_value_us); |
2437 | /* Do not begin KX if WE have no channels waiting! */ | 2437 | /* Do not begin KX if WE have no channels waiting! */ |
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c index 06b4c88ef..b4a9e5d39 100644 --- a/src/consensus/consensus_api.c +++ b/src/consensus/consensus_api.c | |||
@@ -280,7 +280,7 @@ GNUNET_CONSENSUS_insert (struct GNUNET_CONSENSUS_Handle *consensus, | |||
280 | struct GNUNET_MQ_Envelope *ev; | 280 | struct GNUNET_MQ_Envelope *ev; |
281 | struct InsertDoneInfo *i; | 281 | struct InsertDoneInfo *i; |
282 | 282 | ||
283 | LOG (GNUNET_ERROR_TYPE_DEBUG, "inserting, size=%llu\n", element->size); | 283 | LOG (GNUNET_ERROR_TYPE_DEBUG, "inserting, size=%u\n", element->size); |
284 | 284 | ||
285 | ev = GNUNET_MQ_msg_extra (element_msg, element->size, | 285 | ev = GNUNET_MQ_msg_extra (element_msg, element->size, |
286 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT); | 286 | GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT); |
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am index 7645b7973..0f99a6526 100644 --- a/src/conversation/Makefile.am +++ b/src/conversation/Makefile.am | |||
@@ -185,6 +185,7 @@ gnunet_service_conversation_LDADD = \ | |||
185 | libgnunetmicrophone.la \ | 185 | libgnunetmicrophone.la \ |
186 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | 186 | $(top_builddir)/src/cadet/libgnunetcadet.la \ |
187 | $(top_builddir)/src/util/libgnunetutil.la \ | 187 | $(top_builddir)/src/util/libgnunetutil.la \ |
188 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
188 | $(INTLLIBS) | 189 | $(INTLLIBS) |
189 | #gnunet_service_conversation_LDFLAGS = \ | 190 | #gnunet_service_conversation_LDFLAGS = \ |
190 | # | 191 | # |
diff --git a/src/conversation/conversation.h b/src/conversation/conversation.h index ed614ab1b..d244f5163 100644 --- a/src/conversation/conversation.h +++ b/src/conversation/conversation.h | |||
@@ -27,6 +27,8 @@ | |||
27 | #ifndef CONVERSATION_H | 27 | #ifndef CONVERSATION_H |
28 | #define CONVERSATION_H | 28 | #define CONVERSATION_H |
29 | 29 | ||
30 | #include "gnunet_identity_service.h" | ||
31 | |||
30 | #ifdef __cplusplus | 32 | #ifdef __cplusplus |
31 | extern "C" | 33 | extern "C" |
32 | { | 34 | { |
@@ -105,7 +107,7 @@ struct ClientPhoneRingMessage | |||
105 | /** | 107 | /** |
106 | * Who is calling us? | 108 | * Who is calling us? |
107 | */ | 109 | */ |
108 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; | 110 | struct GNUNET_IDENTITY_PublicKey caller_id; |
109 | }; | 111 | }; |
110 | 112 | ||
111 | 113 | ||
@@ -230,7 +232,7 @@ struct ClientCallMessage | |||
230 | /** | 232 | /** |
231 | * Identity of the caller. | 233 | * Identity of the caller. |
232 | */ | 234 | */ |
233 | struct GNUNET_CRYPTO_EcdsaPrivateKey caller_id; | 235 | struct GNUNET_IDENTITY_PrivateKey caller_id; |
234 | }; | 236 | }; |
235 | 237 | ||
236 | 238 | ||
@@ -301,7 +303,7 @@ struct CadetPhoneRingMessage | |||
301 | /** | 303 | /** |
302 | * Who is calling us? (also who is signing). | 304 | * Who is calling us? (also who is signing). |
303 | */ | 305 | */ |
304 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; | 306 | struct GNUNET_IDENTITY_PublicKey caller_id; |
305 | 307 | ||
306 | /** | 308 | /** |
307 | * When does the signature expire? | 309 | * When does the signature expire? |
@@ -311,7 +313,7 @@ struct CadetPhoneRingMessage | |||
311 | /** | 313 | /** |
312 | * Signature over a `struct CadetPhoneRingInfoPS` | 314 | * Signature over a `struct CadetPhoneRingInfoPS` |
313 | */ | 315 | */ |
314 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 316 | struct GNUNET_IDENTITY_Signature signature; |
315 | }; | 317 | }; |
316 | 318 | ||
317 | 319 | ||
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index daf51042a..88fe8f11c 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c | |||
@@ -105,7 +105,7 @@ struct GNUNET_CONVERSATION_Caller | |||
105 | /** | 105 | /** |
106 | * Identity of the person calling us. | 106 | * Identity of the person calling us. |
107 | */ | 107 | */ |
108 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; | 108 | struct GNUNET_IDENTITY_PublicKey caller_id; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Internal handle to identify the caller with the service. | 111 | * Internal handle to identify the caller with the service. |
@@ -192,7 +192,7 @@ struct GNUNET_CONVERSATION_Phone | |||
192 | /** | 192 | /** |
193 | * My GNS zone. | 193 | * My GNS zone. |
194 | */ | 194 | */ |
195 | struct GNUNET_CRYPTO_EcdsaPrivateKey my_zone; | 195 | struct GNUNET_IDENTITY_PrivateKey my_zone; |
196 | 196 | ||
197 | /** | 197 | /** |
198 | * State machine for the phone. | 198 | * State machine for the phone. |
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c index 7a2a727a5..9ff0002e7 100644 --- a/src/conversation/gnunet-conversation.c +++ b/src/conversation/gnunet-conversation.c | |||
@@ -116,7 +116,7 @@ struct CallList | |||
116 | /** | 116 | /** |
117 | * Public key identifying the caller. | 117 | * Public key identifying the caller. |
118 | */ | 118 | */ |
119 | struct GNUNET_CRYPTO_EcdsaPublicKey caller_id; | 119 | struct GNUNET_IDENTITY_PublicKey caller_id; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Unique number of the call. | 122 | * Unique number of the call. |
@@ -194,7 +194,7 @@ static char *ego_name; | |||
194 | /** | 194 | /** |
195 | * Public key of active conversation partner (if any). | 195 | * Public key of active conversation partner (if any). |
196 | */ | 196 | */ |
197 | static struct GNUNET_CRYPTO_EcdsaPublicKey peer_key; | 197 | static struct GNUNET_IDENTITY_PublicKey peer_key; |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * Name of active conversation partner (if any). | 200 | * Name of active conversation partner (if any). |
@@ -244,7 +244,7 @@ static void | |||
244 | phone_event_handler (void *cls, | 244 | phone_event_handler (void *cls, |
245 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 245 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
246 | struct GNUNET_CONVERSATION_Caller *caller, | 246 | struct GNUNET_CONVERSATION_Caller *caller, |
247 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 247 | const struct GNUNET_IDENTITY_PublicKey *caller_id) |
248 | { | 248 | { |
249 | struct CallList *cl; | 249 | struct CallList *cl; |
250 | 250 | ||
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c index 502146255..a69c95a80 100644 --- a/src/conversation/gnunet-service-conversation.c +++ b/src/conversation/gnunet-service-conversation.c | |||
@@ -752,10 +752,11 @@ handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg) | |||
752 | rs.expiration_time = msg->expiration_time; | 752 | rs.expiration_time = msg->expiration_time; |
753 | 753 | ||
754 | if (GNUNET_OK != | 754 | if (GNUNET_OK != |
755 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, | 755 | GNUNET_IDENTITY_signature_verify ( |
756 | &rs, | 756 | GNUNET_SIGNATURE_PURPOSE_CONVERSATION_RING, |
757 | &msg->signature, | 757 | &rs, |
758 | &msg->caller_id)) | 758 | &msg->signature, |
759 | &msg->caller_id)) | ||
759 | { | 760 | { |
760 | GNUNET_break_op (0); | 761 | GNUNET_break_op (0); |
761 | destroy_line_cadet_channels (ch); | 762 | destroy_line_cadet_channels (ch); |
@@ -1136,11 +1137,9 @@ handle_client_call_message (void *cls, const struct ClientCallMessage *msg) | |||
1136 | cadet_handlers); | 1137 | cadet_handlers); |
1137 | ch->mq = GNUNET_CADET_get_mq (ch->channel); | 1138 | ch->mq = GNUNET_CADET_get_mq (ch->channel); |
1138 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); | 1139 | e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); |
1139 | GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id); | 1140 | GNUNET_IDENTITY_key_get_public (&msg->caller_id, &ring->caller_id); |
1140 | ring->expiration_time = rs.expiration_time; | 1141 | ring->expiration_time = rs.expiration_time; |
1141 | GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, | 1142 | GNUNET_IDENTITY_sign (&msg->caller_id, &rs, &ring->signature); |
1142 | &rs, | ||
1143 | &ring->signature); | ||
1144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); | 1143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n"); |
1145 | GNUNET_MQ_send (ch->mq, e); | 1144 | GNUNET_MQ_send (ch->mq, e); |
1146 | GNUNET_SERVICE_client_continue (line->client); | 1145 | GNUNET_SERVICE_client_continue (line->client); |
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c index b51186dc8..c5efecd52 100644 --- a/src/conversation/test_conversation_api.c +++ b/src/conversation/test_conversation_api.c | |||
@@ -305,7 +305,7 @@ static void | |||
305 | phone_event_handler (void *cls, | 305 | phone_event_handler (void *cls, |
306 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 306 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
307 | struct GNUNET_CONVERSATION_Caller *caller, | 307 | struct GNUNET_CONVERSATION_Caller *caller, |
308 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 308 | const struct GNUNET_IDENTITY_PublicKey *caller_id) |
309 | { | 309 | { |
310 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = | 310 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = |
311 | GNUNET_CONVERSATION_EC_PHONE_RING; | 311 | GNUNET_CONVERSATION_EC_PHONE_RING; |
@@ -385,7 +385,7 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | |||
385 | 385 | ||
386 | static void | 386 | static void |
387 | caller_ego_create_cont (void *cls, | 387 | caller_ego_create_cont (void *cls, |
388 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 388 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
389 | const char *emsg) | 389 | const char *emsg) |
390 | { | 390 | { |
391 | (void) cls; | 391 | (void) cls; |
@@ -414,7 +414,7 @@ identity_cb (void *cls, | |||
414 | const char *name) | 414 | const char *name) |
415 | { | 415 | { |
416 | struct GNUNET_GNSRECORD_Data rd; | 416 | struct GNUNET_GNSRECORD_Data rd; |
417 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 417 | struct GNUNET_IDENTITY_PublicKey pub; |
418 | 418 | ||
419 | (void) cls; | 419 | (void) cls; |
420 | (void) ctx; | 420 | (void) ctx; |
@@ -465,7 +465,7 @@ identity_cb (void *cls, | |||
465 | 465 | ||
466 | static void | 466 | static void |
467 | phone_ego_create_cont (void *cls, | 467 | phone_ego_create_cont (void *cls, |
468 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 468 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
469 | const char *emsg) | 469 | const char *emsg) |
470 | { | 470 | { |
471 | (void) cls; | 471 | (void) cls; |
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c index 69fa9f1dc..08c64df37 100644 --- a/src/conversation/test_conversation_api_reject.c +++ b/src/conversation/test_conversation_api_reject.c | |||
@@ -179,7 +179,7 @@ static void | |||
179 | phone_event_handler (void *cls, | 179 | phone_event_handler (void *cls, |
180 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 180 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
181 | struct GNUNET_CONVERSATION_Caller *caller, | 181 | struct GNUNET_CONVERSATION_Caller *caller, |
182 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 182 | const struct GNUNET_IDENTITY_PublicKey *caller_id) |
183 | { | 183 | { |
184 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = | 184 | static enum GNUNET_CONVERSATION_PhoneEventCode expect = |
185 | GNUNET_CONVERSATION_EC_PHONE_RING; | 185 | GNUNET_CONVERSATION_EC_PHONE_RING; |
@@ -238,7 +238,7 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | |||
238 | 238 | ||
239 | static void | 239 | static void |
240 | caller_ego_create_cont (void *cls, | 240 | caller_ego_create_cont (void *cls, |
241 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 241 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
242 | const char *emsg) | 242 | const char *emsg) |
243 | { | 243 | { |
244 | (void) cls; | 244 | (void) cls; |
@@ -267,7 +267,7 @@ identity_cb (void *cls, | |||
267 | const char *name) | 267 | const char *name) |
268 | { | 268 | { |
269 | struct GNUNET_GNSRECORD_Data rd; | 269 | struct GNUNET_GNSRECORD_Data rd; |
270 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 270 | struct GNUNET_IDENTITY_PublicKey pub; |
271 | 271 | ||
272 | (void) cls; | 272 | (void) cls; |
273 | (void) ctx; | 273 | (void) ctx; |
@@ -318,7 +318,7 @@ identity_cb (void *cls, | |||
318 | 318 | ||
319 | static void | 319 | static void |
320 | phone_ego_create_cont (void *cls, | 320 | phone_ego_create_cont (void *cls, |
321 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 321 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
322 | const char *emsg) | 322 | const char *emsg) |
323 | { | 323 | { |
324 | (void) cls; | 324 | (void) cls; |
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c index 83e8cb55a..ac7a3c9dd 100644 --- a/src/conversation/test_conversation_api_twocalls.c +++ b/src/conversation/test_conversation_api_twocalls.c | |||
@@ -403,7 +403,7 @@ static void | |||
403 | phone_event_handler (void *cls, | 403 | phone_event_handler (void *cls, |
404 | enum GNUNET_CONVERSATION_PhoneEventCode code, | 404 | enum GNUNET_CONVERSATION_PhoneEventCode code, |
405 | struct GNUNET_CONVERSATION_Caller *caller, | 405 | struct GNUNET_CONVERSATION_Caller *caller, |
406 | const struct GNUNET_CRYPTO_EcdsaPublicKey *caller_id) | 406 | const struct GNUNET_IDENTITY_PublicKey *caller_id) |
407 | { | 407 | { |
408 | const char *cid; | 408 | const char *cid; |
409 | 409 | ||
@@ -507,7 +507,7 @@ call_event_handler (void *cls, enum GNUNET_CONVERSATION_CallEventCode code) | |||
507 | 507 | ||
508 | static void | 508 | static void |
509 | caller_ego_create_cont (void *cls, | 509 | caller_ego_create_cont (void *cls, |
510 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 510 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
511 | const char *emsg) | 511 | const char *emsg) |
512 | { | 512 | { |
513 | (void) cls; | 513 | (void) cls; |
@@ -536,7 +536,7 @@ identity_cb (void *cls, | |||
536 | const char *name) | 536 | const char *name) |
537 | { | 537 | { |
538 | struct GNUNET_GNSRECORD_Data rd; | 538 | struct GNUNET_GNSRECORD_Data rd; |
539 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 539 | struct GNUNET_IDENTITY_PublicKey pub; |
540 | 540 | ||
541 | (void) cls; | 541 | (void) cls; |
542 | (void) ctx; | 542 | (void) ctx; |
@@ -594,7 +594,7 @@ identity_cb (void *cls, | |||
594 | 594 | ||
595 | static void | 595 | static void |
596 | phone_ego_create_cont (void *cls, | 596 | phone_ego_create_cont (void *cls, |
597 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 597 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
598 | const char *emsg) | 598 | const char *emsg) |
599 | { | 599 | { |
600 | (void) cls; | 600 | (void) cls; |
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index c21be9219..724324ca4 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c | |||
@@ -67,14 +67,19 @@ static int | |||
67 | init_connection (struct Plugin *plugin) | 67 | init_connection (struct Plugin *plugin) |
68 | { | 68 | { |
69 | struct GNUNET_PQ_ExecuteStatement es[] = { | 69 | struct GNUNET_PQ_ExecuteStatement es[] = { |
70 | GNUNET_PQ_make_try_execute ("CREATE TEMPORARY SEQUENCE IF NOT EXISTS gn011dc_oid_seq"), | ||
70 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn011dc (" | 71 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS gn011dc (" |
72 | " oid OID NOT NULL DEFAULT nextval('gn011dc_oid_seq')," | ||
71 | " type INTEGER NOT NULL," | 73 | " type INTEGER NOT NULL," |
72 | " prox INTEGER NOT NULL," | 74 | " prox INTEGER NOT NULL," |
73 | " discard_time BIGINT NOT NULL," | 75 | " discard_time BIGINT NOT NULL," |
74 | " key BYTEA NOT NULL," | 76 | " key BYTEA NOT NULL," |
75 | " value BYTEA NOT NULL," | 77 | " value BYTEA NOT NULL," |
76 | " path BYTEA DEFAULT NULL)" | 78 | " path BYTEA DEFAULT NULL)"), |
77 | "WITH OIDS"), | 79 | GNUNET_PQ_make_try_execute ( |
80 | "ALTER SEQUENCE gnu011dc_oid_seq OWNED BY gn011dc.oid"), | ||
81 | GNUNET_PQ_make_try_execute ( | ||
82 | "CREATE INDEX IF NOT EXISTS idx_oid ON gn011dc (oid)"), | ||
78 | GNUNET_PQ_make_try_execute ( | 83 | GNUNET_PQ_make_try_execute ( |
79 | "CREATE INDEX IF NOT EXISTS idx_key ON gn011dc (key)"), | 84 | "CREATE INDEX IF NOT EXISTS idx_key ON gn011dc (key)"), |
80 | GNUNET_PQ_make_try_execute ( | 85 | GNUNET_PQ_make_try_execute ( |
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index 4537f6efe..bd7a612ed 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c | |||
@@ -994,8 +994,8 @@ GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, | |||
994 | } | 994 | } |
995 | 995 | ||
996 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 996 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
997 | "Asked to put %u bytes of data under key `%s' for %s\n", | 997 | "Asked to put %lu bytes of data under key `%s' for %s\n", |
998 | size, | 998 | (unsigned long) size, |
999 | GNUNET_h2s (key), | 999 | GNUNET_h2s (key), |
1000 | GNUNET_STRINGS_relative_time_to_string ( | 1000 | GNUNET_STRINGS_relative_time_to_string ( |
1001 | GNUNET_TIME_absolute_get_remaining (expiration), | 1001 | GNUNET_TIME_absolute_get_remaining (expiration), |
@@ -1205,8 +1205,8 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, | |||
1205 | if (NULL == cont) | 1205 | if (NULL == cont) |
1206 | cont = &drop_status_cont; | 1206 | cont = &drop_status_cont; |
1207 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1207 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1208 | "Asked to remove %u bytes under key `%s'\n", | 1208 | "Asked to remove %lu bytes under key `%s'\n", |
1209 | size, | 1209 | (unsigned long) size, |
1210 | GNUNET_h2s (key)); | 1210 | GNUNET_h2s (key)); |
1211 | env = GNUNET_MQ_msg_extra (dm, | 1211 | env = GNUNET_MQ_msg_extra (dm, |
1212 | size, | 1212 | size, |
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 88ceb1b0a..6a5d45832 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c | |||
@@ -72,8 +72,10 @@ init_connection (struct Plugin *plugin) | |||
72 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel | 72 | * we only test equality on it and can cast it to/from uint32_t. For repl, prio, and anonLevel |
73 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. | 73 | * we do math or inequality tests, so we can't handle the entire range of uint32_t. |
74 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. | 74 | * This will also cause problems for expiration times after 294247-01-10-04:00:54 UTC. |
75 | * PostgreSQL also recommends against using WITH OIDS. | 75 | */ |
76 | */GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 (" | 76 | GNUNET_PQ_make_try_execute ( |
77 | "CREATE SEQUENCE IF NOT EXISTS gn090_oid_seq"), | ||
78 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS gn090 (" | ||
77 | " repl INTEGER NOT NULL DEFAULT 0," | 79 | " repl INTEGER NOT NULL DEFAULT 0," |
78 | " type INTEGER NOT NULL DEFAULT 0," | 80 | " type INTEGER NOT NULL DEFAULT 0," |
79 | " prio INTEGER NOT NULL DEFAULT 0," | 81 | " prio INTEGER NOT NULL DEFAULT 0," |
@@ -82,8 +84,12 @@ init_connection (struct Plugin *plugin) | |||
82 | " rvalue BIGINT NOT NULL DEFAULT 0," | 84 | " rvalue BIGINT NOT NULL DEFAULT 0," |
83 | " hash BYTEA NOT NULL DEFAULT ''," | 85 | " hash BYTEA NOT NULL DEFAULT ''," |
84 | " vhash BYTEA NOT NULL DEFAULT ''," | 86 | " vhash BYTEA NOT NULL DEFAULT ''," |
85 | " value BYTEA NOT NULL DEFAULT '')" | 87 | " value BYTEA NOT NULL DEFAULT ''," |
86 | "WITH OIDS"), | 88 | " oid OID NOT NULL DEFAULT nextval('gn090_oid_seq'))"), |
89 | GNUNET_PQ_make_try_execute ( | ||
90 | "ALTER SEQUENCE gn090_oid_seq OWNED BY gn090.oid"), | ||
91 | GNUNET_PQ_make_try_execute ( | ||
92 | "CREATE INDEX IF NOT EXISTS oid_hash ON gn090 (oid)"), | ||
87 | GNUNET_PQ_make_try_execute ( | 93 | GNUNET_PQ_make_try_execute ( |
88 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"), | 94 | "CREATE INDEX IF NOT EXISTS idx_hash ON gn090 (hash)"), |
89 | GNUNET_PQ_make_try_execute ( | 95 | GNUNET_PQ_make_try_execute ( |
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 1e44c1fad..5eb3115f4 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -488,8 +488,8 @@ handle_dht_local_put (void *cls, | |||
488 | GNUNET_h2s_full (&dht_msg->key)); | 488 | GNUNET_h2s_full (&dht_msg->key)); |
489 | /* give to local clients */ | 489 | /* give to local clients */ |
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 490 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
491 | "Handling local PUT of %u-bytes for query %s\n", | 491 | "Handling local PUT of %lu-bytes for query %s\n", |
492 | size - sizeof(struct GNUNET_DHT_ClientPutMessage), | 492 | (unsigned long) (size - sizeof(struct GNUNET_DHT_ClientPutMessage)), |
493 | GNUNET_h2s (&dht_msg->key)); | 493 | GNUNET_h2s (&dht_msg->key)); |
494 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), | 494 | GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), |
495 | &dht_msg->key, | 495 | &dht_msg->key, |
@@ -619,7 +619,7 @@ handle_dht_local_get (void *cls, | |||
619 | "Received GET request for %s from local client %p, xq: %.*s\n", | 619 | "Received GET request for %s from local client %p, xq: %.*s\n", |
620 | GNUNET_h2s (&get->key), | 620 | GNUNET_h2s (&get->key), |
621 | ch->client, | 621 | ch->client, |
622 | xquery_size, | 622 | (int) xquery_size, |
623 | xquery); | 623 | xquery); |
624 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, | 624 | LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, |
625 | "CLIENT-GET %s\n", | 625 | "CLIENT-GET %s\n", |
diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 41b7a3a2b..7eded2152 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c | |||
@@ -94,9 +94,9 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, | |||
94 | put_path_length, | 94 | put_path_length, |
95 | put_path); | 95 | put_path); |
96 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 96 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
97 | "DATACACHE PUT for key %s [%u] completed (%d) after %u hops\n", | 97 | "DATACACHE PUT for key %s [%lu] completed (%d) after %u hops\n", |
98 | GNUNET_h2s (key), | 98 | GNUNET_h2s (key), |
99 | data_size, | 99 | (unsigned long) data_size, |
100 | r, | 100 | r, |
101 | put_path_length); | 101 | put_path_length); |
102 | } | 102 | } |
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index b211fca6b..88b0c5d92 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c | |||
@@ -2212,8 +2212,8 @@ handle_dht_p2p_get (void *cls, | |||
2212 | bg, | 2212 | bg, |
2213 | peer_bf); | 2213 | peer_bf); |
2214 | GDS_CLIENTS_process_get (options | 2214 | GDS_CLIENTS_process_get (options |
2215 | | (GNUNET_OK == forwarded) | 2215 | | ((GNUNET_OK == forwarded) |
2216 | ? GNUNET_DHT_RO_LAST_HOP : 0, | 2216 | ? GNUNET_DHT_RO_LAST_HOP : 0), |
2217 | type, | 2217 | type, |
2218 | ntohl (get->hop_count), | 2218 | ntohl (get->hop_count), |
2219 | ntohl (get->desired_replication_level), | 2219 | ntohl (get->desired_replication_level), |
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c index f213433ed..a9f336240 100644 --- a/src/dht/plugin_block_dht.c +++ b/src/dht/plugin_block_dht.c | |||
@@ -195,7 +195,7 @@ block_plugin_dht_get_key (void *cls, | |||
195 | { | 195 | { |
196 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | 196 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, |
197 | "block-dht", | 197 | "block-dht", |
198 | _ ("Size mismatch for block\n"), | 198 | _ ("Size mismatch for block with type %u\n"), |
199 | GNUNET_BLOCK_TYPE_DHT_HELLO); | 199 | GNUNET_BLOCK_TYPE_DHT_HELLO); |
200 | return GNUNET_NO; | 200 | return GNUNET_NO; |
201 | } | 201 | } |
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c index d9830baa4..836d65c79 100644 --- a/src/dns/gnunet-dns-monitor.c +++ b/src/dns/gnunet-dns-monitor.c | |||
@@ -203,7 +203,7 @@ display_record (const struct GNUNET_DNSPARSER_Record *record) | |||
203 | else | 203 | else |
204 | { | 204 | { |
205 | GNUNET_asprintf (&tmp, | 205 | GNUNET_asprintf (&tmp, |
206 | "priority %u, weight = %s, port = %u, target = %s", | 206 | "priority %u, weight = %u, port = %u, target = %s", |
207 | (unsigned int) record->data.srv->priority, | 207 | (unsigned int) record->data.srv->priority, |
208 | (unsigned int) record->data.srv->weight, | 208 | (unsigned int) record->data.srv->weight, |
209 | (unsigned int) record->data.srv->port, | 209 | (unsigned int) record->data.srv->port, |
diff --git a/src/fragmentation/fragmentation.c b/src/fragmentation/fragmentation.c index 3a7da37e8..36e1c33f4 100644 --- a/src/fragmentation/fragmentation.c +++ b/src/fragmentation/fragmentation.c | |||
@@ -158,7 +158,7 @@ GNUNET_FRAGMENT_print_ack (const struct GNUNET_MessageHeader *ack) | |||
158 | sizeof(buf), | 158 | sizeof(buf), |
159 | "%u-%llX", | 159 | "%u-%llX", |
160 | ntohl (fa->fragment_id), | 160 | ntohl (fa->fragment_id), |
161 | GNUNET_ntohll (fa->bits)); | 161 | (unsigned long long) GNUNET_ntohll (fa->bits)); |
162 | return buf; | 162 | return buf; |
163 | } | 163 | } |
164 | 164 | ||
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 6154e8be0..d4677b794 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -1050,7 +1050,7 @@ process_result_with_request (void *cls, | |||
1050 | GNUNET_asprintf ( | 1050 | GNUNET_asprintf ( |
1051 | &dc->emsg, | 1051 | &dc->emsg, |
1052 | _ ( | 1052 | _ ( |
1053 | "Internal error or bogus download URI (expected %u bytes at depth %u and offset %llu/%llu, got %u bytes)"), | 1053 | "Internal error or bogus download URI (expected %lu bytes at depth %u and offset %llu/%llu, got %lu bytes)"), |
1054 | bs, | 1054 | bs, |
1055 | dr->depth, | 1055 | dr->depth, |
1056 | (unsigned long long) dr->offset, | 1056 | (unsigned long long) dr->offset, |
diff --git a/src/fs/gnunet-daemon-fsprofiler.c b/src/fs/gnunet-daemon-fsprofiler.c index 829906461..fbb7c6028 100644 --- a/src/fs/gnunet-daemon-fsprofiler.c +++ b/src/fs/gnunet-daemon-fsprofiler.c | |||
@@ -592,14 +592,14 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
592 | &replication_level)) | 592 | &replication_level)) |
593 | replication_level = 1; | 593 | replication_level = 1; |
594 | GNUNET_snprintf (myoptname, sizeof(myoptname), | 594 | GNUNET_snprintf (myoptname, sizeof(myoptname), |
595 | "DOWNLOAD-PATTERN-%u", my_peerid); | 595 | "DOWNLOAD-PATTERN-%llu", my_peerid); |
596 | if (GNUNET_OK != | 596 | if (GNUNET_OK != |
597 | GNUNET_CONFIGURATION_get_value_string (cfg, | 597 | GNUNET_CONFIGURATION_get_value_string (cfg, |
598 | "FSPROFILER", myoptname, | 598 | "FSPROFILER", myoptname, |
599 | &download_pattern)) | 599 | &download_pattern)) |
600 | download_pattern = GNUNET_strdup (""); | 600 | download_pattern = GNUNET_strdup (""); |
601 | GNUNET_snprintf (myoptname, sizeof(myoptname), | 601 | GNUNET_snprintf (myoptname, sizeof(myoptname), |
602 | "PUBLISH-PATTERN-%u", my_peerid); | 602 | "PUBLISH-PATTERN-%llu", my_peerid); |
603 | if (GNUNET_OK != | 603 | if (GNUNET_OK != |
604 | GNUNET_CONFIGURATION_get_value_string (cfg, | 604 | GNUNET_CONFIGURATION_get_value_string (cfg, |
605 | "FSPROFILER", myoptname, | 605 | "FSPROFILER", myoptname, |
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 91fcd8f8a..dea467669 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -475,6 +475,7 @@ uri_ksk_continuation (void *cls, | |||
475 | const char *emsg) | 475 | const char *emsg) |
476 | { | 476 | { |
477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 477 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
478 | const struct GNUNET_IDENTITY_PrivateKey *pk; | ||
478 | 479 | ||
479 | if (NULL != emsg) | 480 | if (NULL != emsg) |
480 | { | 481 | { |
@@ -486,7 +487,10 @@ uri_ksk_continuation (void *cls, | |||
486 | GNUNET_SCHEDULER_shutdown (); | 487 | GNUNET_SCHEDULER_shutdown (); |
487 | return; | 488 | return; |
488 | } | 489 | } |
489 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 490 | pk = GNUNET_IDENTITY_ego_get_private_key (namespace); |
491 | if (GNUNET_IDENTITY_TYPE_ECDSA != ntohl (pk->type)) | ||
492 | return; | ||
493 | priv = &pk->ecdsa_key; | ||
490 | GNUNET_FS_publish_sks (ctx, | 494 | GNUNET_FS_publish_sks (ctx, |
491 | priv, | 495 | priv, |
492 | this_id, | 496 | this_id, |
@@ -569,6 +573,7 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
569 | { | 573 | { |
570 | struct GNUNET_FS_FileInformation *fi; | 574 | struct GNUNET_FS_FileInformation *fi; |
571 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; | 575 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv; |
576 | const struct GNUNET_IDENTITY_PrivateKey *pk; | ||
572 | 577 | ||
573 | fi = get_file_information (directory_scan_result); | 578 | fi = get_file_information (directory_scan_result); |
574 | GNUNET_FS_share_tree_free (directory_scan_result); | 579 | GNUNET_FS_share_tree_free (directory_scan_result); |
@@ -586,10 +591,13 @@ directory_trim_complete (struct GNUNET_FS_ShareTreeItem *directory_scan_result) | |||
586 | GNUNET_SCHEDULER_shutdown (); | 591 | GNUNET_SCHEDULER_shutdown (); |
587 | return; | 592 | return; |
588 | } | 593 | } |
589 | if (NULL == namespace) | 594 | priv = NULL; |
590 | priv = NULL; | 595 | if (NULL != namespace) |
591 | else | 596 | { |
592 | priv = GNUNET_IDENTITY_ego_get_private_key (namespace); | 597 | pk = GNUNET_IDENTITY_ego_get_private_key (namespace); |
598 | GNUNET_assert (GNUNET_IDENTITY_TYPE_ECDSA == ntohl (pk->type)); | ||
599 | priv = &pk->ecdsa_key; | ||
600 | } | ||
593 | pc = GNUNET_FS_publish_start (ctx, | 601 | pc = GNUNET_FS_publish_start (ctx, |
594 | fi, | 602 | fi, |
595 | priv, | 603 | priv, |
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 5a9c70997..744ba66ec 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -109,6 +109,7 @@ libgnunet_plugin_rest_gns_la_SOURCES = \ | |||
109 | plugin_rest_gns.c | 109 | plugin_rest_gns.c |
110 | libgnunet_plugin_rest_gns_la_LIBADD = \ | 110 | libgnunet_plugin_rest_gns_la_LIBADD = \ |
111 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 111 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
112 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \ | ||
112 | libgnunetgns.la \ | 113 | libgnunetgns.la \ |
113 | $(top_builddir)/src/rest/libgnunetrest.la \ | 114 | $(top_builddir)/src/rest/libgnunetrest.la \ |
114 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 115 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
@@ -124,6 +125,7 @@ libgnunet_plugin_gnsrecord_gns_la_SOURCES = \ | |||
124 | plugin_gnsrecord_gns.c | 125 | plugin_gnsrecord_gns.c |
125 | libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ | 126 | libgnunet_plugin_gnsrecord_gns_la_LIBADD = \ |
126 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 127 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
128 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
127 | $(top_builddir)/src/util/libgnunetutil.la \ | 129 | $(top_builddir)/src/util/libgnunetutil.la \ |
128 | $(LTLIBINTL) | 130 | $(LTLIBINTL) |
129 | libgnunet_plugin_gnsrecord_gns_la_LDFLAGS = \ | 131 | libgnunet_plugin_gnsrecord_gns_la_LDFLAGS = \ |
@@ -135,6 +137,7 @@ gnunet_gns_SOURCES = \ | |||
135 | gnunet_gns_LDADD = \ | 137 | gnunet_gns_LDADD = \ |
136 | libgnunetgns.la \ | 138 | libgnunetgns.la \ |
137 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 139 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
140 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
138 | $(top_builddir)/src/util/libgnunetutil.la \ | 141 | $(top_builddir)/src/util/libgnunetutil.la \ |
139 | $(LIBIDN) $(LIBIDN2) \ | 142 | $(LIBIDN) $(LIBIDN2) \ |
140 | $(GN_LIBINTL) | 143 | $(GN_LIBINTL) |
@@ -144,6 +147,7 @@ gnunet_gns_benchmark_SOURCES = \ | |||
144 | gnunet_gns_benchmark_LDADD = \ | 147 | gnunet_gns_benchmark_LDADD = \ |
145 | libgnunetgns.la \ | 148 | libgnunetgns.la \ |
146 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 149 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
150 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
147 | $(top_builddir)/src/util/libgnunetutil.la \ | 151 | $(top_builddir)/src/util/libgnunetutil.la \ |
148 | $(GN_LIBINTL) | 152 | $(GN_LIBINTL) |
149 | 153 | ||
@@ -247,6 +251,7 @@ libgnunet_plugin_block_gns_la_LIBADD = \ | |||
247 | $(top_builddir)/src/util/libgnunetutil.la \ | 251 | $(top_builddir)/src/util/libgnunetutil.la \ |
248 | $(top_builddir)/src/block/libgnunetblock.la \ | 252 | $(top_builddir)/src/block/libgnunetblock.la \ |
249 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | 253 | $(top_builddir)/src/block/libgnunetblockgroup.la \ |
254 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
250 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la | 255 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la |
251 | libgnunet_plugin_block_gns_la_LDFLAGS = \ | 256 | libgnunet_plugin_block_gns_la_LDFLAGS = \ |
252 | $(GN_LIBINTL) \ | 257 | $(GN_LIBINTL) \ |
diff --git a/src/gns/gns.h b/src/gns/gns.h index a193632b7..d824742ad 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -48,7 +48,7 @@ struct LookupMessage | |||
48 | /** | 48 | /** |
49 | * Zone that is to be used for lookup | 49 | * Zone that is to be used for lookup |
50 | */ | 50 | */ |
51 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 51 | struct GNUNET_IDENTITY_PublicKey zone; |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Local options for where to look for results | 54 | * Local options for where to look for results |
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index bf95bf340..841a0d240 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -343,7 +343,7 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | |||
343 | struct GNUNET_GNS_LookupRequest * | 343 | struct GNUNET_GNS_LookupRequest * |
344 | GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, | 344 | GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, |
345 | const char *name, | 345 | const char *name, |
346 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 346 | const struct GNUNET_IDENTITY_PublicKey *zone, |
347 | uint32_t type, | 347 | uint32_t type, |
348 | enum GNUNET_GNS_LocalOptions options, | 348 | enum GNUNET_GNS_LocalOptions options, |
349 | uint16_t recursion_depth_limit, | 349 | uint16_t recursion_depth_limit, |
@@ -411,7 +411,7 @@ GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, | |||
411 | struct GNUNET_GNS_LookupRequest* | 411 | struct GNUNET_GNS_LookupRequest* |
412 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | 412 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, |
413 | const char *name, | 413 | const char *name, |
414 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 414 | const struct GNUNET_IDENTITY_PublicKey *zone, |
415 | uint32_t type, | 415 | uint32_t type, |
416 | enum GNUNET_GNS_LocalOptions options, | 416 | enum GNUNET_GNS_LocalOptions options, |
417 | GNUNET_GNS_LookupResultProcessor proc, | 417 | GNUNET_GNS_LookupResultProcessor proc, |
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c index 3ebf07db6..b883662ad 100644 --- a/src/gns/gns_tld_api.c +++ b/src/gns/gns_tld_api.c | |||
@@ -167,7 +167,7 @@ process_lookup_result (void *cls, | |||
167 | */ | 167 | */ |
168 | static void | 168 | static void |
169 | lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | 169 | lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, |
170 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 170 | const struct GNUNET_IDENTITY_PublicKey *pkey) |
171 | { | 171 | { |
172 | ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle, | 172 | ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle, |
173 | ltr->name, | 173 | ltr->name, |
@@ -190,11 +190,11 @@ lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, | |||
190 | */ | 190 | */ |
191 | static void | 191 | static void |
192 | identity_zone_cb (void *cls, | 192 | identity_zone_cb (void *cls, |
193 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 193 | const struct GNUNET_IDENTITY_PrivateKey *priv, |
194 | const char *ego_name) | 194 | const char *ego_name) |
195 | { | 195 | { |
196 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; | 196 | struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; |
197 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 197 | struct GNUNET_IDENTITY_PublicKey pkey; |
198 | 198 | ||
199 | ltr->id_co = NULL; | 199 | ltr->id_co = NULL; |
200 | if (NULL == priv) | 200 | if (NULL == priv) |
@@ -219,7 +219,7 @@ identity_zone_cb (void *cls, | |||
219 | ltr->options = GNUNET_GNS_LO_NO_DHT; | 219 | ltr->options = GNUNET_GNS_LO_NO_DHT; |
220 | else | 220 | else |
221 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; | 221 | ltr->options = GNUNET_GNS_LO_LOCAL_MASTER; |
222 | GNUNET_CRYPTO_ecdsa_key_get_public (priv, &pkey); | 222 | GNUNET_IDENTITY_key_get_public (priv, &pkey); |
223 | lookup_with_public_key (ltr, &pkey); | 223 | lookup_with_public_key (ltr, &pkey); |
224 | } | 224 | } |
225 | 225 | ||
@@ -249,7 +249,7 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
249 | const char *tld; | 249 | const char *tld; |
250 | char *dot_tld; | 250 | char *dot_tld; |
251 | char *zonestr; | 251 | char *zonestr; |
252 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 252 | struct GNUNET_IDENTITY_PublicKey pkey; |
253 | 253 | ||
254 | ltr = GNUNET_new (struct GNUNET_GNS_LookupWithTldRequest); | 254 | ltr = GNUNET_new (struct GNUNET_GNS_LookupWithTldRequest); |
255 | ltr->gns_handle = handle; | 255 | ltr->gns_handle = handle; |
@@ -261,8 +261,10 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
261 | /* start with trivial case: TLD is zkey */ | 261 | /* start with trivial case: TLD is zkey */ |
262 | tld = get_tld (ltr->name); | 262 | tld = get_tld (ltr->name); |
263 | if (GNUNET_OK == | 263 | if (GNUNET_OK == |
264 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tld, strlen (tld), &pkey)) | 264 | GNUNET_IDENTITY_public_key_from_string (tld, &pkey)) |
265 | { | 265 | { |
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
267 | "`%s' seems to be a valid zone key\n", tld); | ||
266 | eat_tld (ltr->name, tld); | 268 | eat_tld (ltr->name, tld); |
267 | lookup_with_public_key (ltr, &pkey); | 269 | lookup_with_public_key (ltr, &pkey); |
268 | return ltr; | 270 | return ltr; |
@@ -281,9 +283,8 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
281 | &zonestr)) | 283 | &zonestr)) |
282 | { | 284 | { |
283 | if (GNUNET_OK != | 285 | if (GNUNET_OK != |
284 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zonestr, | 286 | GNUNET_IDENTITY_public_key_from_string (zonestr, |
285 | strlen (zonestr), | 287 | &pkey)) |
286 | &pkey)) | ||
287 | { | 288 | { |
288 | GNUNET_log_config_invalid ( | 289 | GNUNET_log_config_invalid ( |
289 | GNUNET_ERROR_TYPE_ERROR, | 290 | GNUNET_ERROR_TYPE_ERROR, |
@@ -304,6 +305,8 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, | |||
304 | } | 305 | } |
305 | GNUNET_free (dot_tld); | 306 | GNUNET_free (dot_tld); |
306 | } | 307 | } |
308 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
309 | "`%s' should be a valid ego\n", ltr->name); | ||
307 | ltr->id_co = | 310 | ltr->id_co = |
308 | GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg, | 311 | GNUNET_IDENTITY_ego_lookup_by_suffix (ltr->gns_handle->cfg, |
309 | ltr->name, | 312 | ltr->name, |
diff --git a/src/gns/gnunet-gns-import.c b/src/gns/gnunet-gns-import.c index 78db28cab..972fb49cd 100644 --- a/src/gns/gnunet-gns-import.c +++ b/src/gns/gnunet-gns-import.c | |||
@@ -168,12 +168,17 @@ check_pkey (unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, | |||
168 | char *pk, int *found_rec) | 168 | char *pk, int *found_rec) |
169 | { | 169 | { |
170 | int i; | 170 | int i; |
171 | struct GNUNET_IDENTITY_PublicKey pubkey; | ||
171 | 172 | ||
172 | for (i = 0; i < rd_len; i++) | 173 | for (i = 0; i < rd_len; i++) |
173 | { | 174 | { |
174 | char *s; | 175 | char *s; |
175 | if ((GNUNET_GNSRECORD_TYPE_PKEY != rd[i].record_type) || | 176 | if (sizeof (uint32_t) > rd[i].data_size) |
176 | (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) ) | 177 | continue; |
178 | if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (rd[i].data, | ||
179 | rd[i].data_size, | ||
180 | rd[i].record_type, | ||
181 | &pubkey)) | ||
177 | continue; | 182 | continue; |
178 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | 183 | s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
179 | rd[i].data, | 184 | rd[i].data, |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 8c5b2d6c4..52300ae3b 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -123,7 +123,7 @@ struct GNS_TopLevelDomain | |||
123 | /** | 123 | /** |
124 | * Public key associated with the @a tld. | 124 | * Public key associated with the @a tld. |
125 | */ | 125 | */ |
126 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 126 | struct GNUNET_IDENTITY_PublicKey pkey; |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Top-level domain as a string, including leading ".". | 129 | * Top-level domain as a string, including leading ".". |
@@ -177,7 +177,7 @@ static struct GNS_TopLevelDomain *tld_tail; | |||
177 | */ | 177 | */ |
178 | int | 178 | int |
179 | GNS_find_tld (const char *tld_str, | 179 | GNS_find_tld (const char *tld_str, |
180 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 180 | struct GNUNET_IDENTITY_PublicKey *pkey) |
181 | { | 181 | { |
182 | if ('\0' == *tld_str) | 182 | if ('\0' == *tld_str) |
183 | return GNUNET_NO; | 183 | return GNUNET_NO; |
@@ -485,7 +485,7 @@ read_service_conf (void *cls, | |||
485 | const char *option, | 485 | const char *option, |
486 | const char *value) | 486 | const char *value) |
487 | { | 487 | { |
488 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 488 | struct GNUNET_IDENTITY_PublicKey pk; |
489 | struct GNS_TopLevelDomain *tld; | 489 | struct GNS_TopLevelDomain *tld; |
490 | 490 | ||
491 | (void) cls; | 491 | (void) cls; |
diff --git a/src/gns/gnunet-service-gns.h b/src/gns/gnunet-service-gns.h index 2a432f8aa..d4fb9ec9f 100644 --- a/src/gns/gnunet-service-gns.h +++ b/src/gns/gnunet-service-gns.h | |||
@@ -26,6 +26,7 @@ | |||
26 | #ifndef GNUNET_SERVICE_GNS_H | 26 | #ifndef GNUNET_SERVICE_GNS_H |
27 | #define GNUNET_SERVICE_GNS_H | 27 | #define GNUNET_SERVICE_GNS_H |
28 | 28 | ||
29 | #include "gnunet_identity_service.h" | ||
29 | 30 | ||
30 | /** | 31 | /** |
31 | * Find GNS zone belonging to TLD @a tld. | 32 | * Find GNS zone belonging to TLD @a tld. |
@@ -36,7 +37,7 @@ | |||
36 | */ | 37 | */ |
37 | int | 38 | int |
38 | GNS_find_tld (const char *tld_str, | 39 | GNS_find_tld (const char *tld_str, |
39 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | 40 | struct GNUNET_IDENTITY_PublicKey *pkey); |
40 | 41 | ||
41 | 42 | ||
42 | /** | 43 | /** |
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c index 19416a506..b53f4af6b 100644 --- a/src/gns/gnunet-service-gns_interceptor.c +++ b/src/gns/gnunet-service-gns_interceptor.c | |||
@@ -314,7 +314,7 @@ handle_dns_request (void *cls, | |||
314 | { | 314 | { |
315 | struct GNUNET_DNSPARSER_Packet *p; | 315 | struct GNUNET_DNSPARSER_Packet *p; |
316 | struct InterceptLookupHandle *ilh; | 316 | struct InterceptLookupHandle *ilh; |
317 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 317 | struct GNUNET_IDENTITY_PublicKey zone; |
318 | 318 | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
320 | "Hijacked a DNS request. Processing.\n"); | 320 | "Hijacked a DNS request. Processing.\n"); |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index cb75b23c7..d9d0d3099 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -173,7 +173,7 @@ struct AuthorityChain | |||
173 | /** | 173 | /** |
174 | * The zone of the GNS authority | 174 | * The zone of the GNS authority |
175 | */ | 175 | */ |
176 | struct GNUNET_CRYPTO_EcdsaPublicKey gns_authority; | 176 | struct GNUNET_IDENTITY_PublicKey gns_authority; |
177 | 177 | ||
178 | struct | 178 | struct |
179 | { | 179 | { |
@@ -305,7 +305,7 @@ struct GNS_ResolverHandle | |||
305 | /** | 305 | /** |
306 | * The top-level GNS authoritative zone to query | 306 | * The top-level GNS authoritative zone to query |
307 | */ | 307 | */ |
308 | struct GNUNET_CRYPTO_EcdsaPublicKey authority_zone; | 308 | struct GNUNET_IDENTITY_PublicKey authority_zone; |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * called when resolution phase finishes | 311 | * called when resolution phase finishes |
@@ -1251,7 +1251,7 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1251 | const char *tld; | 1251 | const char *tld; |
1252 | struct AuthorityChain *ac; | 1252 | struct AuthorityChain *ac; |
1253 | int af; | 1253 | int af; |
1254 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 1254 | struct GNUNET_IDENTITY_PublicKey zone; |
1255 | 1255 | ||
1256 | nlen = strlen (cname); | 1256 | nlen = strlen (cname); |
1257 | tld = GNS_get_tld (cname); | 1257 | tld = GNS_get_tld (cname); |
@@ -1296,7 +1296,7 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1296 | { | 1296 | { |
1297 | GNUNET_asprintf (&res, | 1297 | GNUNET_asprintf (&res, |
1298 | "%.*s", | 1298 | "%.*s", |
1299 | strlen (cname) - (strlen (tld) + 1), | 1299 | (int) (strlen (cname) - (strlen (tld) + 1)), |
1300 | cname); | 1300 | cname); |
1301 | } | 1301 | } |
1302 | else | 1302 | else |
@@ -1305,7 +1305,7 @@ handle_gns_cname_result (struct GNS_ResolverHandle *rh, | |||
1305 | "%.*s.%.*s", | 1305 | "%.*s.%.*s", |
1306 | (int) rh->name_resolution_pos, | 1306 | (int) rh->name_resolution_pos, |
1307 | rh->name, | 1307 | rh->name, |
1308 | (int) strlen (cname) - (strlen (tld) + 1), | 1308 | (int) (strlen (cname) - (strlen (tld) + 1)), |
1309 | cname); | 1309 | cname); |
1310 | } | 1310 | } |
1311 | rh->name_resolution_pos = strlen (res); | 1311 | rh->name_resolution_pos = strlen (res); |
@@ -1696,10 +1696,13 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | |||
1696 | const struct GNUNET_GNSRECORD_Data *rd) | 1696 | const struct GNUNET_GNSRECORD_Data *rd) |
1697 | { | 1697 | { |
1698 | struct AuthorityChain *ac; | 1698 | struct AuthorityChain *ac; |
1699 | struct GNUNET_IDENTITY_PublicKey auth; | ||
1699 | 1700 | ||
1700 | /* delegation to another zone */ | 1701 | /* delegation to another zone */ |
1701 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != | 1702 | if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (rd->data, |
1702 | rd->data_size) | 1703 | rd->data_size, |
1704 | rd->record_type, | ||
1705 | &auth)) | ||
1703 | { | 1706 | { |
1704 | GNUNET_break_op (0); | 1707 | GNUNET_break_op (0); |
1705 | fail_resolution (rh); | 1708 | fail_resolution (rh); |
@@ -1709,9 +1712,7 @@ recursive_pkey_resolution (struct GNS_ResolverHandle *rh, | |||
1709 | ac = GNUNET_new (struct AuthorityChain); | 1712 | ac = GNUNET_new (struct AuthorityChain); |
1710 | ac->rh = rh; | 1713 | ac->rh = rh; |
1711 | ac->gns_authority = GNUNET_YES; | 1714 | ac->gns_authority = GNUNET_YES; |
1712 | GNUNET_memcpy (&ac->authority_info.gns_authority, | 1715 | ac->authority_info.gns_authority = auth; |
1713 | rd->data, | ||
1714 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
1715 | ac->label = resolver_lookup_get_next_label (rh); | 1716 | ac->label = resolver_lookup_get_next_label (rh); |
1716 | /* add AC to tail */ | 1717 | /* add AC to tail */ |
1717 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 1718 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, |
@@ -1754,7 +1755,7 @@ recursive_gns2dns_resolution (struct GNS_ResolverHandle *rh, | |||
1754 | char *n; | 1755 | char *n; |
1755 | size_t off; | 1756 | size_t off; |
1756 | struct Gns2DnsPending *gp; | 1757 | struct Gns2DnsPending *gp; |
1757 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 1758 | struct GNUNET_IDENTITY_PublicKey zone; |
1758 | struct sockaddr_in v4; | 1759 | struct sockaddr_in v4; |
1759 | struct sockaddr_in6 v6; | 1760 | struct sockaddr_in6 v6; |
1760 | 1761 | ||
@@ -2257,19 +2258,25 @@ handle_gns_resolution_result (void *cls, | |||
2257 | break; | 2258 | break; |
2258 | 2259 | ||
2259 | case GNUNET_GNSRECORD_TYPE_PKEY: | 2260 | case GNUNET_GNSRECORD_TYPE_PKEY: |
2261 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
2260 | { | 2262 | { |
2261 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 2263 | struct GNUNET_IDENTITY_PublicKey pubkey; |
2262 | 2264 | if (rd[i].data_size < sizeof(uint32_t)) | |
2263 | if (rd[i].data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) | 2265 | { |
2266 | GNUNET_break_op (0); | ||
2267 | break; | ||
2268 | } | ||
2269 | if (GNUNET_OK != | ||
2270 | GNUNET_GNSRECORD_identity_from_data (rd[i].data, | ||
2271 | rd[i].data_size, | ||
2272 | rd[i].record_type, | ||
2273 | &pubkey)) | ||
2264 | { | 2274 | { |
2265 | GNUNET_break_op (0); | 2275 | GNUNET_break_op (0); |
2266 | break; | 2276 | break; |
2267 | } | 2277 | } |
2268 | GNUNET_memcpy (&pub, | ||
2269 | rd[i].data, | ||
2270 | rd[i].data_size); | ||
2271 | rd_off++; | 2278 | rd_off++; |
2272 | if (GNUNET_GNSRECORD_TYPE_PKEY != rh->record_type) | 2279 | if (rd[i].record_type != rh->record_type) |
2273 | { | 2280 | { |
2274 | /* try to resolve "@" */ | 2281 | /* try to resolve "@" */ |
2275 | struct AuthorityChain *ac; | 2282 | struct AuthorityChain *ac; |
@@ -2277,7 +2284,7 @@ handle_gns_resolution_result (void *cls, | |||
2277 | ac = GNUNET_new (struct AuthorityChain); | 2284 | ac = GNUNET_new (struct AuthorityChain); |
2278 | ac->rh = rh; | 2285 | ac->rh = rh; |
2279 | ac->gns_authority = GNUNET_YES; | 2286 | ac->gns_authority = GNUNET_YES; |
2280 | ac->authority_info.gns_authority = pub; | 2287 | ac->authority_info.gns_authority = pubkey; |
2281 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); | 2288 | ac->label = GNUNET_strdup (GNUNET_GNS_EMPTY_LABEL_AT); |
2282 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, | 2289 | GNUNET_CONTAINER_DLL_insert_tail (rh->ac_head, |
2283 | rh->ac_tail, | 2290 | rh->ac_tail, |
@@ -2367,6 +2374,7 @@ handle_gns_resolution_result (void *cls, | |||
2367 | return; | 2374 | return; |
2368 | 2375 | ||
2369 | case GNUNET_GNSRECORD_TYPE_PKEY: | 2376 | case GNUNET_GNSRECORD_TYPE_PKEY: |
2377 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
2370 | GNUNET_break_op (1 == rd_count); /* PKEY should be unique */ | 2378 | GNUNET_break_op (1 == rd_count); /* PKEY should be unique */ |
2371 | recursive_pkey_resolution (rh, | 2379 | recursive_pkey_resolution (rh, |
2372 | &rd[0]); | 2380 | &rd[0]); |
@@ -2469,10 +2477,7 @@ handle_dht_response (void *cls, | |||
2469 | return; | 2477 | return; |
2470 | } | 2478 | } |
2471 | block = data; | 2479 | block = data; |
2472 | if (size != | 2480 | if (size != GNUNET_GNSRECORD_block_get_size (block)) |
2473 | ntohl (block->purpose.size) | ||
2474 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
2475 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) | ||
2476 | { | 2481 | { |
2477 | /* how did this pass DHT block validation!? */ | 2482 | /* how did this pass DHT block validation!? */ |
2478 | GNUNET_break (0); | 2483 | GNUNET_break (0); |
@@ -2480,8 +2485,8 @@ handle_dht_response (void *cls, | |||
2480 | return; | 2485 | return; |
2481 | } | 2486 | } |
2482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2487 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2483 | "Decrypting DHT block of size %u for `%s', expires %s\n", | 2488 | "Decrypting DHT block of size %lu for `%s', expires %s\n", |
2484 | ntohl (block->purpose.size), | 2489 | GNUNET_GNSRECORD_block_get_size (block), |
2485 | rh->name, | 2490 | rh->name, |
2486 | GNUNET_STRINGS_absolute_time_to_string (exp)); | 2491 | GNUNET_STRINGS_absolute_time_to_string (exp)); |
2487 | if (GNUNET_OK != | 2492 | if (GNUNET_OK != |
@@ -2495,8 +2500,8 @@ handle_dht_response (void *cls, | |||
2495 | fail_resolution (rh); | 2500 | fail_resolution (rh); |
2496 | return; | 2501 | return; |
2497 | } | 2502 | } |
2498 | if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh ( | 2503 | if (0 == GNUNET_TIME_absolute_get_remaining ( |
2499 | block->expiration_time)). | 2504 | GNUNET_GNSRECORD_block_get_expiration (block)). |
2500 | rel_value_us) | 2505 | rel_value_us) |
2501 | { | 2506 | { |
2502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2594,7 +2599,7 @@ handle_namecache_block_response (void *cls, | |||
2594 | struct GNS_ResolverHandle *rh = cls; | 2599 | struct GNS_ResolverHandle *rh = cls; |
2595 | struct AuthorityChain *ac = rh->ac_tail; | 2600 | struct AuthorityChain *ac = rh->ac_tail; |
2596 | const char *label = ac->label; | 2601 | const char *label = ac->label; |
2597 | const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = | 2602 | const struct GNUNET_IDENTITY_PublicKey *auth = |
2598 | &ac->authority_info.gns_authority; | 2603 | &ac->authority_info.gns_authority; |
2599 | struct GNUNET_HashCode query; | 2604 | struct GNUNET_HashCode query; |
2600 | 2605 | ||
@@ -2604,8 +2609,8 @@ handle_namecache_block_response (void *cls, | |||
2604 | ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && | 2609 | ((GNUNET_GNS_LO_LOCAL_MASTER == rh->options) && |
2605 | (ac != rh->ac_head))) && | 2610 | (ac != rh->ac_head))) && |
2606 | ((NULL == block) || | 2611 | ((NULL == block) || |
2607 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh ( | 2612 | (0 == GNUNET_TIME_absolute_get_remaining ( |
2608 | block->expiration_time)). | 2613 | GNUNET_GNSRECORD_block_get_expiration (block)). |
2609 | rel_value_us))) | 2614 | rel_value_us))) |
2610 | { | 2615 | { |
2611 | /* namecache knows nothing; try DHT lookup */ | 2616 | /* namecache knows nothing; try DHT lookup */ |
@@ -2622,8 +2627,8 @@ handle_namecache_block_response (void *cls, | |||
2622 | } | 2627 | } |
2623 | 2628 | ||
2624 | if ((NULL == block) || | 2629 | if ((NULL == block) || |
2625 | (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh ( | 2630 | (0 == GNUNET_TIME_absolute_get_remaining ( |
2626 | block->expiration_time)). | 2631 | GNUNET_GNSRECORD_block_get_expiration (block)). |
2627 | rel_value_us)) | 2632 | rel_value_us)) |
2628 | { | 2633 | { |
2629 | /* DHT not permitted and no local result, fail */ | 2634 | /* DHT not permitted and no local result, fail */ |
@@ -2857,7 +2862,7 @@ start_resolver_lookup (void *cls) | |||
2857 | * @return handle to cancel operation | 2862 | * @return handle to cancel operation |
2858 | */ | 2863 | */ |
2859 | struct GNS_ResolverHandle * | 2864 | struct GNS_ResolverHandle * |
2860 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 2865 | GNS_resolver_lookup (const struct GNUNET_IDENTITY_PublicKey *zone, |
2861 | uint32_t record_type, | 2866 | uint32_t record_type, |
2862 | const char *name, | 2867 | const char *name, |
2863 | enum GNUNET_GNS_LocalOptions options, | 2868 | enum GNUNET_GNS_LocalOptions options, |
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 3dab3c91a..b099c5d65 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h | |||
@@ -86,7 +86,7 @@ typedef void | |||
86 | * @return handle to cancel operation | 86 | * @return handle to cancel operation |
87 | */ | 87 | */ |
88 | struct GNS_ResolverHandle * | 88 | struct GNS_ResolverHandle * |
89 | GNS_resolver_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 89 | GNS_resolver_lookup (const struct GNUNET_IDENTITY_PublicKey *zone, |
90 | uint32_t record_type, | 90 | uint32_t record_type, |
91 | const char *name, | 91 | const char *name, |
92 | enum GNUNET_GNS_LocalOptions options, | 92 | enum GNUNET_GNS_LocalOptions options, |
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index aabedcaac..9b58c9034 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -145,17 +145,13 @@ block_plugin_gns_evaluate (void *cls, | |||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
146 | } | 146 | } |
147 | block = reply_block; | 147 | block = reply_block; |
148 | if (ntohl (block->purpose.size) + sizeof(struct | 148 | if (GNUNET_GNSRECORD_block_get_size (block) > reply_block_size) |
149 | GNUNET_CRYPTO_EcdsaSignature) | ||
150 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != | ||
151 | reply_block_size) | ||
152 | { | 149 | { |
153 | GNUNET_break_op (0); | 150 | GNUNET_break_op (0); |
154 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
155 | } | 152 | } |
156 | GNUNET_CRYPTO_hash (&block->derived_key, | 153 | GNUNET_GNSRECORD_query_from_block (block, |
157 | sizeof(block->derived_key), | 154 | &h); |
158 | &h); | ||
159 | if (0 != GNUNET_memcmp (&h, query)) | 155 | if (0 != GNUNET_memcmp (&h, query)) |
160 | { | 156 | { |
161 | GNUNET_break_op (0); | 157 | GNUNET_break_op (0); |
@@ -206,9 +202,8 @@ block_plugin_gns_get_key (void *cls, | |||
206 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 202 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
207 | } | 203 | } |
208 | block = reply_block; | 204 | block = reply_block; |
209 | GNUNET_CRYPTO_hash (&block->derived_key, | 205 | GNUNET_GNSRECORD_query_from_block (block, |
210 | sizeof(block->derived_key), | 206 | key); |
211 | key); | ||
212 | return GNUNET_OK; | 207 | return GNUNET_OK; |
213 | } | 208 | } |
214 | 209 | ||
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c index 81f2b9eff..a2ad0b905 100644 --- a/src/gns/plugin_gnsrecord_gns.c +++ b/src/gns/plugin_gnsrecord_gns.c | |||
@@ -50,13 +50,18 @@ gns_value_to_string (void *cls, | |||
50 | size_t data_size) | 50 | size_t data_size) |
51 | { | 51 | { |
52 | const char *cdata; | 52 | const char *cdata; |
53 | struct GNUNET_IDENTITY_PublicKey pk; | ||
53 | 54 | ||
54 | switch (type) | 55 | switch (type) |
55 | { | 56 | { |
56 | case GNUNET_GNSRECORD_TYPE_PKEY: | 57 | case GNUNET_GNSRECORD_TYPE_PKEY: |
57 | if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) | 58 | case GNUNET_GNSRECORD_TYPE_EDKEY: |
59 | if (GNUNET_OK != GNUNET_GNSRECORD_identity_from_data (data, | ||
60 | data_size, | ||
61 | type, | ||
62 | &pk)) | ||
58 | return NULL; | 63 | return NULL; |
59 | return GNUNET_CRYPTO_ecdsa_public_key_to_string (data); | 64 | return GNUNET_IDENTITY_public_key_to_string (&pk); |
60 | 65 | ||
61 | case GNUNET_GNSRECORD_TYPE_NICK: | 66 | case GNUNET_GNSRECORD_TYPE_NICK: |
62 | return GNUNET_strndup (data, data_size); | 67 | return GNUNET_strndup (data, data_size); |
@@ -153,24 +158,35 @@ gns_string_to_value (void *cls, | |||
153 | void **data, | 158 | void **data, |
154 | size_t *data_size) | 159 | size_t *data_size) |
155 | { | 160 | { |
156 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 161 | struct GNUNET_IDENTITY_PublicKey pk; |
162 | uint32_t record_type; | ||
157 | 163 | ||
158 | if (NULL == s) | 164 | if (NULL == s) |
159 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
160 | switch (type) | 166 | switch (type) |
161 | { | 167 | { |
162 | case GNUNET_GNSRECORD_TYPE_PKEY: | 168 | case GNUNET_GNSRECORD_TYPE_PKEY: |
169 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
163 | if (GNUNET_OK != | 170 | if (GNUNET_OK != |
164 | GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey)) | 171 | GNUNET_IDENTITY_public_key_from_string (s, &pk)) |
165 | { | 172 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 173 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
167 | _ ("Unable to parse PKEY record `%s'\n"), | 174 | _ ("Unable to parse zone key record `%s'\n"), |
168 | s); | 175 | s); |
169 | return GNUNET_SYSERR; | 176 | return GNUNET_SYSERR; |
170 | } | 177 | } |
171 | *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | 178 | *data_size = GNUNET_IDENTITY_key_get_length (&pk); |
172 | GNUNET_memcpy (*data, &pkey, sizeof(pkey)); | 179 | if (GNUNET_OK != GNUNET_GNSRECORD_data_from_identity (&pk, |
173 | *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | 180 | (char **) data, |
181 | data_size, | ||
182 | &record_type)) | ||
183 | return GNUNET_SYSERR; | ||
184 | if (record_type != type) | ||
185 | { | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
187 | _("Record type does not match parsed record type\n")); | ||
188 | return GNUNET_SYSERR; | ||
189 | } | ||
174 | return GNUNET_OK; | 190 | return GNUNET_OK; |
175 | 191 | ||
176 | case GNUNET_GNSRECORD_TYPE_NICK: | 192 | case GNUNET_GNSRECORD_TYPE_NICK: |
@@ -301,6 +317,7 @@ static struct | |||
301 | const char *name; | 317 | const char *name; |
302 | uint32_t number; | 318 | uint32_t number; |
303 | } gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, | 319 | } gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, |
320 | { "EDKEY", GNUNET_GNSRECORD_TYPE_PKEY }, | ||
304 | { "NICK", GNUNET_GNSRECORD_TYPE_NICK }, | 321 | { "NICK", GNUNET_GNSRECORD_TYPE_NICK }, |
305 | { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO }, | 322 | { "LEHO", GNUNET_GNSRECORD_TYPE_LEHO }, |
306 | { "VPN", GNUNET_GNSRECORD_TYPE_VPN }, | 323 | { "VPN", GNUNET_GNSRECORD_TYPE_VPN }, |
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c index 6ec921f70..2ccb5be2b 100644 --- a/src/gns/plugin_rest_gns.c +++ b/src/gns/plugin_rest_gns.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "gnunet_rest_lib.h" | 28 | #include "gnunet_rest_lib.h" |
29 | #include "gnunet_json_lib.h" | 29 | #include "gnunet_json_lib.h" |
30 | #include "gnunet_gnsrecord_lib.h" | 30 | #include "gnunet_gnsrecord_lib.h" |
31 | #include "gnunet_gnsrecord_json_lib.h" | ||
31 | #include "gnunet_gns_service.h" | 32 | #include "gnunet_gns_service.h" |
32 | #include "microhttpd.h" | 33 | #include "microhttpd.h" |
33 | #include <jansson.h> | 34 | #include <jansson.h> |
@@ -264,7 +265,7 @@ handle_gns_response (void *cls, | |||
264 | return; | 265 | return; |
265 | } | 266 | } |
266 | 267 | ||
267 | result_obj = GNUNET_JSON_from_gnsrecord (handle->name, rd, rd_count); | 268 | result_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (handle->name, rd, rd_count); |
268 | 269 | ||
269 | result = json_dumps (result_obj, 0); | 270 | result = json_dumps (result_obj, 0); |
270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); | 271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result); |
diff --git a/src/gns/test_gns_dht_lookup.sh b/src/gns/test_gns_dht_lookup.sh index d5516fd03..8d446c507 100755 --- a/src/gns/test_gns_dht_lookup.sh +++ b/src/gns/test_gns_dht_lookup.sh | |||
@@ -26,6 +26,7 @@ gnunet-arm -i datastore -c test_gns_lookup.conf | |||
26 | gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf | 26 | gnunet-identity -C $OTHER_EGO -c test_gns_lookup.conf |
27 | DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}') | 27 | DELEGATED_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep $OTHER_EGO | awk '{print $3}') |
28 | gnunet-identity -C $MY_EGO -c test_gns_lookup.conf | 28 | gnunet-identity -C $MY_EGO -c test_gns_lookup.conf |
29 | echo "MYEGO: $MY_EGO OTHER_EGO: $DELEGATED_PKEY" | ||
29 | gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf | 30 | gnunet-namestore -p -z $MY_EGO -a -n b -t PKEY -V $DELEGATED_PKEY -e never -c test_gns_lookup.conf |
30 | #This works | 31 | #This works |
31 | gnunet-namestore -p -z $OTHER_EGO -a -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf | 32 | gnunet-namestore -p -z $OTHER_EGO -a -n www -t A -V $TEST_IP -e never -c test_gns_lookup.conf |
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am index 2e6eca7ba..ab604eb92 100644 --- a/src/gnsrecord/Makefile.am +++ b/src/gnsrecord/Makefile.am | |||
@@ -1,5 +1,5 @@ | |||
1 | # This Makefile.am is in the public domain | 1 | # This Makefile.am is in the public domain |
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | 2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include ${MHD_CFLAGS} |
3 | 3 | ||
4 | plugindir = $(libdir)/gnunet | 4 | plugindir = $(libdir)/gnunet |
5 | 5 | ||
@@ -30,12 +30,14 @@ TESTS = \ | |||
30 | endif | 30 | endif |
31 | 31 | ||
32 | lib_LTLIBRARIES = \ | 32 | lib_LTLIBRARIES = \ |
33 | libgnunetgnsrecord.la | 33 | libgnunetgnsrecord.la \ |
34 | libgnunetgnsrecordjson.la | ||
34 | 35 | ||
35 | gnunet_gnsrecord_tvg_SOURCES = \ | 36 | gnunet_gnsrecord_tvg_SOURCES = \ |
36 | gnunet-gnsrecord-tvg.c | 37 | gnunet-gnsrecord-tvg.c |
37 | gnunet_gnsrecord_tvg_LDADD = \ | 38 | gnunet_gnsrecord_tvg_LDADD = \ |
38 | $(top_builddir)/src/util/libgnunetutil.la \ | 39 | $(top_builddir)/src/util/libgnunetutil.la \ |
40 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
39 | libgnunetgnsrecord.la \ | 41 | libgnunetgnsrecord.la \ |
40 | $(GN_LIBINTL) | 42 | $(GN_LIBINTL) |
41 | 43 | ||
@@ -47,11 +49,26 @@ libgnunetgnsrecord_la_SOURCES = \ | |||
47 | gnsrecord_misc.c | 49 | gnsrecord_misc.c |
48 | libgnunetgnsrecord_la_LIBADD = \ | 50 | libgnunetgnsrecord_la_LIBADD = \ |
49 | $(top_builddir)/src/util/libgnunetutil.la \ | 51 | $(top_builddir)/src/util/libgnunetutil.la \ |
52 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
53 | $(LIBGCRYPT_LIBS) \ | ||
50 | $(GN_LIBINTL) | 54 | $(GN_LIBINTL) |
55 | libgnunetgnsrecord_la_DEPENDENCIES = \ | ||
56 | $(top_builddir)/src/identity/libgnunetidentity.la | ||
51 | libgnunetgnsrecord_la_LDFLAGS = \ | 57 | libgnunetgnsrecord_la_LDFLAGS = \ |
52 | $(GN_LIB_LDFLAGS) \ | 58 | $(GN_LIB_LDFLAGS) \ |
53 | -version-info 0:0:0 | 59 | -version-info 0:0:0 |
54 | 60 | ||
61 | libgnunetgnsrecordjson_la_SOURCES = \ | ||
62 | json_gnsrecord.c | ||
63 | libgnunetgnsrecordjson_la_LIBADD = \ | ||
64 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
65 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
66 | libgnunetgnsrecord.la \ | ||
67 | -ljansson \ | ||
68 | $(GN_LIBINTL) | ||
69 | libgnunetgnsrecordjson_la_LDFLAGS = \ | ||
70 | $(GN_LIB_LDFLAGS) \ | ||
71 | -version-info 0:0:0 | ||
55 | 72 | ||
56 | plugin_LTLIBRARIES = \ | 73 | plugin_LTLIBRARIES = \ |
57 | libgnunet_plugin_gnsrecord_dns.la | 74 | libgnunet_plugin_gnsrecord_dns.la |
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index c8919760a..9c551a936 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -37,6 +37,61 @@ | |||
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__) |
39 | 39 | ||
40 | ssize_t | ||
41 | ecdsa_symmetric_decrypt ( | ||
42 | const void *block, | ||
43 | size_t size, | ||
44 | const unsigned char *key, | ||
45 | const unsigned char *ctr, | ||
46 | void *result) | ||
47 | { | ||
48 | gcry_cipher_hd_t handle; | ||
49 | int rc; | ||
50 | |||
51 | GNUNET_assert (0 == gcry_cipher_open (&handle, GCRY_CIPHER_AES256, | ||
52 | GCRY_CIPHER_MODE_CTR, 0)); | ||
53 | rc = gcry_cipher_setkey (handle, | ||
54 | key, | ||
55 | GNUNET_CRYPTO_AES_KEY_LENGTH); | ||
56 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
57 | rc = gcry_cipher_setctr (handle, | ||
58 | ctr, | ||
59 | GNUNET_CRYPTO_AES_KEY_LENGTH / 2); | ||
60 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
61 | GNUNET_assert (0 == gcry_cipher_decrypt (handle, result, size, block, size)); | ||
62 | gcry_cipher_close (handle); | ||
63 | return size; | ||
64 | } | ||
65 | |||
66 | |||
67 | |||
68 | ssize_t | ||
69 | ecdsa_symmetric_encrypt ( | ||
70 | const void *block, | ||
71 | size_t size, | ||
72 | const unsigned char *key, | ||
73 | const unsigned char *ctr, | ||
74 | void *result) | ||
75 | { | ||
76 | gcry_cipher_hd_t handle; | ||
77 | int rc; | ||
78 | |||
79 | GNUNET_assert (0 == gcry_cipher_open (&handle, GCRY_CIPHER_AES256, | ||
80 | GCRY_CIPHER_MODE_CTR, 0)); | ||
81 | rc = gcry_cipher_setkey (handle, | ||
82 | key, | ||
83 | GNUNET_CRYPTO_AES_KEY_LENGTH); | ||
84 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
85 | rc = gcry_cipher_setctr (handle, | ||
86 | ctr, | ||
87 | GNUNET_CRYPTO_AES_KEY_LENGTH / 2); | ||
88 | GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); | ||
89 | GNUNET_assert (0 == gcry_cipher_encrypt (handle, result, size, block, size)); | ||
90 | gcry_cipher_close (handle); | ||
91 | return size; | ||
92 | } | ||
93 | |||
94 | |||
40 | 95 | ||
41 | /** | 96 | /** |
42 | * Derive session key and iv from label and public key. | 97 | * Derive session key and iv from label and public key. |
@@ -47,25 +102,31 @@ | |||
47 | * @param pub public key to use for KDF | 102 | * @param pub public key to use for KDF |
48 | */ | 103 | */ |
49 | static void | 104 | static void |
50 | derive_block_aes_key (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | 105 | derive_block_aes_key (unsigned char *ctr, |
51 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | 106 | unsigned char *key, |
52 | const char *label, | 107 | const char *label, |
108 | uint64_t exp, | ||
53 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | 109 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
54 | { | 110 | { |
55 | static const char ctx_key[] = "gns-aes-ctx-key"; | 111 | static const char ctx_key[] = "gns-aes-ctx-key"; |
56 | static const char ctx_iv[] = "gns-aes-ctx-iv"; | 112 | static const char ctx_iv[] = "gns-aes-ctx-iv"; |
57 | 113 | ||
58 | GNUNET_CRYPTO_kdf (skey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey), | 114 | GNUNET_CRYPTO_kdf (key, GNUNET_CRYPTO_AES_KEY_LENGTH, |
59 | ctx_key, strlen (ctx_key), | 115 | ctx_key, strlen (ctx_key), |
60 | pub, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 116 | pub, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
61 | label, strlen (label), | 117 | label, strlen (label), |
62 | NULL, 0); | 118 | NULL, 0); |
63 | GNUNET_CRYPTO_kdf (iv, sizeof(struct | 119 | memset (ctr, 0, GNUNET_CRYPTO_AES_KEY_LENGTH / 2); |
64 | GNUNET_CRYPTO_SymmetricInitializationVector), | 120 | /** 4 byte nonce **/ |
121 | GNUNET_CRYPTO_kdf (ctr, 4, | ||
65 | ctx_iv, strlen (ctx_iv), | 122 | ctx_iv, strlen (ctx_iv), |
66 | pub, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 123 | pub, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), |
67 | label, strlen (label), | 124 | label, strlen (label), |
68 | NULL, 0); | 125 | NULL, 0); |
126 | /** Expiration time 64 bit. **/ | ||
127 | memcpy (ctr + 4, &exp, sizeof (exp)); | ||
128 | /** Set counter part to 1 **/ | ||
129 | ctr[15] |= 0x01; | ||
69 | } | 130 | } |
70 | 131 | ||
71 | 132 | ||
@@ -81,19 +142,20 @@ derive_block_aes_key (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
81 | * @return NULL on error (block too large) | 142 | * @return NULL on error (block too large) |
82 | */ | 143 | */ |
83 | static struct GNUNET_GNSRECORD_Block * | 144 | static struct GNUNET_GNSRECORD_Block * |
84 | block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 145 | block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
85 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, | 146 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, |
86 | struct GNUNET_TIME_Absolute expire, | 147 | struct GNUNET_TIME_Absolute expire, |
87 | const char *label, | 148 | const char *label, |
88 | const struct GNUNET_GNSRECORD_Data *rd, | 149 | const struct GNUNET_GNSRECORD_Data *rd, |
89 | unsigned int rd_count) | 150 | unsigned int rd_count) |
90 | { | 151 | { |
91 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, | 152 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, |
92 | rd); | 153 | rd); |
93 | struct GNUNET_GNSRECORD_Block *block; | 154 | struct GNUNET_GNSRECORD_Block *block; |
155 | struct GNUNET_GNSRECORD_EcdsaBlock *ecblock; | ||
94 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; | 156 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; |
95 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 157 | unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; |
96 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 158 | unsigned char skey[GNUNET_CRYPTO_AES_KEY_LENGTH]; |
97 | struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)]; | 159 | struct GNUNET_GNSRECORD_Data rdc[GNUNET_NZL (rd_count)]; |
98 | uint32_t rd_count_nbo; | 160 | uint32_t rd_count_nbo; |
99 | struct GNUNET_TIME_Absolute now; | 161 | struct GNUNET_TIME_Absolute now; |
@@ -140,35 +202,38 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
140 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) | 202 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) |
141 | + sizeof(uint32_t) | 203 | + sizeof(uint32_t) |
142 | + payload_len); | 204 | + payload_len); |
143 | block->purpose.size = htonl (sizeof(uint32_t) | 205 | ecblock = &block->ecdsa_block; |
144 | + payload_len | 206 | block->type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
145 | + sizeof(struct | 207 | ecblock->purpose.size = htonl (sizeof(uint32_t) |
146 | GNUNET_CRYPTO_EccSignaturePurpose) | 208 | + payload_len |
147 | + sizeof(struct GNUNET_TIME_AbsoluteNBO)); | 209 | + sizeof(struct |
148 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 210 | GNUNET_CRYPTO_EccSignaturePurpose) |
149 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); | 211 | + sizeof(struct GNUNET_TIME_AbsoluteNBO)); |
212 | ecblock->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
213 | ecblock->expiration_time = GNUNET_TIME_absolute_hton (expire); | ||
150 | /* encrypt and sign */ | 214 | /* encrypt and sign */ |
151 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, | 215 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, |
152 | label, | 216 | label, |
153 | "gns"); | 217 | "gns"); |
154 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, | 218 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, |
155 | &block->derived_key); | 219 | &ecblock->derived_key); |
156 | derive_block_aes_key (&iv, | 220 | derive_block_aes_key (ctr, |
157 | &skey, | 221 | skey, |
158 | label, | 222 | label, |
223 | ecblock->expiration_time.abs_value_us__, | ||
159 | pkey); | 224 | pkey); |
160 | GNUNET_break (payload_len + sizeof(uint32_t) == | 225 | GNUNET_break (payload_len + sizeof(uint32_t) == |
161 | GNUNET_CRYPTO_symmetric_encrypt (payload, | 226 | ecdsa_symmetric_encrypt (payload, |
162 | payload_len | 227 | payload_len |
163 | + sizeof(uint32_t), | 228 | + sizeof(uint32_t), |
164 | &skey, | 229 | skey, |
165 | &iv, | 230 | ctr, |
166 | &block[1])); | 231 | &ecblock[1])); |
167 | } | 232 | } |
168 | if (GNUNET_OK != | 233 | if (GNUNET_OK != |
169 | GNUNET_CRYPTO_ecdsa_sign_ (dkey, | 234 | GNUNET_CRYPTO_ecdsa_sign_ (dkey, |
170 | &block->purpose, | 235 | &ecblock->purpose, |
171 | &block->signature)) | 236 | &ecblock->signature)) |
172 | { | 237 | { |
173 | GNUNET_break (0); | 238 | GNUNET_break (0); |
174 | GNUNET_free (dkey); | 239 | GNUNET_free (dkey); |
@@ -191,7 +256,7 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
191 | * @return NULL on error (block too large) | 256 | * @return NULL on error (block too large) |
192 | */ | 257 | */ |
193 | struct GNUNET_GNSRECORD_Block * | 258 | struct GNUNET_GNSRECORD_Block * |
194 | GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 259 | GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, |
195 | struct GNUNET_TIME_Absolute expire, | 260 | struct GNUNET_TIME_Absolute expire, |
196 | const char *label, | 261 | const char *label, |
197 | const struct GNUNET_GNSRECORD_Data *rd, | 262 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -199,14 +264,21 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
199 | { | 264 | { |
200 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 265 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
201 | 266 | ||
202 | GNUNET_CRYPTO_ecdsa_key_get_public (key, | 267 | switch (ntohl (key->type)) |
203 | &pkey); | 268 | { |
204 | return block_create (key, | 269 | case GNUNET_GNSRECORD_TYPE_PKEY: |
205 | &pkey, | 270 | GNUNET_CRYPTO_ecdsa_key_get_public (&key->ecdsa_key, |
206 | expire, | 271 | &pkey); |
207 | label, | 272 | return block_create_ecdsa (&key->ecdsa_key, |
208 | rd, | 273 | &pkey, |
209 | rd_count); | 274 | expire, |
275 | label, | ||
276 | rd, | ||
277 | rd_count); | ||
278 | default: | ||
279 | GNUNET_assert (0); | ||
280 | } | ||
281 | return NULL; | ||
210 | } | 282 | } |
211 | 283 | ||
212 | 284 | ||
@@ -240,12 +312,19 @@ struct KeyCacheLine | |||
240 | * @return NULL on error (block too large) | 312 | * @return NULL on error (block too large) |
241 | */ | 313 | */ |
242 | struct GNUNET_GNSRECORD_Block * | 314 | struct GNUNET_GNSRECORD_Block * |
243 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 315 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *pkey, |
244 | struct GNUNET_TIME_Absolute expire, | 316 | struct GNUNET_TIME_Absolute expire, |
245 | const char *label, | 317 | const char *label, |
246 | const struct GNUNET_GNSRECORD_Data *rd, | 318 | const struct GNUNET_GNSRECORD_Data *rd, |
247 | unsigned int rd_count) | 319 | unsigned int rd_count) |
248 | { | 320 | { |
321 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key; | ||
322 | |||
323 | if (GNUNET_IDENTITY_TYPE_ECDSA != ntohl (pkey->type)) | ||
324 | { | ||
325 | return NULL; // FIXME | ||
326 | } | ||
327 | key = &pkey->ecdsa_key; | ||
249 | #define CSIZE 64 | 328 | #define CSIZE 64 |
250 | static struct KeyCacheLine cache[CSIZE]; | 329 | static struct KeyCacheLine cache[CSIZE]; |
251 | struct KeyCacheLine *line; | 330 | struct KeyCacheLine *line; |
@@ -261,12 +340,12 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
261 | &line->pkey); | 340 | &line->pkey); |
262 | } | 341 | } |
263 | #undef CSIZE | 342 | #undef CSIZE |
264 | return block_create (key, | 343 | return block_create_ecdsa (key, |
265 | &line->pkey, | 344 | &line->pkey, |
266 | expire, | 345 | expire, |
267 | label, | 346 | label, |
268 | rd, | 347 | rd, |
269 | rd_count); | 348 | rd_count); |
270 | } | 349 | } |
271 | 350 | ||
272 | 351 | ||
@@ -277,40 +356,40 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
277 | * @param block block to verify | 356 | * @param block block to verify |
278 | * @return #GNUNET_OK if the signature is valid | 357 | * @return #GNUNET_OK if the signature is valid |
279 | */ | 358 | */ |
280 | int | 359 | enum GNUNET_GenericReturnValue |
281 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) | 360 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) |
282 | { | 361 | { |
362 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key; | ||
363 | const struct GNUNET_GNSRECORD_EcdsaBlock *ecblock; | ||
364 | |||
365 | if (GNUNET_GNSRECORD_TYPE_PKEY != ntohl (block->type)) | ||
366 | { | ||
367 | GNUNET_break (0); | ||
368 | return GNUNET_NO; | ||
369 | } | ||
370 | ecblock = &block->ecdsa_block; | ||
371 | key = &ecblock->derived_key; | ||
372 | |||
283 | return GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, | 373 | return GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, |
284 | &block->purpose, | 374 | &ecblock->purpose, |
285 | &block->signature, | 375 | &ecblock->signature, |
286 | &block->derived_key); | 376 | key); |
287 | } | 377 | } |
288 | 378 | ||
289 | 379 | ||
290 | /** | 380 | enum GNUNET_GenericReturnValue |
291 | * Decrypt block. | 381 | block_decrypt_ecdsa (const struct GNUNET_GNSRECORD_EcdsaBlock *block, |
292 | * | 382 | const struct |
293 | * @param block block to decrypt | 383 | GNUNET_CRYPTO_EcdsaPublicKey *zone_key, |
294 | * @param zone_key public key of the zone | 384 | const char *label, |
295 | * @param label the name for the records | 385 | GNUNET_GNSRECORD_RecordCallback proc, |
296 | * @param proc function to call with the result | 386 | void *proc_cls) |
297 | * @param proc_cls closure for proc | ||
298 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | ||
299 | * not well-formed | ||
300 | */ | ||
301 | int | ||
302 | GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | ||
303 | const struct | ||
304 | GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | ||
305 | const char *label, | ||
306 | GNUNET_GNSRECORD_RecordCallback proc, | ||
307 | void *proc_cls) | ||
308 | { | 387 | { |
309 | size_t payload_len = ntohl (block->purpose.size) | 388 | size_t payload_len = ntohl (block->purpose.size) |
310 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 389 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
311 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | 390 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); |
312 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 391 | unsigned char ctr[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; |
313 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 392 | unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH]; |
314 | 393 | ||
315 | if (ntohl (block->purpose.size) < | 394 | if (ntohl (block->purpose.size) < |
316 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 395 | sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
@@ -319,18 +398,19 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
319 | GNUNET_break_op (0); | 398 | GNUNET_break_op (0); |
320 | return GNUNET_SYSERR; | 399 | return GNUNET_SYSERR; |
321 | } | 400 | } |
322 | derive_block_aes_key (&iv, | 401 | derive_block_aes_key (ctr, |
323 | &skey, | 402 | key, |
324 | label, | 403 | label, |
404 | block->expiration_time.abs_value_us__, | ||
325 | zone_key); | 405 | zone_key); |
326 | { | 406 | { |
327 | char payload[payload_len]; | 407 | char payload[payload_len]; |
328 | uint32_t rd_count; | 408 | uint32_t rd_count; |
329 | 409 | ||
330 | GNUNET_break (payload_len == | 410 | GNUNET_break (payload_len == |
331 | GNUNET_CRYPTO_symmetric_decrypt (&block[1], payload_len, | 411 | ecdsa_symmetric_decrypt (&block[1], payload_len, |
332 | &skey, &iv, | 412 | key, ctr, |
333 | payload)); | 413 | payload)); |
334 | GNUNET_memcpy (&rd_count, | 414 | GNUNET_memcpy (&rd_count, |
335 | payload, | 415 | payload, |
336 | sizeof(uint32_t)); | 416 | sizeof(uint32_t)); |
@@ -426,6 +506,39 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
426 | 506 | ||
427 | 507 | ||
428 | /** | 508 | /** |
509 | * Decrypt block. | ||
510 | * | ||
511 | * @param block block to decrypt | ||
512 | * @param zone_key public key of the zone | ||
513 | * @param label the name for the records | ||
514 | * @param proc function to call with the result | ||
515 | * @param proc_cls closure for proc | ||
516 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | ||
517 | * not well-formed | ||
518 | */ | ||
519 | enum GNUNET_GenericReturnValue | ||
520 | GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | ||
521 | const struct | ||
522 | GNUNET_IDENTITY_PublicKey *zone_key, | ||
523 | const char *label, | ||
524 | GNUNET_GNSRECORD_RecordCallback proc, | ||
525 | void *proc_cls) | ||
526 | { | ||
527 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key; | ||
528 | |||
529 | if (GNUNET_IDENTITY_TYPE_ECDSA != ntohl (zone_key->type)) | ||
530 | { | ||
531 | return GNUNET_NO; | ||
532 | } | ||
533 | key = &zone_key->ecdsa_key; | ||
534 | |||
535 | return block_decrypt_ecdsa (&block->ecdsa_block, | ||
536 | key, label, proc, proc_cls); | ||
537 | |||
538 | } | ||
539 | |||
540 | |||
541 | /** | ||
429 | * Calculate the DHT query for a given @a label in a given @a zone. | 542 | * Calculate the DHT query for a given @a label in a given @a zone. |
430 | * | 543 | * |
431 | * @param zone private key of the zone | 544 | * @param zone private key of the zone |
@@ -434,17 +547,24 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
434 | */ | 547 | */ |
435 | void | 548 | void |
436 | GNUNET_GNSRECORD_query_from_private_key (const struct | 549 | GNUNET_GNSRECORD_query_from_private_key (const struct |
437 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 550 | GNUNET_IDENTITY_PrivateKey *zone, |
438 | const char *label, | 551 | const char *label, |
439 | struct GNUNET_HashCode *query) | 552 | struct GNUNET_HashCode *query) |
440 | { | 553 | { |
441 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 554 | struct GNUNET_IDENTITY_PublicKey pub; |
442 | 555 | switch (ntohl (zone->type)) | |
443 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, | 556 | { |
444 | &pub); | 557 | case GNUNET_GNSRECORD_TYPE_PKEY: |
445 | GNUNET_GNSRECORD_query_from_public_key (&pub, | 558 | |
446 | label, | 559 | GNUNET_IDENTITY_key_get_public (zone, |
447 | query); | 560 | &pub); |
561 | GNUNET_GNSRECORD_query_from_public_key (&pub, | ||
562 | label, | ||
563 | query); | ||
564 | break; | ||
565 | default: | ||
566 | GNUNET_assert (0); | ||
567 | } | ||
448 | } | 568 | } |
449 | 569 | ||
450 | 570 | ||
@@ -457,18 +577,27 @@ GNUNET_GNSRECORD_query_from_private_key (const struct | |||
457 | */ | 577 | */ |
458 | void | 578 | void |
459 | GNUNET_GNSRECORD_query_from_public_key (const struct | 579 | GNUNET_GNSRECORD_query_from_public_key (const struct |
460 | GNUNET_CRYPTO_EcdsaPublicKey *pub, | 580 | GNUNET_IDENTITY_PublicKey *pub, |
461 | const char *label, | 581 | const char *label, |
462 | struct GNUNET_HashCode *query) | 582 | struct GNUNET_HashCode *query) |
463 | { | 583 | { |
464 | struct GNUNET_CRYPTO_EcdsaPublicKey pd; | 584 | struct GNUNET_IDENTITY_PublicKey pd; |
465 | GNUNET_CRYPTO_ecdsa_public_key_derive (pub, | 585 | |
466 | label, | 586 | switch (ntohl (pub->type)) |
467 | "gns", | 587 | { |
468 | &pd); | 588 | case GNUNET_GNSRECORD_TYPE_PKEY: |
469 | GNUNET_CRYPTO_hash (&pd, | 589 | pd.type = pub->type; |
470 | sizeof(pd), | 590 | GNUNET_CRYPTO_ecdsa_public_key_derive (&pub->ecdsa_key, |
471 | query); | 591 | label, |
592 | "gns", | ||
593 | &pd.ecdsa_key); | ||
594 | GNUNET_CRYPTO_hash (&pd.ecdsa_key, | ||
595 | sizeof (pd.ecdsa_key), | ||
596 | query); | ||
597 | break; | ||
598 | default: | ||
599 | GNUNET_assert (0); | ||
600 | } | ||
472 | } | 601 | } |
473 | 602 | ||
474 | 603 | ||
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 5061f8493..82c38f19a 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -62,14 +62,14 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src) | |||
62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s | 62 | * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s |
63 | */ | 63 | */ |
64 | const char * | 64 | const char * |
65 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) | 65 | GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z) |
66 | { | 66 | { |
67 | static char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) * 8]; | 67 | static char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) * 8]; |
68 | char *end; | 68 | char *end; |
69 | 69 | ||
70 | end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z, | 70 | end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z, |
71 | sizeof(struct | 71 | sizeof(struct |
72 | GNUNET_CRYPTO_EcdsaPublicKey), | 72 | GNUNET_IDENTITY_PublicKey), |
73 | buf, sizeof(buf)); | 73 | buf, sizeof(buf)); |
74 | if (NULL == end) | 74 | if (NULL == end) |
75 | { | 75 | { |
@@ -99,7 +99,7 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
99 | if (a->record_type != b->record_type) | 99 | if (a->record_type != b->record_type) |
100 | { | 100 | { |
101 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 101 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
102 | "Record type %lu != %lu\n", a->record_type, b->record_type); | 102 | "Record type %u != %u\n", a->record_type, b->record_type); |
103 | return GNUNET_NO; | 103 | return GNUNET_NO; |
104 | } | 104 | } |
105 | if ((a->expiration_time != b->expiration_time) && | 105 | if ((a->expiration_time != b->expiration_time) && |
@@ -107,15 +107,15 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | |||
107 | { | 107 | { |
108 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 108 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
109 | "Expiration time %llu != %llu\n", | 109 | "Expiration time %llu != %llu\n", |
110 | a->expiration_time, | 110 | (unsigned long long) a->expiration_time, |
111 | b->expiration_time); | 111 | (unsigned long long) b->expiration_time); |
112 | return GNUNET_NO; | 112 | return GNUNET_NO; |
113 | } | 113 | } |
114 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) | 114 | if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS) |
115 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) | 115 | != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)) |
116 | { | 116 | { |
117 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
118 | "Flags %lu (%lu) != %lu (%lu)\n", a->flags, | 118 | "Flags %u (%u) != %u (%u)\n", a->flags, |
119 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, | 119 | a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, |
120 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); | 120 | b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); |
121 | return GNUNET_NO; | 121 | return GNUNET_NO; |
@@ -236,12 +236,12 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd) | |||
236 | * key in an encoding suitable for DNS labels. | 236 | * key in an encoding suitable for DNS labels. |
237 | */ | 237 | */ |
238 | const char * | 238 | const char * |
239 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 239 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey) |
240 | { | 240 | { |
241 | static char ret[128]; | 241 | static char ret[128]; |
242 | char *pkeys; | 242 | char *pkeys; |
243 | 243 | ||
244 | pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey); | 244 | pkeys = GNUNET_IDENTITY_public_key_to_string (pkey); |
245 | GNUNET_snprintf (ret, | 245 | GNUNET_snprintf (ret, |
246 | sizeof(ret), | 246 | sizeof(ret), |
247 | "%s", | 247 | "%s", |
@@ -262,15 +262,140 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | |||
262 | */ | 262 | */ |
263 | int | 263 | int |
264 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 264 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
265 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | 265 | struct GNUNET_IDENTITY_PublicKey *pkey) |
266 | { | 266 | { |
267 | if (GNUNET_OK != | 267 | if (GNUNET_OK != |
268 | GNUNET_CRYPTO_ecdsa_public_key_from_string (zkey, | 268 | GNUNET_IDENTITY_public_key_from_string (zkey, |
269 | strlen (zkey), | 269 | pkey)) |
270 | pkey)) | ||
271 | return GNUNET_SYSERR; | 270 | return GNUNET_SYSERR; |
272 | return GNUNET_OK; | 271 | return GNUNET_OK; |
273 | } | 272 | } |
274 | 273 | ||
275 | 274 | ||
275 | enum GNUNET_GenericReturnValue | ||
276 | GNUNET_GNSRECORD_identity_from_data (const char *data, | ||
277 | size_t data_size, | ||
278 | uint32_t type, | ||
279 | struct GNUNET_IDENTITY_PublicKey *key) | ||
280 | { | ||
281 | if (GNUNET_NO == GNUNET_GNSRECORD_is_zonekey_type (type)) | ||
282 | return GNUNET_SYSERR; | ||
283 | if (data_size > sizeof (struct GNUNET_IDENTITY_PublicKey)) | ||
284 | return GNUNET_SYSERR; | ||
285 | return (GNUNET_IDENTITY_read_key_from_buffer (key, data, data_size) == | ||
286 | data_size? | ||
287 | GNUNET_OK : | ||
288 | GNUNET_SYSERR); | ||
289 | } | ||
290 | |||
291 | |||
292 | enum GNUNET_GenericReturnValue | ||
293 | GNUNET_GNSRECORD_data_from_identity (const struct | ||
294 | GNUNET_IDENTITY_PublicKey *key, | ||
295 | char **data, | ||
296 | size_t *data_size, | ||
297 | uint32_t *type) | ||
298 | { | ||
299 | *type = ntohl (key->type); | ||
300 | *data_size = GNUNET_IDENTITY_key_get_length (key); | ||
301 | if (0 == *data_size) | ||
302 | return GNUNET_SYSERR; | ||
303 | *data = GNUNET_malloc (*data_size); | ||
304 | return (GNUNET_IDENTITY_write_key_to_buffer (key, *data, *data_size) == | ||
305 | *data_size? | ||
306 | GNUNET_OK : | ||
307 | GNUNET_SYSERR); | ||
308 | } | ||
309 | |||
310 | |||
311 | enum GNUNET_GenericReturnValue | ||
312 | GNUNET_GNSRECORD_is_zonekey_type (uint32_t type) | ||
313 | { | ||
314 | switch (type) | ||
315 | { | ||
316 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
317 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
318 | return GNUNET_YES; | ||
319 | default: | ||
320 | return GNUNET_NO; | ||
321 | } | ||
322 | } | ||
323 | |||
324 | |||
325 | size_t | ||
326 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block) | ||
327 | { | ||
328 | switch (ntohl (block->type)) | ||
329 | { | ||
330 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
331 | return sizeof (uint32_t) /* zone type */ | ||
332 | + sizeof (block->ecdsa_block) /* EcdsaBlock */ | ||
333 | + ntohl (block->ecdsa_block.purpose.size) /* Length of signed data */ | ||
334 | - sizeof (block->ecdsa_block.purpose); /* Purpose already in EcdsaBlock */ | ||
335 | break; | ||
336 | default: | ||
337 | return 0; | ||
338 | } | ||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | |||
343 | struct GNUNET_TIME_Absolute | ||
344 | GNUNET_GNSRECORD_block_get_expiration (const struct | ||
345 | GNUNET_GNSRECORD_Block *block) | ||
346 | { | ||
347 | |||
348 | switch (ntohl (block->type)) | ||
349 | { | ||
350 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
351 | return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time); | ||
352 | default: | ||
353 | return GNUNET_TIME_absolute_get_zero_ (); | ||
354 | } | ||
355 | return GNUNET_TIME_absolute_get_zero_ (); | ||
356 | |||
357 | } | ||
358 | |||
359 | |||
360 | enum GNUNET_GenericReturnValue | ||
361 | GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | ||
362 | struct GNUNET_HashCode *query) | ||
363 | { | ||
364 | switch (ntohl (block->type)) | ||
365 | { | ||
366 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
367 | GNUNET_CRYPTO_hash (&block->ecdsa_block.derived_key, | ||
368 | sizeof (block->ecdsa_block.derived_key), | ||
369 | query); | ||
370 | return GNUNET_OK; | ||
371 | default: | ||
372 | return GNUNET_SYSERR; | ||
373 | } | ||
374 | return GNUNET_SYSERR; | ||
375 | |||
376 | } | ||
377 | |||
378 | |||
379 | enum GNUNET_GenericReturnValue | ||
380 | GNUNET_GNSRECORD_record_to_identity_key (const struct GNUNET_GNSRECORD_Data *rd, | ||
381 | struct GNUNET_IDENTITY_PublicKey *key) | ||
382 | { | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Got record of type %u\n", | ||
385 | rd->record_type); | ||
386 | switch (rd->record_type) | ||
387 | { | ||
388 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
389 | key->type = htonl (rd->record_type); | ||
390 | memcpy (&key->ecdsa_key, rd->data, sizeof (key->ecdsa_key)); | ||
391 | return GNUNET_OK; | ||
392 | default: | ||
393 | return GNUNET_SYSERR; | ||
394 | } | ||
395 | return GNUNET_SYSERR; | ||
396 | |||
397 | |||
398 | } | ||
399 | |||
400 | |||
276 | /* end of gnsrecord_misc.c */ | 401 | /* end of gnsrecord_misc.c */ |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index 789ff8aa3..47b13bdab 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -90,28 +90,38 @@ run (void *cls, | |||
90 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | 90 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); |
91 | struct GNUNET_GNSRECORD_Block *rrblock; | 91 | struct GNUNET_GNSRECORD_Block *rrblock; |
92 | char *bdata; | 92 | char *bdata; |
93 | struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv; | 93 | struct GNUNET_IDENTITY_PrivateKey id_priv; |
94 | struct GNUNET_CRYPTO_EcdsaPublicKey id_pub; | 94 | struct GNUNET_IDENTITY_PublicKey id_pub; |
95 | struct GNUNET_CRYPTO_EcdsaPrivateKey pkey_data_p; | 95 | struct GNUNET_IDENTITY_PrivateKey pkey_data_p; |
96 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey_data; | 96 | struct GNUNET_IDENTITY_PublicKey pkey_data; |
97 | void *data; | 97 | void *data; |
98 | size_t data_size; | 98 | size_t data_size; |
99 | char *rdata; | 99 | char *rdata; |
100 | size_t rdata_size; | 100 | size_t rdata_size; |
101 | 101 | char ztld[128]; | |
102 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); | 102 | |
103 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, | 103 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
104 | &id_pub); | 104 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
105 | fprintf (stdout, "Zone private key (d, little-endian scalar):\n"); | 105 | GNUNET_IDENTITY_key_get_public (&id_priv, |
106 | print_bytes (&id_priv, sizeof(id_priv), 0); | 106 | &id_pub); |
107 | fprintf (stdout, "Zone private key (d, little-endian, with ztype prepended):\n"); | ||
108 | print_bytes (&id_priv, GNUNET_IDENTITY_key_get_length (&id_pub), 8); //FIXME length for privkey? | ||
109 | fprintf (stdout, "\n"); | ||
110 | fprintf (stdout, "Zone identifier (zid):\n"); | ||
111 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | ||
112 | GNUNET_STRINGS_data_to_string (&id_pub, | ||
113 | GNUNET_IDENTITY_key_get_length (&id_pub), | ||
114 | ztld, | ||
115 | sizeof (ztld)); | ||
107 | fprintf (stdout, "\n"); | 116 | fprintf (stdout, "\n"); |
108 | fprintf (stdout, "Zone public key (zk):\n"); | 117 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); |
109 | print_bytes (&id_pub, sizeof(id_pub), 0); | 118 | fprintf (stdout, "%s\n", ztld); |
110 | fprintf (stdout, "\n"); | 119 | fprintf (stdout, "\n"); |
111 | 120 | ||
112 | GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p); | 121 | pkey_data_p.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
113 | GNUNET_CRYPTO_ecdsa_key_get_public (&pkey_data_p, | 122 | GNUNET_CRYPTO_ecdsa_key_create (&pkey_data_p.ecdsa_key); |
114 | &pkey_data); | 123 | GNUNET_IDENTITY_key_get_public (&pkey_data_p, |
124 | &pkey_data); | ||
115 | fprintf (stdout, | 125 | fprintf (stdout, |
116 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); | 126 | "Label: %s\nRRCOUNT: %d\n\n", TEST_RECORD_LABEL, TEST_RRCOUNT); |
117 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); | 127 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * 2); |
@@ -147,19 +157,20 @@ run (void *cls, | |||
147 | TEST_RECORD_LABEL, | 157 | TEST_RECORD_LABEL, |
148 | rd, | 158 | rd, |
149 | TEST_RRCOUNT); | 159 | TEST_RRCOUNT); |
150 | size_t bdata_size = ntohl (rrblock->purpose.size) | 160 | size_t bdata_size = ntohl (rrblock->ecdsa_block.purpose.size) |
151 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 161 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
152 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | 162 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); |
153 | size_t rrblock_size = ntohl (rrblock->purpose.size) | 163 | size_t ecblock_size = ntohl (rrblock->ecdsa_block.purpose.size) |
154 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 164 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) |
155 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 165 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); |
166 | size_t block_size = ecblock_size + sizeof (uint32_t); | ||
156 | 167 | ||
157 | bdata = (char*) &rrblock[1]; | 168 | bdata = (char*) &(&rrblock->ecdsa_block)[1]; |
158 | fprintf (stdout, "BDATA:\n"); | 169 | fprintf (stdout, "BDATA:\n"); |
159 | print_bytes (bdata, bdata_size, 8); | 170 | print_bytes (bdata, bdata_size, 8); |
160 | fprintf (stdout, "\n"); | 171 | fprintf (stdout, "\n"); |
161 | fprintf (stdout, "RRBLOCK:\n"); | 172 | fprintf (stdout, "RRBLOCK:\n"); |
162 | print_bytes (rrblock, rrblock_size, 8); | 173 | print_bytes (rrblock, block_size, 8); |
163 | fprintf (stdout, "\n"); | 174 | fprintf (stdout, "\n"); |
164 | 175 | ||
165 | } | 176 | } |
diff --git a/src/json/json_gnsrecord.c b/src/gnsrecord/json_gnsrecord.c index 7e11aba94..068ff48c1 100644 --- a/src/json/json_gnsrecord.c +++ b/src/gnsrecord/json_gnsrecord.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_json_lib.h" | 28 | #include "gnunet_json_lib.h" |
29 | #include "gnunet_gnsrecord_lib.h" | ||
29 | 30 | ||
30 | #define GNUNET_JSON_GNSRECORD_VALUE "value" | 31 | #define GNUNET_JSON_GNSRECORD_VALUE "value" |
31 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" | 32 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" |
@@ -258,7 +259,7 @@ clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec) | |||
258 | * @return JSON Specification | 259 | * @return JSON Specification |
259 | */ | 260 | */ |
260 | struct GNUNET_JSON_Specification | 261 | struct GNUNET_JSON_Specification |
261 | GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | 262 | GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, |
262 | unsigned int *rd_count, | 263 | unsigned int *rd_count, |
263 | char **name) | 264 | char **name) |
264 | { | 265 | { |
@@ -277,3 +278,114 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | |||
277 | .size_ptr = NULL }; | 278 | .size_ptr = NULL }; |
278 | return ret; | 279 | return ret; |
279 | } | 280 | } |
281 | |||
282 | |||
283 | /** | ||
284 | * Convert GNS record to JSON. | ||
285 | * | ||
286 | * @param rname name of record | ||
287 | * @param rd record data | ||
288 | * @return corresponding JSON encoding | ||
289 | */ | ||
290 | json_t * | ||
291 | GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, | ||
292 | const struct GNUNET_GNSRECORD_Data *rd, | ||
293 | unsigned int rd_count) | ||
294 | { | ||
295 | struct GNUNET_TIME_Absolute abs_exp; | ||
296 | struct GNUNET_TIME_Relative rel_exp; | ||
297 | const char *expiration_time_str; | ||
298 | const char *record_type_str; | ||
299 | char *value_str; | ||
300 | json_t *data; | ||
301 | json_t *record; | ||
302 | json_t *records; | ||
303 | |||
304 | data = json_object (); | ||
305 | if (NULL == data) | ||
306 | { | ||
307 | GNUNET_break (0); | ||
308 | return NULL; | ||
309 | } | ||
310 | if (0 != | ||
311 | json_object_set_new (data, | ||
312 | "record_name", | ||
313 | json_string (rname))) | ||
314 | { | ||
315 | GNUNET_break (0); | ||
316 | json_decref (data); | ||
317 | return NULL; | ||
318 | } | ||
319 | records = json_array (); | ||
320 | if (NULL == records) | ||
321 | { | ||
322 | GNUNET_break (0); | ||
323 | json_decref (data); | ||
324 | return NULL; | ||
325 | } | ||
326 | for (int i = 0; i < rd_count; i++) | ||
327 | { | ||
328 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
329 | rd[i].data, | ||
330 | rd[i].data_size); | ||
331 | if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags) | ||
332 | { | ||
333 | rel_exp.rel_value_us = rd[i].expiration_time; | ||
334 | expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp, | ||
335 | GNUNET_NO); | ||
336 | } | ||
337 | else | ||
338 | { | ||
339 | abs_exp.abs_value_us = rd[i].expiration_time; | ||
340 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp); | ||
341 | } | ||
342 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
344 | "Packing %s %s %s %d\n", | ||
345 | value_str, record_type_str, expiration_time_str, rd[i].flags); | ||
346 | record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}", | ||
347 | "value", | ||
348 | value_str, | ||
349 | "record_type", | ||
350 | record_type_str, | ||
351 | "expiration_time", | ||
352 | expiration_time_str, | ||
353 | "private", | ||
354 | rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE, | ||
355 | "relative_expiration", | ||
356 | rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, | ||
357 | "supplemental", | ||
358 | rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL, | ||
359 | "shadow", | ||
360 | rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD); | ||
361 | GNUNET_free (value_str); | ||
362 | if (NULL == record) | ||
363 | { | ||
364 | GNUNET_break (0); | ||
365 | json_decref (records); | ||
366 | json_decref (data); | ||
367 | return NULL; | ||
368 | } | ||
369 | if (0 != | ||
370 | json_array_append_new (records, | ||
371 | record)) | ||
372 | { | ||
373 | GNUNET_break (0); | ||
374 | json_decref (records); | ||
375 | json_decref (data); | ||
376 | return NULL; | ||
377 | } | ||
378 | } | ||
379 | if (0 != | ||
380 | json_object_set_new (data, | ||
381 | "data", | ||
382 | records)) | ||
383 | { | ||
384 | GNUNET_break (0); | ||
385 | json_decref (data); | ||
386 | return NULL; | ||
387 | } | ||
388 | return data; | ||
389 | } | ||
390 | |||
391 | |||
diff --git a/src/gnsrecord/perf_gnsrecord_crypto.c b/src/gnsrecord/perf_gnsrecord_crypto.c index eb4633f75..d9a3c20cf 100644 --- a/src/gnsrecord/perf_gnsrecord_crypto.c +++ b/src/gnsrecord/perf_gnsrecord_crypto.c | |||
@@ -73,7 +73,7 @@ run (void *cls, | |||
73 | struct GNUNET_GNSRECORD_Data *s_rd; | 73 | struct GNUNET_GNSRECORD_Data *s_rd; |
74 | const char *s_name; | 74 | const char *s_name; |
75 | struct GNUNET_TIME_Absolute start_time; | 75 | struct GNUNET_TIME_Absolute start_time; |
76 | struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 76 | struct GNUNET_IDENTITY_PrivateKey privkey; |
77 | struct GNUNET_TIME_Absolute expire; | 77 | struct GNUNET_TIME_Absolute expire; |
78 | 78 | ||
79 | (void) cls; | 79 | (void) cls; |
@@ -81,7 +81,8 @@ run (void *cls, | |||
81 | (void) cfgfile; | 81 | (void) cfgfile; |
82 | (void) cfg; | 82 | (void) cfg; |
83 | expire = GNUNET_TIME_absolute_get (); | 83 | expire = GNUNET_TIME_absolute_get (); |
84 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 84 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
85 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
85 | 86 | ||
86 | /* test block creation */ | 87 | /* test block creation */ |
87 | s_name = "DUMMY.dummy.gnunet"; | 88 | s_name = "DUMMY.dummy.gnunet"; |
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c index 9ac6fb9e6..bde9944e2 100644 --- a/src/gnsrecord/plugin_gnsrecord_dns.c +++ b/src/gnsrecord/plugin_gnsrecord_dns.c | |||
@@ -100,7 +100,7 @@ dns_value_to_string (void *cls, | |||
100 | return NULL; | 100 | return NULL; |
101 | } | 101 | } |
102 | GNUNET_asprintf (&result, | 102 | GNUNET_asprintf (&result, |
103 | "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", | 103 | "rname=%s mname=%s %u,%u,%u,%u,%u", |
104 | soa->rname, | 104 | soa->rname, |
105 | soa->mname, | 105 | soa->mname, |
106 | soa->serial, | 106 | soa->serial, |
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c index b67e9a123..d541f3076 100644 --- a/src/gnsrecord/test_gnsrecord_crypto.c +++ b/src/gnsrecord/test_gnsrecord_crypto.c | |||
@@ -100,17 +100,18 @@ run (void *cls, | |||
100 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 100 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
101 | { | 101 | { |
102 | struct GNUNET_GNSRECORD_Block *block; | 102 | struct GNUNET_GNSRECORD_Block *block; |
103 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 103 | struct GNUNET_IDENTITY_PublicKey pubkey; |
104 | struct GNUNET_HashCode query_pub; | 104 | struct GNUNET_HashCode query_pub; |
105 | struct GNUNET_HashCode query_priv; | 105 | struct GNUNET_HashCode query_priv; |
106 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); | 106 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get (); |
107 | struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 107 | struct GNUNET_IDENTITY_PrivateKey privkey; |
108 | 108 | ||
109 | 109 | ||
110 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 110 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
111 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
111 | /* get public key */ | 112 | /* get public key */ |
112 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 113 | GNUNET_IDENTITY_key_get_public (&privkey, |
113 | &pubkey); | 114 | &pubkey); |
114 | 115 | ||
115 | /* test query derivation */ | 116 | /* test query derivation */ |
116 | GNUNET_GNSRECORD_query_from_private_key (&privkey, | 117 | GNUNET_GNSRECORD_query_from_private_key (&privkey, |
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index d0f5546f3..a01cd1ed7 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -66,6 +66,11 @@ static unsigned int verbose; | |||
66 | static int quiet; | 66 | static int quiet; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Was "eddsa" specified? | ||
70 | */ | ||
71 | static int type_eddsa; | ||
72 | |||
73 | /** | ||
69 | * -C option | 74 | * -C option |
70 | */ | 75 | */ |
71 | static char *create_ego; | 76 | static char *create_ego; |
@@ -108,7 +113,7 @@ static struct GNUNET_IDENTITY_Operation *delete_op; | |||
108 | /** | 113 | /** |
109 | * Private key from command line option, or NULL. | 114 | * Private key from command line option, or NULL. |
110 | */ | 115 | */ |
111 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 116 | struct GNUNET_IDENTITY_PrivateKey pk; |
112 | 117 | ||
113 | /** | 118 | /** |
114 | * Value to return from #main(). | 119 | * Value to return from #main(). |
@@ -197,7 +202,7 @@ delete_finished (void *cls, | |||
197 | */ | 202 | */ |
198 | static void | 203 | static void |
199 | create_finished (void *cls, | 204 | create_finished (void *cls, |
200 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 205 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
201 | const char *emsg) | 206 | const char *emsg) |
202 | { | 207 | { |
203 | struct GNUNET_IDENTITY_Operation **op = cls; | 208 | struct GNUNET_IDENTITY_Operation **op = cls; |
@@ -212,16 +217,16 @@ create_finished (void *cls, | |||
212 | } | 217 | } |
213 | else if (verbose) | 218 | else if (verbose) |
214 | { | 219 | { |
215 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 220 | struct GNUNET_IDENTITY_PublicKey pub; |
216 | char *pubs; | 221 | char *pubs; |
217 | 222 | ||
218 | GNUNET_CRYPTO_ecdsa_key_get_public (pk, &pub); | 223 | GNUNET_IDENTITY_key_get_public (pk, &pub); |
219 | pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub); | 224 | pubs = GNUNET_IDENTITY_public_key_to_string (&pub); |
220 | if (private_keys) | 225 | if (private_keys) |
221 | { | 226 | { |
222 | char *privs; | 227 | char *privs; |
223 | 228 | ||
224 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); | 229 | privs = GNUNET_IDENTITY_private_key_to_string (pk); |
225 | fprintf (stdout, "%s - %s\n", pubs, privs); | 230 | fprintf (stdout, "%s - %s\n", pubs, privs); |
226 | GNUNET_free (privs); | 231 | GNUNET_free (privs); |
227 | } | 232 | } |
@@ -293,7 +298,7 @@ print_ego (void *cls, | |||
293 | void **ctx, | 298 | void **ctx, |
294 | const char *identifier) | 299 | const char *identifier) |
295 | { | 300 | { |
296 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 301 | struct GNUNET_IDENTITY_PublicKey pk; |
297 | char *s; | 302 | char *s; |
298 | char *privs; | 303 | char *privs; |
299 | 304 | ||
@@ -342,8 +347,8 @@ print_ego (void *cls, | |||
342 | set_ego)) ) | 347 | set_ego)) ) |
343 | return; | 348 | return; |
344 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 349 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
345 | s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 350 | s = GNUNET_IDENTITY_public_key_to_string (&pk); |
346 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | 351 | privs = GNUNET_IDENTITY_private_key_to_string ( |
347 | GNUNET_IDENTITY_ego_get_private_key (ego)); | 352 | GNUNET_IDENTITY_ego_get_private_key (ego)); |
348 | if ((monitor) || (NULL != identifier)) | 353 | if ((monitor) || (NULL != identifier)) |
349 | { | 354 | { |
@@ -357,9 +362,16 @@ print_ego (void *cls, | |||
357 | else | 362 | else |
358 | { | 363 | { |
359 | if (private_keys) | 364 | if (private_keys) |
360 | fprintf (stdout, "%s - %s - %s\n", identifier, s, privs); | 365 | fprintf (stdout, "%s - %s - %s - %s\n", |
366 | identifier, s, privs, | ||
367 | (ntohl (pk.type) == GNUNET_IDENTITY_TYPE_ECDSA) ? | ||
368 | "ECDSA" : "EdDSA"); | ||
361 | else | 369 | else |
362 | fprintf (stdout, "%s - %s\n", identifier, s); | 370 | fprintf (stdout, "%s - %s - %s\n", |
371 | identifier, s, | ||
372 | (ntohl (pk.type) == GNUNET_IDENTITY_TYPE_ECDSA) ? | ||
373 | "ECDSA" : "EdDSA"); | ||
374 | |||
363 | } | 375 | } |
364 | } | 376 | } |
365 | GNUNET_free (privs); | 377 | GNUNET_free (privs); |
@@ -407,11 +419,12 @@ run (void *cls, | |||
407 | strlen (privkey_ego), | 419 | strlen (privkey_ego), |
408 | &pk, | 420 | &pk, |
409 | sizeof(struct | 421 | sizeof(struct |
410 | GNUNET_CRYPTO_EcdsaPrivateKey)); | 422 | GNUNET_IDENTITY_PrivateKey)); |
411 | create_op = | 423 | create_op = |
412 | GNUNET_IDENTITY_create (sh, | 424 | GNUNET_IDENTITY_create (sh, |
413 | create_ego, | 425 | create_ego, |
414 | &pk, | 426 | &pk, |
427 | 0, // Ignored | ||
415 | &create_finished, | 428 | &create_finished, |
416 | &create_op); | 429 | &create_op); |
417 | } | 430 | } |
@@ -420,6 +433,9 @@ run (void *cls, | |||
420 | GNUNET_IDENTITY_create (sh, | 433 | GNUNET_IDENTITY_create (sh, |
421 | create_ego, | 434 | create_ego, |
422 | NULL, | 435 | NULL, |
436 | (type_eddsa) ? | ||
437 | GNUNET_IDENTITY_TYPE_EDDSA : | ||
438 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
423 | &create_finished, | 439 | &create_finished, |
424 | &create_op); | 440 | &create_op); |
425 | } | 441 | } |
@@ -456,6 +472,11 @@ main (int argc, char *const *argv) | |||
456 | gettext_noop ( | 472 | gettext_noop ( |
457 | "set the private key for the identity to PRIVATE_KEY (use together with -C)"), | 473 | "set the private key for the identity to PRIVATE_KEY (use together with -C)"), |
458 | &privkey_ego), | 474 | &privkey_ego), |
475 | GNUNET_GETOPT_option_flag ('X', | ||
476 | "eddsa", | ||
477 | gettext_noop ( | ||
478 | "generate an EdDSA identity. (use together with -C) EXPERIMENTAL"), | ||
479 | &type_eddsa), | ||
459 | GNUNET_GETOPT_option_flag ('d', | 480 | GNUNET_GETOPT_option_flag ('d', |
460 | "display", | 481 | "display", |
461 | gettext_noop ("display all egos"), | 482 | gettext_noop ("display all egos"), |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index bdacf3ba0..6cdb1c2f7 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -57,7 +57,7 @@ struct Ego | |||
57 | /** | 57 | /** |
58 | * Private key of the ego. | 58 | * Private key of the ego. |
59 | */ | 59 | */ |
60 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 60 | struct GNUNET_IDENTITY_PrivateKey pk; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * String identifier for the ego. | 63 | * String identifier for the ego. |
@@ -538,8 +538,8 @@ handle_get_default_message (void *cls, | |||
538 | * @return 0 if the keys are equal | 538 | * @return 0 if the keys are equal |
539 | */ | 539 | */ |
540 | static int | 540 | static int |
541 | key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, | 541 | key_cmp (const struct GNUNET_IDENTITY_PrivateKey *pk1, |
542 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) | 542 | const struct GNUNET_IDENTITY_PrivateKey *pk2) |
543 | { | 543 | { |
544 | return GNUNET_memcmp (pk1, pk2); | 544 | return GNUNET_memcmp (pk1, pk2); |
545 | } | 545 | } |
@@ -738,10 +738,10 @@ handle_create_message (void *cls, | |||
738 | send_result_code (client, 0, NULL); | 738 | send_result_code (client, 0, NULL); |
739 | fn = get_ego_filename (ego); | 739 | fn = get_ego_filename (ego); |
740 | (void) GNUNET_DISK_directory_create_for_file (fn); | 740 | (void) GNUNET_DISK_directory_create_for_file (fn); |
741 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) != | 741 | if (sizeof(struct GNUNET_IDENTITY_PrivateKey) != |
742 | GNUNET_DISK_fn_write (fn, | 742 | GNUNET_DISK_fn_write (fn, |
743 | &crm->private_key, | 743 | &crm->private_key, |
744 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | 744 | sizeof(struct GNUNET_IDENTITY_PrivateKey), |
745 | GNUNET_DISK_PERM_USER_READ | 745 | GNUNET_DISK_PERM_USER_READ |
746 | | GNUNET_DISK_PERM_USER_WRITE)) | 746 | | GNUNET_DISK_PERM_USER_WRITE)) |
747 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); | 747 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); |
@@ -1038,6 +1038,67 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | 1040 | ||
1041 | static int | ||
1042 | read_from_file (const char *filename, | ||
1043 | void *buf, | ||
1044 | size_t buf_size) | ||
1045 | { | ||
1046 | int fd; | ||
1047 | struct stat sb; | ||
1048 | |||
1049 | fd = open (filename, | ||
1050 | O_RDONLY); | ||
1051 | if (-1 == fd) | ||
1052 | { | ||
1053 | memset (buf, | ||
1054 | 0, | ||
1055 | buf_size); | ||
1056 | return GNUNET_SYSERR; | ||
1057 | } | ||
1058 | if (0 != fstat (fd, | ||
1059 | &sb)) | ||
1060 | { | ||
1061 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1062 | "stat", | ||
1063 | filename); | ||
1064 | GNUNET_assert (0 == close (fd)); | ||
1065 | memset (buf, | ||
1066 | 0, | ||
1067 | buf_size); | ||
1068 | return GNUNET_SYSERR; | ||
1069 | } | ||
1070 | if (sb.st_size != buf_size) | ||
1071 | { | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1073 | "File `%s' has wrong size (%llu), expected %llu bytes\n", | ||
1074 | filename, | ||
1075 | (unsigned long long) sb.st_size, | ||
1076 | (unsigned long long) buf_size); | ||
1077 | GNUNET_assert (0 == close (fd)); | ||
1078 | memset (buf, | ||
1079 | 0, | ||
1080 | buf_size); | ||
1081 | return GNUNET_SYSERR; | ||
1082 | } | ||
1083 | if (buf_size != | ||
1084 | read (fd, | ||
1085 | buf, | ||
1086 | buf_size)) | ||
1087 | { | ||
1088 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
1089 | "read", | ||
1090 | filename); | ||
1091 | GNUNET_assert (0 == close (fd)); | ||
1092 | memset (buf, | ||
1093 | 0, | ||
1094 | buf_size); | ||
1095 | return GNUNET_SYSERR; | ||
1096 | } | ||
1097 | GNUNET_assert (0 == close (fd)); | ||
1098 | return GNUNET_OK; | ||
1099 | } | ||
1100 | |||
1101 | |||
1041 | /** | 1102 | /** |
1042 | * Process the given file from the "EGODIR". Parses the file | 1103 | * Process the given file from the "EGODIR". Parses the file |
1043 | * and creates the respective 'struct Ego' in memory. | 1104 | * and creates the respective 'struct Ego' in memory. |
@@ -1063,9 +1124,9 @@ process_ego_file (void *cls, | |||
1063 | } | 1124 | } |
1064 | ego = GNUNET_new (struct Ego); | 1125 | ego = GNUNET_new (struct Ego); |
1065 | if (GNUNET_OK != | 1126 | if (GNUNET_OK != |
1066 | GNUNET_CRYPTO_ecdsa_key_from_file (filename, | 1127 | read_from_file (filename, |
1067 | GNUNET_NO, | 1128 | &ego->pk, |
1068 | &ego->pk)) | 1129 | sizeof (ego->pk))) |
1069 | { | 1130 | { |
1070 | GNUNET_free (ego); | 1131 | GNUNET_free (ego); |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1132 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
diff --git a/src/identity/identity.h b/src/identity/identity.h index ef638fa36..11c5883bc 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h | |||
@@ -30,6 +30,44 @@ | |||
30 | 30 | ||
31 | #include "gnunet_common.h" | 31 | #include "gnunet_common.h" |
32 | 32 | ||
33 | /** | ||
34 | * Handle for an ego. | ||
35 | */ | ||
36 | struct GNUNET_IDENTITY_Ego | ||
37 | { | ||
38 | /** | ||
39 | * Hash of the private key of this ego. | ||
40 | */ | ||
41 | struct GNUNET_HashCode id; | ||
42 | |||
43 | /** | ||
44 | * The identity key pair | ||
45 | */ | ||
46 | struct GNUNET_IDENTITY_PublicKey pub; | ||
47 | |||
48 | /** | ||
49 | * The identity key pair | ||
50 | */ | ||
51 | struct GNUNET_IDENTITY_PrivateKey pk; | ||
52 | |||
53 | /** | ||
54 | * Current name associated with this ego. | ||
55 | */ | ||
56 | char *name; | ||
57 | |||
58 | /** | ||
59 | * Client context associated with this ego. | ||
60 | */ | ||
61 | void *ctx; | ||
62 | |||
63 | /** | ||
64 | * Set to true once @e pub was initialized | ||
65 | */ | ||
66 | bool pub_initialized; | ||
67 | }; | ||
68 | |||
69 | |||
70 | |||
33 | 71 | ||
34 | GNUNET_NETWORK_STRUCT_BEGIN | 72 | GNUNET_NETWORK_STRUCT_BEGIN |
35 | 73 | ||
@@ -95,7 +133,7 @@ struct UpdateMessage | |||
95 | /** | 133 | /** |
96 | * The private key | 134 | * The private key |
97 | */ | 135 | */ |
98 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 136 | struct GNUNET_IDENTITY_PrivateKey private_key; |
99 | 137 | ||
100 | /* followed by 0-terminated ego name */ | 138 | /* followed by 0-terminated ego name */ |
101 | }; | 139 | }; |
@@ -151,7 +189,7 @@ struct SetDefaultMessage | |||
151 | /** | 189 | /** |
152 | * The private key | 190 | * The private key |
153 | */ | 191 | */ |
154 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 192 | struct GNUNET_IDENTITY_PrivateKey private_key; |
155 | 193 | ||
156 | /* followed by 0-terminated service name */ | 194 | /* followed by 0-terminated service name */ |
157 | }; | 195 | }; |
@@ -181,7 +219,7 @@ struct CreateRequestMessage | |||
181 | /** | 219 | /** |
182 | * The private key | 220 | * The private key |
183 | */ | 221 | */ |
184 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 222 | struct GNUNET_IDENTITY_PrivateKey private_key; |
185 | 223 | ||
186 | /* followed by 0-terminated identity name */ | 224 | /* followed by 0-terminated identity name */ |
187 | }; | 225 | }; |
@@ -239,42 +277,5 @@ struct DeleteMessage | |||
239 | 277 | ||
240 | GNUNET_NETWORK_STRUCT_END | 278 | GNUNET_NETWORK_STRUCT_END |
241 | 279 | ||
242 | /** | ||
243 | * Handle for an ego. | ||
244 | */ | ||
245 | struct GNUNET_IDENTITY_Ego | ||
246 | { | ||
247 | /** | ||
248 | * Hash of the private key of this ego. | ||
249 | */ | ||
250 | struct GNUNET_HashCode id; | ||
251 | |||
252 | /** | ||
253 | * Private key associated with this ego. | ||
254 | */ | ||
255 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | ||
256 | |||
257 | /** | ||
258 | * Public key associated with this ego. Initialized on demand. | ||
259 | * Always use #GNUNET_IDENTITY_ego_get_public_key() to obtain. | ||
260 | */ | ||
261 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
262 | |||
263 | /** | ||
264 | * Current name associated with this ego. | ||
265 | */ | ||
266 | char *name; | ||
267 | |||
268 | /** | ||
269 | * Client context associated with this ego. | ||
270 | */ | ||
271 | void *ctx; | ||
272 | |||
273 | /** | ||
274 | * Set to true once @e pub was initialized | ||
275 | */ | ||
276 | bool pub_initialized; | ||
277 | }; | ||
278 | |||
279 | 280 | ||
280 | #endif | 281 | #endif |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index f7aca1655..64c088923 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -74,7 +74,7 @@ struct GNUNET_IDENTITY_Operation | |||
74 | /** | 74 | /** |
75 | * Private key to return to @e create_cont, or NULL. | 75 | * Private key to return to @e create_cont, or NULL. |
76 | */ | 76 | */ |
77 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 77 | struct GNUNET_IDENTITY_PrivateKey pk; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Continuation to invoke with the result of the transmission for | 80 | * Continuation to invoke with the result of the transmission for |
@@ -157,13 +157,12 @@ GNUNET_IDENTITY_ego_get_anonymous () | |||
157 | { | 157 | { |
158 | static struct GNUNET_IDENTITY_Ego anon; | 158 | static struct GNUNET_IDENTITY_Ego anon; |
159 | static int setup; | 159 | static int setup; |
160 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
161 | 160 | ||
162 | if (setup) | 161 | if (setup) |
163 | return &anon; | 162 | return &anon; |
164 | anon.pk = *GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 163 | anon.pk.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
165 | GNUNET_CRYPTO_ecdsa_key_get_public (&anon.pk, | 164 | anon.pub.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
166 | &pub); | 165 | anon.pk.ecdsa_key = *GNUNET_CRYPTO_ecdsa_key_get_anonymous (); |
167 | GNUNET_CRYPTO_hash (&anon.pk, | 166 | GNUNET_CRYPTO_hash (&anon.pk, |
168 | sizeof(anon.pk), | 167 | sizeof(anon.pk), |
169 | &anon.id); | 168 | &anon.id); |
@@ -172,6 +171,51 @@ GNUNET_IDENTITY_ego_get_anonymous () | |||
172 | } | 171 | } |
173 | 172 | ||
174 | 173 | ||
174 | enum GNUNET_GenericReturnValue | ||
175 | GNUNET_IDENTITY_key_get_public (const struct | ||
176 | GNUNET_IDENTITY_PrivateKey *privkey, | ||
177 | struct GNUNET_IDENTITY_PublicKey *key) | ||
178 | { | ||
179 | key->type = privkey->type; | ||
180 | switch (ntohl (privkey->type)) | ||
181 | { | ||
182 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
183 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey->ecdsa_key, | ||
184 | &key->ecdsa_key); | ||
185 | break; | ||
186 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
187 | GNUNET_CRYPTO_eddsa_key_get_public (&privkey->eddsa_key, | ||
188 | &key->eddsa_key); | ||
189 | break; | ||
190 | default: | ||
191 | GNUNET_break (0); | ||
192 | return GNUNET_SYSERR; | ||
193 | } | ||
194 | return GNUNET_OK; | ||
195 | } | ||
196 | |||
197 | |||
198 | static int | ||
199 | private_key_create (enum GNUNET_IDENTITY_KeyType ktype, | ||
200 | struct GNUNET_IDENTITY_PrivateKey *key) | ||
201 | { | ||
202 | key->type = htonl (ktype); | ||
203 | switch (ktype) | ||
204 | { | ||
205 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
206 | GNUNET_CRYPTO_ecdsa_key_create (&key->ecdsa_key); | ||
207 | break; | ||
208 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
209 | GNUNET_CRYPTO_eddsa_key_create (&key->eddsa_key); | ||
210 | break; | ||
211 | default: | ||
212 | GNUNET_break (0); | ||
213 | return GNUNET_SYSERR; | ||
214 | } | ||
215 | return GNUNET_OK; | ||
216 | } | ||
217 | |||
218 | |||
175 | /** | 219 | /** |
176 | * Try again to connect to the identity service. | 220 | * Try again to connect to the identity service. |
177 | * | 221 | * |
@@ -591,7 +635,7 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
591 | * @param ego the ego | 635 | * @param ego the ego |
592 | * @return associated ECC key, valid as long as the ego is valid | 636 | * @return associated ECC key, valid as long as the ego is valid |
593 | */ | 637 | */ |
594 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 638 | const struct GNUNET_IDENTITY_PrivateKey * |
595 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | 639 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) |
596 | { | 640 | { |
597 | return &ego->pk; | 641 | return &ego->pk; |
@@ -606,12 +650,11 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | |||
606 | */ | 650 | */ |
607 | void | 651 | void |
608 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | 652 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, |
609 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) | 653 | struct GNUNET_IDENTITY_PublicKey *pk) |
610 | { | 654 | { |
611 | if (GNUNET_NO == ego->pub_initialized) | 655 | if (GNUNET_NO == ego->pub_initialized) |
612 | { | 656 | { |
613 | GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk, | 657 | GNUNET_IDENTITY_key_get_public (&ego->pk, &ego->pub); |
614 | &ego->pub); | ||
615 | ego->pub_initialized = GNUNET_YES; | 658 | ego->pub_initialized = GNUNET_YES; |
616 | } | 659 | } |
617 | *pk = ego->pub; | 660 | *pk = ego->pub; |
@@ -710,20 +753,11 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
710 | } | 753 | } |
711 | 754 | ||
712 | 755 | ||
713 | /** | ||
714 | * Create a new identity with the given name. | ||
715 | * | ||
716 | * @param h identity service to use | ||
717 | * @param name desired name | ||
718 | * @param privkey desired private key or NULL to create one | ||
719 | * @param cont function to call with the result (will only be called once) | ||
720 | * @param cont_cls closure for @a cont | ||
721 | * @return handle to abort the operation | ||
722 | */ | ||
723 | struct GNUNET_IDENTITY_Operation * | 756 | struct GNUNET_IDENTITY_Operation * |
724 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 757 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, |
725 | const char *name, | 758 | const char *name, |
726 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | 759 | const struct GNUNET_IDENTITY_PrivateKey *privkey, |
760 | enum GNUNET_IDENTITY_KeyType ktype, | ||
727 | GNUNET_IDENTITY_CreateContinuation cont, | 761 | GNUNET_IDENTITY_CreateContinuation cont, |
728 | void *cont_cls) | 762 | void *cont_cls) |
729 | { | 763 | { |
@@ -749,7 +783,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
749 | crm->name_len = htons (slen); | 783 | crm->name_len = htons (slen); |
750 | crm->reserved = htons (0); | 784 | crm->reserved = htons (0); |
751 | if (NULL == privkey) | 785 | if (NULL == privkey) |
752 | GNUNET_CRYPTO_ecdsa_key_create (&crm->private_key); | 786 | { |
787 | GNUNET_assert (GNUNET_OK == | ||
788 | private_key_create (ktype, &crm->private_key)); | ||
789 | } | ||
753 | else | 790 | else |
754 | crm->private_key = *privkey; | 791 | crm->private_key = *privkey; |
755 | op->pk = crm->private_key; | 792 | op->pk = crm->private_key; |
@@ -917,4 +954,316 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) | |||
917 | } | 954 | } |
918 | 955 | ||
919 | 956 | ||
957 | ssize_t | ||
958 | private_key_get_length (const struct GNUNET_IDENTITY_PrivateKey *key) | ||
959 | { | ||
960 | switch (ntohl (key->type)) | ||
961 | { | ||
962 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
963 | return sizeof (key->type) + sizeof (key->ecdsa_key); | ||
964 | break; | ||
965 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
966 | return sizeof (key->type) + sizeof (key->eddsa_key); | ||
967 | break; | ||
968 | default: | ||
969 | GNUNET_break (0); | ||
970 | } | ||
971 | return -1; | ||
972 | } | ||
973 | |||
974 | |||
975 | ssize_t | ||
976 | GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key) | ||
977 | { | ||
978 | switch (ntohl (key->type)) | ||
979 | { | ||
980 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
981 | return sizeof (key->type) + sizeof (key->ecdsa_key); | ||
982 | break; | ||
983 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
984 | return sizeof (key->type) + sizeof (key->eddsa_key); | ||
985 | break; | ||
986 | default: | ||
987 | GNUNET_break (0); | ||
988 | } | ||
989 | return -1; | ||
990 | } | ||
991 | |||
992 | |||
993 | ssize_t | ||
994 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | ||
995 | const void*buffer, | ||
996 | size_t len) | ||
997 | { | ||
998 | if (len < sizeof (key->type)) | ||
999 | return -1; | ||
1000 | GNUNET_memcpy (&(key->type), buffer, sizeof (key->type)); | ||
1001 | const ssize_t length = GNUNET_IDENTITY_key_get_length (key); | ||
1002 | if (len < length) | ||
1003 | return -1; | ||
1004 | if (length < 0) | ||
1005 | return -2; | ||
1006 | GNUNET_memcpy (&(key->ecdsa_key), buffer + sizeof (key->type), length | ||
1007 | - sizeof (key->type)); | ||
1008 | return length; | ||
1009 | } | ||
1010 | |||
1011 | |||
1012 | ssize_t | ||
1013 | GNUNET_IDENTITY_write_key_to_buffer (const struct | ||
1014 | GNUNET_IDENTITY_PublicKey *key, | ||
1015 | void*buffer, | ||
1016 | size_t len) | ||
1017 | { | ||
1018 | const ssize_t length = GNUNET_IDENTITY_key_get_length (key); | ||
1019 | if (len < length) | ||
1020 | return -1; | ||
1021 | if (length < 0) | ||
1022 | return -2; | ||
1023 | GNUNET_memcpy (buffer, key, length); | ||
1024 | return length; | ||
1025 | } | ||
1026 | |||
1027 | |||
1028 | ssize_t | ||
1029 | GNUNET_IDENTITY_signature_get_length (const struct | ||
1030 | GNUNET_IDENTITY_Signature *sig) | ||
1031 | { | ||
1032 | switch (ntohl (sig->type)) | ||
1033 | { | ||
1034 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
1035 | return sizeof (sig->type) + sizeof (sig->ecdsa_signature); | ||
1036 | break; | ||
1037 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
1038 | return sizeof (sig->type) + sizeof (sig->eddsa_signature); | ||
1039 | break; | ||
1040 | default: | ||
1041 | GNUNET_break (0); | ||
1042 | } | ||
1043 | return -1; | ||
1044 | } | ||
1045 | |||
1046 | |||
1047 | ssize_t | ||
1048 | GNUNET_IDENTITY_read_signature_from_buffer (struct | ||
1049 | GNUNET_IDENTITY_Signature *sig, | ||
1050 | const void*buffer, | ||
1051 | size_t len) | ||
1052 | { | ||
1053 | if (len < sizeof (sig->type)) | ||
1054 | return -1; | ||
1055 | GNUNET_memcpy (&(sig->type), buffer, sizeof (sig->type)); | ||
1056 | const ssize_t length = GNUNET_IDENTITY_signature_get_length (sig); | ||
1057 | if (len < length) | ||
1058 | return -1; | ||
1059 | if (length < 0) | ||
1060 | return -2; | ||
1061 | GNUNET_memcpy (&(sig->ecdsa_signature), buffer + sizeof (sig->type), length | ||
1062 | - sizeof (sig->type)); | ||
1063 | return length; | ||
1064 | } | ||
1065 | |||
1066 | |||
1067 | ssize_t | ||
1068 | GNUNET_IDENTITY_write_signature_to_buffer (const struct | ||
1069 | GNUNET_IDENTITY_Signature *sig, | ||
1070 | void*buffer, | ||
1071 | size_t len) | ||
1072 | { | ||
1073 | const ssize_t length = GNUNET_IDENTITY_signature_get_length (sig); | ||
1074 | if (len < length) | ||
1075 | return -1; | ||
1076 | if (length < 0) | ||
1077 | return -2; | ||
1078 | GNUNET_memcpy (buffer, &(sig->type), sizeof (sig->type)); | ||
1079 | GNUNET_memcpy (buffer + sizeof (sig->type), &(sig->ecdsa_signature), length | ||
1080 | - sizeof (sig->type)); | ||
1081 | return length; | ||
1082 | } | ||
1083 | |||
1084 | |||
1085 | int | ||
1086 | GNUNET_IDENTITY_sign_ (const struct | ||
1087 | GNUNET_IDENTITY_PrivateKey *priv, | ||
1088 | const struct | ||
1089 | GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
1090 | struct GNUNET_IDENTITY_Signature *sig) | ||
1091 | { | ||
1092 | sig->type = priv->type; | ||
1093 | switch (ntohl (priv->type)) | ||
1094 | { | ||
1095 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
1096 | return GNUNET_CRYPTO_ecdsa_sign_ (&(priv->ecdsa_key), purpose, | ||
1097 | &(sig->ecdsa_signature)); | ||
1098 | break; | ||
1099 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
1100 | return GNUNET_CRYPTO_eddsa_sign_ (&(priv->eddsa_key), purpose, | ||
1101 | &(sig->eddsa_signature)); | ||
1102 | break; | ||
1103 | default: | ||
1104 | GNUNET_break (0); | ||
1105 | } | ||
1106 | |||
1107 | return GNUNET_SYSERR; | ||
1108 | } | ||
1109 | |||
1110 | |||
1111 | int | ||
1112 | GNUNET_IDENTITY_signature_verify_ (uint32_t purpose, | ||
1113 | const struct | ||
1114 | GNUNET_CRYPTO_EccSignaturePurpose *validate, | ||
1115 | const struct GNUNET_IDENTITY_Signature *sig, | ||
1116 | const struct GNUNET_IDENTITY_PublicKey *pub) | ||
1117 | { | ||
1118 | /* check type matching of 'sig' and 'pub' */ | ||
1119 | GNUNET_assert (ntohl (pub->type) == ntohl (sig->type)); | ||
1120 | switch (ntohl (pub->type)) | ||
1121 | { | ||
1122 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
1123 | return GNUNET_CRYPTO_ecdsa_verify_ (purpose, validate, | ||
1124 | &(sig->ecdsa_signature), | ||
1125 | &(pub->ecdsa_key)); | ||
1126 | break; | ||
1127 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
1128 | return GNUNET_CRYPTO_eddsa_verify_ (purpose, validate, | ||
1129 | &(sig->eddsa_signature), | ||
1130 | &(pub->eddsa_key)); | ||
1131 | break; | ||
1132 | default: | ||
1133 | GNUNET_break (0); | ||
1134 | } | ||
1135 | |||
1136 | return GNUNET_SYSERR; | ||
1137 | } | ||
1138 | |||
1139 | |||
1140 | ssize_t | ||
1141 | GNUNET_IDENTITY_encrypt (const void *block, | ||
1142 | size_t size, | ||
1143 | const struct GNUNET_IDENTITY_PublicKey *pub, | ||
1144 | struct GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
1145 | void *result) | ||
1146 | { | ||
1147 | struct GNUNET_CRYPTO_EcdhePrivateKey pk; | ||
1148 | GNUNET_CRYPTO_ecdhe_key_create (&pk); | ||
1149 | struct GNUNET_HashCode hash; | ||
1150 | switch (ntohl (pub->type)) | ||
1151 | { | ||
1152 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
1153 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_ecdsa (&pk, &(pub->ecdsa_key), | ||
1154 | &hash)) | ||
1155 | return -1; | ||
1156 | break; | ||
1157 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
1158 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdh_eddsa (&pk, &(pub->eddsa_key), | ||
1159 | &hash)) | ||
1160 | return -1; | ||
1161 | break; | ||
1162 | default: | ||
1163 | return -1; | ||
1164 | } | ||
1165 | GNUNET_CRYPTO_ecdhe_key_get_public (&pk, ecc); | ||
1166 | GNUNET_CRYPTO_ecdhe_key_clear (&pk); | ||
1167 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | ||
1168 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | ||
1169 | GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv); | ||
1170 | GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash)); | ||
1171 | const ssize_t encrypted = GNUNET_CRYPTO_symmetric_encrypt (block, size, &key, | ||
1172 | &iv, result); | ||
1173 | GNUNET_CRYPTO_zero_keys (&key, sizeof(key)); | ||
1174 | GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv)); | ||
1175 | return encrypted; | ||
1176 | } | ||
1177 | |||
1178 | |||
1179 | ssize_t | ||
1180 | GNUNET_IDENTITY_decrypt (const void *block, | ||
1181 | size_t size, | ||
1182 | const struct GNUNET_IDENTITY_PrivateKey *priv, | ||
1183 | const struct GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
1184 | void *result) | ||
1185 | { | ||
1186 | struct GNUNET_HashCode hash; | ||
1187 | switch (ntohl (priv->type)) | ||
1188 | { | ||
1189 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
1190 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_ecdh (&(priv->ecdsa_key), ecc, | ||
1191 | &hash)) | ||
1192 | return -1; | ||
1193 | break; | ||
1194 | case GNUNET_IDENTITY_TYPE_EDDSA: | ||
1195 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_ecdh (&(priv->eddsa_key), ecc, | ||
1196 | &hash)) | ||
1197 | return -1; | ||
1198 | break; | ||
1199 | default: | ||
1200 | return -1; | ||
1201 | } | ||
1202 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | ||
1203 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | ||
1204 | GNUNET_CRYPTO_hash_to_aes_key (&hash, &key, &iv); | ||
1205 | GNUNET_CRYPTO_zero_keys (&hash, sizeof(hash)); | ||
1206 | const ssize_t decrypted = GNUNET_CRYPTO_symmetric_decrypt (block, size, &key, | ||
1207 | &iv, result); | ||
1208 | GNUNET_CRYPTO_zero_keys (&key, sizeof(key)); | ||
1209 | GNUNET_CRYPTO_zero_keys (&iv, sizeof(iv)); | ||
1210 | return decrypted; | ||
1211 | } | ||
1212 | |||
1213 | |||
1214 | char * | ||
1215 | GNUNET_IDENTITY_public_key_to_string (const struct | ||
1216 | GNUNET_IDENTITY_PublicKey *key) | ||
1217 | { | ||
1218 | size_t size = GNUNET_IDENTITY_key_get_length (key); | ||
1219 | return GNUNET_STRINGS_data_to_string_alloc (key, | ||
1220 | size); | ||
1221 | } | ||
1222 | |||
1223 | |||
1224 | char * | ||
1225 | GNUNET_IDENTITY_private_key_to_string (const struct | ||
1226 | GNUNET_IDENTITY_PrivateKey *key) | ||
1227 | { | ||
1228 | size_t size = private_key_get_length (key); | ||
1229 | return GNUNET_STRINGS_data_to_string_alloc (key, | ||
1230 | size); | ||
1231 | } | ||
1232 | |||
1233 | |||
1234 | enum GNUNET_GenericReturnValue | ||
1235 | GNUNET_IDENTITY_public_key_from_string (const char *str, | ||
1236 | struct GNUNET_IDENTITY_PublicKey *key) | ||
1237 | { | ||
1238 | enum GNUNET_GenericReturnValue ret; | ||
1239 | enum GNUNET_IDENTITY_KeyType ktype; | ||
1240 | ret = GNUNET_STRINGS_string_to_data (str, | ||
1241 | strlen (str), | ||
1242 | key, | ||
1243 | sizeof (*key)); | ||
1244 | if (GNUNET_OK != ret) | ||
1245 | return GNUNET_SYSERR; | ||
1246 | ktype = ntohl (key->type); | ||
1247 | return (GNUNET_IDENTITY_TYPE_ECDSA == ktype) ? GNUNET_OK : GNUNET_SYSERR; // FIXME other keys, cleaner way? | ||
1248 | |||
1249 | } | ||
1250 | |||
1251 | |||
1252 | enum GNUNET_GenericReturnValue | ||
1253 | GNUNET_IDENTITY_private_key_from_string (const char *str, | ||
1254 | struct GNUNET_IDENTITY_PrivateKey *key) | ||
1255 | { | ||
1256 | enum GNUNET_GenericReturnValue ret; | ||
1257 | enum GNUNET_IDENTITY_KeyType ktype; | ||
1258 | ret = GNUNET_STRINGS_string_to_data (str, | ||
1259 | strlen (str), | ||
1260 | key, | ||
1261 | sizeof (*key)); | ||
1262 | if (GNUNET_OK != ret) | ||
1263 | return GNUNET_SYSERR; | ||
1264 | ktype = ntohl (key->type); | ||
1265 | return (GNUNET_IDENTITY_TYPE_ECDSA == ktype) ? GNUNET_OK : GNUNET_SYSERR; // FIXME other keys, cleaner way? | ||
1266 | } | ||
1267 | |||
1268 | |||
920 | /* end of identity_api.c */ | 1269 | /* end of identity_api.c */ |
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c index 26b1eacd7..51afb2515 100644 --- a/src/identity/identity_api_lookup.c +++ b/src/identity/identity_api_lookup.c | |||
@@ -127,14 +127,12 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
127 | struct GNUNET_IDENTITY_EgoLookup *el = cls; | 127 | struct GNUNET_IDENTITY_EgoLookup *el = cls; |
128 | uint16_t name_len = ntohs (um->name_len); | 128 | uint16_t name_len = ntohs (um->name_len); |
129 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; | 129 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; |
130 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
131 | struct GNUNET_HashCode id; | 130 | struct GNUNET_HashCode id; |
132 | struct GNUNET_IDENTITY_Ego ego; | 131 | struct GNUNET_IDENTITY_Ego ego; |
133 | memset (&ego, 0, sizeof (ego)); | 132 | memset (&ego, 0, sizeof (ego)); |
134 | 133 | ||
135 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); | 134 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); |
136 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); | 135 | GNUNET_CRYPTO_hash (&um->private_key, sizeof(um->private_key), &id); |
137 | GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id); | ||
138 | ego.pk = um->private_key; | 136 | ego.pk = um->private_key; |
139 | ego.name = (char *) str; | 137 | ego.name = (char *) str; |
140 | ego.id = id; | 138 | ego.id = id; |
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index d86d29e36..dba1d478d 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -384,7 +384,7 @@ ego_get_for_subsystem (void *cls, | |||
384 | { | 384 | { |
385 | struct RequestHandle *handle = cls; | 385 | struct RequestHandle *handle = cls; |
386 | struct MHD_Response *resp; | 386 | struct MHD_Response *resp; |
387 | struct GNUNET_CRYPTO_EcdsaPublicKey public_key; | 387 | struct GNUNET_IDENTITY_PublicKey public_key; |
388 | json_t *json_root; | 388 | json_t *json_root; |
389 | char *result_str; | 389 | char *result_str; |
390 | char *public_key_string; | 390 | char *public_key_string; |
@@ -398,7 +398,7 @@ ego_get_for_subsystem (void *cls, | |||
398 | } | 398 | } |
399 | 399 | ||
400 | GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); | 400 | GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); |
401 | public_key_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (&public_key); | 401 | public_key_string = GNUNET_IDENTITY_public_key_to_string (&public_key); |
402 | 402 | ||
403 | // create json with subsystem identity | 403 | // create json with subsystem identity |
404 | json_root = json_object (); | 404 | json_root = json_object (); |
@@ -496,7 +496,7 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
496 | GNUNET_CONTAINER_multihashmap_contains ( | 496 | GNUNET_CONTAINER_multihashmap_contains ( |
497 | handle->rest_handle->url_param_map, &key)) | 497 | handle->rest_handle->url_param_map, &key)) |
498 | { | 498 | { |
499 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | 499 | privkey_str = GNUNET_IDENTITY_private_key_to_string ( |
500 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | 500 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); |
501 | json_object_set_new (json_ego, | 501 | json_object_set_new (json_ego, |
502 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | 502 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, |
@@ -549,7 +549,7 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
549 | GNUNET_CONTAINER_multihashmap_contains ( | 549 | GNUNET_CONTAINER_multihashmap_contains ( |
550 | handle->rest_handle->url_param_map, &key)) | 550 | handle->rest_handle->url_param_map, &key)) |
551 | { | 551 | { |
552 | privkey_str = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | 552 | privkey_str = GNUNET_IDENTITY_private_key_to_string ( |
553 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); | 553 | GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego)); |
554 | json_object_set_new (json_ego, | 554 | json_object_set_new (json_ego, |
555 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, | 555 | GNUNET_REST_IDENTITY_PARAM_PRIVKEY, |
@@ -686,7 +686,7 @@ do_finished (void *cls, const char *emsg) | |||
686 | */ | 686 | */ |
687 | static void | 687 | static void |
688 | do_finished_create (void *cls, | 688 | do_finished_create (void *cls, |
689 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 689 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
690 | const char *emsg) | 690 | const char *emsg) |
691 | { | 691 | { |
692 | struct RequestHandle *handle = cls; | 692 | struct RequestHandle *handle = cls; |
@@ -999,8 +999,8 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
999 | json_error_t err; | 999 | json_error_t err; |
1000 | char *egoname; | 1000 | char *egoname; |
1001 | char *privkey; | 1001 | char *privkey; |
1002 | struct GNUNET_CRYPTO_EcdsaPrivateKey pk; | 1002 | struct GNUNET_IDENTITY_PrivateKey pk; |
1003 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk_ptr; | 1003 | struct GNUNET_IDENTITY_PrivateKey *pk_ptr; |
1004 | int json_unpack_state; | 1004 | int json_unpack_state; |
1005 | char term_data[handle->data_size + 1]; | 1005 | char term_data[handle->data_size + 1]; |
1006 | 1006 | ||
@@ -1074,7 +1074,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1074 | strlen (privkey), | 1074 | strlen (privkey), |
1075 | &pk, | 1075 | &pk, |
1076 | sizeof(struct | 1076 | sizeof(struct |
1077 | GNUNET_CRYPTO_EcdsaPrivateKey)); | 1077 | GNUNET_IDENTITY_PrivateKey)); |
1078 | pk_ptr = &pk; | 1078 | pk_ptr = &pk; |
1079 | } | 1079 | } |
1080 | else | 1080 | else |
@@ -1084,6 +1084,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1084 | handle->op = GNUNET_IDENTITY_create (identity_handle, | 1084 | handle->op = GNUNET_IDENTITY_create (identity_handle, |
1085 | handle->name, | 1085 | handle->name, |
1086 | pk_ptr, | 1086 | pk_ptr, |
1087 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
1087 | &do_finished_create, | 1088 | &do_finished_create, |
1088 | handle); | 1089 | handle); |
1089 | } | 1090 | } |
@@ -1208,7 +1209,7 @@ list_ego (void *cls, | |||
1208 | const char *identifier) | 1209 | const char *identifier) |
1209 | { | 1210 | { |
1210 | struct EgoEntry *ego_entry; | 1211 | struct EgoEntry *ego_entry; |
1211 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1212 | struct GNUNET_IDENTITY_PublicKey pk; |
1212 | 1213 | ||
1213 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) | 1214 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1214 | { | 1215 | { |
@@ -1219,7 +1220,7 @@ list_ego (void *cls, | |||
1219 | { | 1220 | { |
1220 | ego_entry = GNUNET_new (struct EgoEntry); | 1221 | ego_entry = GNUNET_new (struct EgoEntry); |
1221 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1222 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1222 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1223 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
1223 | ego_entry->ego = ego; | 1224 | ego_entry->ego = ego; |
1224 | ego_entry->identifier = GNUNET_strdup (identifier); | 1225 | ego_entry->identifier = GNUNET_strdup (identifier); |
1225 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 1226 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
@@ -1245,7 +1246,7 @@ list_ego (void *cls, | |||
1245 | /* Add */ | 1246 | /* Add */ |
1246 | ego_entry = GNUNET_new (struct EgoEntry); | 1247 | ego_entry = GNUNET_new (struct EgoEntry); |
1247 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1248 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1248 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1249 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
1249 | ego_entry->ego = ego; | 1250 | ego_entry->ego = ego; |
1250 | ego_entry->identifier = GNUNET_strdup (identifier); | 1251 | ego_entry->identifier = GNUNET_strdup (identifier); |
1251 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 1252 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index 37eeab238..4954fe7be 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c | |||
@@ -253,7 +253,7 @@ success_rename_cont (void *cls, const char *emsg) | |||
253 | */ | 253 | */ |
254 | static void | 254 | static void |
255 | create_cb (void *cls, | 255 | create_cb (void *cls, |
256 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 256 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
257 | const char *emsg) | 257 | const char *emsg) |
258 | { | 258 | { |
259 | CHECK (NULL != pk); | 259 | CHECK (NULL != pk); |
@@ -279,7 +279,11 @@ run (void *cls, | |||
279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 279 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 280 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
281 | CHECK (NULL != h); | 281 | CHECK (NULL != h); |
282 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); | 282 | op = GNUNET_IDENTITY_create (h, |
283 | "test-id", | ||
284 | NULL, | ||
285 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
286 | &create_cb, NULL); | ||
283 | } | 287 | } |
284 | 288 | ||
285 | 289 | ||
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index 53eec1252..2d5244d1b 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.c | |||
@@ -241,7 +241,7 @@ notification_cb (void *cls, | |||
241 | */ | 241 | */ |
242 | static void | 242 | static void |
243 | create_cb (void *cls, | 243 | create_cb (void *cls, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 244 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
245 | const char *emsg) | 245 | const char *emsg) |
246 | { | 246 | { |
247 | CHECK (NULL == emsg); | 247 | CHECK (NULL == emsg); |
@@ -266,7 +266,11 @@ run_set (void *cls, | |||
266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
268 | CHECK (NULL != h); | 268 | CHECK (NULL != h); |
269 | op = GNUNET_IDENTITY_create (h, "test-id", NULL, &create_cb, NULL); | 269 | op = GNUNET_IDENTITY_create (h, |
270 | "test-id", | ||
271 | NULL, | ||
272 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
273 | &create_cb, NULL); | ||
270 | } | 274 | } |
271 | 275 | ||
272 | 276 | ||
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 202abb7ac..fc3d745a6 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -62,6 +62,7 @@ gnunetinclude_HEADERS = \ | |||
62 | gnunet_json_lib.h \ | 62 | gnunet_json_lib.h \ |
63 | gnunet_load_lib.h \ | 63 | gnunet_load_lib.h \ |
64 | gnunet_cadet_service.h \ | 64 | gnunet_cadet_service.h \ |
65 | gnunet_messenger_service.h \ | ||
65 | gnunet_mhd_compat.h \ | 66 | gnunet_mhd_compat.h \ |
66 | gnunet_microphone_lib.h \ | 67 | gnunet_microphone_lib.h \ |
67 | gnunet_mst_lib.h \ | 68 | gnunet_mst_lib.h \ |
diff --git a/src/include/gnunet_buffer_lib.h b/src/include/gnunet_buffer_lib.h index 0c566df75..7239eccfb 100644 --- a/src/include/gnunet_buffer_lib.h +++ b/src/include/gnunet_buffer_lib.h | |||
@@ -147,7 +147,8 @@ GNUNET_buffer_write_path (struct GNUNET_Buffer *buf, const char *str); | |||
147 | * @param ... format arguments | 147 | * @param ... format arguments |
148 | */ | 148 | */ |
149 | void | 149 | void |
150 | GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...); | 150 | GNUNET_buffer_write_fstr (struct GNUNET_Buffer *buf, const char *fmt, ...) |
151 | __attribute__ ((format (printf, 2, 3))); | ||
151 | 152 | ||
152 | 153 | ||
153 | /** | 154 | /** |
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index fcaae1026..21b87b0f5 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -488,7 +488,8 @@ void | |||
488 | GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, | 488 | GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, |
489 | const char *comp, | 489 | const char *comp, |
490 | const char *message, | 490 | const char *message, |
491 | ...); | 491 | ...) |
492 | __attribute__ ((format (printf, 3, 4))); | ||
492 | 493 | ||
493 | #if ! defined(GNUNET_CULL_LOGGING) | 494 | #if ! defined(GNUNET_CULL_LOGGING) |
494 | #define GNUNET_log_from(kind, comp, ...) \ | 495 | #define GNUNET_log_from(kind, comp, ...) \ |
@@ -1445,6 +1446,7 @@ GNUNET_is_zero_ (const void *a, | |||
1445 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ | 1446 | memcpy (&(arr1) [(len1) - (len2)], _a2, (len2) * sizeof (*arr1)); \ |
1446 | } while (0) | 1447 | } while (0) |
1447 | 1448 | ||
1449 | |||
1448 | /** | 1450 | /** |
1449 | * @ingroup memory | 1451 | * @ingroup memory |
1450 | * Like snprintf, just aborts if the buffer is of insufficient size. | 1452 | * Like snprintf, just aborts if the buffer is of insufficient size. |
@@ -1456,7 +1458,11 @@ GNUNET_is_zero_ (const void *a, | |||
1456 | * @return number of bytes written to buf or negative value on error | 1458 | * @return number of bytes written to buf or negative value on error |
1457 | */ | 1459 | */ |
1458 | int | 1460 | int |
1459 | GNUNET_snprintf (char *buf, size_t size, const char *format, ...); | 1461 | GNUNET_snprintf (char *buf, |
1462 | size_t size, | ||
1463 | const char *format, | ||
1464 | ...) | ||
1465 | __attribute__ ((format (printf, 3, 4))); | ||
1460 | 1466 | ||
1461 | 1467 | ||
1462 | /** | 1468 | /** |
@@ -1469,7 +1475,10 @@ GNUNET_snprintf (char *buf, size_t size, const char *format, ...); | |||
1469 | * @return number of bytes in "*buf" excluding 0-termination | 1475 | * @return number of bytes in "*buf" excluding 0-termination |
1470 | */ | 1476 | */ |
1471 | int | 1477 | int |
1472 | GNUNET_asprintf (char **buf, const char *format, ...); | 1478 | GNUNET_asprintf (char **buf, |
1479 | const char *format, | ||
1480 | ...) | ||
1481 | __attribute__ ((format (printf, 2, 3))); | ||
1473 | 1482 | ||
1474 | 1483 | ||
1475 | /* ************** internal implementations, use macros above! ************** */ | 1484 | /* ************** internal implementations, use macros above! ************** */ |
diff --git a/src/include/gnunet_conversation_service.h b/src/include/gnunet_conversation_service.h index 4566caad0..be5a81cfb 100644 --- a/src/include/gnunet_conversation_service.h +++ b/src/include/gnunet_conversation_service.h | |||
@@ -147,7 +147,7 @@ typedef void | |||
147 | struct GNUNET_CONVERSATION_Caller * | 147 | struct GNUNET_CONVERSATION_Caller * |
148 | caller, | 148 | caller, |
149 | const struct | 149 | const struct |
150 | GNUNET_CRYPTO_EcdsaPublicKey *caller_id); | 150 | GNUNET_IDENTITY_PublicKey *caller_id); |
151 | 151 | ||
152 | 152 | ||
153 | /** | 153 | /** |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 03fb16a43..2bbf2b1e7 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1700,7 +1700,7 @@ GNUNET_CRYPTO_eddsa_sign_ ( | |||
1700 | */ | 1700 | */ |
1701 | #define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \ | 1701 | #define GNUNET_CRYPTO_eddsa_sign(priv,ps,sig) do { \ |
1702 | /* check size is set correctly */ \ | 1702 | /* check size is set correctly */ \ |
1703 | GNUNET_assert (htonl ((ps)->purpose.size) == sizeof (*ps)); \ | 1703 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*ps)); \ |
1704 | /* check 'ps' begins with the purpose */ \ | 1704 | /* check 'ps' begins with the purpose */ \ |
1705 | GNUNET_static_assert (((void*) (ps)) == \ | 1705 | GNUNET_static_assert (((void*) (ps)) == \ |
1706 | ((void*) &(ps)->purpose)); \ | 1706 | ((void*) &(ps)->purpose)); \ |
@@ -1747,7 +1747,7 @@ GNUNET_CRYPTO_ecdsa_sign_ ( | |||
1747 | */ | 1747 | */ |
1748 | #define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \ | 1748 | #define GNUNET_CRYPTO_ecdsa_sign(priv,ps,sig) do { \ |
1749 | /* check size is set correctly */ \ | 1749 | /* check size is set correctly */ \ |
1750 | GNUNET_assert (htonl ((ps)->purpose.size) == sizeof (*(ps))); \ | 1750 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
1751 | /* check 'ps' begins with the purpose */ \ | 1751 | /* check 'ps' begins with the purpose */ \ |
1752 | GNUNET_static_assert (((void*) (ps)) == \ | 1752 | GNUNET_static_assert (((void*) (ps)) == \ |
1753 | ((void*) &(ps)->purpose)); \ | 1753 | ((void*) &(ps)->purpose)); \ |
@@ -1853,7 +1853,7 @@ GNUNET_CRYPTO_ecdsa_verify_ ( | |||
1853 | */ | 1853 | */ |
1854 | #define GNUNET_CRYPTO_ecdsa_verify(purp,ps,sig,pub) ({ \ | 1854 | #define GNUNET_CRYPTO_ecdsa_verify(purp,ps,sig,pub) ({ \ |
1855 | /* check size is set correctly */ \ | 1855 | /* check size is set correctly */ \ |
1856 | GNUNET_assert (htonl ((ps)->purpose.size) == sizeof (*(ps))); \ | 1856 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
1857 | /* check 'ps' begins with the purpose */ \ | 1857 | /* check 'ps' begins with the purpose */ \ |
1858 | GNUNET_static_assert (((void*) (ps)) == \ | 1858 | GNUNET_static_assert (((void*) (ps)) == \ |
1859 | ((void*) &(ps)->purpose)); \ | 1859 | ((void*) &(ps)->purpose)); \ |
diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index ef81e9a88..3f6c9b9aa 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h | |||
@@ -36,6 +36,7 @@ | |||
36 | 36 | ||
37 | #include "gnunet_util_lib.h" | 37 | #include "gnunet_util_lib.h" |
38 | #include "gnunet_dnsparser_lib.h" | 38 | #include "gnunet_dnsparser_lib.h" |
39 | #include "gnunet_identity_service.h" | ||
39 | #include "gnunet_namestore_service.h" | 40 | #include "gnunet_namestore_service.h" |
40 | 41 | ||
41 | #ifdef __cplusplus | 42 | #ifdef __cplusplus |
@@ -139,7 +140,7 @@ enum GNUNET_GNS_LocalOptions | |||
139 | struct GNUNET_GNS_LookupRequest * | 140 | struct GNUNET_GNS_LookupRequest * |
140 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | 141 | GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, |
141 | const char *name, | 142 | const char *name, |
142 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 143 | const struct GNUNET_IDENTITY_PublicKey *zone, |
143 | uint32_t type, | 144 | uint32_t type, |
144 | enum GNUNET_GNS_LocalOptions options, | 145 | enum GNUNET_GNS_LocalOptions options, |
145 | GNUNET_GNS_LookupResultProcessor proc, | 146 | GNUNET_GNS_LookupResultProcessor proc, |
@@ -163,7 +164,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
163 | struct GNUNET_GNS_LookupRequest * | 164 | struct GNUNET_GNS_LookupRequest * |
164 | GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, | 165 | GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, |
165 | const char *name, | 166 | const char *name, |
166 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 167 | const struct GNUNET_IDENTITY_PublicKey *zone, |
167 | uint32_t type, | 168 | uint32_t type, |
168 | enum GNUNET_GNS_LocalOptions options, | 169 | enum GNUNET_GNS_LocalOptions options, |
169 | uint16_t recursion_depth_limit, | 170 | uint16_t recursion_depth_limit, |
diff --git a/src/include/gnunet_gnsrecord_json_lib.h b/src/include/gnunet_gnsrecord_json_lib.h new file mode 100644 index 000000000..966461705 --- /dev/null +++ b/src/include/gnunet_gnsrecord_json_lib.h | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2012, 2013 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 | /** | ||
22 | * @author Martin Schanzenbach | ||
23 | * | ||
24 | * @file | ||
25 | * API that can be used to manipulate JSON GNS record data | ||
26 | * | ||
27 | * @defgroup gnsrecord GNS Record library | ||
28 | * Manipulate GNS record data | ||
29 | * | ||
30 | * @see [Documentation](https://gnunet.org/gns-plugins) | ||
31 | * | ||
32 | * @{ | ||
33 | */ | ||
34 | #ifndef GNUNET_GNSRECORD_JSON_LIB_H | ||
35 | #define GNUNET_GNSRECORD_JSON_LIB_H | ||
36 | |||
37 | #include "gnunet_gnsrecord_lib.h" | ||
38 | #include "gnunet_json_lib.h" | ||
39 | |||
40 | #ifdef __cplusplus | ||
41 | extern "C" { | ||
42 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
43 | } | ||
44 | #endif | ||
45 | #endif | ||
46 | |||
47 | |||
48 | /** | ||
49 | * JSON Specification for GNS Records. | ||
50 | * | ||
51 | * @param gnsrecord_object struct of GNUNET_GNSRECORD_Data to fill | ||
52 | * @return JSON Specification | ||
53 | */ | ||
54 | struct GNUNET_JSON_Specification | ||
55 | GNUNET_GNSRECORD_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | ||
56 | unsigned int *rd_count, | ||
57 | char **name); | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Convert GNS record to JSON. | ||
62 | * | ||
63 | * @param rname name of record | ||
64 | * @param rd record data | ||
65 | * @return corresponding JSON encoding | ||
66 | */ | ||
67 | json_t * | ||
68 | GNUNET_GNSRECORD_JSON_from_gnsrecord (const char*rname, | ||
69 | const struct GNUNET_GNSRECORD_Data *rd, | ||
70 | unsigned int rd_count); | ||
71 | |||
72 | |||
73 | #endif | ||
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 960203fb1..0bf2ceed7 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -34,6 +34,8 @@ | |||
34 | #ifndef GNUNET_GNSRECORD_LIB_H | 34 | #ifndef GNUNET_GNSRECORD_LIB_H |
35 | #define GNUNET_GNSRECORD_LIB_H | 35 | #define GNUNET_GNSRECORD_LIB_H |
36 | 36 | ||
37 | #include "gnunet_identity_service.h" | ||
38 | |||
37 | #ifdef __cplusplus | 39 | #ifdef __cplusplus |
38 | extern "C" { | 40 | extern "C" { |
39 | #if 0 /* keep Emacsens' auto-indent happy */ | 41 | #if 0 /* keep Emacsens' auto-indent happy */ |
@@ -55,7 +57,7 @@ extern "C" { | |||
55 | /** | 57 | /** |
56 | * Record type for GNS zone transfer ("PKEY"). | 58 | * Record type for GNS zone transfer ("PKEY"). |
57 | */ | 59 | */ |
58 | #define GNUNET_GNSRECORD_TYPE_PKEY 65536 | 60 | #define GNUNET_GNSRECORD_TYPE_PKEY GNUNET_IDENTITY_TYPE_ECDSA |
59 | 61 | ||
60 | /** | 62 | /** |
61 | * Record type for GNS nick names ("NICK"). | 63 | * Record type for GNS nick names ("NICK"). |
@@ -151,6 +153,11 @@ extern "C" { | |||
151 | */ | 153 | */ |
152 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555 | 154 | #define GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION 65555 |
153 | 155 | ||
156 | /** | ||
157 | * Record type for EDKEY delegations. | ||
158 | */ | ||
159 | #define GNUNET_GNSRECORD_TYPE_EDKEY GNUNET_IDENTITY_TYPE_EDDSA | ||
160 | |||
154 | 161 | ||
155 | /** | 162 | /** |
156 | * Flags that can be set for a record. | 163 | * Flags that can be set for a record. |
@@ -261,21 +268,20 @@ struct GNUNET_GNSRECORD_PlaceData | |||
261 | /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */ | 268 | /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */ |
262 | }; | 269 | }; |
263 | 270 | ||
264 | |||
265 | /** | 271 | /** |
266 | * Information we have in an encrypted block with record data (i.e. in the DHT). | 272 | * Information we have in an encrypted block with record data (i.e. in the DHT). |
267 | */ | 273 | */ |
268 | struct GNUNET_GNSRECORD_Block | 274 | struct GNUNET_GNSRECORD_EcdsaBlock |
269 | { | 275 | { |
270 | /** | 276 | /** |
271 | * Signature of the block. | 277 | * Derived key used for signing; hash of this is the query. |
272 | */ | 278 | */ |
273 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 279 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; |
274 | 280 | ||
275 | /** | 281 | /** |
276 | * Derived key used for signing; hash of this is the query. | 282 | * Signature of the block. |
277 | */ | 283 | */ |
278 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | 284 | struct GNUNET_CRYPTO_EcdsaSignature signature; |
279 | 285 | ||
280 | /** | 286 | /** |
281 | * Number of bytes signed; also specifies the number of bytes | 287 | * Number of bytes signed; also specifies the number of bytes |
@@ -291,6 +297,17 @@ struct GNUNET_GNSRECORD_Block | |||
291 | /* followed by encrypted data */ | 297 | /* followed by encrypted data */ |
292 | }; | 298 | }; |
293 | 299 | ||
300 | struct GNUNET_GNSRECORD_Block | ||
301 | { | ||
302 | uint32_t type; | ||
303 | |||
304 | union | ||
305 | { | ||
306 | struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block; | ||
307 | //struct GNUNET_GNSRECORD_EddsaBlock eddsa_block; | ||
308 | }; | ||
309 | }; | ||
310 | |||
294 | 311 | ||
295 | /** | 312 | /** |
296 | * Record type used to box up SRV and TLSA records. For example, a | 313 | * Record type used to box up SRV and TLSA records. For example, a |
@@ -335,7 +352,7 @@ struct GNUNET_GNSRECORD_ReverseRecord | |||
335 | /** | 352 | /** |
336 | * The public key of the namespace the is delegating to our namespace | 353 | * The public key of the namespace the is delegating to our namespace |
337 | */ | 354 | */ |
338 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 355 | struct GNUNET_IDENTITY_PublicKey pkey; |
339 | 356 | ||
340 | /** | 357 | /** |
341 | * The expiration time of the delegation | 358 | * The expiration time of the delegation |
@@ -488,7 +505,7 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src); | |||
488 | * #GNUNET_GNSRECORD_z2s. | 505 | * #GNUNET_GNSRECORD_z2s. |
489 | */ | 506 | */ |
490 | const char * | 507 | const char * |
491 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); | 508 | GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); |
492 | 509 | ||
493 | 510 | ||
494 | /** | 511 | /** |
@@ -502,7 +519,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z); | |||
502 | * key in an encoding suitable for DNS labels. | 519 | * key in an encoding suitable for DNS labels. |
503 | */ | 520 | */ |
504 | const char * | 521 | const char * |
505 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | 522 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); |
506 | 523 | ||
507 | 524 | ||
508 | /** | 525 | /** |
@@ -516,7 +533,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | |||
516 | */ | 533 | */ |
517 | int | 534 | int |
518 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 535 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
519 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkey); | 536 | struct GNUNET_IDENTITY_PublicKey *pkey); |
520 | 537 | ||
521 | 538 | ||
522 | /** | 539 | /** |
@@ -528,7 +545,7 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
528 | */ | 545 | */ |
529 | void | 546 | void |
530 | GNUNET_GNSRECORD_query_from_private_key ( | 547 | GNUNET_GNSRECORD_query_from_private_key ( |
531 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, | 548 | const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, |
532 | struct GNUNET_HashCode *query); | 549 | struct GNUNET_HashCode *query); |
533 | 550 | ||
534 | 551 | ||
@@ -541,7 +558,7 @@ GNUNET_GNSRECORD_query_from_private_key ( | |||
541 | */ | 558 | */ |
542 | void | 559 | void |
543 | GNUNET_GNSRECORD_query_from_public_key ( | 560 | GNUNET_GNSRECORD_query_from_public_key ( |
544 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label, | 561 | const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, |
545 | struct GNUNET_HashCode *query); | 562 | struct GNUNET_HashCode *query); |
546 | 563 | ||
547 | 564 | ||
@@ -555,7 +572,7 @@ GNUNET_GNSRECORD_query_from_public_key ( | |||
555 | * @param rd_count number of records in @a rd | 572 | * @param rd_count number of records in @a rd |
556 | */ | 573 | */ |
557 | struct GNUNET_GNSRECORD_Block * | 574 | struct GNUNET_GNSRECORD_Block * |
558 | GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 575 | GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, |
559 | struct GNUNET_TIME_Absolute expire, | 576 | struct GNUNET_TIME_Absolute expire, |
560 | const char *label, | 577 | const char *label, |
561 | const struct GNUNET_GNSRECORD_Data *rd, | 578 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -574,7 +591,7 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
574 | * @param rd_count number of records in @a rd | 591 | * @param rd_count number of records in @a rd |
575 | */ | 592 | */ |
576 | struct GNUNET_GNSRECORD_Block * | 593 | struct GNUNET_GNSRECORD_Block * |
577 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 594 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, |
578 | struct GNUNET_TIME_Absolute expire, | 595 | struct GNUNET_TIME_Absolute expire, |
579 | const char *label, | 596 | const char *label, |
580 | const struct GNUNET_GNSRECORD_Data *rd, | 597 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -606,7 +623,7 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | |||
606 | int | 623 | int |
607 | GNUNET_GNSRECORD_block_decrypt ( | 624 | GNUNET_GNSRECORD_block_decrypt ( |
608 | const struct GNUNET_GNSRECORD_Block *block, | 625 | const struct GNUNET_GNSRECORD_Block *block, |
609 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label, | 626 | const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, |
610 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); | 627 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); |
611 | 628 | ||
612 | 629 | ||
@@ -636,6 +653,82 @@ GNUNET_GNSRECORD_record_get_expiration_time ( | |||
636 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); | 653 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); |
637 | 654 | ||
638 | 655 | ||
656 | /** | ||
657 | * Returns the length of this block in bytes. | ||
658 | * Block length strongly depends on the zone type. | ||
659 | * | ||
660 | * @param block the block. | ||
661 | * @return the length of this block in bytes | ||
662 | */ | ||
663 | size_t | ||
664 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block); | ||
665 | |||
666 | /** | ||
667 | * Returns the expiration of a block. | ||
668 | * | ||
669 | * @param block the block. | ||
670 | * @return the block expiration. | ||
671 | */ | ||
672 | struct GNUNET_TIME_Absolute | ||
673 | GNUNET_GNSRECORD_block_get_expiration (const struct GNUNET_GNSRECORD_Block *block); | ||
674 | |||
675 | |||
676 | /** | ||
677 | * Builds the query hash from a block. | ||
678 | * | ||
679 | * @param block the block. | ||
680 | * @param query where to write the query hash. | ||
681 | * @return GNUNET_SYSERR on error. | ||
682 | */ | ||
683 | enum GNUNET_GenericReturnValue | ||
684 | GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | ||
685 | struct GNUNET_HashCode *query); | ||
686 | |||
687 | |||
688 | /** | ||
689 | * Build a #GNUNET_GNSRECORD_PublicKey from | ||
690 | * zone delegation resource record data. | ||
691 | * | ||
692 | * @param data the record data- | ||
693 | * @param data_size the data size. | ||
694 | * @param type the record type | ||
695 | * @param key the identity key to store the data in (must be allocated). | ||
696 | * @return GNUNET_OK if successful. | ||
697 | */ | ||
698 | enum GNUNET_GenericReturnValue | ||
699 | GNUNET_GNSRECORD_identity_from_data (const char *data, | ||
700 | size_t data_size, | ||
701 | uint32_t type, | ||
702 | struct GNUNET_IDENTITY_PublicKey *key); | ||
703 | |||
704 | |||
705 | /** | ||
706 | * Create record data and size from an identity key. | ||
707 | * | ||
708 | * @param key the identity key to use. | ||
709 | * @param data the record data (will be allocated) | ||
710 | * @param data_size the allocated data size. | ||
711 | * @param type the resulting record type | ||
712 | * @return GNUNET_OK if successful. | ||
713 | */ | ||
714 | enum GNUNET_GenericReturnValue | ||
715 | GNUNET_GNSRECORD_data_from_identity (const struct GNUNET_IDENTITY_PublicKey *key, | ||
716 | char **data, | ||
717 | size_t *data_size, | ||
718 | uint32_t *type); | ||
719 | |||
720 | |||
721 | /** | ||
722 | * Check if this type is one of the supported GNS zone | ||
723 | * types. | ||
724 | * | ||
725 | * @param type the type to check | ||
726 | * @return GNUNET_YES if it is one of the supported types. | ||
727 | */ | ||
728 | enum GNUNET_GenericReturnValue | ||
729 | GNUNET_GNSRECORD_is_zonekey_type (uint32_t type); | ||
730 | |||
731 | |||
639 | #if 0 /* keep Emacsens' auto-indent happy */ | 732 | #if 0 /* keep Emacsens' auto-indent happy */ |
640 | { | 733 | { |
641 | #endif | 734 | #endif |
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index 94127248e..2974568db 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -57,6 +57,21 @@ extern "C" { | |||
57 | */ | 57 | */ |
58 | #define GNUNET_IDENTITY_VERSION 0x00000100 | 58 | #define GNUNET_IDENTITY_VERSION 0x00000100 |
59 | 59 | ||
60 | enum GNUNET_IDENTITY_KeyType | ||
61 | { | ||
62 | /** | ||
63 | * The identity type. The value is the same as the | ||
64 | * PKEY record type. | ||
65 | */ | ||
66 | GNUNET_IDENTITY_TYPE_ECDSA = 65536, | ||
67 | |||
68 | /** | ||
69 | * EDDSA identity. The value is the same as the EDKEY | ||
70 | * record type. | ||
71 | */ | ||
72 | GNUNET_IDENTITY_TYPE_EDDSA = 65556 | ||
73 | }; | ||
74 | |||
60 | /** | 75 | /** |
61 | * Handle to access the identity service. | 76 | * Handle to access the identity service. |
62 | */ | 77 | */ |
@@ -67,6 +82,88 @@ struct GNUNET_IDENTITY_Handle; | |||
67 | */ | 82 | */ |
68 | struct GNUNET_IDENTITY_Ego; | 83 | struct GNUNET_IDENTITY_Ego; |
69 | 84 | ||
85 | |||
86 | /** | ||
87 | * A private key for an identity as per LSD0001. | ||
88 | */ | ||
89 | struct GNUNET_IDENTITY_PrivateKey | ||
90 | { | ||
91 | /** | ||
92 | * Type of public key. | ||
93 | * Defined by the GNS zone type value. | ||
94 | * In NBO. | ||
95 | */ | ||
96 | uint32_t type; | ||
97 | |||
98 | union | ||
99 | { | ||
100 | /** | ||
101 | * An ECDSA identity key. | ||
102 | */ | ||
103 | struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key; | ||
104 | |||
105 | /** | ||
106 | * AN EdDSA identtiy key | ||
107 | */ | ||
108 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key; | ||
109 | }; | ||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * An identity key as per LSD0001. | ||
115 | */ | ||
116 | struct GNUNET_IDENTITY_PublicKey | ||
117 | { | ||
118 | /** | ||
119 | * Type of public key. | ||
120 | * Defined by the GNS zone type value. | ||
121 | * In NBO. | ||
122 | */ | ||
123 | uint32_t type; | ||
124 | |||
125 | union | ||
126 | { | ||
127 | /** | ||
128 | * An ECDSA identity key. | ||
129 | */ | ||
130 | struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key; | ||
131 | |||
132 | /** | ||
133 | * AN EdDSA identtiy key | ||
134 | */ | ||
135 | struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key; | ||
136 | }; | ||
137 | }; | ||
138 | |||
139 | |||
140 | /** | ||
141 | * An identity signature as per LSD0001. | ||
142 | */ | ||
143 | struct GNUNET_IDENTITY_Signature | ||
144 | { | ||
145 | /** | ||
146 | * Type of signature. | ||
147 | * Defined by the GNS zone type value. | ||
148 | * In NBO. | ||
149 | */ | ||
150 | uint32_t type; | ||
151 | |||
152 | union | ||
153 | { | ||
154 | /** | ||
155 | * An ECDSA signature | ||
156 | */ | ||
157 | struct GNUNET_CRYPTO_EcdsaSignature ecdsa_signature; | ||
158 | |||
159 | /** | ||
160 | * AN EdDSA signature | ||
161 | */ | ||
162 | struct GNUNET_CRYPTO_EddsaSignature eddsa_signature; | ||
163 | }; | ||
164 | }; | ||
165 | |||
166 | |||
70 | /** | 167 | /** |
71 | * Handle for an operation with the identity service. | 168 | * Handle for an operation with the identity service. |
72 | */ | 169 | */ |
@@ -79,7 +176,7 @@ struct GNUNET_IDENTITY_Operation; | |||
79 | * @param ego the ego | 176 | * @param ego the ego |
80 | * @return associated ECC key, valid as long as the ego is valid | 177 | * @return associated ECC key, valid as long as the ego is valid |
81 | */ | 178 | */ |
82 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 179 | const struct GNUNET_IDENTITY_PrivateKey * |
83 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); | 180 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); |
84 | 181 | ||
85 | 182 | ||
@@ -100,7 +197,7 @@ GNUNET_IDENTITY_ego_get_anonymous (void); | |||
100 | */ | 197 | */ |
101 | void | 198 | void |
102 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | 199 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, |
103 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk); | 200 | struct GNUNET_IDENTITY_PublicKey *pk); |
104 | 201 | ||
105 | 202 | ||
106 | /** | 203 | /** |
@@ -224,7 +321,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h); | |||
224 | typedef void | 321 | typedef void |
225 | (*GNUNET_IDENTITY_CreateContinuation) ( | 322 | (*GNUNET_IDENTITY_CreateContinuation) ( |
226 | void *cls, | 323 | void *cls, |
227 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 324 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
228 | const char *emsg); | 325 | const char *emsg); |
229 | 326 | ||
230 | 327 | ||
@@ -234,6 +331,7 @@ typedef void | |||
234 | * @param id identity service to use | 331 | * @param id identity service to use |
235 | * @param name desired name | 332 | * @param name desired name |
236 | * @param privkey desired private key or NULL to create one | 333 | * @param privkey desired private key or NULL to create one |
334 | * @param ktype the type of key to create. Ignored if privkey != NULL. | ||
237 | * @param cont function to call with the result (will only be called once) | 335 | * @param cont function to call with the result (will only be called once) |
238 | * @param cont_cls closure for @a cont | 336 | * @param cont_cls closure for @a cont |
239 | * @return handle to abort the operation | 337 | * @return handle to abort the operation |
@@ -241,7 +339,8 @@ typedef void | |||
241 | struct GNUNET_IDENTITY_Operation * | 339 | struct GNUNET_IDENTITY_Operation * |
242 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, | 340 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, |
243 | const char *name, | 341 | const char *name, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | 342 | const struct GNUNET_IDENTITY_PrivateKey *privkey, |
343 | enum GNUNET_IDENTITY_KeyType ktype, | ||
245 | GNUNET_IDENTITY_CreateContinuation cont, | 344 | GNUNET_IDENTITY_CreateContinuation cont, |
246 | void *cont_cls); | 345 | void *cont_cls); |
247 | 346 | ||
@@ -292,6 +391,319 @@ void | |||
292 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); | 391 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); |
293 | 392 | ||
294 | 393 | ||
394 | /** | ||
395 | * Get the compacted length of a #GNUNET_IDENTITY_PublicKey. | ||
396 | * Compacted means that it returns the minimum number of bytes this | ||
397 | * key is long, as opposed to the union structure inside | ||
398 | * #GNUNET_IDENTITY_PublicKey. | ||
399 | * Useful for compact serializations. | ||
400 | * | ||
401 | * @param key the key. | ||
402 | * @return -1 on error, else the compacted length of the key. | ||
403 | */ | ||
404 | ssize_t | ||
405 | GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key); | ||
406 | |||
407 | |||
408 | /** | ||
409 | * Reads a #GNUNET_IDENTITY_PublicKey from a compact buffer. | ||
410 | * The buffer has to contain at least the compacted length of | ||
411 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
412 | * If the buffer is too small, the function returns -1 as error. | ||
413 | * If the buffer does not contain a valid key, it returns -2 as error. | ||
414 | * | ||
415 | * @param key the key | ||
416 | * @param buffer the buffer | ||
417 | * @param len the length of buffer | ||
418 | * @return -1 or -2 on error, else the amount of bytes read from the buffer | ||
419 | */ | ||
420 | ssize_t | ||
421 | GNUNET_IDENTITY_read_key_from_buffer (struct GNUNET_IDENTITY_PublicKey *key, | ||
422 | const void*buffer, | ||
423 | size_t len); | ||
424 | |||
425 | |||
426 | /** | ||
427 | * Writes a #GNUNET_IDENTITY_PublicKey to a compact buffer. | ||
428 | * The buffer requires space for at least the compacted length of | ||
429 | * a #GNUNET_IDENTITY_PublicKey in bytes. | ||
430 | * If the buffer is too small, the function returns -1 as error. | ||
431 | * If the key is not valid, it returns -2 as error. | ||
432 | * | ||
433 | * @param key the key | ||
434 | * @param buffer the buffer | ||
435 | * @param len the length of buffer | ||
436 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
437 | */ | ||
438 | ssize_t | ||
439 | GNUNET_IDENTITY_write_key_to_buffer (const struct | ||
440 | GNUNET_IDENTITY_PublicKey *key, | ||
441 | void*buffer, | ||
442 | size_t len); | ||
443 | |||
444 | |||
445 | /** | ||
446 | * Get the compacted length of a #GNUNET_IDENTITY_Signature. | ||
447 | * Compacted means that it returns the minimum number of bytes this | ||
448 | * signature is long, as opposed to the union structure inside | ||
449 | * #GNUNET_IDENTITY_Signature. | ||
450 | * Useful for compact serializations. | ||
451 | * | ||
452 | * @param sig the signature. | ||
453 | * @return -1 on error, else the compacted length of the signature. | ||
454 | */ | ||
455 | ssize_t | ||
456 | GNUNET_IDENTITY_signature_get_length (const struct | ||
457 | GNUNET_IDENTITY_Signature *sig); | ||
458 | |||
459 | |||
460 | /** | ||
461 | * Reads a #GNUNET_IDENTITY_Signature from a compact buffer. | ||
462 | * The buffer has to contain at least the compacted length of | ||
463 | * a #GNUNET_IDENTITY_Signature in bytes. | ||
464 | * If the buffer is too small, the function returns -1 as error. | ||
465 | * If the buffer does not contain a valid key, it returns -2 as error. | ||
466 | * | ||
467 | * @param sig the signature | ||
468 | * @param buffer the buffer | ||
469 | * @param len the length of buffer | ||
470 | * @return -1 or -2 on error, else the amount of bytes read from the buffer | ||
471 | */ | ||
472 | ssize_t | ||
473 | GNUNET_IDENTITY_read_signature_from_buffer (struct | ||
474 | GNUNET_IDENTITY_Signature *sig, | ||
475 | const void*buffer, | ||
476 | size_t len); | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Writes a #GNUNET_IDENTITY_Signature to a compact buffer. | ||
481 | * The buffer requires space for at least the compacted length of | ||
482 | * a #GNUNET_IDENTITY_Signature in bytes. | ||
483 | * If the buffer is too small, the function returns -1 as error. | ||
484 | * If the key is not valid, it returns -2 as error. | ||
485 | * | ||
486 | * @param sig the signature | ||
487 | * @param buffer the buffer | ||
488 | * @param len the length of buffer | ||
489 | * @return -1 or -2 on error, else the amount of bytes written to the buffer | ||
490 | */ | ||
491 | ssize_t | ||
492 | GNUNET_IDENTITY_write_signature_to_buffer (const struct | ||
493 | GNUNET_IDENTITY_Signature *sig, | ||
494 | void*buffer, | ||
495 | size_t len); | ||
496 | |||
497 | |||
498 | /** | ||
499 | * @brief Sign a given block. | ||
500 | * | ||
501 | * The @a purpose data is the beginning of the data of which the signature is | ||
502 | * to be created. The `size` field in @a purpose must correctly indicate the | ||
503 | * number of bytes of the data structure, including its header. If possible, | ||
504 | * use #GNUNET_IDENTITY_sign() instead of this function. | ||
505 | * | ||
506 | * @param priv private key to use for the signing | ||
507 | * @param purpose what to sign (size, purpose) | ||
508 | * @param[out] sig where to write the signature | ||
509 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
510 | */ | ||
511 | int | ||
512 | GNUNET_IDENTITY_sign_ (const struct | ||
513 | GNUNET_IDENTITY_PrivateKey *priv, | ||
514 | const struct | ||
515 | GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
516 | struct GNUNET_IDENTITY_Signature *sig); | ||
517 | |||
518 | |||
519 | /** | ||
520 | * @brief Sign a given block with #GNUNET_IDENTITY_PrivateKey. | ||
521 | * | ||
522 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
523 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
524 | * number of bytes of the data structure, including its header. | ||
525 | * | ||
526 | * @param priv private key to use for the signing | ||
527 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
528 | * @param[out] sig where to write the signature | ||
529 | */ | ||
530 | #define GNUNET_IDENTITY_sign(priv,ps,sig) do { \ | ||
531 | /* check size is set correctly */ \ | ||
532 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
533 | /* check 'ps' begins with the purpose */ \ | ||
534 | GNUNET_static_assert (((void*) (ps)) == \ | ||
535 | ((void*) &(ps)->purpose)); \ | ||
536 | GNUNET_assert (GNUNET_OK == \ | ||
537 | GNUNET_IDENTITY_sign_ (priv, \ | ||
538 | &(ps)->purpose, \ | ||
539 | sig)); \ | ||
540 | } while (0) | ||
541 | |||
542 | |||
543 | /** | ||
544 | * @brief Verify a given signature. | ||
545 | * | ||
546 | * The @a validate data is the beginning of the data of which the signature | ||
547 | * is to be verified. The `size` field in @a validate must correctly indicate | ||
548 | * the number of bytes of the data structure, including its header. If @a | ||
549 | * purpose does not match the purpose given in @a validate (the latter must be | ||
550 | * in big endian), signature verification fails. If possible, | ||
551 | * use #GNUNET_IDENTITY_signature_verify() instead of this function (only if @a validate | ||
552 | * is not fixed-size, you must use this function directly). | ||
553 | * | ||
554 | * @param purpose what is the purpose that the signature should have? | ||
555 | * @param validate block to validate (size, purpose, data) | ||
556 | * @param sig signature that is being validated | ||
557 | * @param pub public key of the signer | ||
558 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
559 | */ | ||
560 | int | ||
561 | GNUNET_IDENTITY_signature_verify_ (uint32_t purpose, | ||
562 | const struct | ||
563 | GNUNET_CRYPTO_EccSignaturePurpose *validate, | ||
564 | const struct GNUNET_IDENTITY_Signature *sig, | ||
565 | const struct | ||
566 | GNUNET_IDENTITY_PublicKey *pub); | ||
567 | |||
568 | |||
569 | /** | ||
570 | * @brief Verify a given signature with #GNUNET_IDENTITY_PublicKey. | ||
571 | * | ||
572 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
573 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
574 | * number of bytes of the data structure, including its header. | ||
575 | * | ||
576 | * @param purp purpose of the signature, must match 'ps->purpose.purpose' | ||
577 | * (except in host byte order) | ||
578 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
579 | * @param sig where to read the signature from | ||
580 | * @param pub public key to use for the verifying | ||
581 | */ | ||
582 | #define GNUNET_IDENTITY_signature_verify(purp,ps,sig,pub) ({ \ | ||
583 | /* check size is set correctly */ \ | ||
584 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
585 | /* check 'ps' begins with the purpose */ \ | ||
586 | GNUNET_static_assert (((void*) (ps)) == \ | ||
587 | ((void*) &(ps)->purpose)); \ | ||
588 | GNUNET_IDENTITY_signature_verify_ (purp, \ | ||
589 | &(ps)->purpose, \ | ||
590 | sig, \ | ||
591 | pub); \ | ||
592 | }) | ||
593 | |||
594 | |||
595 | /** | ||
596 | * Encrypt a block with #GNUNET_IDENTITY_PublicKey and derives a | ||
597 | * #GNUNET_CRYPTO_EcdhePublicKey which is required for decryption | ||
598 | * using ecdh to derive a symmetric key. | ||
599 | * | ||
600 | * @param block the block to encrypt | ||
601 | * @param size the size of the @a block | ||
602 | * @param pub public key to use for ecdh | ||
603 | * @param ecc where to write the ecc public key | ||
604 | * @param result the output parameter in which to store the encrypted result | ||
605 | * can be the same or overlap with @c block | ||
606 | * @returns the size of the encrypted block, -1 for errors. | ||
607 | * Due to the use of CFB and therefore an effective stream cipher, | ||
608 | * this size should be the same as @c len. | ||
609 | */ | ||
610 | ssize_t | ||
611 | GNUNET_IDENTITY_encrypt (const void *block, | ||
612 | size_t size, | ||
613 | const struct GNUNET_IDENTITY_PublicKey *pub, | ||
614 | struct GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
615 | void *result); | ||
616 | |||
617 | |||
618 | /** | ||
619 | * Decrypt a given block with #GNUNET_IDENTITY_PrivateKey and a given | ||
620 | * #GNUNET_CRYPTO_EcdhePublicKey using ecdh to derive a symmetric key. | ||
621 | * | ||
622 | * @param block the data to decrypt, encoded as returned by encrypt | ||
623 | * @param size the size of the @a block to decrypt | ||
624 | * @param priv private key to use for ecdh | ||
625 | * @param ecc the ecc public key | ||
626 | * @param result address to store the result at | ||
627 | * can be the same or overlap with @c block | ||
628 | * @return -1 on failure, size of decrypted block on success. | ||
629 | * Due to the use of CFB and therefore an effective stream cipher, | ||
630 | * this size should be the same as @c size. | ||
631 | */ | ||
632 | ssize_t | ||
633 | GNUNET_IDENTITY_decrypt (const void *block, | ||
634 | size_t size, | ||
635 | const struct | ||
636 | GNUNET_IDENTITY_PrivateKey *priv, | ||
637 | const struct | ||
638 | GNUNET_CRYPTO_EcdhePublicKey *ecc, | ||
639 | void *result); | ||
640 | |||
641 | |||
642 | /** | ||
643 | * Creates a (Base32) string representation of the public key. | ||
644 | * The resulting string encodes a compacted representation of the key. | ||
645 | * See also #GNUNET_IDENTITY_key_get_length. | ||
646 | * | ||
647 | * @param key the key. | ||
648 | * @return the string representation of the key, or NULL on error. | ||
649 | */ | ||
650 | char * | ||
651 | GNUNET_IDENTITY_public_key_to_string (const struct | ||
652 | GNUNET_IDENTITY_PublicKey *key); | ||
653 | |||
654 | |||
655 | /** | ||
656 | * Creates a (Base32) string representation of the private key. | ||
657 | * The resulting string encodes a compacted representation of the key. | ||
658 | * See also #GNUNET_IDENTITY_key_get_length. | ||
659 | * | ||
660 | * @param key the key. | ||
661 | * @return the string representation of the key, or NULL on error. | ||
662 | */ | ||
663 | char * | ||
664 | GNUNET_IDENTITY_private_key_to_string (const struct | ||
665 | GNUNET_IDENTITY_PrivateKey *key); | ||
666 | |||
667 | |||
668 | /** | ||
669 | * Parses a (Base32) string representation of the public key. | ||
670 | * See also #GNUNET_IDENTITY_public_key_to_string. | ||
671 | * | ||
672 | * @param str the encoded key. | ||
673 | * @param key where to write the key. | ||
674 | * @return GNUNET_SYSERR on error. | ||
675 | */ | ||
676 | enum GNUNET_GenericReturnValue | ||
677 | GNUNET_IDENTITY_public_key_from_string (const char*str, | ||
678 | struct GNUNET_IDENTITY_PublicKey *key); | ||
679 | |||
680 | |||
681 | /** | ||
682 | * Parses a (Base32) string representation of the private key. | ||
683 | * See also #GNUNET_IDENTITY_private_key_to_string. | ||
684 | * | ||
685 | * @param str the encoded key. | ||
686 | * @param key where to write the key. | ||
687 | * @return GNUNET_SYSERR on error. | ||
688 | */ | ||
689 | enum GNUNET_GenericReturnValue | ||
690 | GNUNET_IDENTITY_private_key_from_string (const char*str, | ||
691 | struct GNUNET_IDENTITY_PrivateKey *key); | ||
692 | |||
693 | |||
694 | /** | ||
695 | * Retrieves the public key representation of a private key. | ||
696 | * | ||
697 | * @param privkey the private key. | ||
698 | * @param key the public key result. | ||
699 | * @return GNUNET_SYSERR on error. | ||
700 | */ | ||
701 | enum GNUNET_GenericReturnValue | ||
702 | GNUNET_IDENTITY_key_get_public (const struct | ||
703 | GNUNET_IDENTITY_PrivateKey *privkey, | ||
704 | struct GNUNET_IDENTITY_PublicKey *key); | ||
705 | |||
706 | |||
295 | /* ************* convenience API to lookup an ego ***************** */ | 707 | /* ************* convenience API to lookup an ego ***************** */ |
296 | 708 | ||
297 | /** | 709 | /** |
@@ -344,7 +756,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el); | |||
344 | typedef void | 756 | typedef void |
345 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( | 757 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( |
346 | void *cls, | 758 | void *cls, |
347 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 759 | const struct GNUNET_IDENTITY_PrivateKey *priv, |
348 | const char *ego_name); | 760 | const char *ego_name); |
349 | 761 | ||
350 | 762 | ||
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index 07a14d329..3dc79105e 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016, 2020 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 |
@@ -28,7 +28,6 @@ | |||
28 | #define GNUNET_JSON_LIB_H | 28 | #define GNUNET_JSON_LIB_H |
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_gnsrecord_lib.h" | ||
32 | #include <jansson.h> | 31 | #include <jansson.h> |
33 | #include <microhttpd.h> | 32 | #include <microhttpd.h> |
34 | 33 | ||
@@ -359,18 +358,6 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
359 | struct GNUNET_CRYPTO_RsaSignature **sig); | 358 | struct GNUNET_CRYPTO_RsaSignature **sig); |
360 | 359 | ||
361 | 360 | ||
362 | /** | ||
363 | * JSON Specification for GNS Records. | ||
364 | * | ||
365 | * @param gnsrecord_object struct of GNUNET_GNSRECORD_Data to fill | ||
366 | * @return JSON Specification | ||
367 | */ | ||
368 | struct GNUNET_JSON_Specification | ||
369 | GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | ||
370 | unsigned int *rd_count, | ||
371 | char **name); | ||
372 | |||
373 | |||
374 | /* ****************** Generic generator interface ******************* */ | 361 | /* ****************** Generic generator interface ******************* */ |
375 | 362 | ||
376 | 363 | ||
@@ -446,18 +433,6 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk); | |||
446 | json_t * | 433 | json_t * |
447 | GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); | 434 | GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); |
448 | 435 | ||
449 | /** | ||
450 | * Convert Gns record to JSON. | ||
451 | * | ||
452 | * @param rname name of record | ||
453 | * @param rd record data | ||
454 | * @return corresponding JSON encoding | ||
455 | */ | ||
456 | json_t * | ||
457 | GNUNET_JSON_from_gnsrecord (const char *rname, | ||
458 | const struct GNUNET_GNSRECORD_Data *rd, | ||
459 | unsigned int rd_count); | ||
460 | |||
461 | /* ******************* Helpers for MHD upload handling ******************* */ | 436 | /* ******************* Helpers for MHD upload handling ******************* */ |
462 | 437 | ||
463 | /** | 438 | /** |
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h new file mode 100644 index 000000000..8f5315c30 --- /dev/null +++ b/src/include/gnunet_messenger_service.h | |||
@@ -0,0 +1,436 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | * | ||
23 | * @file | ||
24 | * MESSENGER service; manages decentralized chat groups | ||
25 | * | ||
26 | * @defgroup messenger MESSENGER service | ||
27 | * Instant messaging based on the CADET subsystem | ||
28 | * | ||
29 | * @{ | ||
30 | */ | ||
31 | |||
32 | #ifndef GNUNET_MESSENGER_SERVICE_H | ||
33 | #define GNUNET_MESSENGER_SERVICE_H | ||
34 | |||
35 | #ifdef __cplusplus | ||
36 | extern "C" { | ||
37 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
38 | } | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | #include "platform.h" | ||
43 | #include "gnunet_configuration_lib.h" | ||
44 | #include "gnunet_crypto_lib.h" | ||
45 | #include "gnunet_identity_service.h" | ||
46 | #include "gnunet_mq_lib.h" | ||
47 | #include "gnunet_protocols.h" | ||
48 | #include "gnunet_scheduler_lib.h" | ||
49 | #include "gnunet_time_lib.h" | ||
50 | |||
51 | #define GNUNET_MESSENGER_SERVICE_NAME "messenger" | ||
52 | |||
53 | /** | ||
54 | * Opaque handle to the messenger | ||
55 | */ | ||
56 | struct GNUNET_MESSENGER_Handle; | ||
57 | |||
58 | /** | ||
59 | * Opaque handle to a room | ||
60 | */ | ||
61 | struct GNUNET_MESSENGER_Room; | ||
62 | |||
63 | /** | ||
64 | * Opaque handle to a contact | ||
65 | */ | ||
66 | struct GNUNET_MESSENGER_Contact; | ||
67 | |||
68 | /** | ||
69 | * Enum for the different supported kinds of messages | ||
70 | */ | ||
71 | enum GNUNET_MESSENGER_MessageKind | ||
72 | { | ||
73 | GNUNET_MESSENGER_KIND_INFO = 1, | ||
74 | |||
75 | GNUNET_MESSENGER_KIND_JOIN = 2, | ||
76 | GNUNET_MESSENGER_KIND_LEAVE = 3, | ||
77 | |||
78 | GNUNET_MESSENGER_KIND_NAME = 4, | ||
79 | GNUNET_MESSENGER_KIND_KEY = 5, | ||
80 | GNUNET_MESSENGER_KIND_PEER = 6, | ||
81 | GNUNET_MESSENGER_KIND_ID = 7, | ||
82 | |||
83 | GNUNET_MESSENGER_KIND_MISS = 8, | ||
84 | GNUNET_MESSENGER_KIND_MERGE = 9, | ||
85 | GNUNET_MESSENGER_KIND_REQUEST = 10, | ||
86 | |||
87 | GNUNET_MESSENGER_KIND_INVITE = 11, | ||
88 | GNUNET_MESSENGER_KIND_TEXT = 12, | ||
89 | GNUNET_MESSENGER_KIND_FILE = 13, | ||
90 | |||
91 | GNUNET_MESSENGER_KIND_PRIVATE = 14, | ||
92 | |||
93 | GNUNET_MESSENGER_KIND_UNKNOWN = 0 | ||
94 | }__attribute__((__packed__)); | ||
95 | |||
96 | /** | ||
97 | * Get the name of a message <i>kind</i>. | ||
98 | * | ||
99 | * @param kind Kind of a message | ||
100 | * @return Name of that kind | ||
101 | */ | ||
102 | const char* | ||
103 | GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind); | ||
104 | |||
105 | struct GNUNET_MESSENGER_MessageHeader | ||
106 | { | ||
107 | struct GNUNET_IDENTITY_Signature signature; | ||
108 | |||
109 | struct GNUNET_TIME_AbsoluteNBO timestamp; | ||
110 | |||
111 | struct GNUNET_ShortHashCode sender_id; | ||
112 | struct GNUNET_HashCode previous; | ||
113 | |||
114 | enum GNUNET_MESSENGER_MessageKind kind; | ||
115 | }; | ||
116 | |||
117 | struct GNUNET_MESSENGER_MessageInfo | ||
118 | { | ||
119 | struct GNUNET_IDENTITY_PublicKey host_key; | ||
120 | struct GNUNET_ShortHashCode unique_id; | ||
121 | }; | ||
122 | |||
123 | struct GNUNET_MESSENGER_MessageJoin | ||
124 | { | ||
125 | struct GNUNET_IDENTITY_PublicKey key; | ||
126 | }; | ||
127 | |||
128 | struct GNUNET_MESSENGER_MessageLeave | ||
129 | { | ||
130 | }; | ||
131 | |||
132 | struct GNUNET_MESSENGER_MessageName | ||
133 | { | ||
134 | char *name; | ||
135 | }; | ||
136 | |||
137 | struct GNUNET_MESSENGER_MessageKey | ||
138 | { | ||
139 | struct GNUNET_IDENTITY_PublicKey key; | ||
140 | }; | ||
141 | |||
142 | struct GNUNET_MESSENGER_MessagePeer | ||
143 | { | ||
144 | struct GNUNET_PeerIdentity peer; | ||
145 | }; | ||
146 | |||
147 | struct GNUNET_MESSENGER_MessageId | ||
148 | { | ||
149 | struct GNUNET_ShortHashCode id; | ||
150 | }; | ||
151 | |||
152 | struct GNUNET_MESSENGER_MessageMiss | ||
153 | { | ||
154 | struct GNUNET_PeerIdentity peer; | ||
155 | }; | ||
156 | |||
157 | struct GNUNET_MESSENGER_MessageMerge | ||
158 | { | ||
159 | struct GNUNET_HashCode previous; | ||
160 | }; | ||
161 | |||
162 | struct GNUNET_MESSENGER_MessageRequest | ||
163 | { | ||
164 | struct GNUNET_HashCode hash; | ||
165 | }; | ||
166 | |||
167 | struct GNUNET_MESSENGER_MessageInvite | ||
168 | { | ||
169 | struct GNUNET_PeerIdentity door; | ||
170 | struct GNUNET_HashCode key; | ||
171 | }; | ||
172 | |||
173 | struct GNUNET_MESSENGER_MessageText | ||
174 | { | ||
175 | char *text; | ||
176 | }; | ||
177 | |||
178 | struct GNUNET_MESSENGER_MessageFile | ||
179 | { | ||
180 | struct GNUNET_CRYPTO_SymmetricSessionKey key; | ||
181 | struct GNUNET_HashCode hash; | ||
182 | char name[NAME_MAX]; | ||
183 | char *uri; | ||
184 | }; | ||
185 | |||
186 | struct GNUNET_MESSENGER_MessagePrivate | ||
187 | { | ||
188 | struct GNUNET_CRYPTO_EcdhePublicKey key; | ||
189 | |||
190 | uint16_t length; | ||
191 | char *data; | ||
192 | }; | ||
193 | |||
194 | struct GNUNET_MESSENGER_MessageBody | ||
195 | { | ||
196 | union | ||
197 | { | ||
198 | struct GNUNET_MESSENGER_MessageInfo info; | ||
199 | |||
200 | struct GNUNET_MESSENGER_MessageJoin join; | ||
201 | struct GNUNET_MESSENGER_MessageLeave leave; | ||
202 | |||
203 | struct GNUNET_MESSENGER_MessageName name; | ||
204 | struct GNUNET_MESSENGER_MessageKey key; | ||
205 | struct GNUNET_MESSENGER_MessagePeer peer; | ||
206 | struct GNUNET_MESSENGER_MessageId id; | ||
207 | |||
208 | struct GNUNET_MESSENGER_MessageMiss miss; | ||
209 | struct GNUNET_MESSENGER_MessageMerge merge; | ||
210 | struct GNUNET_MESSENGER_MessageRequest request; | ||
211 | |||
212 | struct GNUNET_MESSENGER_MessageInvite invite; | ||
213 | struct GNUNET_MESSENGER_MessageText text; | ||
214 | struct GNUNET_MESSENGER_MessageFile file; | ||
215 | |||
216 | struct GNUNET_MESSENGER_MessagePrivate private; | ||
217 | }; | ||
218 | }; | ||
219 | |||
220 | /** | ||
221 | * Struct to a message | ||
222 | */ | ||
223 | struct GNUNET_MESSENGER_Message | ||
224 | { | ||
225 | struct GNUNET_MESSENGER_MessageHeader header; | ||
226 | struct GNUNET_MESSENGER_MessageBody body; | ||
227 | }; | ||
228 | |||
229 | /** | ||
230 | * Method called whenever the EGO of a <i>handle</i> changes or if the first connection fails | ||
231 | * to load a valid EGO and the anonymous keypair will be used instead. | ||
232 | * | ||
233 | * @param cls Closure from <i>GNUNET_MESSENGER_connect</i> | ||
234 | * @param handle Messenger handle | ||
235 | */ | ||
236 | typedef void | ||
237 | (*GNUNET_MESSENGER_IdentityCallback) (void *cls, struct GNUNET_MESSENGER_Handle *handle); | ||
238 | |||
239 | /** | ||
240 | * Method called whenever a message is sent or received from a <i>room</i>. | ||
241 | * | ||
242 | * @param cls Closure from <i>GNUNET_MESSENGER_connect</i> | ||
243 | * @param room Room handle | ||
244 | * @param message Newly received or sent message | ||
245 | * @param hash Hash identifying the message | ||
246 | */ | ||
247 | typedef void | ||
248 | (*GNUNET_MESSENGER_MessageCallback) (void *cls, const struct GNUNET_MESSENGER_Room *room, | ||
249 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
250 | |||
251 | /** | ||
252 | * Set up a handle for the messenger related functions and connects to all necessary services. It will look up the ego | ||
253 | * key identified by its <i>name</i> and use it for signing all messages from the handle. | ||
254 | * | ||
255 | * @param cfg Configuration to use | ||
256 | * @param name Name to look up an ego or NULL to stay anonymous | ||
257 | * @param identity_callback Function called when the EGO of the handle changes | ||
258 | * @param identity_cls Closure for the <i>identity_callback</i> handler | ||
259 | * @param msg_callback Function called when a new message is sent or received | ||
260 | * @param msg_cls Closure for the <i>msg_callback</i> handler | ||
261 | * @return Messenger handle to use, NULL on error | ||
262 | */ | ||
263 | struct GNUNET_MESSENGER_Handle* | ||
264 | GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, | ||
265 | GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, | ||
266 | GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls); | ||
267 | |||
268 | /** | ||
269 | * Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. All | ||
270 | * participated rooms get informed about the key renewal. The handle requires a set name for this function to work and | ||
271 | * it needs to be unused by other egos. | ||
272 | * | ||
273 | * Keep in mind that this will fully delete the old ego key (if any is used) even if any other service wants to use it | ||
274 | * as default. | ||
275 | * | ||
276 | * @param handle Messenger handle to use | ||
277 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
278 | */ | ||
279 | int | ||
280 | GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle); | ||
281 | |||
282 | /** | ||
283 | * Disconnect all of the messengers used services and clears up its used memory. | ||
284 | * | ||
285 | * @param handle Messenger handle to use | ||
286 | */ | ||
287 | void | ||
288 | GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle); | ||
289 | |||
290 | /** | ||
291 | * Get the name (if specified, otherwise NULL) used by the messenger. | ||
292 | * | ||
293 | * @param handle Messenger handle to use | ||
294 | * @return Name used by the messenger or NULL | ||
295 | */ | ||
296 | const char* | ||
297 | GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle); | ||
298 | |||
299 | /** | ||
300 | * Set the name for the messenger. This will rename the currently used ego and move all stored files related to the current | ||
301 | * name to its new directory. If anything fails during this process the function returns GNUNET_NO and the name for | ||
302 | * the messenger won't change as specified. | ||
303 | * | ||
304 | * @param handle Messenger handle to use | ||
305 | * @param name Name for the messenger to change to | ||
306 | * @return GNUNET_YES on success, GNUNET_NO on failure and GNUNET_SYSERR if <i>handle</i> is NULL | ||
307 | */ | ||
308 | int | ||
309 | GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name); | ||
310 | |||
311 | /** | ||
312 | * Get the public key used by the messenger. | ||
313 | * | ||
314 | * @param handle Messenger handle to use | ||
315 | * @return Used ego's public key | ||
316 | */ | ||
317 | const struct GNUNET_IDENTITY_PublicKey* | ||
318 | GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle); | ||
319 | |||
320 | /** | ||
321 | * Open a room to send and receive messages. The room will use the specified <i>key</i> as port for the underlying cadet | ||
322 | * service. Opening a room results in opening the port for incoming connections as possible <b>door</b>. | ||
323 | * | ||
324 | * Notice that there can only be one room related to a specific <i>key</i>. So trying to open two rooms with the same | ||
325 | * <i>key</i> will result in opening the room once but returning the handle both times because the room stays open. | ||
326 | * | ||
327 | * You can also open a room after entering it through a <b>door</b> using <i>GNUNET_MESSENGER_entry_room(...)</i>. This | ||
328 | * will notify all entered <b>doors</b> to list you as new <b>door</b>. | ||
329 | * | ||
330 | * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) | ||
331 | * | ||
332 | * @param handle Messenger handle to use | ||
333 | * @param key Hash identifying the port | ||
334 | * @return Room handle, NULL on error | ||
335 | */ | ||
336 | struct GNUNET_MESSENGER_Room* | ||
337 | GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
338 | |||
339 | /** | ||
340 | * Enter a room to send and receive messages through a <b>door</b> opened using <i>GNUNET_MESSENGER_open_room(...)</i>. | ||
341 | * | ||
342 | * Notice that there can only be one room related to a specific <i>key</i>. So trying to enter two rooms with the same | ||
343 | * <i>key</i> will result in entering the room once but returning the handle both times because the room stays entered. | ||
344 | * You can however enter a room through multiple <b>doors</b> in parallel which results in connecting both ends. But | ||
345 | * entering the room through the same <b>door</b> won't have any effect after the first time. | ||
346 | * | ||
347 | * You can also enter a room through a <b>door</b> after opening it using <i>GNUNET_MESSENGER_open_room(...)</i>. But the | ||
348 | * <b>door</b> may not be your own peer identity. | ||
349 | * | ||
350 | * ( All <b>doors</b> form a ring structured network to shorten the latency sending and receiving messages. ) | ||
351 | * | ||
352 | * @param handle Messenger handle to use | ||
353 | * @param door Peer identity of an open <b>door</b> | ||
354 | * @param key Hash identifying the port | ||
355 | * @return Room handle, NULL on error | ||
356 | */ | ||
357 | struct GNUNET_MESSENGER_Room* | ||
358 | GNUNET_MESSENGER_entry_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | ||
359 | const struct GNUNET_HashCode *key); | ||
360 | |||
361 | /** | ||
362 | * Close a room which was entered, opened or both in various order and variety. Closing a room will destroy all connections | ||
363 | * from your peer to another and the other way around. | ||
364 | * | ||
365 | * ( After a member closes a <b>door</b>, all members entered through that specific <b>door</b> have to use another one | ||
366 | * or open the room on their own. ) | ||
367 | * | ||
368 | * @param room Room handle | ||
369 | */ | ||
370 | void | ||
371 | GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room); | ||
372 | |||
373 | /** | ||
374 | * Get the contact of a member in a <i>room</i> identified by their <i>id</i>. | ||
375 | * | ||
376 | * Notice that contacts are independent of rooms but will be removed if all rooms containing these contacts get closed. | ||
377 | * | ||
378 | * @param room Room handle | ||
379 | * @param id Hash identifying a member | ||
380 | * @return Contact handle, NULL if <i>id</i> is not in use | ||
381 | */ | ||
382 | struct GNUNET_MESSENGER_Contact* | ||
383 | GNUNET_MESSENGER_get_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id); | ||
384 | |||
385 | /** | ||
386 | * Get the name used by the <i>contact</i>. | ||
387 | * | ||
388 | * @param contact Contact handle | ||
389 | * @return Name of <i>contact</i> or NULL | ||
390 | */ | ||
391 | const char* | ||
392 | GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact); | ||
393 | |||
394 | /** | ||
395 | * Get the public key used by the <i>contact</i>. | ||
396 | * | ||
397 | * @param contact Contact handle | ||
398 | * @return Public key of the ego used by <i>contact</i> | ||
399 | */ | ||
400 | const struct GNUNET_IDENTITY_PublicKey* | ||
401 | GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact); | ||
402 | |||
403 | /** | ||
404 | * Send a <i>message</i> into a </i>room</i>. If you opened the <i>room</i> all entered members will receive the | ||
405 | * <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so entered <b>doors</b> will receive the | ||
406 | * <i>message</i> as well. All members receiving the <i>message</i> will also propagate this <i>message</i> recursively | ||
407 | * as long as the <i>message</i> is unknown to them. | ||
408 | * | ||
409 | * Notice that all messages sent and received are also stored and can be propagated to new members entering the room. | ||
410 | * | ||
411 | * @param room Room handle | ||
412 | * @param message New message to send | ||
413 | */ | ||
414 | void | ||
415 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message); | ||
416 | |||
417 | /** | ||
418 | * Get the message in a <i>room</i> identified by its <i>hash</i>. | ||
419 | * | ||
420 | * @param room Room handle | ||
421 | * @param hash Hash identifying a message | ||
422 | * @return Message struct or NULL if no message with that hash is known | ||
423 | */ | ||
424 | const struct GNUNET_MESSENGER_Message* | ||
425 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); | ||
426 | |||
427 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
428 | { | ||
429 | #endif | ||
430 | #ifdef __cplusplus | ||
431 | } | ||
432 | #endif | ||
433 | |||
434 | #endif //GNUNET_MESSENGER_SERVICE_H | ||
435 | |||
436 | /** @} *//* end of group */ | ||
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 443c9e451..9cc8abc6e 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h | |||
@@ -58,7 +58,7 @@ typedef void | |||
58 | (*GNUNET_NAMESTORE_RecordIterator) (void *cls, | 58 | (*GNUNET_NAMESTORE_RecordIterator) (void *cls, |
59 | uint64_t serial, | 59 | uint64_t serial, |
60 | const struct | 60 | const struct |
61 | GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 61 | GNUNET_IDENTITY_PrivateKey *private_key, |
62 | const char *label, | 62 | const char *label, |
63 | unsigned int rd_count, | 63 | unsigned int rd_count, |
64 | const struct GNUNET_GNSRECORD_Data *rd); | 64 | const struct GNUNET_GNSRECORD_Data *rd); |
@@ -87,7 +87,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
87 | */ | 87 | */ |
88 | int | 88 | int |
89 | (*store_records) (void *cls, | 89 | (*store_records) (void *cls, |
90 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 90 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
91 | const char *label, | 91 | const char *label, |
92 | unsigned int rd_count, | 92 | unsigned int rd_count, |
93 | const struct GNUNET_GNSRECORD_Data *rd); | 93 | const struct GNUNET_GNSRECORD_Data *rd); |
@@ -104,7 +104,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
104 | */ | 104 | */ |
105 | int | 105 | int |
106 | (*lookup_records) (void *cls, | 106 | (*lookup_records) (void *cls, |
107 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 107 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
108 | const char *label, | 108 | const char *label, |
109 | GNUNET_NAMESTORE_RecordIterator iter, | 109 | GNUNET_NAMESTORE_RecordIterator iter, |
110 | void *iter_cls); | 110 | void *iter_cls); |
@@ -126,7 +126,7 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
126 | */ | 126 | */ |
127 | int | 127 | int |
128 | (*iterate_records) (void *cls, | 128 | (*iterate_records) (void *cls, |
129 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 129 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
130 | uint64_t serial, | 130 | uint64_t serial, |
131 | uint64_t limit, | 131 | uint64_t limit, |
132 | GNUNET_NAMESTORE_RecordIterator iter, | 132 | GNUNET_NAMESTORE_RecordIterator iter, |
@@ -146,8 +146,8 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
146 | */ | 146 | */ |
147 | int | 147 | int |
148 | (*zone_to_name) (void *cls, | 148 | (*zone_to_name) (void *cls, |
149 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 149 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
150 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 150 | const struct GNUNET_IDENTITY_PublicKey *value_zone, |
151 | GNUNET_NAMESTORE_RecordIterator iter, | 151 | GNUNET_NAMESTORE_RecordIterator iter, |
152 | void *iter_cls); | 152 | void *iter_cls); |
153 | }; | 153 | }; |
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index bf42c8d34..ca4d2cb52 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #include "gnunet_util_lib.h" | 41 | #include "gnunet_util_lib.h" |
42 | #include "gnunet_block_lib.h" | 42 | #include "gnunet_block_lib.h" |
43 | #include "gnunet_gnsrecord_lib.h" | 43 | #include "gnunet_gnsrecord_lib.h" |
44 | #include "gnunet_identity_service.h" | ||
44 | 45 | ||
45 | #ifdef __cplusplus | 46 | #ifdef __cplusplus |
46 | extern "C" | 47 | extern "C" |
@@ -127,7 +128,7 @@ typedef void | |||
127 | struct GNUNET_NAMESTORE_QueueEntry * | 128 | struct GNUNET_NAMESTORE_QueueEntry * |
128 | GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | 129 | GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, |
129 | const struct | 130 | const struct |
130 | GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 131 | GNUNET_IDENTITY_PrivateKey *pkey, |
131 | const char *label, | 132 | const char *label, |
132 | unsigned int rd_count, | 133 | unsigned int rd_count, |
133 | const struct GNUNET_GNSRECORD_Data *rd, | 134 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -147,7 +148,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
147 | typedef void | 148 | typedef void |
148 | (*GNUNET_NAMESTORE_RecordMonitor) (void *cls, | 149 | (*GNUNET_NAMESTORE_RecordMonitor) (void *cls, |
149 | const struct | 150 | const struct |
150 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 151 | GNUNET_IDENTITY_PrivateKey *zone, |
151 | const char *label, | 152 | const char *label, |
152 | unsigned int rd_count, | 153 | unsigned int rd_count, |
153 | const struct GNUNET_GNSRECORD_Data *rd); | 154 | const struct GNUNET_GNSRECORD_Data *rd); |
@@ -170,7 +171,7 @@ typedef void | |||
170 | struct GNUNET_NAMESTORE_QueueEntry * | 171 | struct GNUNET_NAMESTORE_QueueEntry * |
171 | GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | 172 | GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, |
172 | const struct | 173 | const struct |
173 | GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 174 | GNUNET_IDENTITY_PrivateKey *pkey, |
174 | const char *label, | 175 | const char *label, |
175 | GNUNET_SCHEDULER_TaskCallback error_cb, | 176 | GNUNET_SCHEDULER_TaskCallback error_cb, |
176 | void *error_cb_cls, | 177 | void *error_cb_cls, |
@@ -197,9 +198,9 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | |||
197 | */ | 198 | */ |
198 | struct GNUNET_NAMESTORE_QueueEntry * | 199 | struct GNUNET_NAMESTORE_QueueEntry * |
199 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | 200 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, |
200 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 201 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
201 | const struct | 202 | const struct |
202 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 203 | GNUNET_IDENTITY_PublicKey *value_zone, |
203 | GNUNET_SCHEDULER_TaskCallback error_cb, | 204 | GNUNET_SCHEDULER_TaskCallback error_cb, |
204 | void *error_cb_cls, | 205 | void *error_cb_cls, |
205 | GNUNET_NAMESTORE_RecordMonitor proc, | 206 | GNUNET_NAMESTORE_RecordMonitor proc, |
@@ -246,7 +247,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); | |||
246 | struct GNUNET_NAMESTORE_ZoneIterator * | 247 | struct GNUNET_NAMESTORE_ZoneIterator * |
247 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, | 248 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, |
248 | const struct | 249 | const struct |
249 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 250 | GNUNET_IDENTITY_PrivateKey *zone, |
250 | GNUNET_SCHEDULER_TaskCallback error_cb, | 251 | GNUNET_SCHEDULER_TaskCallback error_cb, |
251 | void *error_cb_cls, | 252 | void *error_cb_cls, |
252 | GNUNET_NAMESTORE_RecordMonitor proc, | 253 | GNUNET_NAMESTORE_RecordMonitor proc, |
@@ -316,7 +317,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor * | |||
316 | GNUNET_NAMESTORE_zone_monitor_start (const struct | 317 | GNUNET_NAMESTORE_zone_monitor_start (const struct |
317 | GNUNET_CONFIGURATION_Handle *cfg, | 318 | GNUNET_CONFIGURATION_Handle *cfg, |
318 | const struct | 319 | const struct |
319 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 320 | GNUNET_IDENTITY_PrivateKey *zone, |
320 | int iterate_first, | 321 | int iterate_first, |
321 | GNUNET_SCHEDULER_TaskCallback error_cb, | 322 | GNUNET_SCHEDULER_TaskCallback error_cb, |
322 | void *error_cb_cls, | 323 | void *error_cb_cls, |
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h index ca549f77c..de717526c 100644 --- a/src/include/gnunet_pq_lib.h +++ b/src/include/gnunet_pq_lib.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2016, 2017, 2020 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 |
@@ -87,6 +87,7 @@ struct GNUNET_PQ_QueryParam | |||
87 | * Number of parameters eaten by this operation. | 87 | * Number of parameters eaten by this operation. |
88 | */ | 88 | */ |
89 | unsigned int num_params; | 89 | unsigned int num_params; |
90 | |||
90 | }; | 91 | }; |
91 | 92 | ||
92 | 93 | ||
@@ -100,20 +101,32 @@ struct GNUNET_PQ_QueryParam | |||
100 | 101 | ||
101 | 102 | ||
102 | /** | 103 | /** |
104 | * Generate query parameter to create a NULL value. | ||
105 | * | ||
106 | * @return query parameter to use to insert NULL into DB | ||
107 | */ | ||
108 | struct GNUNET_PQ_QueryParam | ||
109 | GNUNET_PQ_query_param_null (void); | ||
110 | |||
111 | |||
112 | /** | ||
103 | * Generate query parameter for a buffer @a ptr of | 113 | * Generate query parameter for a buffer @a ptr of |
104 | * @a ptr_size bytes. | 114 | * @a ptr_size bytes. |
105 | * | 115 | * |
106 | * @param ptr pointer to the query parameter to pass | 116 | * @param ptr pointer to the query parameter to pass |
107 | * @oaran ptr_size number of bytes in @a ptr | 117 | * @oaran ptr_size number of bytes in @a ptr |
118 | * @return query parameter to use | ||
108 | */ | 119 | */ |
109 | struct GNUNET_PQ_QueryParam | 120 | struct GNUNET_PQ_QueryParam |
110 | GNUNET_PQ_query_param_fixed_size (const void *ptr, size_t ptr_size); | 121 | GNUNET_PQ_query_param_fixed_size (const void *ptr, |
122 | size_t ptr_size); | ||
111 | 123 | ||
112 | 124 | ||
113 | /** | 125 | /** |
114 | * Generate query parameter for a string. | 126 | * Generate query parameter for a string. |
115 | * | 127 | * |
116 | * @param ptr pointer to the string query parameter to pass | 128 | * @param ptr pointer to the string query parameter to pass |
129 | * @return query parameter to use | ||
117 | */ | 130 | */ |
118 | struct GNUNET_PQ_QueryParam | 131 | struct GNUNET_PQ_QueryParam |
119 | GNUNET_PQ_query_param_string (const char *ptr); | 132 | GNUNET_PQ_query_param_string (const char *ptr); |
@@ -124,6 +137,7 @@ GNUNET_PQ_query_param_string (const char *ptr); | |||
124 | * by variable type. | 137 | * by variable type. |
125 | * | 138 | * |
126 | * @param x pointer to the query parameter to pass. | 139 | * @param x pointer to the query parameter to pass. |
140 | * @return query parameter to use | ||
127 | */ | 141 | */ |
128 | #define GNUNET_PQ_query_param_auto_from_type(x) \ | 142 | #define GNUNET_PQ_query_param_auto_from_type(x) \ |
129 | GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) | 143 | GNUNET_PQ_query_param_fixed_size ((x), sizeof(*(x))) |
@@ -134,6 +148,7 @@ GNUNET_PQ_query_param_string (const char *ptr); | |||
134 | * database must contain a BLOB type in the respective position. | 148 | * database must contain a BLOB type in the respective position. |
135 | * | 149 | * |
136 | * @param x the query parameter to pass. | 150 | * @param x the query parameter to pass. |
151 | * @return query parameter to use | ||
137 | */ | 152 | */ |
138 | struct GNUNET_PQ_QueryParam | 153 | struct GNUNET_PQ_QueryParam |
139 | GNUNET_PQ_query_param_rsa_public_key ( | 154 | GNUNET_PQ_query_param_rsa_public_key ( |
@@ -145,6 +160,7 @@ GNUNET_PQ_query_param_rsa_public_key ( | |||
145 | * database must contain a BLOB type in the respective position. | 160 | * database must contain a BLOB type in the respective position. |
146 | * | 161 | * |
147 | * @param x the query parameter to pass | 162 | * @param x the query parameter to pass |
163 | * @return query parameter to use | ||
148 | */ | 164 | */ |
149 | struct GNUNET_PQ_QueryParam | 165 | struct GNUNET_PQ_QueryParam |
150 | GNUNET_PQ_query_param_rsa_signature ( | 166 | GNUNET_PQ_query_param_rsa_signature ( |
@@ -156,6 +172,7 @@ GNUNET_PQ_query_param_rsa_signature ( | |||
156 | * The database must store a 64-bit integer. | 172 | * The database must store a 64-bit integer. |
157 | * | 173 | * |
158 | * @param x pointer to the query parameter to pass | 174 | * @param x pointer to the query parameter to pass |
175 | * @return query parameter to use | ||
159 | */ | 176 | */ |
160 | struct GNUNET_PQ_QueryParam | 177 | struct GNUNET_PQ_QueryParam |
161 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x); | 178 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x); |
@@ -166,6 +183,7 @@ GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x); | |||
166 | * The database must store a 64-bit integer. | 183 | * The database must store a 64-bit integer. |
167 | * | 184 | * |
168 | * @param x pointer to the query parameter to pass | 185 | * @param x pointer to the query parameter to pass |
186 | * @return query parameter to use | ||
169 | */ | 187 | */ |
170 | struct GNUNET_PQ_QueryParam | 188 | struct GNUNET_PQ_QueryParam |
171 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); | 189 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); |
@@ -176,6 +194,7 @@ GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x); | |||
176 | * The database must store a 64-bit integer. | 194 | * The database must store a 64-bit integer. |
177 | * | 195 | * |
178 | * @param x pointer to the query parameter to pass | 196 | * @param x pointer to the query parameter to pass |
197 | * @return query parameter to use | ||
179 | */ | 198 | */ |
180 | struct GNUNET_PQ_QueryParam | 199 | struct GNUNET_PQ_QueryParam |
181 | GNUNET_PQ_query_param_absolute_time_nbo ( | 200 | GNUNET_PQ_query_param_absolute_time_nbo ( |
@@ -186,6 +205,7 @@ GNUNET_PQ_query_param_absolute_time_nbo ( | |||
186 | * Generate query parameter for an uint16_t in host byte order. | 205 | * Generate query parameter for an uint16_t in host byte order. |
187 | * | 206 | * |
188 | * @param x pointer to the query parameter to pass | 207 | * @param x pointer to the query parameter to pass |
208 | * @return query parameter to use | ||
189 | */ | 209 | */ |
190 | struct GNUNET_PQ_QueryParam | 210 | struct GNUNET_PQ_QueryParam |
191 | GNUNET_PQ_query_param_uint16 (const uint16_t *x); | 211 | GNUNET_PQ_query_param_uint16 (const uint16_t *x); |
@@ -195,6 +215,7 @@ GNUNET_PQ_query_param_uint16 (const uint16_t *x); | |||
195 | * Generate query parameter for an uint32_t in host byte order. | 215 | * Generate query parameter for an uint32_t in host byte order. |
196 | * | 216 | * |
197 | * @param x pointer to the query parameter to pass | 217 | * @param x pointer to the query parameter to pass |
218 | * @return query parameter to use | ||
198 | */ | 219 | */ |
199 | struct GNUNET_PQ_QueryParam | 220 | struct GNUNET_PQ_QueryParam |
200 | GNUNET_PQ_query_param_uint32 (const uint32_t *x); | 221 | GNUNET_PQ_query_param_uint32 (const uint32_t *x); |
@@ -204,6 +225,7 @@ GNUNET_PQ_query_param_uint32 (const uint32_t *x); | |||
204 | * Generate query parameter for an uint16_t in host byte order. | 225 | * Generate query parameter for an uint16_t in host byte order. |
205 | * | 226 | * |
206 | * @param x pointer to the query parameter to pass | 227 | * @param x pointer to the query parameter to pass |
228 | * @return query parameter to use | ||
207 | */ | 229 | */ |
208 | struct GNUNET_PQ_QueryParam | 230 | struct GNUNET_PQ_QueryParam |
209 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); | 231 | GNUNET_PQ_query_param_uint64 (const uint64_t *x); |
@@ -288,6 +310,20 @@ struct GNUNET_PQ_ResultSpec | |||
288 | * Where to store actual size of the result. | 310 | * Where to store actual size of the result. |
289 | */ | 311 | */ |
290 | size_t *result_size; | 312 | size_t *result_size; |
313 | |||
314 | /** | ||
315 | * True if NULL is allowed for a value in the database. | ||
316 | */ | ||
317 | bool is_nullable; | ||
318 | |||
319 | /** | ||
320 | * Points to a location where we should store | ||
321 | * "true" if the result found is NULL, and | ||
322 | * otherwise "false". Only used if @e is_nullable | ||
323 | * is true. | ||
324 | */ | ||
325 | bool *is_null; | ||
326 | |||
291 | }; | 327 | }; |
292 | 328 | ||
293 | 329 | ||
@@ -303,6 +339,21 @@ struct GNUNET_PQ_ResultSpec | |||
303 | 339 | ||
304 | 340 | ||
305 | /** | 341 | /** |
342 | * Allow NULL value to be found in the database | ||
343 | * for the given value. | ||
344 | * | ||
345 | * @param rs result spec entry to modify | ||
346 | * @param[out] is_null location set to 'true' if the | ||
347 | * value was indeed NULL, set to 'false' if the | ||
348 | * value was non-NULL | ||
349 | * @return array entry for the result specification to use | ||
350 | */ | ||
351 | struct GNUNET_PQ_ResultSpec | ||
352 | GNUNET_PQ_result_spec_allow_null (struct GNUNET_PQ_ResultSpec rs, | ||
353 | bool *is_null); | ||
354 | |||
355 | |||
356 | /** | ||
306 | * Variable-size result expected. | 357 | * Variable-size result expected. |
307 | * | 358 | * |
308 | * @param name name of the field in the table | 359 | * @param name name of the field in the table |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index d9821ffe8..3bdebeb50 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2001--2018 GNUnet e.V. | 3 | Copyright (C) 2001--2020 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 |
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * @author Tobias Frisch | ||
23 | * | 24 | * |
24 | * @file | 25 | * @file |
25 | * Constants for network protocols | 26 | * Constants for network protocols |
@@ -3518,6 +3519,46 @@ extern "C" { | |||
3518 | #define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT 1501 | 3519 | #define GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_RESULT 1501 |
3519 | 3520 | ||
3520 | 3521 | ||
3522 | /*********************************************************************************/ | ||
3523 | /********************************** MESSENGER **********************************/ | ||
3524 | /*********************************************************************************/ | ||
3525 | /* MESSENGER: message types 1600-1629 | ||
3526 | * 1600-1609 Connection-level Messages | ||
3527 | * 1610-1619 Room-level Messages | ||
3528 | */ | ||
3529 | |||
3530 | /********************************* Connection **********************************/ | ||
3531 | |||
3532 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE 1600 | ||
3533 | |||
3534 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE 1601 | ||
3535 | |||
3536 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY 1602 | ||
3537 | |||
3538 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME 1603 | ||
3539 | |||
3540 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME 1604 | ||
3541 | |||
3542 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY 1605 | ||
3543 | |||
3544 | #define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID 1606 | ||
3545 | |||
3546 | /************************************ Room *************************************/ | ||
3547 | |||
3548 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN 1610 | ||
3549 | |||
3550 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY 1611 | ||
3551 | |||
3552 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE 1612 | ||
3553 | |||
3554 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE 1614 | ||
3555 | |||
3556 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE 1615 | ||
3557 | |||
3558 | #define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE 1616 | ||
3559 | |||
3560 | /*********************************************************************************/ | ||
3561 | |||
3521 | /** | 3562 | /** |
3522 | * Type used to match 'all' message types. | 3563 | * Type used to match 'all' message types. |
3523 | */ | 3564 | */ |
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index 368058f56..8549081a1 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h | |||
@@ -38,6 +38,7 @@ extern "C" { | |||
38 | #endif | 38 | #endif |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | #include "gnunet_identity_service.h" | ||
41 | #include "gnunet_reclaim_lib.h" | 42 | #include "gnunet_reclaim_lib.h" |
42 | #include "gnunet_util_lib.h" | 43 | #include "gnunet_util_lib.h" |
43 | 44 | ||
@@ -69,12 +70,12 @@ struct GNUNET_RECLAIM_Ticket | |||
69 | /** | 70 | /** |
70 | * The ticket issuer (= the user) | 71 | * The ticket issuer (= the user) |
71 | */ | 72 | */ |
72 | struct GNUNET_CRYPTO_EcdsaPublicKey identity; | 73 | struct GNUNET_IDENTITY_PublicKey identity; |
73 | 74 | ||
74 | /** | 75 | /** |
75 | * The ticket audience (= relying party) | 76 | * The ticket audience (= relying party) |
76 | */ | 77 | */ |
77 | struct GNUNET_CRYPTO_EcdsaPublicKey audience; | 78 | struct GNUNET_IDENTITY_PublicKey audience; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * The ticket random identifier | 81 | * The ticket random identifier |
@@ -129,7 +130,7 @@ typedef void (*GNUNET_RECLAIM_ContinuationWithStatus) (void *cls, | |||
129 | * @param attr The attribute | 130 | * @param attr The attribute |
130 | */ | 131 | */ |
131 | typedef void (*GNUNET_RECLAIM_AttributeResult) ( | 132 | typedef void (*GNUNET_RECLAIM_AttributeResult) ( |
132 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 133 | void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, |
133 | const struct GNUNET_RECLAIM_Attribute *attr); | 134 | const struct GNUNET_RECLAIM_Attribute *attr); |
134 | 135 | ||
135 | /** | 136 | /** |
@@ -141,7 +142,7 @@ typedef void (*GNUNET_RECLAIM_AttributeResult) ( | |||
141 | * @param presentation The presentation for the credential (may be NULL) | 142 | * @param presentation The presentation for the credential (may be NULL) |
142 | */ | 143 | */ |
143 | typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( | 144 | typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( |
144 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 145 | void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, |
145 | const struct GNUNET_RECLAIM_Attribute *attr, | 146 | const struct GNUNET_RECLAIM_Attribute *attr, |
146 | const struct GNUNET_RECLAIM_Presentation *presentation); | 147 | const struct GNUNET_RECLAIM_Presentation *presentation); |
147 | 148 | ||
@@ -155,7 +156,7 @@ typedef void (*GNUNET_RECLAIM_AttributeTicketResult) ( | |||
155 | * @param attributes the parsed attributes | 156 | * @param attributes the parsed attributes |
156 | */ | 157 | */ |
157 | typedef void (*GNUNET_RECLAIM_CredentialResult) ( | 158 | typedef void (*GNUNET_RECLAIM_CredentialResult) ( |
158 | void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 159 | void *cls, const struct GNUNET_IDENTITY_PublicKey *identity, |
159 | const struct GNUNET_RECLAIM_Credential *credential); | 160 | const struct GNUNET_RECLAIM_Credential *credential); |
160 | 161 | ||
161 | 162 | ||
@@ -184,7 +185,7 @@ GNUNET_RECLAIM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
184 | struct GNUNET_RECLAIM_Operation * | 185 | struct GNUNET_RECLAIM_Operation * |
185 | GNUNET_RECLAIM_attribute_store ( | 186 | GNUNET_RECLAIM_attribute_store ( |
186 | struct GNUNET_RECLAIM_Handle *h, | 187 | struct GNUNET_RECLAIM_Handle *h, |
187 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 188 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
188 | const struct GNUNET_RECLAIM_Attribute *attr, | 189 | const struct GNUNET_RECLAIM_Attribute *attr, |
189 | const struct GNUNET_TIME_Relative *exp_interval, | 190 | const struct GNUNET_TIME_Relative *exp_interval, |
190 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); | 191 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); |
@@ -205,7 +206,7 @@ GNUNET_RECLAIM_attribute_store ( | |||
205 | struct GNUNET_RECLAIM_Operation * | 206 | struct GNUNET_RECLAIM_Operation * |
206 | GNUNET_RECLAIM_credential_store ( | 207 | GNUNET_RECLAIM_credential_store ( |
207 | struct GNUNET_RECLAIM_Handle *h, | 208 | struct GNUNET_RECLAIM_Handle *h, |
208 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 209 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
209 | const struct GNUNET_RECLAIM_Credential *credential, | 210 | const struct GNUNET_RECLAIM_Credential *credential, |
210 | const struct GNUNET_TIME_Relative *exp_interval, | 211 | const struct GNUNET_TIME_Relative *exp_interval, |
211 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 212 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
@@ -226,7 +227,7 @@ GNUNET_RECLAIM_credential_store ( | |||
226 | struct GNUNET_RECLAIM_Operation * | 227 | struct GNUNET_RECLAIM_Operation * |
227 | GNUNET_RECLAIM_attribute_delete ( | 228 | GNUNET_RECLAIM_attribute_delete ( |
228 | struct GNUNET_RECLAIM_Handle *h, | 229 | struct GNUNET_RECLAIM_Handle *h, |
229 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 230 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
230 | const struct GNUNET_RECLAIM_Attribute *attr, | 231 | const struct GNUNET_RECLAIM_Attribute *attr, |
231 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); | 232 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); |
232 | 233 | ||
@@ -244,7 +245,7 @@ GNUNET_RECLAIM_attribute_delete ( | |||
244 | struct GNUNET_RECLAIM_Operation * | 245 | struct GNUNET_RECLAIM_Operation * |
245 | GNUNET_RECLAIM_credential_delete ( | 246 | GNUNET_RECLAIM_credential_delete ( |
246 | struct GNUNET_RECLAIM_Handle *h, | 247 | struct GNUNET_RECLAIM_Handle *h, |
247 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 248 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
248 | const struct GNUNET_RECLAIM_Credential *cred, | 249 | const struct GNUNET_RECLAIM_Credential *cred, |
249 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 250 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
250 | void *cont_cls); | 251 | void *cont_cls); |
@@ -276,7 +277,7 @@ GNUNET_RECLAIM_credential_delete ( | |||
276 | struct GNUNET_RECLAIM_AttributeIterator * | 277 | struct GNUNET_RECLAIM_AttributeIterator * |
277 | GNUNET_RECLAIM_get_attributes_start ( | 278 | GNUNET_RECLAIM_get_attributes_start ( |
278 | struct GNUNET_RECLAIM_Handle *h, | 279 | struct GNUNET_RECLAIM_Handle *h, |
279 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 280 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
280 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, | 281 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, |
281 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, | 282 | GNUNET_RECLAIM_AttributeResult proc, void *proc_cls, |
282 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); | 283 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); |
@@ -332,7 +333,7 @@ GNUNET_RECLAIM_get_attributes_stop ( | |||
332 | struct GNUNET_RECLAIM_CredentialIterator * | 333 | struct GNUNET_RECLAIM_CredentialIterator * |
333 | GNUNET_RECLAIM_get_credentials_start ( | 334 | GNUNET_RECLAIM_get_credentials_start ( |
334 | struct GNUNET_RECLAIM_Handle *h, | 335 | struct GNUNET_RECLAIM_Handle *h, |
335 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 336 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
336 | GNUNET_SCHEDULER_TaskCallback error_cb, | 337 | GNUNET_SCHEDULER_TaskCallback error_cb, |
337 | void *error_cb_cls, | 338 | void *error_cb_cls, |
338 | GNUNET_RECLAIM_CredentialResult proc, | 339 | GNUNET_RECLAIM_CredentialResult proc, |
@@ -380,8 +381,8 @@ GNUNET_RECLAIM_get_credentials_stop ( | |||
380 | struct GNUNET_RECLAIM_Operation * | 381 | struct GNUNET_RECLAIM_Operation * |
381 | GNUNET_RECLAIM_ticket_issue ( | 382 | GNUNET_RECLAIM_ticket_issue ( |
382 | struct GNUNET_RECLAIM_Handle *h, | 383 | struct GNUNET_RECLAIM_Handle *h, |
383 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, | 384 | const struct GNUNET_IDENTITY_PrivateKey *iss, |
384 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, | 385 | const struct GNUNET_IDENTITY_PublicKey *rp, |
385 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 386 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
386 | GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); | 387 | GNUNET_RECLAIM_IssueTicketCallback cb, void *cb_cls); |
387 | 388 | ||
@@ -402,7 +403,7 @@ GNUNET_RECLAIM_ticket_issue ( | |||
402 | struct GNUNET_RECLAIM_Operation * | 403 | struct GNUNET_RECLAIM_Operation * |
403 | GNUNET_RECLAIM_ticket_revoke ( | 404 | GNUNET_RECLAIM_ticket_revoke ( |
404 | struct GNUNET_RECLAIM_Handle *h, | 405 | struct GNUNET_RECLAIM_Handle *h, |
405 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 406 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
406 | const struct GNUNET_RECLAIM_Ticket *ticket, | 407 | const struct GNUNET_RECLAIM_Ticket *ticket, |
407 | GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls); | 408 | GNUNET_RECLAIM_ContinuationWithStatus cb, void *cb_cls); |
408 | 409 | ||
@@ -422,7 +423,7 @@ GNUNET_RECLAIM_ticket_revoke ( | |||
422 | struct GNUNET_RECLAIM_Operation * | 423 | struct GNUNET_RECLAIM_Operation * |
423 | GNUNET_RECLAIM_ticket_consume ( | 424 | GNUNET_RECLAIM_ticket_consume ( |
424 | struct GNUNET_RECLAIM_Handle *h, | 425 | struct GNUNET_RECLAIM_Handle *h, |
425 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 426 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
426 | const struct GNUNET_RECLAIM_Ticket *ticket, | 427 | const struct GNUNET_RECLAIM_Ticket *ticket, |
427 | GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); | 428 | GNUNET_RECLAIM_AttributeTicketResult cb, void *cb_cls); |
428 | 429 | ||
@@ -447,7 +448,7 @@ GNUNET_RECLAIM_ticket_consume ( | |||
447 | struct GNUNET_RECLAIM_TicketIterator * | 448 | struct GNUNET_RECLAIM_TicketIterator * |
448 | GNUNET_RECLAIM_ticket_iteration_start ( | 449 | GNUNET_RECLAIM_ticket_iteration_start ( |
449 | struct GNUNET_RECLAIM_Handle *h, | 450 | struct GNUNET_RECLAIM_Handle *h, |
450 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 451 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
451 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, | 452 | GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, |
452 | GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, | 453 | GNUNET_RECLAIM_TicketCallback proc, void *proc_cls, |
453 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); | 454 | GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls); |
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h index 105bb1149..d56116914 100644 --- a/src/include/gnunet_revocation_service.h +++ b/src/include/gnunet_revocation_service.h | |||
@@ -21,6 +21,8 @@ | |||
21 | #ifndef GNUNET_REVOCATION_SERVICE_H_ | 21 | #ifndef GNUNET_REVOCATION_SERVICE_H_ |
22 | #define GNUNET_REVOCATION_SERVICE_H_ | 22 | #define GNUNET_REVOCATION_SERVICE_H_ |
23 | 23 | ||
24 | #include "gnunet_identity_service.h" | ||
25 | |||
24 | /** | 26 | /** |
25 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
26 | * | 28 | * |
@@ -51,6 +53,13 @@ extern "C" | |||
51 | #define GNUNET_REVOCATION_VERSION 0x00000001 | 53 | #define GNUNET_REVOCATION_VERSION 0x00000001 |
52 | 54 | ||
53 | /** | 55 | /** |
56 | * Maximum length of a revocation | ||
57 | */ | ||
58 | #define GNUNET_REVOCATION_MAX_PROOF_SIZE sizeof(struct GNUNET_REVOCATION_PowP) +\ | ||
59 | sizeof(struct GNUNET_IDENTITY_PublicKey) +\ | ||
60 | 1024 //FIXME max sig_len | ||
61 | |||
62 | /** | ||
54 | * The proof-of-work narrowing factor. | 63 | * The proof-of-work narrowing factor. |
55 | * The number of PoWs that are calculates as part of revocation. | 64 | * The number of PoWs that are calculates as part of revocation. |
56 | */ | 65 | */ |
@@ -79,15 +88,7 @@ struct GNUNET_REVOCATION_PowP | |||
79 | */ | 88 | */ |
80 | uint64_t pow[POW_COUNT] GNUNET_PACKED; | 89 | uint64_t pow[POW_COUNT] GNUNET_PACKED; |
81 | 90 | ||
82 | /** | 91 | /** followed by the public key type, the key and a signature **/ |
83 | * The signature | ||
84 | */ | ||
85 | struct GNUNET_CRYPTO_EcdsaSignature signature; | ||
86 | |||
87 | /** | ||
88 | * The revoked public key | ||
89 | */ | ||
90 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
91 | }; | 92 | }; |
92 | 93 | ||
93 | 94 | ||
@@ -102,14 +103,11 @@ struct GNUNET_REVOCATION_SignaturePurposePS | |||
102 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | 103 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; |
103 | 104 | ||
104 | /** | 105 | /** |
105 | * The revoked public key | ||
106 | */ | ||
107 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | ||
108 | |||
109 | /** | ||
110 | * The timestamp of the revocation | 106 | * The timestamp of the revocation |
111 | */ | 107 | */ |
112 | struct GNUNET_TIME_AbsoluteNBO timestamp; | 108 | struct GNUNET_TIME_AbsoluteNBO timestamp; |
109 | |||
110 | /** Followed by the zone public key type and key **/ | ||
113 | }; | 111 | }; |
114 | 112 | ||
115 | GNUNET_NETWORK_STRUCT_END | 113 | GNUNET_NETWORK_STRUCT_END |
@@ -150,7 +148,7 @@ typedef void (*GNUNET_REVOCATION_Callback) (void *cls, | |||
150 | */ | 148 | */ |
151 | struct GNUNET_REVOCATION_Query * | 149 | struct GNUNET_REVOCATION_Query * |
152 | GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, | 150 | GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, |
153 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 151 | const struct GNUNET_IDENTITY_PublicKey *key, |
154 | GNUNET_REVOCATION_Callback func, void *func_cls); | 152 | GNUNET_REVOCATION_Callback func, void *func_cls); |
155 | 153 | ||
156 | 154 | ||
@@ -217,7 +215,7 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
217 | * @param pow the pow object to work with in the calculation. | 215 | * @param pow the pow object to work with in the calculation. |
218 | */ | 216 | */ |
219 | void | 217 | void |
220 | GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 218 | GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key, |
221 | struct GNUNET_REVOCATION_PowP *pow); | 219 | struct GNUNET_REVOCATION_PowP *pow); |
222 | 220 | ||
223 | 221 | ||
@@ -256,6 +254,10 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc); | |||
256 | void | 254 | void |
257 | GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc); | 255 | GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc); |
258 | 256 | ||
257 | size_t | ||
258 | GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow); | ||
259 | |||
260 | |||
259 | #if 0 /* keep Emacsens' auto-indent happy */ | 261 | #if 0 /* keep Emacsens' auto-indent happy */ |
260 | { | 262 | { |
261 | #endif | 263 | #endif |
diff --git a/src/include/gnunet_uri_lib.h b/src/include/gnunet_uri_lib.h index d428bdd9a..57c9e9316 100644 --- a/src/include/gnunet_uri_lib.h +++ b/src/include/gnunet_uri_lib.h | |||
@@ -26,12 +26,13 @@ | |||
26 | /** | 26 | /** |
27 | * The struct where the parsed values will be stored: | 27 | * The struct where the parsed values will be stored: |
28 | * | 28 | * |
29 | * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] | 29 | * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] [ "#" fragment ] |
30 | * | 30 | * |
31 | * Note: to make sure that no strings are copied, the first slash "/" in the | 31 | * Note: to make sure that no strings are copied, the first slash "/" in the |
32 | * path will be used to null terminate the hostname if no port is supplied. | 32 | * path will be used to null terminate the hostname if no port is supplied. |
33 | */ | 33 | */ |
34 | struct GNUNET_Uri { | 34 | struct GNUNET_Uri |
35 | { | ||
35 | char *scheme; /* scheme, without ":" and "//" */ | 36 | char *scheme; /* scheme, without ":" and "//" */ |
36 | char *username; /* username, default: NULL */ | 37 | char *username; /* username, default: NULL */ |
37 | char *password; /* password, default: NULL */ | 38 | char *password; /* password, default: NULL */ |
@@ -44,7 +45,8 @@ struct GNUNET_Uri { | |||
44 | 45 | ||
45 | 46 | ||
46 | /* A struct to hold the query string parameter values. */ | 47 | /* A struct to hold the query string parameter values. */ |
47 | struct GNUNET_UriParam { | 48 | struct GNUNET_UriParam |
49 | { | ||
48 | char *key; | 50 | char *key; |
49 | char *val; | 51 | char *val; |
50 | }; | 52 | }; |
diff --git a/src/json/Makefile.am b/src/json/Makefile.am index 2ed05c35a..d4ea38adf 100644 --- a/src/json/Makefile.am +++ b/src/json/Makefile.am | |||
@@ -18,18 +18,15 @@ libgnunetjson_la_SOURCES = \ | |||
18 | json.c \ | 18 | json.c \ |
19 | json_mhd.c \ | 19 | json_mhd.c \ |
20 | json_generator.c \ | 20 | json_generator.c \ |
21 | json_helper.c \ | 21 | json_helper.c |
22 | json_gnsrecord.c | ||
23 | libgnunetjson_la_LIBADD = \ | 22 | libgnunetjson_la_LIBADD = \ |
24 | $(top_builddir)/src/util/libgnunetutil.la \ | 23 | $(top_builddir)/src/util/libgnunetutil.la \ |
25 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
26 | -ljansson \ | 24 | -ljansson \ |
27 | $(MHD_LIBS) \ | 25 | $(MHD_LIBS) \ |
28 | $(XLIB) \ | 26 | $(XLIB) \ |
29 | $(Z_LIBS) | 27 | $(Z_LIBS) |
30 | libgnunetjson_la_DEPENDENCIES = \ | 28 | libgnunetjson_la_DEPENDENCIES = \ |
31 | $(top_builddir)/src/util/libgnunetutil.la \ | 29 | $(top_builddir)/src/util/libgnunetutil.la |
32 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la | ||
33 | 30 | ||
34 | 31 | ||
35 | check_PROGRAMS = \ | 32 | check_PROGRAMS = \ |
diff --git a/src/json/json.c b/src/json/json.c index 0631c51bb..503702962 100644 --- a/src/json/json.c +++ b/src/json/json.c | |||
@@ -56,11 +56,17 @@ GNUNET_JSON_parse (const json_t *root, | |||
56 | if (NULL == spec[i].field) | 56 | if (NULL == spec[i].field) |
57 | pos = (json_t *) root; | 57 | pos = (json_t *) root; |
58 | else | 58 | else |
59 | pos = json_object_get (root, spec[i].field); | 59 | pos = json_object_get (root, |
60 | if ((NULL == pos) && (spec[i].is_optional)) | 60 | spec[i].field); |
61 | if ( ( (NULL == pos) || | ||
62 | (json_is_null (pos) ) ) && | ||
63 | (spec[i].is_optional) ) | ||
61 | continue; | 64 | continue; |
62 | if ((NULL == pos) || | 65 | if ( (NULL == pos) || |
63 | (GNUNET_OK != spec[i].parser (spec[i].cls, pos, &spec[i]))) | 66 | (GNUNET_OK != |
67 | spec[i].parser (spec[i].cls, | ||
68 | pos, | ||
69 | &spec[i])) ) | ||
64 | { | 70 | { |
65 | if (NULL != error_json_name) | 71 | if (NULL != error_json_name) |
66 | *error_json_name = spec[i].field; | 72 | *error_json_name = spec[i].field; |
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index 3f82a5f17..5806eb174 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -201,113 +201,5 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) | |||
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
204 | /** | ||
205 | * Convert GNS record to JSON. | ||
206 | * | ||
207 | * @param rname name of record | ||
208 | * @param rd record data | ||
209 | * @return corresponding JSON encoding | ||
210 | */ | ||
211 | json_t * | ||
212 | GNUNET_JSON_from_gnsrecord (const char*rname, | ||
213 | const struct GNUNET_GNSRECORD_Data *rd, | ||
214 | unsigned int rd_count) | ||
215 | { | ||
216 | struct GNUNET_TIME_Absolute abs_exp; | ||
217 | struct GNUNET_TIME_Relative rel_exp; | ||
218 | const char *expiration_time_str; | ||
219 | const char *record_type_str; | ||
220 | char *value_str; | ||
221 | json_t *data; | ||
222 | json_t *record; | ||
223 | json_t *records; | ||
224 | |||
225 | data = json_object (); | ||
226 | if (NULL == data) | ||
227 | { | ||
228 | GNUNET_break (0); | ||
229 | return NULL; | ||
230 | } | ||
231 | if (0 != | ||
232 | json_object_set_new (data, | ||
233 | "record_name", | ||
234 | json_string (rname))) | ||
235 | { | ||
236 | GNUNET_break (0); | ||
237 | json_decref (data); | ||
238 | return NULL; | ||
239 | } | ||
240 | records = json_array (); | ||
241 | if (NULL == records) | ||
242 | { | ||
243 | GNUNET_break (0); | ||
244 | json_decref (data); | ||
245 | return NULL; | ||
246 | } | ||
247 | for (int i = 0; i < rd_count; i++) | ||
248 | { | ||
249 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | ||
250 | rd[i].data, | ||
251 | rd[i].data_size); | ||
252 | if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags) | ||
253 | { | ||
254 | rel_exp.rel_value_us = rd[i].expiration_time; | ||
255 | expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp, | ||
256 | GNUNET_NO); | ||
257 | } | ||
258 | else | ||
259 | { | ||
260 | abs_exp.abs_value_us = rd[i].expiration_time; | ||
261 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp); | ||
262 | } | ||
263 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | "Packing %s %s %s %d\n", | ||
266 | value_str, record_type_str, expiration_time_str, rd[i].flags); | ||
267 | record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}", | ||
268 | "value", | ||
269 | value_str, | ||
270 | "record_type", | ||
271 | record_type_str, | ||
272 | "expiration_time", | ||
273 | expiration_time_str, | ||
274 | "private", | ||
275 | rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE, | ||
276 | "relative_expiration", | ||
277 | rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, | ||
278 | "supplemental", | ||
279 | rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL, | ||
280 | "shadow", | ||
281 | rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD); | ||
282 | GNUNET_free (value_str); | ||
283 | if (NULL == record) | ||
284 | { | ||
285 | GNUNET_break (0); | ||
286 | json_decref (records); | ||
287 | json_decref (data); | ||
288 | return NULL; | ||
289 | } | ||
290 | if (0 != | ||
291 | json_array_append_new (records, | ||
292 | record)) | ||
293 | { | ||
294 | GNUNET_break (0); | ||
295 | json_decref (records); | ||
296 | json_decref (data); | ||
297 | return NULL; | ||
298 | } | ||
299 | } | ||
300 | if (0 != | ||
301 | json_object_set_new (data, | ||
302 | "data", | ||
303 | records)) | ||
304 | { | ||
305 | GNUNET_break (0); | ||
306 | json_decref (data); | ||
307 | return NULL; | ||
308 | } | ||
309 | return data; | ||
310 | } | ||
311 | |||
312 | 204 | ||
313 | /* End of json/json_generator.c */ | 205 | /* End of json/json_generator.c */ |
diff --git a/src/messenger/.gitignore b/src/messenger/.gitignore new file mode 100644 index 000000000..9de3fb304 --- /dev/null +++ b/src/messenger/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | gnunet-service-messenger | ||
2 | gnunet-messenger | ||
3 | test_messenger_api | ||
4 | test_messenger_anonymous | ||
diff --git a/src/messenger/Makefile.am b/src/messenger/Makefile.am new file mode 100644 index 000000000..ebe08290e --- /dev/null +++ b/src/messenger/Makefile.am | |||
@@ -0,0 +1,131 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | if USE_COVERAGE | ||
5 | AM_CFLAGS = --coverage -O0 | ||
6 | XLIB = -lgcov | ||
7 | endif | ||
8 | |||
9 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
10 | |||
11 | libexecdir= $(pkglibdir)/libexec/ | ||
12 | |||
13 | pkgcfg_DATA = \ | ||
14 | messenger.conf | ||
15 | |||
16 | plugindir = $(libdir)/gnunet | ||
17 | |||
18 | AM_CLFAGS = -g | ||
19 | |||
20 | libexec_PROGRAMS = \ | ||
21 | gnunet-service-messenger \ | ||
22 | $(EXP_LIBEXEC) | ||
23 | |||
24 | bin_PROGRAMS = \ | ||
25 | gnunet-messenger | ||
26 | |||
27 | lib_LTLIBRARIES = \ | ||
28 | libgnunetmessenger_common.la \ | ||
29 | libgnunetmessenger.la \ | ||
30 | $(EXP_LIB) | ||
31 | |||
32 | libgnunetmessenger_common_la_SOURCES = \ | ||
33 | messenger_api_ego.h \ | ||
34 | messenger_api_message.c messenger_api_message.h \ | ||
35 | messenger_api_list_tunnels.c messenger_api_list_tunnels.h | ||
36 | libgnunetmessenger_common_la_LIBADD = \ | ||
37 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
38 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
39 | $(XLIB) \ | ||
40 | $(LTLIBINTL) | ||
41 | libgnunetmessenger_common_la_LDFLAGS = \ | ||
42 | $(GN_LIB_LDFLAGS) \ | ||
43 | -version-info 0:0:0 | ||
44 | |||
45 | libgnunetmessenger_la_SOURCES = \ | ||
46 | messenger_api.c \ | ||
47 | messenger_api_contact.c messenger_api_contact.h \ | ||
48 | messenger_api_handle.c messenger_api_handle.h \ | ||
49 | messenger_api_room.c messenger_api_room.h | ||
50 | libgnunetmessenger_la_LIBADD = \ | ||
51 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
52 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
53 | libgnunetmessenger_common.la \ | ||
54 | $(XLIB) \ | ||
55 | $(LTLIBINTL) | ||
56 | libgnunetmessenger_la_LDFLAGS = \ | ||
57 | $(GN_LIB_LDFLAGS) \ | ||
58 | -version-info 0:0:0 | ||
59 | |||
60 | gnunet_messenger_SOURCES = \ | ||
61 | gnunet-messenger.c | ||
62 | gnunet_messenger_LDADD = \ | ||
63 | libgnunetmessenger_common.la \ | ||
64 | libgnunetmessenger.la \ | ||
65 | $(top_builddir)/src/util/libgnunetutil.la | ||
66 | gnunet_messenger_LDFLAGS = \ | ||
67 | $(GN_LIBINTL) | ||
68 | |||
69 | gnunet_service_messenger_SOURCES = \ | ||
70 | gnunet-service-messenger.c gnunet-service-messenger.h \ | ||
71 | gnunet-service-messenger_service.c gnunet-service-messenger_service.h \ | ||
72 | gnunet-service-messenger_list_handles.c gnunet-service-messenger_list_handles.h \ | ||
73 | gnunet-service-messenger_list_messages.c gnunet-service-messenger_list_messages.h \ | ||
74 | gnunet-service-messenger_message_handle.c gnunet-service-messenger_message_handle.h \ | ||
75 | gnunet-service-messenger_message_kind.c gnunet-service-messenger_message_kind.h \ | ||
76 | gnunet-service-messenger_message_recv.c gnunet-service-messenger_message_recv.h \ | ||
77 | gnunet-service-messenger_message_send.c gnunet-service-messenger_message_send.h \ | ||
78 | gnunet-service-messenger_message_store.c gnunet-service-messenger_message_store.h \ | ||
79 | gnunet-service-messenger_basement.c gnunet-service-messenger_basement.h \ | ||
80 | gnunet-service-messenger_contact.c gnunet-service-messenger_contact.h \ | ||
81 | gnunet-service-messenger_handle.c gnunet-service-messenger_handle.h \ | ||
82 | gnunet-service-messenger_room.c gnunet-service-messenger_room.h \ | ||
83 | gnunet-service-messenger_tunnel.c gnunet-service-messenger_tunnel.h \ | ||
84 | gnunet-service-messenger_util.c gnunet-service-messenger_util.h | ||
85 | gnunet_service_messenger_LDADD = \ | ||
86 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
87 | $(top_builddir)/src/cadet/libgnunetcadet.la \ | ||
88 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
89 | libgnunetmessenger_common.la \ | ||
90 | libgnunetmessenger.la \ | ||
91 | $(GN_LIBINTL) | ||
92 | |||
93 | check_PROGRAMS = \ | ||
94 | test_messenger_api \ | ||
95 | test_messenger_anonymous \ | ||
96 | test_messenger_comm0 | ||
97 | |||
98 | if ENABLE_TEST_RUN | ||
99 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | ||
100 | TESTS = \ | ||
101 | $(check_PROGRAMS) | ||
102 | endif | ||
103 | |||
104 | test_messenger_api_SOURCES = \ | ||
105 | test_messenger.c | ||
106 | test_messenger_api_LDADD = \ | ||
107 | libgnunetmessenger_common.la \ | ||
108 | libgnunetmessenger.la \ | ||
109 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
110 | $(top_builddir)/src/util/libgnunetutil.la | ||
111 | |||
112 | test_messenger_anonymous_SOURCES = \ | ||
113 | test_messenger_anonymous.c | ||
114 | test_messenger_anonymous_LDADD = \ | ||
115 | libgnunetmessenger_common.la \ | ||
116 | libgnunetmessenger.la \ | ||
117 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
118 | $(top_builddir)/src/util/libgnunetutil.la | ||
119 | |||
120 | test_messenger_comm0_SOURCES = \ | ||
121 | test_messenger_comm0.c | ||
122 | test_messenger_comm0_LDADD = \ | ||
123 | libgnunetmessenger_common.la \ | ||
124 | libgnunetmessenger.la \ | ||
125 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
126 | $(top_builddir)/src/testbed-logger/libgnunettestbedlogger.la \ | ||
127 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
128 | $(top_builddir)/src/util/libgnunetutil.la | ||
129 | |||
130 | EXTRA_DIST = \ | ||
131 | test_messenger_api.conf | ||
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c new file mode 100644 index 000000000..579e5c3ad --- /dev/null +++ b/src/messenger/gnunet-messenger.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-messenger.c | ||
23 | * @brief Print information about messenger groups. | ||
24 | */ | ||
25 | |||
26 | #include <stdio.h> | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_messenger_service.h" | ||
31 | |||
32 | struct GNUNET_MESSENGER_Handle *messenger; | ||
33 | |||
34 | /** | ||
35 | * Function called whenever a message is received or sent. | ||
36 | * | ||
37 | * @param cls Closure | ||
38 | * @param room Room | ||
39 | * @param message Message | ||
40 | * @param hash Hash of message | ||
41 | */ | ||
42 | void | ||
43 | on_message (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
44 | const struct GNUNET_HashCode *hash) | ||
45 | { | ||
46 | struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_member (room, &(message->header.sender_id)); | ||
47 | |||
48 | const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); | ||
49 | |||
50 | if (!sender_name) | ||
51 | sender_name = "anonymous"; | ||
52 | |||
53 | switch (message->header.kind) | ||
54 | { | ||
55 | case GNUNET_MESSENGER_KIND_JOIN: | ||
56 | { | ||
57 | printf ("* '%s' joined the room! [ %u %u %u %u ]\n", sender_name, message->body.join.key.ecdsa_key.q_y[0], | ||
58 | message->body.join.key.ecdsa_key.q_y[1], message->body.join.key.ecdsa_key.q_y[2], | ||
59 | message->body.join.key.ecdsa_key.q_y[3]); | ||
60 | break; | ||
61 | } | ||
62 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
63 | { | ||
64 | printf ("* '%s' leaves the room!\n", sender_name); | ||
65 | break; | ||
66 | } | ||
67 | case GNUNET_MESSENGER_KIND_PEER: | ||
68 | { | ||
69 | printf ("* '%s' opened the room on: %s\n", sender_name, GNUNET_i2s_full (&(message->body.peer.peer))); | ||
70 | break; | ||
71 | } | ||
72 | case GNUNET_MESSENGER_KIND_TEXT: | ||
73 | { | ||
74 | printf ("* '%s' says: \"%s\"\n", sender_name, message->body.text.text); | ||
75 | break; | ||
76 | } | ||
77 | default: | ||
78 | { | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | struct GNUNET_SCHEDULER_Task *read_task; | ||
85 | |||
86 | /** | ||
87 | * Task to shut down this application. | ||
88 | * | ||
89 | * @param cls Closure | ||
90 | */ | ||
91 | static void | ||
92 | shutdown_hook (void *cls) | ||
93 | { | ||
94 | struct GNUNET_MESSENGER_Room *room = cls; | ||
95 | |||
96 | if (read_task) | ||
97 | GNUNET_SCHEDULER_cancel (read_task); | ||
98 | |||
99 | if (room) | ||
100 | GNUNET_MESSENGER_close_room (room); | ||
101 | |||
102 | if (messenger) | ||
103 | GNUNET_MESSENGER_disconnect (messenger); | ||
104 | } | ||
105 | |||
106 | static void | ||
107 | listen_stdio (void *cls); | ||
108 | |||
109 | #define MAX_BUFFER_SIZE 60000 | ||
110 | |||
111 | /** | ||
112 | * Task run in stdio mode, after some data is available at stdin. | ||
113 | * | ||
114 | * @param cls Closure | ||
115 | */ | ||
116 | static void | ||
117 | read_stdio (void *cls) | ||
118 | { | ||
119 | read_task = NULL; | ||
120 | |||
121 | char buffer[MAX_BUFFER_SIZE]; | ||
122 | ssize_t length; | ||
123 | |||
124 | length = read (0, buffer, MAX_BUFFER_SIZE); | ||
125 | |||
126 | if ((length <= 0) || (length >= MAX_BUFFER_SIZE)) | ||
127 | { | ||
128 | GNUNET_SCHEDULER_shutdown (); | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | if (buffer[length - 1] == '\n') | ||
133 | buffer[length - 1] = '\0'; | ||
134 | else | ||
135 | buffer[length] = '\0'; | ||
136 | |||
137 | struct GNUNET_MESSENGER_Room *room = cls; | ||
138 | |||
139 | struct GNUNET_MESSENGER_Message message; | ||
140 | message.header.kind = GNUNET_MESSENGER_KIND_TEXT; | ||
141 | message.body.text.text = buffer; | ||
142 | |||
143 | GNUNET_MESSENGER_send_message (room, &message); | ||
144 | |||
145 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, cls); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * Wait for input on STDIO and send it out over the #ch. | ||
150 | * | ||
151 | * @param cls Closure | ||
152 | */ | ||
153 | static void | ||
154 | listen_stdio (void *cls) | ||
155 | { | ||
156 | read_task = NULL; | ||
157 | |||
158 | struct GNUNET_NETWORK_FDSet *rs = GNUNET_NETWORK_fdset_create (); | ||
159 | |||
160 | GNUNET_NETWORK_fdset_set_native (rs, 0); | ||
161 | |||
162 | read_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
163 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
164 | rs, | ||
165 | NULL, | ||
166 | &read_stdio, cls); | ||
167 | |||
168 | GNUNET_NETWORK_fdset_destroy (rs); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Initial task to startup application. | ||
173 | * | ||
174 | * @param cls Closure | ||
175 | */ | ||
176 | static void | ||
177 | idle (void *cls) | ||
178 | { | ||
179 | struct GNUNET_MESSENGER_Room *room = cls; | ||
180 | |||
181 | printf ("* You joined the room.\n"); | ||
182 | |||
183 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, room); | ||
184 | } | ||
185 | |||
186 | char *door_id; | ||
187 | char *ego_name; | ||
188 | char *room_key; | ||
189 | |||
190 | struct GNUNET_SCHEDULER_Task *shutdown_task; | ||
191 | |||
192 | /** | ||
193 | * Function called when an identity is retrieved. | ||
194 | * | ||
195 | * @param cls Closure | ||
196 | * @param handle Handle of messenger service | ||
197 | */ | ||
198 | static void | ||
199 | on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
200 | { | ||
201 | struct GNUNET_HashCode key; | ||
202 | memset (&key, 0, sizeof(key)); | ||
203 | |||
204 | if (room_key) | ||
205 | GNUNET_CRYPTO_hash (room_key, strlen (room_key), &key); | ||
206 | |||
207 | struct GNUNET_PeerIdentity *door = NULL; | ||
208 | |||
209 | if (door_id) | ||
210 | { | ||
211 | door = GNUNET_new(struct GNUNET_PeerIdentity); | ||
212 | |||
213 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door->public_key))) | ||
214 | { | ||
215 | GNUNET_free(door); | ||
216 | door = NULL; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | const char *name = GNUNET_MESSENGER_get_name (handle); | ||
221 | |||
222 | if (!name) | ||
223 | name = "anonymous"; | ||
224 | |||
225 | printf ("* Welcome to the messenger, '%s'!\n", name); | ||
226 | |||
227 | struct GNUNET_MESSENGER_Room *room; | ||
228 | |||
229 | if (door) | ||
230 | { | ||
231 | printf ("* You try to entry a room...\n"); | ||
232 | |||
233 | room = GNUNET_MESSENGER_entry_room (messenger, door, &key); | ||
234 | } | ||
235 | else | ||
236 | { | ||
237 | printf ("* You try to open a room...\n"); | ||
238 | |||
239 | room = GNUNET_MESSENGER_open_room (messenger, &key); | ||
240 | } | ||
241 | |||
242 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
243 | |||
244 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, room); | ||
245 | |||
246 | if (!room) | ||
247 | GNUNET_SCHEDULER_shutdown (); | ||
248 | else | ||
249 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle, | ||
250 | room); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Main function that will be run by the scheduler. | ||
255 | * | ||
256 | * @param cls closure | ||
257 | * @param args remaining command-line arguments | ||
258 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
259 | * @param cfg configuration | ||
260 | */ | ||
261 | static void | ||
262 | run (void *cls, char *const*args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
263 | { | ||
264 | messenger = GNUNET_MESSENGER_connect (cfg, ego_name, &on_identity, NULL, &on_message, NULL); | ||
265 | |||
266 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, NULL); | ||
267 | } | ||
268 | |||
269 | /** | ||
270 | * The main function to obtain messenger information. | ||
271 | * | ||
272 | * @param argc number of arguments from the command line | ||
273 | * @param argv command line arguments | ||
274 | * @return 0 ok, 1 on error | ||
275 | */ | ||
276 | int | ||
277 | main (int argc, char **argv) | ||
278 | { | ||
279 | const char *description = "Open and connect to rooms using the MESSENGER to chat."; | ||
280 | |||
281 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
282 | GNUNET_GETOPT_option_string ('d', | ||
283 | "door", | ||
284 | "PEERIDENTITY", | ||
285 | "peer identity to entry into the room", | ||
286 | &door_id), | ||
287 | GNUNET_GETOPT_option_string ('e', | ||
288 | "ego", | ||
289 | "IDENTITY", | ||
290 | "identity to use for messaging", | ||
291 | &ego_name), | ||
292 | GNUNET_GETOPT_option_string ('r', | ||
293 | "room", | ||
294 | "ROOMKEY", | ||
295 | "key of the room to connect to", | ||
296 | &room_key), | ||
297 | GNUNET_GETOPT_OPTION_END }; | ||
298 | |||
299 | return (GNUNET_OK == GNUNET_PROGRAM_run (argc, | ||
300 | argv, | ||
301 | "gnunet-messenger\0", | ||
302 | gettext_noop(description), | ||
303 | options, | ||
304 | &run, | ||
305 | NULL) ? EXIT_SUCCESS : EXIT_FAILURE); | ||
306 | } | ||
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c new file mode 100644 index 000000000..2c92305c4 --- /dev/null +++ b/src/messenger/gnunet-service-messenger.c | |||
@@ -0,0 +1,306 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_service.h" | ||
29 | #include "messenger_api_message.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_Client | ||
32 | { | ||
33 | struct GNUNET_SERVICE_Client *client; | ||
34 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
35 | }; | ||
36 | |||
37 | struct GNUNET_MESSENGER_Service *messenger; | ||
38 | |||
39 | static int | ||
40 | check_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg) | ||
41 | { | ||
42 | GNUNET_MQ_check_zero_termination(msg); | ||
43 | return GNUNET_OK; | ||
44 | } | ||
45 | |||
46 | static void | ||
47 | handle_create (void *cls, const struct GNUNET_MESSENGER_CreateMessage *msg) | ||
48 | { | ||
49 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
50 | |||
51 | const char *name = ((const char*) msg) + sizeof(*msg); | ||
52 | |||
53 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handle created with name: %s\n", name); | ||
54 | |||
55 | setup_handle_name (msg_client->handle, strlen (name) > 0? name : NULL); | ||
56 | |||
57 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
58 | } | ||
59 | |||
60 | static void | ||
61 | handle_update (void *cls, const struct GNUNET_MESSENGER_UpdateMessage *msg) | ||
62 | { | ||
63 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
64 | |||
65 | if (GNUNET_OK != update_handle (msg_client->handle)) | ||
66 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Name is required to update key!\n"); | ||
67 | |||
68 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
69 | } | ||
70 | |||
71 | static void | ||
72 | handle_destroy (void *cls, const struct GNUNET_MESSENGER_DestroyMessage *msg) | ||
73 | { | ||
74 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
75 | |||
76 | GNUNET_SERVICE_client_drop (msg_client->client); | ||
77 | } | ||
78 | |||
79 | static int | ||
80 | check_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) | ||
81 | { | ||
82 | GNUNET_MQ_check_zero_termination(msg); | ||
83 | return GNUNET_OK; | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | handle_set_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) | ||
88 | { | ||
89 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
90 | |||
91 | const char *name = ((const char*) msg) + sizeof(*msg); | ||
92 | |||
93 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handles name is now: %s\n", name); | ||
94 | |||
95 | if (GNUNET_YES != set_handle_name (msg_client->handle, name)) | ||
96 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "No valid name: %s\n", name); | ||
97 | |||
98 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
99 | } | ||
100 | |||
101 | static void | ||
102 | handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
103 | { | ||
104 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
105 | |||
106 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening room: %s\n", | ||
107 | GNUNET_h2s (&(msg->key))); | ||
108 | |||
109 | if (GNUNET_YES == open_handle_room (msg_client->handle, &(msg->key))) | ||
110 | { | ||
111 | const struct GNUNET_ShortHashCode* member_id = get_handle_member_id(msg_client->handle, &(msg->key)); | ||
112 | |||
113 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opening room with member id: %s\n", | ||
114 | GNUNET_sh2s (member_id)); | ||
115 | |||
116 | struct GNUNET_MESSENGER_RoomMessage *response; | ||
117 | struct GNUNET_MQ_Envelope *env; | ||
118 | |||
119 | env = GNUNET_MQ_msg(response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); | ||
120 | GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key)); | ||
121 | GNUNET_MQ_send (msg_client->handle->mq, env); | ||
122 | } | ||
123 | else | ||
124 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Opening room failed: %s\n", | ||
125 | GNUNET_h2s (&(msg->key))); | ||
126 | |||
127 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
128 | } | ||
129 | |||
130 | static void | ||
131 | handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
132 | { | ||
133 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
134 | |||
135 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entering room: %s, %s\n", | ||
136 | GNUNET_h2s (&(msg->key)), GNUNET_i2s (&(msg->door))); | ||
137 | |||
138 | if (GNUNET_YES == entry_handle_room (msg_client->handle, &(msg->door), &(msg->key))) | ||
139 | { | ||
140 | const struct GNUNET_ShortHashCode* member_id = get_handle_member_id(msg_client->handle, &(msg->key)); | ||
141 | |||
142 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entering room with member id: %s\n", | ||
143 | GNUNET_sh2s (member_id)); | ||
144 | |||
145 | struct GNUNET_MESSENGER_RoomMessage *response; | ||
146 | struct GNUNET_MQ_Envelope *env; | ||
147 | |||
148 | env = GNUNET_MQ_msg(response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); | ||
149 | GNUNET_memcpy(&(response->door), &(msg->door), sizeof(msg->door)); | ||
150 | GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key)); | ||
151 | GNUNET_MQ_send (msg_client->handle->mq, env); | ||
152 | } | ||
153 | else | ||
154 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Entrance into room failed: %s, %s\n", | ||
155 | GNUNET_h2s (&(msg->key)), GNUNET_i2s (&(msg->door))); | ||
156 | |||
157 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
162 | { | ||
163 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
164 | |||
165 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room: %s\n", GNUNET_h2s (&(msg->key))); | ||
166 | |||
167 | if (GNUNET_YES == close_handle_room (msg_client->handle, &(msg->key))) | ||
168 | { | ||
169 | const struct GNUNET_ShortHashCode* member_id = get_handle_member_id(msg_client->handle, &(msg->key)); | ||
170 | |||
171 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room with member id: %s\n", | ||
172 | GNUNET_sh2s (member_id)); | ||
173 | |||
174 | struct GNUNET_MESSENGER_RoomMessage *response; | ||
175 | struct GNUNET_MQ_Envelope *env; | ||
176 | |||
177 | env = GNUNET_MQ_msg(response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); | ||
178 | GNUNET_memcpy(&(response->key), &(msg->key), sizeof(msg->key)); | ||
179 | GNUNET_MQ_send (msg_client->handle->mq, env); | ||
180 | } | ||
181 | else | ||
182 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Closing room failed: %s\n", GNUNET_h2s (&(msg->key))); | ||
183 | |||
184 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
185 | } | ||
186 | |||
187 | static int | ||
188 | check_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg) | ||
189 | { | ||
190 | const uint16_t full_length = ntohs (msg->header.size) - sizeof(msg->header); | ||
191 | |||
192 | if (full_length < sizeof(msg->key)) | ||
193 | return GNUNET_NO; | ||
194 | |||
195 | const uint16_t length = full_length - sizeof(msg->key); | ||
196 | const char *buffer = ((const char*) msg) + sizeof(*msg); | ||
197 | |||
198 | struct GNUNET_MESSENGER_Message message; | ||
199 | |||
200 | if (GNUNET_YES != decode_message (&message, length, buffer)) | ||
201 | return GNUNET_NO; | ||
202 | |||
203 | return GNUNET_OK; | ||
204 | } | ||
205 | |||
206 | static void | ||
207 | handle_send_message (void *cls, const struct GNUNET_MESSENGER_SendMessage *msg) | ||
208 | { | ||
209 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
210 | |||
211 | const struct GNUNET_HashCode *key = &(msg->key); | ||
212 | const char *buffer = ((const char*) msg) + sizeof(*msg); | ||
213 | |||
214 | const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); | ||
215 | |||
216 | struct GNUNET_MESSENGER_Message message; | ||
217 | decode_message (&message, length, buffer); | ||
218 | |||
219 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending message: %s to %s\n", | ||
220 | GNUNET_MESSENGER_name_of_kind (message.header.kind), | ||
221 | GNUNET_h2s (key)); | ||
222 | |||
223 | if (GNUNET_YES != send_handle_message (msg_client->handle, key, &message)) | ||
224 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message failed: %s to %s\n", | ||
225 | GNUNET_MESSENGER_name_of_kind (message.header.kind), | ||
226 | GNUNET_h2s (key)); | ||
227 | |||
228 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
229 | } | ||
230 | |||
231 | static void | ||
232 | handle_get_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) | ||
233 | { | ||
234 | struct GNUNET_MESSENGER_Client *msg_client = cls; | ||
235 | |||
236 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Requesting message from room: %s\n", | ||
237 | GNUNET_h2s (&(msg->key))); | ||
238 | |||
239 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (messenger, &(msg->key)); | ||
240 | |||
241 | if (room) | ||
242 | get_room_message (room, msg_client->handle, &(msg->hash), GNUNET_YES); | ||
243 | else | ||
244 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Room not found: %s\n", | ||
245 | GNUNET_h2s (&(msg->key))); | ||
246 | |||
247 | GNUNET_SERVICE_client_continue (msg_client->client); | ||
248 | } | ||
249 | |||
250 | static void* | ||
251 | callback_client_connect (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq) | ||
252 | { | ||
253 | struct GNUNET_MESSENGER_Client *msg_client = GNUNET_new(struct GNUNET_MESSENGER_Client); | ||
254 | |||
255 | msg_client->client = client; | ||
256 | msg_client->handle = add_service_handle (messenger, mq); | ||
257 | |||
258 | return msg_client; | ||
259 | } | ||
260 | |||
261 | static void | ||
262 | callback_client_disconnect (void *cls, struct GNUNET_SERVICE_Client *client, void *internal_cls) | ||
263 | { | ||
264 | struct GNUNET_MESSENGER_Client *msg_client = internal_cls; | ||
265 | |||
266 | remove_service_handle (messenger, msg_client->handle); | ||
267 | |||
268 | GNUNET_free(msg_client); | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * Setup MESSENGER internals. | ||
273 | * | ||
274 | * @param cls closure | ||
275 | * @param config configuration to use | ||
276 | * @param service the initialized service | ||
277 | */ | ||
278 | static void | ||
279 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service) | ||
280 | { | ||
281 | messenger = create_service (config, service); | ||
282 | |||
283 | if ((!messenger) || (!messenger->cadet) || (!messenger->identity)) | ||
284 | GNUNET_SCHEDULER_shutdown (); | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * Define "main" method using service macro. | ||
289 | */ | ||
290 | GNUNET_SERVICE_MAIN( | ||
291 | GNUNET_MESSENGER_SERVICE_NAME, | ||
292 | GNUNET_SERVICE_OPTION_NONE, | ||
293 | &run, | ||
294 | &callback_client_connect, | ||
295 | &callback_client_disconnect, | ||
296 | NULL, | ||
297 | GNUNET_MQ_hd_var_size( create, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, struct GNUNET_MESSENGER_CreateMessage, NULL ), | ||
298 | GNUNET_MQ_hd_fixed_size( update, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE, struct GNUNET_MESSENGER_UpdateMessage, NULL ), | ||
299 | GNUNET_MQ_hd_fixed_size( destroy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, struct GNUNET_MESSENGER_DestroyMessage, NULL ), | ||
300 | GNUNET_MQ_hd_var_size( set_name, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME, struct GNUNET_MESSENGER_NameMessage, NULL ), | ||
301 | GNUNET_MQ_hd_fixed_size( room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, struct GNUNET_MESSENGER_RoomMessage, NULL ), | ||
302 | GNUNET_MQ_hd_fixed_size( room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, struct GNUNET_MESSENGER_RoomMessage, NULL ), | ||
303 | GNUNET_MQ_hd_fixed_size( room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, struct GNUNET_MESSENGER_RoomMessage, NULL ), | ||
304 | GNUNET_MQ_hd_var_size( send_message, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, struct GNUNET_MESSENGER_SendMessage, NULL ), | ||
305 | GNUNET_MQ_hd_fixed_size( get_message, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, struct GNUNET_MESSENGER_RecvMessage, NULL ), | ||
306 | GNUNET_MQ_handler_end()); | ||
diff --git a/src/messenger/gnunet-service-messenger.h b/src/messenger/gnunet-service-messenger.h new file mode 100644 index 000000000..85a1d2549 --- /dev/null +++ b/src/messenger/gnunet-service-messenger.h | |||
@@ -0,0 +1,121 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_mq_lib.h" | ||
35 | #include "gnunet_peer_lib.h" | ||
36 | #include "gnunet_protocols.h" | ||
37 | #include "gnunet_util_lib.h" | ||
38 | |||
39 | /** | ||
40 | * Message to create a handle for a client | ||
41 | */ | ||
42 | struct GNUNET_MESSENGER_CreateMessage | ||
43 | { | ||
44 | struct GNUNET_MessageHeader header; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Message to update the handle (its EGO key) for a client | ||
49 | */ | ||
50 | struct GNUNET_MESSENGER_UpdateMessage | ||
51 | { | ||
52 | struct GNUNET_MessageHeader header; | ||
53 | }; | ||
54 | |||
55 | /** | ||
56 | * Message to destroy the handle for a client | ||
57 | */ | ||
58 | struct GNUNET_MESSENGER_DestroyMessage | ||
59 | { | ||
60 | struct GNUNET_MessageHeader header; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Message to receive the current name of a handle | ||
65 | */ | ||
66 | struct GNUNET_MESSENGER_NameMessage | ||
67 | { | ||
68 | struct GNUNET_MessageHeader header; | ||
69 | }; | ||
70 | |||
71 | /** | ||
72 | * Message to receive the current public key of a handle | ||
73 | */ | ||
74 | struct GNUNET_MESSENGER_KeyMessage | ||
75 | { | ||
76 | struct GNUNET_MessageHeader header; | ||
77 | struct GNUNET_IDENTITY_PublicKey pubkey; | ||
78 | }; | ||
79 | |||
80 | /** | ||
81 | * General message to confirm interaction with a room | ||
82 | */ | ||
83 | struct GNUNET_MESSENGER_RoomMessage | ||
84 | { | ||
85 | struct GNUNET_MessageHeader header; | ||
86 | |||
87 | struct GNUNET_PeerIdentity door; | ||
88 | struct GNUNET_HashCode key; | ||
89 | }; | ||
90 | |||
91 | /** | ||
92 | * Message to receive the current member id of a handle in room | ||
93 | */ | ||
94 | struct GNUNET_MESSENGER_MemberMessage | ||
95 | { | ||
96 | struct GNUNET_MessageHeader header; | ||
97 | |||
98 | struct GNUNET_HashCode key; | ||
99 | struct GNUNET_ShortHashCode id; | ||
100 | }; | ||
101 | |||
102 | /** | ||
103 | * Message to send something into a room | ||
104 | */ | ||
105 | struct GNUNET_MESSENGER_SendMessage | ||
106 | { | ||
107 | struct GNUNET_MessageHeader header; | ||
108 | struct GNUNET_HashCode key; | ||
109 | }; | ||
110 | |||
111 | /** | ||
112 | * Message to receive something from a room | ||
113 | */ | ||
114 | struct GNUNET_MESSENGER_RecvMessage | ||
115 | { | ||
116 | struct GNUNET_MessageHeader header; | ||
117 | struct GNUNET_HashCode key; | ||
118 | struct GNUNET_HashCode hash; | ||
119 | }; | ||
120 | |||
121 | #endif //GNUNET_SERVICE_MESSENGER_H | ||
diff --git a/src/messenger/gnunet-service-messenger_basement.c b/src/messenger/gnunet-service-messenger_basement.c new file mode 100644 index 000000000..190cf2de5 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_basement.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_basement.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_basement.h" | ||
27 | |||
28 | size_t | ||
29 | count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels) | ||
30 | { | ||
31 | const struct GNUNET_MESSENGER_ListTunnel *element; | ||
32 | size_t count = 0; | ||
33 | |||
34 | for (element = tunnels->head; element; element = element->next) | ||
35 | count++; | ||
36 | |||
37 | return count; | ||
38 | } | ||
39 | |||
40 | int | ||
41 | should_connect_tunnel_to (size_t count, size_t src, size_t dst) | ||
42 | { | ||
43 | if ((src + 1) % count == dst % count) | ||
44 | return GNUNET_YES; | ||
45 | |||
46 | return GNUNET_NO; | ||
47 | } | ||
48 | |||
49 | int | ||
50 | required_connection_between (size_t count, size_t src, size_t dst) | ||
51 | { | ||
52 | if (GNUNET_YES == should_connect_tunnel_to (count, src, dst)) | ||
53 | return GNUNET_YES; | ||
54 | if (GNUNET_YES == should_connect_tunnel_to (count, dst, src)) | ||
55 | return GNUNET_YES; | ||
56 | |||
57 | return GNUNET_NO; | ||
58 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_basement.h b/src/messenger/gnunet-service-messenger_basement.h new file mode 100644 index 000000000..0a1a9b126 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_basement.h | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_basement.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_BASEMENT_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_BASEMENT_H | ||
28 | |||
29 | #include "messenger_api_list_tunnels.h" | ||
30 | |||
31 | /** | ||
32 | * Returns the count of peers in a list (typically from the basement of a room). | ||
33 | * | ||
34 | * @param tunnels List of peer identities | ||
35 | * @return Count of the entries in the list | ||
36 | */ | ||
37 | size_t | ||
38 | count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels); | ||
39 | |||
40 | /** | ||
41 | * Returns GNUNET_YES or GNUNET_NO to determine if the peer at index <i>src</i> should | ||
42 | * or should not connect outgoing to the peer at index <i>dst</i> to construct a complete | ||
43 | * basement with a given <i>count</i> of peers. | ||
44 | * | ||
45 | * @param count Count of peers | ||
46 | * @param src Source index | ||
47 | * @param dst Destination index | ||
48 | * @return GNUNET_YES or GNUNET_NO based on topologic requirement | ||
49 | */ | ||
50 | int | ||
51 | should_connect_tunnel_to (size_t count, size_t src, size_t dst); | ||
52 | |||
53 | /** | ||
54 | * Returns GNUNET_YES or GNUNET_NO to determine if the peers of index <i>src</i> and | ||
55 | * index <i>dst</i> should be connected in any direction to construct a complete | ||
56 | * basement with a given <i>count</i> of peers. | ||
57 | * | ||
58 | * @param count Count of peers | ||
59 | * @param src Source index | ||
60 | * @param dst Destination index | ||
61 | * @return GNUNET_YES or GNUNET_NO based on topologic requirement | ||
62 | */ | ||
63 | int | ||
64 | required_connection_between (size_t count, size_t src, size_t dst); | ||
65 | |||
66 | #endif //GNUNET_SERVICE_MESSENGER_BASEMENT_H | ||
diff --git a/src/messenger/gnunet-service-messenger_contact.c b/src/messenger/gnunet-service-messenger_contact.c new file mode 100644 index 000000000..1ec125402 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_contact.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_contact.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_contact.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_SrvContact* | ||
29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | ||
30 | { | ||
31 | struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_new(struct GNUNET_MESSENGER_SrvContact); | ||
32 | |||
33 | contact->name = NULL; | ||
34 | contact->rc = 0; | ||
35 | |||
36 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | ||
37 | |||
38 | return contact; | ||
39 | } | ||
40 | |||
41 | void | ||
42 | destroy_contact (struct GNUNET_MESSENGER_SrvContact *contact) | ||
43 | { | ||
44 | if (contact->name) | ||
45 | GNUNET_free(contact->name); | ||
46 | |||
47 | GNUNET_free(contact); | ||
48 | } | ||
49 | |||
50 | const char* | ||
51 | get_contact_name (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
52 | { | ||
53 | return contact->name; | ||
54 | } | ||
55 | |||
56 | void | ||
57 | set_contact_name (struct GNUNET_MESSENGER_SrvContact *contact, const char *name) | ||
58 | { | ||
59 | GNUNET_assert(name); | ||
60 | |||
61 | if (contact->name) | ||
62 | GNUNET_free(contact->name); | ||
63 | |||
64 | contact->name = GNUNET_strdup(name); | ||
65 | } | ||
66 | |||
67 | const struct GNUNET_IDENTITY_PublicKey* | ||
68 | get_contact_key (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
69 | { | ||
70 | return &(contact->public_key); | ||
71 | } | ||
72 | |||
73 | void | ||
74 | increase_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact) | ||
75 | { | ||
76 | contact->rc++; | ||
77 | } | ||
78 | |||
79 | int | ||
80 | decrease_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact) | ||
81 | { | ||
82 | if (contact->rc > 0) | ||
83 | contact->rc--; | ||
84 | |||
85 | return contact->rc ? GNUNET_NO : GNUNET_YES; | ||
86 | } | ||
87 | |||
88 | const struct GNUNET_HashCode* | ||
89 | get_contact_id_from_key (const struct GNUNET_MESSENGER_SrvContact *contact) | ||
90 | { | ||
91 | static struct GNUNET_HashCode id; | ||
92 | |||
93 | GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id); | ||
94 | |||
95 | return &id; | ||
96 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_contact.h b/src/messenger/gnunet-service-messenger_contact.h new file mode 100644 index 000000000..4a4f8bf0f --- /dev/null +++ b/src/messenger/gnunet-service-messenger_contact.h | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_contact.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_CONTACT_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_CONTACT_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | #include "gnunet_identity_service.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_SrvContact | ||
34 | { | ||
35 | char *name; | ||
36 | size_t rc; | ||
37 | |||
38 | struct GNUNET_IDENTITY_PublicKey public_key; | ||
39 | }; | ||
40 | |||
41 | /** | ||
42 | * Creates and allocates a new contact with a given public <i>key</i> from an EGO. | ||
43 | * | ||
44 | * @param key Public key | ||
45 | * @return New contact | ||
46 | */ | ||
47 | struct GNUNET_MESSENGER_SrvContact* | ||
48 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key); | ||
49 | |||
50 | /** | ||
51 | * Destroys a contact and frees its memory fully. | ||
52 | * | ||
53 | * @param contact Contact | ||
54 | */ | ||
55 | void | ||
56 | destroy_contact (struct GNUNET_MESSENGER_SrvContact *contact); | ||
57 | |||
58 | /** | ||
59 | * Returns the current name of a given <i>contact</i> or NULL if no valid name was assigned yet. | ||
60 | * | ||
61 | * @param contact Contact | ||
62 | * @return Name of the contact or NULL | ||
63 | */ | ||
64 | const char* | ||
65 | get_contact_name (const struct GNUNET_MESSENGER_SrvContact *contact); | ||
66 | |||
67 | /** | ||
68 | * Changes the current name of a given <i>contact</i> by copying it from the parameter <i>name</i>. | ||
69 | * | ||
70 | * @param contact Contact | ||
71 | * @param name Valid name (may not be NULL!) | ||
72 | */ | ||
73 | void | ||
74 | set_contact_name (struct GNUNET_MESSENGER_SrvContact *contact, const char *name); | ||
75 | |||
76 | /** | ||
77 | * Returns the public key of a given <i>contact</i>. | ||
78 | * | ||
79 | * @param contact Contact | ||
80 | * @return Public key of the contact | ||
81 | */ | ||
82 | const struct GNUNET_IDENTITY_PublicKey* | ||
83 | get_contact_key (const struct GNUNET_MESSENGER_SrvContact *contact); | ||
84 | |||
85 | /** | ||
86 | * Increases the reference counter of a given <i>contact</i> which is zero as default. | ||
87 | * | ||
88 | * @param contact Contact | ||
89 | */ | ||
90 | void | ||
91 | increase_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact); | ||
92 | |||
93 | /** | ||
94 | * Decreases the reference counter if possible (can not underflow!) of a given <i>contact</i> | ||
95 | * and returns GNUNET_YES if the counter is equal to zero, otherwise GNUNET_NO. | ||
96 | * | ||
97 | * @param contact Contact | ||
98 | * @return GNUNET_YES or GNUNET_NO depending on the reference counter | ||
99 | */ | ||
100 | int | ||
101 | decrease_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact); | ||
102 | |||
103 | /** | ||
104 | * Returns the resulting hashcode of the public key from a given <i>contact</i>. | ||
105 | * | ||
106 | * @param contact Contact | ||
107 | * @return Hash of the contacts public key | ||
108 | */ | ||
109 | const struct GNUNET_HashCode* | ||
110 | get_contact_id_from_key (const struct GNUNET_MESSENGER_SrvContact *contact); | ||
111 | |||
112 | #endif //GNUNET_SERVICE_MESSENGER_CONTACT_H | ||
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c new file mode 100644 index 000000000..38ad6fbb4 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_handle.c | |||
@@ -0,0 +1,503 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_handle.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_handle.h" | ||
27 | |||
28 | #include "gnunet-service-messenger.h" | ||
29 | #include "gnunet-service-messenger_message_kind.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_SrvHandle* | ||
32 | create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq) | ||
33 | { | ||
34 | struct GNUNET_MESSENGER_SrvHandle *handle = GNUNET_new(struct GNUNET_MESSENGER_SrvHandle); | ||
35 | |||
36 | handle->service = service; | ||
37 | handle->mq = mq; | ||
38 | |||
39 | handle->name = NULL; | ||
40 | |||
41 | handle->operation = NULL; | ||
42 | |||
43 | handle->ego = NULL; | ||
44 | |||
45 | handle->member_ids = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
46 | |||
47 | return handle; | ||
48 | } | ||
49 | |||
50 | int | ||
51 | iterate_free_member_ids (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
52 | { | ||
53 | GNUNET_free(value); | ||
54 | |||
55 | return GNUNET_YES; | ||
56 | } | ||
57 | |||
58 | void | ||
59 | destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle) | ||
60 | { | ||
61 | if (handle->service->dir) | ||
62 | save_handle_configuration(handle); | ||
63 | |||
64 | if (handle->operation) | ||
65 | GNUNET_IDENTITY_cancel (handle->operation); | ||
66 | |||
67 | if (handle->name) | ||
68 | GNUNET_free(handle->name); | ||
69 | |||
70 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL); | ||
71 | GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); | ||
72 | |||
73 | GNUNET_free(handle); | ||
74 | } | ||
75 | |||
76 | void | ||
77 | get_handle_data_subdir (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir) | ||
78 | { | ||
79 | if (name) | ||
80 | GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities", | ||
81 | DIR_SEPARATOR, name, DIR_SEPARATOR); | ||
82 | else | ||
83 | GNUNET_asprintf (dir, "%s%s%c", handle->service->dir, "anonymous", | ||
84 | DIR_SEPARATOR); | ||
85 | } | ||
86 | |||
87 | static int | ||
88 | create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) | ||
89 | { | ||
90 | struct GNUNET_ShortHashCode *random_id = generate_service_new_member_id (handle->service, key); | ||
91 | |||
92 | if (!random_id) | ||
93 | return GNUNET_NO; | ||
94 | |||
95 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, random_id, | ||
96 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
97 | { | ||
98 | GNUNET_free(random_id); | ||
99 | return GNUNET_NO; | ||
100 | } | ||
101 | |||
102 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Created a new member id (%s) for room: %s\n", | ||
103 | GNUNET_sh2s(random_id), GNUNET_h2s(key)); | ||
104 | |||
105 | return GNUNET_YES; | ||
106 | } | ||
107 | |||
108 | const struct GNUNET_ShortHashCode* | ||
109 | get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) | ||
110 | { | ||
111 | return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | ||
112 | } | ||
113 | |||
114 | void | ||
115 | change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
116 | const struct GNUNET_ShortHashCode *unique_id) | ||
117 | { | ||
118 | struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | ||
119 | |||
120 | if (member_id) | ||
121 | { | ||
122 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Changed a member id (%s) for room (%s) ", | ||
123 | GNUNET_sh2s(member_id), GNUNET_h2s(key)); | ||
124 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "into (%s).\n", | ||
125 | GNUNET_sh2s(unique_id)); | ||
126 | |||
127 | GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id)); | ||
128 | |||
129 | struct GNUNET_MESSENGER_MemberMessage *msg; | ||
130 | struct GNUNET_MQ_Envelope *env; | ||
131 | |||
132 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID); | ||
133 | |||
134 | GNUNET_memcpy(&(msg->key), key, sizeof(*key)); | ||
135 | GNUNET_memcpy(&(msg->id), member_id, sizeof(*member_id)); | ||
136 | |||
137 | GNUNET_MQ_send (handle->mq, env); | ||
138 | } | ||
139 | else | ||
140 | { | ||
141 | member_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
142 | GNUNET_memcpy(member_id, unique_id, sizeof(*member_id)); | ||
143 | |||
144 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id, | ||
145 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
146 | GNUNET_free(member_id); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | static void | ||
151 | change_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) | ||
152 | { | ||
153 | if (handle->name) | ||
154 | GNUNET_free(handle->name); | ||
155 | |||
156 | handle->name = name ? GNUNET_strdup(name) : NULL; | ||
157 | |||
158 | const uint16_t name_len = handle->name ? strlen (handle->name) : 0; | ||
159 | |||
160 | struct GNUNET_MESSENGER_NameMessage *msg; | ||
161 | struct GNUNET_MQ_Envelope *env; | ||
162 | |||
163 | env = GNUNET_MQ_msg_extra(msg, name_len + 1, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME); | ||
164 | |||
165 | char *extra = ((char*) msg) + sizeof(*msg); | ||
166 | |||
167 | if (name_len) | ||
168 | GNUNET_memcpy(extra, handle->name, name_len); | ||
169 | |||
170 | extra[name_len] = '\0'; | ||
171 | |||
172 | GNUNET_MQ_send (handle->mq, env); | ||
173 | } | ||
174 | |||
175 | static void | ||
176 | change_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Ego *ego) | ||
177 | { | ||
178 | handle->ego = ego; | ||
179 | |||
180 | ego = get_handle_ego(handle); | ||
181 | |||
182 | struct GNUNET_MESSENGER_KeyMessage *msg; | ||
183 | struct GNUNET_MQ_Envelope *env; | ||
184 | |||
185 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY); | ||
186 | |||
187 | GNUNET_memcpy(&(msg->pubkey), &(ego->pub), sizeof(ego->pub)); | ||
188 | |||
189 | GNUNET_MQ_send (handle->mq, env); | ||
190 | } | ||
191 | |||
192 | struct GNUNET_MESSENGER_Ego* | ||
193 | get_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle) | ||
194 | { | ||
195 | static struct GNUNET_MESSENGER_Ego anonymous; | ||
196 | static int read_keys = 0; | ||
197 | |||
198 | if (handle->ego) | ||
199 | return handle->ego; | ||
200 | |||
201 | if (!read_keys) | ||
202 | { | ||
203 | struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous (); | ||
204 | GNUNET_memcpy(&(anonymous.priv), GNUNET_IDENTITY_ego_get_private_key(ego), sizeof(anonymous.priv)); | ||
205 | GNUNET_IDENTITY_ego_get_public_key(ego, &(anonymous.pub)); | ||
206 | read_keys = 1; | ||
207 | } | ||
208 | |||
209 | return &anonymous; | ||
210 | } | ||
211 | |||
212 | void | ||
213 | setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) | ||
214 | { | ||
215 | change_handle_name (handle, name); | ||
216 | change_handle_ego (handle, handle->name? lookup_service_ego(handle->service, handle->name) : NULL); | ||
217 | |||
218 | if (handle->service->dir) | ||
219 | load_handle_configuration(handle); | ||
220 | } | ||
221 | |||
222 | struct GNUNET_MESSENGER_MessageHandle | ||
223 | { | ||
224 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
225 | struct GNUNET_MESSENGER_Message *message; | ||
226 | }; | ||
227 | |||
228 | static int | ||
229 | iterate_send_message (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
230 | { | ||
231 | struct GNUNET_MESSENGER_MessageHandle *msg_handle = cls; | ||
232 | |||
233 | send_handle_message (msg_handle->handle, key, msg_handle->message); | ||
234 | |||
235 | return GNUNET_YES; | ||
236 | } | ||
237 | |||
238 | static void | ||
239 | callback_ego_create (void *cls, const struct GNUNET_IDENTITY_PrivateKey *key, const char *emsg) | ||
240 | { | ||
241 | struct GNUNET_MESSENGER_SrvHandle *handle = cls; | ||
242 | |||
243 | handle->operation = NULL; | ||
244 | |||
245 | if (emsg) | ||
246 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | ||
247 | |||
248 | if (key) | ||
249 | { | ||
250 | struct GNUNET_MESSENGER_MessageHandle msg_handle; | ||
251 | |||
252 | msg_handle.handle = handle; | ||
253 | msg_handle.message = create_message_key (key); | ||
254 | |||
255 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle); | ||
256 | |||
257 | destroy_message (msg_handle.message); | ||
258 | |||
259 | update_service_ego(handle->service, handle->name, key); | ||
260 | |||
261 | change_handle_ego (handle, lookup_service_ego(handle->service, handle->name)); | ||
262 | } | ||
263 | } | ||
264 | |||
265 | int | ||
266 | update_handle (struct GNUNET_MESSENGER_SrvHandle *handle) | ||
267 | { | ||
268 | GNUNET_assert(handle); | ||
269 | |||
270 | if (!handle->name) | ||
271 | return GNUNET_SYSERR; | ||
272 | |||
273 | struct GNUNET_MESSENGER_Ego *ego = lookup_service_ego(handle->service, handle->name); | ||
274 | |||
275 | if (!ego) | ||
276 | handle->operation = GNUNET_IDENTITY_create (handle->service->identity, handle->name, NULL, | ||
277 | GNUNET_IDENTITY_TYPE_ECDSA, callback_ego_create, handle); | ||
278 | else | ||
279 | change_handle_ego (handle, ego); | ||
280 | |||
281 | return GNUNET_OK; | ||
282 | } | ||
283 | |||
284 | int | ||
285 | set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name) | ||
286 | { | ||
287 | GNUNET_assert(handle); | ||
288 | |||
289 | if ((name) && (lookup_service_ego(handle->service, name))) | ||
290 | return GNUNET_NO; | ||
291 | |||
292 | struct GNUNET_IDENTITY_Operation *operation = handle->operation; | ||
293 | |||
294 | if (handle->name) | ||
295 | handle->operation = GNUNET_IDENTITY_rename (handle->service->identity, handle->name, name, NULL, NULL); | ||
296 | |||
297 | char *old_dir; | ||
298 | get_handle_data_subdir (handle, handle->name, &old_dir); | ||
299 | |||
300 | char *new_dir; | ||
301 | get_handle_data_subdir (handle, name, &new_dir); | ||
302 | |||
303 | int result = 0; | ||
304 | |||
305 | if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES)) | ||
306 | { | ||
307 | GNUNET_DISK_directory_create_for_file (new_dir); | ||
308 | |||
309 | result = rename (old_dir, new_dir); | ||
310 | } | ||
311 | else if (GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO)) | ||
312 | result = -1; | ||
313 | |||
314 | if (0 == result) | ||
315 | { | ||
316 | struct GNUNET_MESSENGER_MessageHandle msg_handle; | ||
317 | |||
318 | msg_handle.handle = handle; | ||
319 | msg_handle.message = create_message_name (name); | ||
320 | |||
321 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle); | ||
322 | |||
323 | destroy_message (msg_handle.message); | ||
324 | |||
325 | change_handle_name (handle, name); | ||
326 | |||
327 | if (operation) | ||
328 | GNUNET_IDENTITY_cancel (operation); | ||
329 | } | ||
330 | else | ||
331 | { | ||
332 | if (handle->operation) | ||
333 | { | ||
334 | GNUNET_IDENTITY_cancel (handle->operation); | ||
335 | |||
336 | handle->operation = operation; | ||
337 | } | ||
338 | } | ||
339 | |||
340 | GNUNET_free(old_dir); | ||
341 | GNUNET_free(new_dir); | ||
342 | |||
343 | return (result == 0 ? GNUNET_OK : GNUNET_NO); | ||
344 | } | ||
345 | |||
346 | int | ||
347 | open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) | ||
348 | { | ||
349 | if ((!get_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | ||
350 | return GNUNET_NO; | ||
351 | |||
352 | return open_service_room (handle->service, handle, key); | ||
353 | } | ||
354 | |||
355 | int | ||
356 | entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, | ||
357 | const struct GNUNET_HashCode *key) | ||
358 | { | ||
359 | if ((!get_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | ||
360 | return GNUNET_NO; | ||
361 | |||
362 | return entry_service_room (handle->service, handle, door, key); | ||
363 | } | ||
364 | |||
365 | int | ||
366 | close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) | ||
367 | { | ||
368 | if (!get_handle_member_id (handle, key)) | ||
369 | return GNUNET_NO; | ||
370 | |||
371 | return close_service_room (handle->service, handle, key); | ||
372 | } | ||
373 | |||
374 | int | ||
375 | send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
376 | struct GNUNET_MESSENGER_Message *message) | ||
377 | { | ||
378 | const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key); | ||
379 | |||
380 | if (!id) | ||
381 | { | ||
382 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n"); | ||
383 | return GNUNET_NO; | ||
384 | } | ||
385 | |||
386 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key); | ||
387 | |||
388 | if (!room) | ||
389 | { | ||
390 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key)); | ||
391 | return GNUNET_NO; | ||
392 | } | ||
393 | |||
394 | struct GNUNET_HashCode hash; | ||
395 | |||
396 | GNUNET_memcpy(&(message->header.sender_id), id, sizeof(*id)); | ||
397 | |||
398 | send_room_message (room, handle, message, &hash); | ||
399 | return GNUNET_YES; | ||
400 | } | ||
401 | |||
402 | static int callback_scan_for_rooms(void* cls, const char *filename) { | ||
403 | struct GNUNET_MESSENGER_SrvHandle* handle = cls; | ||
404 | |||
405 | struct GNUNET_CONFIGURATION_Handle* cfg = GNUNET_CONFIGURATION_create(); | ||
406 | |||
407 | if ((GNUNET_YES == GNUNET_DISK_file_test(filename)) && | ||
408 | (GNUNET_OK == GNUNET_CONFIGURATION_parse(cfg, filename))) | ||
409 | { | ||
410 | struct GNUNET_HashCode key; | ||
411 | struct GNUNET_ShortHashCode member_id; | ||
412 | |||
413 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_data(cfg, "room", "key", &key, sizeof(key))) && | ||
414 | (GNUNET_OK == GNUNET_CONFIGURATION_get_data(cfg, "room", "member_id", &member_id, sizeof(member_id)))) | ||
415 | change_handle_member_id(handle, &key, &member_id); | ||
416 | } | ||
417 | |||
418 | GNUNET_CONFIGURATION_destroy(cfg); | ||
419 | return GNUNET_OK; | ||
420 | } | ||
421 | |||
422 | void load_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle) { | ||
423 | char* id_dir; | ||
424 | get_handle_data_subdir(handle, handle->name, &id_dir); | ||
425 | |||
426 | if (GNUNET_YES == GNUNET_DISK_directory_test(id_dir, GNUNET_YES)) | ||
427 | { | ||
428 | char* scan_dir; | ||
429 | GNUNET_asprintf(&scan_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR); | ||
430 | |||
431 | if (GNUNET_OK == GNUNET_DISK_directory_test(scan_dir, GNUNET_YES)) | ||
432 | GNUNET_DISK_directory_scan(scan_dir, callback_scan_for_rooms, handle); | ||
433 | |||
434 | GNUNET_free(scan_dir); | ||
435 | } | ||
436 | |||
437 | GNUNET_free(id_dir); | ||
438 | } | ||
439 | |||
440 | static int | ||
441 | iterate_save_rooms(void* cls, const struct GNUNET_HashCode* key, void* value) | ||
442 | { | ||
443 | struct GNUNET_MESSENGER_SrvHandle* handle = cls; | ||
444 | struct GNUNET_ShortHashCode* member_id = value; | ||
445 | |||
446 | char* id_dir; | ||
447 | get_handle_data_subdir(handle, handle->name, &id_dir); | ||
448 | |||
449 | char* filename; | ||
450 | GNUNET_asprintf(&filename, "%s%s%c%s.cfg", | ||
451 | id_dir, "rooms", DIR_SEPARATOR, | ||
452 | GNUNET_h2s(key)); | ||
453 | |||
454 | GNUNET_free(id_dir); | ||
455 | |||
456 | struct GNUNET_CONFIGURATION_Handle* cfg = GNUNET_CONFIGURATION_create(); | ||
457 | |||
458 | char* key_data = GNUNET_STRINGS_data_to_string_alloc(key, sizeof(*key)); | ||
459 | |||
460 | if (key_data) | ||
461 | { | ||
462 | GNUNET_CONFIGURATION_set_value_string(cfg, "room", "key", key_data); | ||
463 | |||
464 | GNUNET_free(key_data); | ||
465 | } | ||
466 | |||
467 | char* member_id_data = GNUNET_STRINGS_data_to_string_alloc(member_id, sizeof(*member_id)); | ||
468 | |||
469 | if (member_id_data) | ||
470 | { | ||
471 | GNUNET_CONFIGURATION_set_value_string(cfg, "room", "member_id", member_id_data); | ||
472 | |||
473 | GNUNET_free(member_id_data); | ||
474 | } | ||
475 | |||
476 | GNUNET_CONFIGURATION_write(cfg, filename); | ||
477 | GNUNET_CONFIGURATION_destroy(cfg); | ||
478 | |||
479 | GNUNET_free(filename); | ||
480 | |||
481 | return GNUNET_YES; | ||
482 | } | ||
483 | |||
484 | void save_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle) | ||
485 | { | ||
486 | char* id_dir; | ||
487 | get_handle_data_subdir(handle, handle->name, &id_dir); | ||
488 | |||
489 | if ((GNUNET_YES == GNUNET_DISK_directory_test(id_dir, GNUNET_NO)) || | ||
490 | (GNUNET_OK == GNUNET_DISK_directory_create(id_dir))) | ||
491 | { | ||
492 | char* save_dir; | ||
493 | GNUNET_asprintf(&save_dir, "%s%s%c", id_dir, "rooms", DIR_SEPARATOR); | ||
494 | |||
495 | if ((GNUNET_YES == GNUNET_DISK_directory_test(save_dir, GNUNET_NO)) || | ||
496 | (GNUNET_OK == GNUNET_DISK_directory_create(save_dir))) | ||
497 | GNUNET_CONTAINER_multihashmap_iterate(handle->member_ids, iterate_save_rooms, handle); | ||
498 | |||
499 | GNUNET_free(save_dir); | ||
500 | } | ||
501 | |||
502 | GNUNET_free(id_dir); | ||
503 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_handle.h b/src/messenger/gnunet-service-messenger_handle.h new file mode 100644 index 000000000..81cf377a8 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_handle.h | |||
@@ -0,0 +1,216 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_handle.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_HANDLE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_HANDLE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_peer_lib.h" | ||
35 | #include "gnunet_mq_lib.h" | ||
36 | |||
37 | #include "gnunet-service-messenger_service.h" | ||
38 | |||
39 | #include "messenger_api_ego.h" | ||
40 | #include "messenger_api_message.h" | ||
41 | |||
42 | struct GNUNET_MESSENGER_SrvHandle | ||
43 | { | ||
44 | struct GNUNET_MESSENGER_Service *service; | ||
45 | struct GNUNET_MQ_Handle *mq; | ||
46 | |||
47 | char *name; | ||
48 | |||
49 | struct GNUNET_IDENTITY_Operation *operation; | ||
50 | |||
51 | struct GNUNET_MESSENGER_Ego *ego; | ||
52 | |||
53 | struct GNUNET_CONTAINER_MultiHashMap *member_ids; | ||
54 | }; | ||
55 | |||
56 | /** | ||
57 | * Creates and allocates a new handle related to a <i>service</i> and using a given <i>mq</i> (message queue). | ||
58 | * | ||
59 | * @param service MESSENGER Service | ||
60 | * @param mq Message queue | ||
61 | * @return New handle | ||
62 | */ | ||
63 | struct GNUNET_MESSENGER_SrvHandle* | ||
64 | create_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); | ||
65 | |||
66 | /** | ||
67 | * Destroys a handle and frees its memory fully. | ||
68 | * | ||
69 | * @param handle Handle | ||
70 | */ | ||
71 | void | ||
72 | destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
73 | |||
74 | /** | ||
75 | * Writes the path of the directory for a given <i>handle</i> using a specific <i>name</i> to the parameter | ||
76 | * <i>dir</i>. This directory will be used to store data regarding the handle and its messages. | ||
77 | * | ||
78 | * @param handle Handle | ||
79 | * @param name Potential name of the handle | ||
80 | * @param dir[out] Path to store data | ||
81 | */ | ||
82 | void | ||
83 | get_handle_data_subdir (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir); | ||
84 | |||
85 | /** | ||
86 | * Returns the member id of a given <i>handle</i> in a specific <i>room</i>. | ||
87 | * | ||
88 | * If the handle is not a member of the specific <i>room</i>, NULL gets returned. | ||
89 | * | ||
90 | * @param handle Handle | ||
91 | * @param key Key of a room | ||
92 | * @return Member id or NULL | ||
93 | */ | ||
94 | const struct GNUNET_ShortHashCode* | ||
95 | get_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
96 | |||
97 | /** | ||
98 | * Changes the member id of a given <i>handle</i> in a specific <i>room</i> to match a <i>unique_id</i>. | ||
99 | * | ||
100 | * The client connected to the <i>handle</i> will be informed afterwards automatically. | ||
101 | * | ||
102 | * @param handle Handle | ||
103 | * @param key Key of a room | ||
104 | * @param unique_id Unique member id | ||
105 | */ | ||
106 | void | ||
107 | change_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
108 | const struct GNUNET_ShortHashCode *unique_id); | ||
109 | |||
110 | /** | ||
111 | * Returns the EGO used by a given <i>handle</i>. | ||
112 | * | ||
113 | * @param handle Handle | ||
114 | * @return EGO keypair | ||
115 | */ | ||
116 | struct GNUNET_MESSENGER_Ego* | ||
117 | get_handle_ego (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
118 | |||
119 | /** | ||
120 | * Tries to set the name and EGO key of a <i>handle</i> initially by looking up a specific <i>name</i>. | ||
121 | * | ||
122 | * @param handle Handle | ||
123 | * @param name Name (optionally: valid EGO name) | ||
124 | */ | ||
125 | void | ||
126 | setup_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); | ||
127 | |||
128 | /** | ||
129 | * Tries to change the keypair of an EGO of a <i>handle</i> under the same name and informs all rooms | ||
130 | * about the change automatically. | ||
131 | * | ||
132 | * @param handle Handle | ||
133 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
134 | */ | ||
135 | int | ||
136 | update_handle (struct GNUNET_MESSENGER_SrvHandle *handle); | ||
137 | |||
138 | /** | ||
139 | * Tries to rename the handle which implies renaming the EGO its using and moving all related data into | ||
140 | * the directory fitting to the changed <i>name</i>. | ||
141 | * | ||
142 | * The client connected to the <i>handle</i> will be informed afterwards automatically. | ||
143 | * | ||
144 | * @param handle Handle | ||
145 | * @param name New name | ||
146 | * @return GNUNET_OK on success, otherwise GNUNET_NO | ||
147 | */ | ||
148 | int | ||
149 | set_handle_name (struct GNUNET_MESSENGER_SrvHandle *handle, const char *name); | ||
150 | |||
151 | /** | ||
152 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and opens the | ||
153 | * room from the handles service. | ||
154 | * | ||
155 | * @param handle Handle | ||
156 | * @param key Key of a room | ||
157 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
158 | */ | ||
159 | int | ||
160 | open_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
161 | |||
162 | /** | ||
163 | * Makes a given <i>handle</i> a member of the room using a specific <i>key</i> and enters the room | ||
164 | * through a tunnel to a peer identified by a given <i>door</i> (peer identity). | ||
165 | * | ||
166 | * @param handle Handle | ||
167 | * @param door Peer identity | ||
168 | * @param key Key of a room | ||
169 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
170 | */ | ||
171 | int | ||
172 | entry_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, | ||
173 | const struct GNUNET_HashCode *key); | ||
174 | |||
175 | /** | ||
176 | * Removes the membership of the room using a specific <i>key</i> and closes it if no other handle | ||
177 | * from this service is still a member of it. | ||
178 | * | ||
179 | * @param handle Handle | ||
180 | * @param key Key of a room | ||
181 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
182 | */ | ||
183 | int | ||
184 | close_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
185 | |||
186 | /** | ||
187 | * Sends a <i>message</i> from a given <i>handle</i> to the room using a specific <i>key</i>. | ||
188 | * | ||
189 | * @param handle Handle | ||
190 | * @param key Key of a room | ||
191 | * @param message Message | ||
192 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
193 | */ | ||
194 | int | ||
195 | send_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, | ||
196 | struct GNUNET_MESSENGER_Message *message); | ||
197 | |||
198 | /** | ||
199 | * Loads member ids and other potential configuration from a given <i>handle</i> which | ||
200 | * depends on the given name the <i>handle</i> uses. | ||
201 | * | ||
202 | * @param handle Handle | ||
203 | */ | ||
204 | void | ||
205 | load_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle); | ||
206 | |||
207 | /** | ||
208 | * Saves member ids and other potential configuration from a given <i>handle</i> which | ||
209 | * depends on the given name the <i>handle</i> uses. | ||
210 | * | ||
211 | * @param handle Handle | ||
212 | */ | ||
213 | void | ||
214 | save_handle_configuration(struct GNUNET_MESSENGER_SrvHandle *handle); | ||
215 | |||
216 | #endif //GNUNET_SERVICE_MESSENGER_HANDLE_H | ||
diff --git a/src/messenger/gnunet-service-messenger_list_handles.c b/src/messenger/gnunet-service-messenger_list_handles.c new file mode 100644 index 000000000..16a160dea --- /dev/null +++ b/src/messenger/gnunet-service-messenger_list_handles.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_list_handles.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_list_handles.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_handle.h" | ||
29 | |||
30 | void | ||
31 | init_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) | ||
32 | { | ||
33 | GNUNET_assert(handles); | ||
34 | |||
35 | handles->head = NULL; | ||
36 | handles->tail = NULL; | ||
37 | } | ||
38 | |||
39 | void | ||
40 | clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) | ||
41 | { | ||
42 | GNUNET_assert(handles); | ||
43 | |||
44 | while (handles->head) | ||
45 | { | ||
46 | struct GNUNET_MESSENGER_ListHandle *element = handles->head; | ||
47 | |||
48 | GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element); | ||
49 | destroy_handle (element->handle); | ||
50 | GNUNET_free(element); | ||
51 | } | ||
52 | |||
53 | handles->head = NULL; | ||
54 | handles->tail = NULL; | ||
55 | } | ||
56 | |||
57 | void | ||
58 | add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, void *handle) | ||
59 | { | ||
60 | struct GNUNET_MESSENGER_ListHandle *element = GNUNET_new(struct GNUNET_MESSENGER_ListHandle); | ||
61 | |||
62 | element->handle = handle; | ||
63 | |||
64 | GNUNET_CONTAINER_DLL_insert_tail(handles->head, handles->tail, element); | ||
65 | } | ||
66 | |||
67 | int | ||
68 | remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, void *handle) | ||
69 | { | ||
70 | struct GNUNET_MESSENGER_ListHandle *element; | ||
71 | |||
72 | for (element = handles->head; element; element = element->next) | ||
73 | if (element->handle == handle) | ||
74 | break; | ||
75 | |||
76 | if (!element) | ||
77 | return GNUNET_NO; | ||
78 | |||
79 | GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element); | ||
80 | GNUNET_free(element); | ||
81 | |||
82 | return GNUNET_YES; | ||
83 | } | ||
84 | |||
85 | void* | ||
86 | find_list_handle_by_member (struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key) | ||
87 | { | ||
88 | struct GNUNET_MESSENGER_ListHandle *element; | ||
89 | |||
90 | for (element = handles->head; element; element = element->next) | ||
91 | if (get_handle_member_id ((struct GNUNET_MESSENGER_SrvHandle*) element->handle, key)) | ||
92 | return element->handle; | ||
93 | |||
94 | return NULL; | ||
95 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_list_handles.h b/src/messenger/gnunet-service-messenger_list_handles.h new file mode 100644 index 000000000..fe92cc58a --- /dev/null +++ b/src/messenger/gnunet-service-messenger_list_handles.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_list_handles.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_LIST_HANDLES_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_LIST_HANDLES_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_ListHandle | ||
34 | { | ||
35 | struct GNUNET_MESSENGER_ListHandle *prev; | ||
36 | struct GNUNET_MESSENGER_ListHandle *next; | ||
37 | |||
38 | void *handle; | ||
39 | }; | ||
40 | |||
41 | struct GNUNET_MESSENGER_ListHandles | ||
42 | { | ||
43 | struct GNUNET_MESSENGER_ListHandle *head; | ||
44 | struct GNUNET_MESSENGER_ListHandle *tail; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Initializes list of handles as empty list. | ||
49 | * | ||
50 | * @param handles List of handles | ||
51 | */ | ||
52 | void | ||
53 | init_list_handles (struct GNUNET_MESSENGER_ListHandles *handles); | ||
54 | |||
55 | /** | ||
56 | * Destroys remaining handles and clears the list. | ||
57 | * | ||
58 | * @param handles List of handles | ||
59 | */ | ||
60 | void | ||
61 | clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles); | ||
62 | |||
63 | /** | ||
64 | * Adds a specific <i>handle</i> to the end of the list. | ||
65 | * | ||
66 | * @param handles List of handles | ||
67 | * @param handle Handle | ||
68 | */ | ||
69 | void | ||
70 | add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, void *handle); | ||
71 | |||
72 | /** | ||
73 | * Removes the first entry matching with a specific <i>handle</i> from the list and | ||
74 | * returns GNUNET_YES on success or GNUNET_NO on failure. | ||
75 | * | ||
76 | * @param handles List of handles | ||
77 | * @param handle Handle | ||
78 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
79 | */ | ||
80 | int | ||
81 | remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, void *handle); | ||
82 | |||
83 | /** | ||
84 | * Searches linearly through the list of handles for members of a specific room | ||
85 | * which is identified by a given <i>key</i>. | ||
86 | * | ||
87 | * If no handle is found which is a current member, NULL gets returned. | ||
88 | * | ||
89 | * @param handles List of handles | ||
90 | * @param key Common key of a room | ||
91 | * @return First handle which is a current member | ||
92 | */ | ||
93 | void* | ||
94 | find_list_handle_by_member (struct GNUNET_MESSENGER_ListHandles *handles, const struct GNUNET_HashCode *key); | ||
95 | |||
96 | #endif //GNUNET_SERVICE_MESSENGER_LIST_HANDLES_H | ||
diff --git a/src/messenger/gnunet-service-messenger_list_messages.c b/src/messenger/gnunet-service-messenger_list_messages.c new file mode 100644 index 000000000..c4f1f7043 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_list_messages.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_list_messages.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_list_messages.h" | ||
27 | |||
28 | void | ||
29 | init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) | ||
30 | { | ||
31 | GNUNET_assert(messages); | ||
32 | |||
33 | messages->head = NULL; | ||
34 | messages->tail = NULL; | ||
35 | } | ||
36 | |||
37 | void | ||
38 | clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) | ||
39 | { | ||
40 | GNUNET_assert(messages); | ||
41 | |||
42 | while (messages->head) | ||
43 | { | ||
44 | struct GNUNET_MESSENGER_ListMessage *element = messages->head; | ||
45 | |||
46 | GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element); | ||
47 | GNUNET_free(element); | ||
48 | } | ||
49 | |||
50 | messages->head = NULL; | ||
51 | messages->tail = NULL; | ||
52 | } | ||
53 | |||
54 | void | ||
55 | add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash) | ||
56 | { | ||
57 | struct GNUNET_MESSENGER_ListMessage *element = GNUNET_new(struct GNUNET_MESSENGER_ListMessage); | ||
58 | |||
59 | GNUNET_memcpy(&(element->hash), hash, sizeof(struct GNUNET_HashCode)); | ||
60 | |||
61 | GNUNET_CONTAINER_DLL_insert_tail(messages->head, messages->tail, element); | ||
62 | } | ||
63 | |||
64 | void | ||
65 | remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash) | ||
66 | { | ||
67 | struct GNUNET_MESSENGER_ListMessage *element; | ||
68 | |||
69 | for (element = messages->head; element; element = element->next) | ||
70 | if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), hash)) | ||
71 | { | ||
72 | GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element); | ||
73 | GNUNET_free(element); | ||
74 | break; | ||
75 | } | ||
76 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_list_messages.h b/src/messenger/gnunet-service-messenger_list_messages.h new file mode 100644 index 000000000..266c30ec6 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_list_messages.h | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_list_messages.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_LIST_MESSAGES_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_LIST_MESSAGES_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_ListMessage | ||
34 | { | ||
35 | struct GNUNET_MESSENGER_ListMessage *prev; | ||
36 | struct GNUNET_MESSENGER_ListMessage *next; | ||
37 | |||
38 | struct GNUNET_HashCode hash; | ||
39 | }; | ||
40 | |||
41 | struct GNUNET_MESSENGER_ListMessages | ||
42 | { | ||
43 | struct GNUNET_MESSENGER_ListMessage *head; | ||
44 | struct GNUNET_MESSENGER_ListMessage *tail; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Initializes list of message hashes as empty list. | ||
49 | * | ||
50 | * @param messages List of hashes | ||
51 | */ | ||
52 | void | ||
53 | init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages); | ||
54 | |||
55 | /** | ||
56 | * Clears the list of message hashes. | ||
57 | * | ||
58 | * @param messages List of hashes | ||
59 | */ | ||
60 | void | ||
61 | clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages); | ||
62 | |||
63 | /** | ||
64 | * Adds a specific <i>hash</i> from a message to the end of the list. | ||
65 | * | ||
66 | * @param messages List of hashes | ||
67 | * @param hash Hash of message | ||
68 | */ | ||
69 | void | ||
70 | add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash); | ||
71 | |||
72 | /** | ||
73 | * Removes the first entry with a matching <i>hash</i> from the list. | ||
74 | * | ||
75 | * @param messages List of hashes | ||
76 | * @param hash Hash of message | ||
77 | */ | ||
78 | void | ||
79 | remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash); | ||
80 | |||
81 | #endif //GNUNET_SERVICE_MESSENGER_LIST_MESSAGES_H | ||
diff --git a/src/messenger/gnunet-service-messenger_message_handle.c b/src/messenger/gnunet-service-messenger_message_handle.c new file mode 100644 index 000000000..1652435c8 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_handle.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_handle.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_handle.h" | ||
27 | |||
28 | void | ||
29 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
30 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
31 | { | ||
32 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
33 | |||
34 | if (!contact) | ||
35 | add_room_contact (room, &(message->header.sender_id), &(message->body.join.key)); | ||
36 | |||
37 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
38 | |||
39 | if (!info) | ||
40 | { | ||
41 | info = GNUNET_new(struct GNUNET_MESSENGER_MemberInfo); | ||
42 | |||
43 | info->access = GNUNET_MESSENGER_MEMBER_UNKNOWN; | ||
44 | init_list_messages (&(info->session_messages)); | ||
45 | } | ||
46 | else | ||
47 | clear_list_messages (&(info->session_messages)); | ||
48 | |||
49 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_put (room->member_infos, &(message->header.sender_id), info, | ||
50 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
51 | add_to_list_messages (&(info->session_messages), hash); | ||
52 | } | ||
53 | |||
54 | void | ||
55 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
56 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
57 | { | ||
58 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
59 | |||
60 | if (info) | ||
61 | clear_list_messages (&(info->session_messages)); | ||
62 | } | ||
63 | |||
64 | void | ||
65 | handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
66 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
67 | { | ||
68 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
69 | |||
70 | if (contact) | ||
71 | set_contact_name (contact, message->body.name.name); | ||
72 | |||
73 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
74 | |||
75 | if (info) | ||
76 | add_to_list_messages (&(info->session_messages), hash); | ||
77 | } | ||
78 | |||
79 | void | ||
80 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
81 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
82 | { | ||
83 | struct GNUNET_MESSENGER_SrvContact *contact = get_room_contact (room, &(message->header.sender_id)); | ||
84 | |||
85 | if (contact) | ||
86 | swap_service_contact_by_pubkey (room->service, contact, &(message->body.key.key)); | ||
87 | |||
88 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
89 | |||
90 | if (info) | ||
91 | add_to_list_messages (&(info->session_messages), hash); | ||
92 | } | ||
93 | |||
94 | void | ||
95 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
96 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
97 | { | ||
98 | if (GNUNET_NO == contains_list_tunnels (&(room->basement), &(message->body.peer.peer))) | ||
99 | add_to_list_tunnels (&(room->basement), &(message->body.peer.peer)); | ||
100 | |||
101 | if (room->peer_message) | ||
102 | rebuild_room_basement_structure (room); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
107 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
108 | { | ||
109 | struct GNUNET_MESSENGER_MemberInfo *info = get_room_member_info (room, &(message->header.sender_id)); | ||
110 | |||
111 | if (info) | ||
112 | add_to_list_messages (&(info->session_messages), hash); | ||
113 | |||
114 | switch_room_member_id (room, &(message->header.sender_id), &(message->body.id.id), hash); | ||
115 | } | ||
116 | |||
117 | void | ||
118 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
119 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
120 | { | ||
121 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (&(room->basement), &(message->body.peer.peer), NULL); | ||
122 | |||
123 | if (!element) | ||
124 | return; | ||
125 | |||
126 | remove_from_list_tunnels (&(room->basement), element); | ||
127 | |||
128 | if (room->peer_message) | ||
129 | rebuild_room_basement_structure (room); | ||
130 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_message_handle.h b/src/messenger/gnunet-service-messenger_message_handle.h new file mode 100644 index 000000000..d091e1d11 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_handle.h | |||
@@ -0,0 +1,128 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_handle.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_HANDLE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_HANDLE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | |||
32 | #include "gnunet-service-messenger_message_kind.h" | ||
33 | |||
34 | #include "gnunet-service-messenger_tunnel.h" | ||
35 | #include "messenger_api_message.h" | ||
36 | |||
37 | /** | ||
38 | * Handles a received or sent join message to make changes of current member information. | ||
39 | * (add matching member and clear member info) | ||
40 | * | ||
41 | * @param room Room of the message | ||
42 | * @param tunnel Receiving/sending connection (may be NULL) | ||
43 | * @param message JOIN-Message | ||
44 | * @param hash Hash of the message | ||
45 | */ | ||
46 | void | ||
47 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
48 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
49 | |||
50 | /** | ||
51 | * Handles a received or sent leave message to make changes of current member information. | ||
52 | * (remove matching member and clear member info) | ||
53 | * | ||
54 | * @param room Room of the message | ||
55 | * @param tunnel Receiving/sending connection (may be NULL) | ||
56 | * @param message LEAVE-Message | ||
57 | * @param hash Hash of the message | ||
58 | */ | ||
59 | void | ||
60 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
61 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
62 | |||
63 | /** | ||
64 | * Handles a received or sent name message to rename a current member. | ||
65 | * (change name of matching member) | ||
66 | * | ||
67 | * @param room Room of the message | ||
68 | * @param tunnel Receiving/sending connection (may be NULL) | ||
69 | * @param message NAME-Message | ||
70 | * @param hash Hash of the message | ||
71 | */ | ||
72 | void | ||
73 | handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
74 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
75 | |||
76 | /** | ||
77 | * Handles a received or sent key message to change the key of a member and rearrange the contacts accordingly. | ||
78 | * (move the member in the contacts and change its key) | ||
79 | * | ||
80 | * @param room Room of the message | ||
81 | * @param tunnel Receiving/sending connection (may be NULL) | ||
82 | * @param message KEY-Message | ||
83 | * @param hash Hash of the message | ||
84 | */ | ||
85 | void | ||
86 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
87 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
88 | |||
89 | /** | ||
90 | * Handles a received or sent peer message to make changes of the basement in the room. | ||
91 | * (add a new peer to the basement and restructure connections based on updated list of peers) | ||
92 | * | ||
93 | * @param room Room of the message | ||
94 | * @param tunnel Receiving/sending connection (may be NULL) | ||
95 | * @param message PEER-Message | ||
96 | * @param hash Hash of the message | ||
97 | */ | ||
98 | void | ||
99 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
100 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
101 | |||
102 | /** | ||
103 | * Handles a received or sent id message to change a members id. | ||
104 | * (change id of matching member) | ||
105 | * | ||
106 | * @param room Room of the message | ||
107 | * @param tunnel Receiving/sending connection (may be NULL) | ||
108 | * @param message ID-Message | ||
109 | * @param hash Hash of the message | ||
110 | */ | ||
111 | void | ||
112 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
113 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
114 | |||
115 | /** | ||
116 | * Handles a received or sent miss message to drop a peer from the basement in the room. | ||
117 | * (remove a peer from the basement and restructure connections based on updated list of peers) | ||
118 | * | ||
119 | * @param room Room of the message | ||
120 | * @param tunnel Receiving/sending connection (may be NULL) | ||
121 | * @param message MISS-Message | ||
122 | * @param hash Hash of the message | ||
123 | */ | ||
124 | void | ||
125 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
126 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
127 | |||
128 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_HANDLE_H | ||
diff --git a/src/messenger/gnunet-service-messenger_message_kind.c b/src/messenger/gnunet-service-messenger_message_kind.c new file mode 100644 index 000000000..9c829fe09 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_kind.c | |||
@@ -0,0 +1,192 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_kind.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_kind.h" | ||
27 | #include "gnunet-service-messenger_util.h" | ||
28 | |||
29 | struct GNUNET_MESSENGER_Message* | ||
30 | create_message_info (struct GNUNET_MESSENGER_Ego *ego, struct GNUNET_CONTAINER_MultiShortmap *members) | ||
31 | { | ||
32 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_INFO); | ||
33 | |||
34 | if (!message) | ||
35 | return NULL; | ||
36 | |||
37 | GNUNET_memcpy(&(message->body.info.host_key), &(ego->pub), sizeof(ego->pub)); | ||
38 | |||
39 | if (GNUNET_YES == generate_free_member_id (&(message->body.info.unique_id), members)) | ||
40 | return message; | ||
41 | else | ||
42 | { | ||
43 | destroy_message (message); | ||
44 | return NULL; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | struct GNUNET_MESSENGER_Message* | ||
49 | create_message_join (struct GNUNET_MESSENGER_Ego *ego) | ||
50 | { | ||
51 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_JOIN); | ||
52 | |||
53 | if (!message) | ||
54 | return NULL; | ||
55 | |||
56 | GNUNET_memcpy(&(message->body.join.key), &(ego->pub), sizeof(ego->pub)); | ||
57 | |||
58 | return message; | ||
59 | } | ||
60 | |||
61 | struct GNUNET_MESSENGER_Message* | ||
62 | create_message_leave () | ||
63 | { | ||
64 | return create_message (GNUNET_MESSENGER_KIND_LEAVE); | ||
65 | } | ||
66 | |||
67 | struct GNUNET_MESSENGER_Message* | ||
68 | create_message_name (const char *name) | ||
69 | { | ||
70 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_NAME); | ||
71 | |||
72 | if (!message) | ||
73 | return NULL; | ||
74 | |||
75 | message->body.name.name = GNUNET_strdup(name); | ||
76 | return message; | ||
77 | } | ||
78 | |||
79 | struct GNUNET_MESSENGER_Message* | ||
80 | create_message_key (const struct GNUNET_IDENTITY_PrivateKey *key) | ||
81 | { | ||
82 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_KEY); | ||
83 | |||
84 | if (!message) | ||
85 | return NULL; | ||
86 | |||
87 | GNUNET_IDENTITY_key_get_public (key, &(message->body.key.key)); | ||
88 | return message; | ||
89 | } | ||
90 | |||
91 | struct GNUNET_MESSENGER_Message* | ||
92 | create_message_peer (const struct GNUNET_MESSENGER_Service *service) | ||
93 | { | ||
94 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_PEER); | ||
95 | |||
96 | if (!message) | ||
97 | return NULL; | ||
98 | |||
99 | if (GNUNET_OK == get_service_peer_identity (service, &(message->body.peer.peer))) | ||
100 | return message; | ||
101 | else | ||
102 | { | ||
103 | destroy_message (message); | ||
104 | return NULL; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | struct GNUNET_MESSENGER_Message* | ||
109 | create_message_id (const struct GNUNET_ShortHashCode *unique_id) | ||
110 | { | ||
111 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_ID); | ||
112 | |||
113 | if (!message) | ||
114 | return NULL; | ||
115 | |||
116 | GNUNET_memcpy(&(message->body.id.id), unique_id, sizeof(struct GNUNET_ShortHashCode)); | ||
117 | |||
118 | return message; | ||
119 | } | ||
120 | |||
121 | struct GNUNET_MESSENGER_Message* | ||
122 | create_message_miss (const struct GNUNET_PeerIdentity *peer) | ||
123 | { | ||
124 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_MISS); | ||
125 | |||
126 | if (!message) | ||
127 | { | ||
128 | return NULL; | ||
129 | } | ||
130 | |||
131 | GNUNET_memcpy(&(message->body.miss.peer), peer, sizeof(struct GNUNET_PeerIdentity)); | ||
132 | |||
133 | return message; | ||
134 | } | ||
135 | |||
136 | struct GNUNET_MESSENGER_Message* | ||
137 | create_message_merge (const struct GNUNET_HashCode *previous) | ||
138 | { | ||
139 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_MERGE); | ||
140 | |||
141 | if (!message) | ||
142 | return NULL; | ||
143 | |||
144 | GNUNET_memcpy(&(message->body.merge.previous), previous, sizeof(struct GNUNET_HashCode)); | ||
145 | |||
146 | return message; | ||
147 | } | ||
148 | |||
149 | struct GNUNET_MESSENGER_Message* | ||
150 | create_message_request (const struct GNUNET_HashCode *hash) | ||
151 | { | ||
152 | struct GNUNET_HashCode zero; | ||
153 | memset (&zero, 0, sizeof(zero)); | ||
154 | |||
155 | if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero)) | ||
156 | return NULL; | ||
157 | |||
158 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_REQUEST); | ||
159 | |||
160 | if (!message) | ||
161 | return NULL; | ||
162 | |||
163 | GNUNET_memcpy(&(message->body.request.hash), hash, sizeof(struct GNUNET_HashCode)); | ||
164 | |||
165 | return message; | ||
166 | } | ||
167 | |||
168 | struct GNUNET_MESSENGER_Message* | ||
169 | create_message_invite (const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) | ||
170 | { | ||
171 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_INVITE); | ||
172 | |||
173 | if (!message) | ||
174 | return NULL; | ||
175 | |||
176 | GNUNET_memcpy(&(message->body.invite.door), door, sizeof(struct GNUNET_PeerIdentity)); | ||
177 | GNUNET_memcpy(&(message->body.invite.key), key, sizeof(struct GNUNET_HashCode)); | ||
178 | |||
179 | return message; | ||
180 | } | ||
181 | |||
182 | struct GNUNET_MESSENGER_Message* | ||
183 | create_message_text (const char *text) | ||
184 | { | ||
185 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_TEXT); | ||
186 | |||
187 | if (!message) | ||
188 | return NULL; | ||
189 | |||
190 | message->body.text.text = GNUNET_strdup(text); | ||
191 | return message; | ||
192 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_message_kind.h b/src/messenger/gnunet-service-messenger_message_kind.h new file mode 100644 index 000000000..dd89d0b2f --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_kind.h | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_kind.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_KIND_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_KIND_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_container_lib.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | #include "gnunet_identity_service.h" | ||
33 | |||
34 | #include "messenger_api_message.h" | ||
35 | #include "gnunet-service-messenger_service.h" | ||
36 | #include "messenger_api_ego.h" | ||
37 | |||
38 | /** | ||
39 | * Creates and allocates a new info message containing the hosts public key and a newly generated unique member id. | ||
40 | * (all values are stored as copy) | ||
41 | * | ||
42 | * @param ego EGO of the host | ||
43 | * @param members Map of all assigned member ids | ||
44 | * @return New message | ||
45 | */ | ||
46 | struct GNUNET_MESSENGER_Message* | ||
47 | create_message_info (struct GNUNET_MESSENGER_Ego *ego, struct GNUNET_CONTAINER_MultiShortmap *members); | ||
48 | |||
49 | /** | ||
50 | * Creates and allocates a new join message containing the clients public key. | ||
51 | * (all values are stored as copy) | ||
52 | * | ||
53 | * @param ego EGO of the client | ||
54 | * @return New message | ||
55 | */ | ||
56 | struct GNUNET_MESSENGER_Message* | ||
57 | create_message_join (struct GNUNET_MESSENGER_Ego *ego); | ||
58 | |||
59 | /** | ||
60 | * Creates and allocates a new leave message. | ||
61 | * | ||
62 | * @return New message | ||
63 | */ | ||
64 | struct GNUNET_MESSENGER_Message* | ||
65 | create_message_leave (); | ||
66 | |||
67 | /** | ||
68 | * Creates and allocates a new name message containing the <i>name</i> to change to. | ||
69 | * (all values are stored as copy) | ||
70 | * | ||
71 | * @param name New name | ||
72 | * @return New message | ||
73 | */ | ||
74 | struct GNUNET_MESSENGER_Message* | ||
75 | create_message_name (const char *name); | ||
76 | |||
77 | /** | ||
78 | * Creates and allocates a new key message containing the public key to change to derived | ||
79 | * from its private counterpart. (all values are stored as copy) | ||
80 | * | ||
81 | * @param key Private key of EGO | ||
82 | * @return New message | ||
83 | */ | ||
84 | struct GNUNET_MESSENGER_Message* | ||
85 | create_message_key (const struct GNUNET_IDENTITY_PrivateKey *key); | ||
86 | |||
87 | /** | ||
88 | * Creates and allocates a new peer message containing a services peer identity. | ||
89 | * (all values are stored as copy) | ||
90 | * | ||
91 | * @param service Service | ||
92 | * @return New message | ||
93 | */ | ||
94 | struct GNUNET_MESSENGER_Message* | ||
95 | create_message_peer (const struct GNUNET_MESSENGER_Service *service); | ||
96 | |||
97 | /** | ||
98 | * Creates and allocates a new id message containing the unique member id to change to. | ||
99 | * (all values are stored as copy) | ||
100 | * | ||
101 | * @param unique_id Unique member id | ||
102 | * @return New message | ||
103 | */ | ||
104 | struct GNUNET_MESSENGER_Message* | ||
105 | create_message_id (const struct GNUNET_ShortHashCode *unique_id); | ||
106 | |||
107 | /** | ||
108 | * Creates and allocates a new miss message containing the missing peer identity. | ||
109 | * (all values are stored as copy) | ||
110 | * | ||
111 | * @param peer Missing peer identity | ||
112 | * @return New message | ||
113 | */ | ||
114 | struct GNUNET_MESSENGER_Message* | ||
115 | create_message_miss (const struct GNUNET_PeerIdentity *peer); | ||
116 | |||
117 | /** | ||
118 | * Creates and allocates a new merge message containing the hash of a second previous message | ||
119 | * besides the regular previous message mentioned in a messages header. | ||
120 | * (all values are stored as copy) | ||
121 | * | ||
122 | * @param previous Hash of message | ||
123 | * @return New message | ||
124 | */ | ||
125 | struct GNUNET_MESSENGER_Message* | ||
126 | create_message_merge (const struct GNUNET_HashCode *previous); | ||
127 | |||
128 | /** | ||
129 | * Creates and allocates a new request message containing the hash of a missing message. | ||
130 | * (all values are stored as copy) | ||
131 | * | ||
132 | * @param hash Hash of message | ||
133 | * @return New message | ||
134 | */ | ||
135 | struct GNUNET_MESSENGER_Message* | ||
136 | create_message_request (const struct GNUNET_HashCode *hash); | ||
137 | |||
138 | /** | ||
139 | * Creates and allocates a new invite message containing the peer identity of an entrance peer | ||
140 | * to a room using a given <i>key</i> as shared secret for communication. | ||
141 | * (all values are stored as copy) | ||
142 | * | ||
143 | * @param door Peer identity | ||
144 | * @param key Shared secret of a room | ||
145 | * @return New message | ||
146 | */ | ||
147 | struct GNUNET_MESSENGER_Message* | ||
148 | create_message_invite (const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); | ||
149 | |||
150 | /** | ||
151 | * Creates and allocates a new text message containing a string representing text. | ||
152 | * (all values are stored as copy) | ||
153 | * | ||
154 | * @param text Text | ||
155 | * @return New message | ||
156 | */ | ||
157 | struct GNUNET_MESSENGER_Message* | ||
158 | create_message_text (const char *text); | ||
159 | |||
160 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_KIND_H | ||
diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c new file mode 100644 index 000000000..aa28a36ea --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_recv.c | |||
@@ -0,0 +1,204 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_recv.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_recv.h" | ||
27 | #include "gnunet-service-messenger_message_handle.h" | ||
28 | |||
29 | void | ||
30 | recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
31 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
32 | { | ||
33 | int conflict = GNUNET_CONTAINER_multishortmap_contains (room->members, &(message->body.info.unique_id)); | ||
34 | |||
35 | if (GNUNET_NO == conflict) | ||
36 | { | ||
37 | struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&(message->body.info.unique_id)); | ||
38 | struct GNUNET_HashCode sync_hash; | ||
39 | |||
40 | send_room_message_ext (room, room->host, sync_message, &sync_hash, tunnel); | ||
41 | destroy_message (sync_message); | ||
42 | |||
43 | switch_room_member_id (room, get_room_host_id (room), &(message->body.info.unique_id), NULL); | ||
44 | |||
45 | change_room_host_id (room, &(message->body.info.unique_id)); | ||
46 | } | ||
47 | |||
48 | if (!tunnel->contact_id) | ||
49 | tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
50 | |||
51 | GNUNET_memcpy(tunnel->contact_id, &(message->header.sender_id), sizeof(struct GNUNET_ShortHashCode)); | ||
52 | |||
53 | struct GNUNET_ShortHashCode original_id; | ||
54 | |||
55 | if (GNUNET_YES == conflict) | ||
56 | { | ||
57 | GNUNET_memcpy(&original_id, get_room_host_id (room), sizeof(struct GNUNET_ShortHashCode)); | ||
58 | |||
59 | change_room_host_id (room, &(message->body.info.unique_id)); | ||
60 | } | ||
61 | |||
62 | { | ||
63 | struct GNUNET_MESSENGER_Message *join_message = create_message_join (room->host->ego); | ||
64 | struct GNUNET_HashCode join_hash; | ||
65 | |||
66 | send_tunnel_message (tunnel, room->host, join_message, &join_hash); | ||
67 | destroy_message (join_message); | ||
68 | } | ||
69 | |||
70 | if ((GNUNET_YES == conflict) && (0 != GNUNET_memcmp(&original_id, get_room_host_id (room)))) | ||
71 | { | ||
72 | struct GNUNET_MESSENGER_Message *sync_message = create_message_id (&original_id); | ||
73 | struct GNUNET_HashCode sync_hash; | ||
74 | |||
75 | send_tunnel_message (tunnel, room->host, sync_message, &sync_hash); | ||
76 | destroy_message (sync_message); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | struct GNUNET_MESSENGER_MemberInfoSpread | ||
81 | { | ||
82 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
83 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; | ||
84 | }; | ||
85 | |||
86 | static int | ||
87 | iterate_send_member_infos (void *cls, const struct GNUNET_ShortHashCode *key, void *value) | ||
88 | { | ||
89 | struct GNUNET_MESSENGER_MemberInfo *info = value; | ||
90 | struct GNUNET_MESSENGER_MemberInfoSpread *spread = cls; | ||
91 | |||
92 | struct GNUNET_MESSENGER_ListMessage *element = info->session_messages.head; | ||
93 | |||
94 | while (element) | ||
95 | { | ||
96 | const struct GNUNET_MESSENGER_Message *message = get_room_message (spread->room, spread->room->host, | ||
97 | &(element->hash), GNUNET_NO); | ||
98 | |||
99 | if (message) | ||
100 | forward_tunnel_message (spread->tunnel, message, &(element->hash)); | ||
101 | |||
102 | element = element->next; | ||
103 | } | ||
104 | |||
105 | return GNUNET_YES; | ||
106 | } | ||
107 | |||
108 | void | ||
109 | recv_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
110 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
111 | { | ||
112 | const struct GNUNET_MESSENGER_Message *info_msg = get_room_message (room, room->host, &(message->header.previous), | ||
113 | GNUNET_NO); | ||
114 | |||
115 | if ((info_msg) && (0 == GNUNET_memcmp(&(info_msg->header.sender_id), get_room_host_id (room))) | ||
116 | && (GNUNET_MESSENGER_KIND_INFO == info_msg->header.kind)) | ||
117 | { | ||
118 | struct GNUNET_MESSENGER_MemberInfoSpread spread; | ||
119 | |||
120 | spread.room = room; | ||
121 | |||
122 | if ((tunnel) && (tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, &(message->header.sender_id)))) | ||
123 | spread.tunnel = tunnel; | ||
124 | else | ||
125 | spread.tunnel = find_room_tunnel_to (room, &(message->header.sender_id)); | ||
126 | |||
127 | if (spread.tunnel) | ||
128 | GNUNET_CONTAINER_multishortmap_iterate (room->member_infos, iterate_send_member_infos, &spread); | ||
129 | } | ||
130 | |||
131 | handle_message_join (room, tunnel, message, hash); | ||
132 | } | ||
133 | |||
134 | void | ||
135 | recv_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
136 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
137 | { | ||
138 | handle_message_leave (room, tunnel, message, hash); | ||
139 | } | ||
140 | |||
141 | void | ||
142 | recv_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
143 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
144 | { | ||
145 | handle_message_name (room, tunnel, message, hash); | ||
146 | } | ||
147 | |||
148 | void | ||
149 | recv_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
150 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
151 | { | ||
152 | handle_message_key (room, tunnel, message, hash); | ||
153 | } | ||
154 | |||
155 | void | ||
156 | recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
157 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
158 | { | ||
159 | struct GNUNET_PeerIdentity peer; | ||
160 | GNUNET_PEER_resolve (tunnel->peer, &peer); | ||
161 | |||
162 | if (0 == GNUNET_memcmp(&peer, &(message->body.peer.peer))) | ||
163 | { | ||
164 | if (!tunnel->peer_message) | ||
165 | tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode); | ||
166 | |||
167 | GNUNET_memcpy(tunnel->peer_message, hash, sizeof(struct GNUNET_HashCode)); | ||
168 | |||
169 | if (!tunnel->contact_id) | ||
170 | tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
171 | |||
172 | GNUNET_memcpy(tunnel->contact_id, &(message->header.sender_id), sizeof(struct GNUNET_ShortHashCode)); | ||
173 | } | ||
174 | |||
175 | handle_message_peer (room, tunnel, message, hash); | ||
176 | } | ||
177 | |||
178 | void | ||
179 | recv_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
180 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
181 | { | ||
182 | if ((tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, &(message->header.sender_id)))) | ||
183 | GNUNET_memcpy(tunnel->contact_id, &(message->body.id.id), sizeof(struct GNUNET_ShortHashCode)); | ||
184 | |||
185 | handle_message_id (room, tunnel, message, hash); | ||
186 | } | ||
187 | |||
188 | void | ||
189 | recv_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
190 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
191 | { | ||
192 | handle_message_miss (room, tunnel, message, hash); | ||
193 | } | ||
194 | |||
195 | void | ||
196 | recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
197 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
198 | { | ||
199 | const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, room->host, &(message->body.request.hash), | ||
200 | GNUNET_NO); | ||
201 | |||
202 | if (msg) | ||
203 | forward_tunnel_message (tunnel, msg, &(message->body.request.hash)); | ||
204 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_message_recv.h b/src/messenger/gnunet-service-messenger_message_recv.h new file mode 100644 index 000000000..245612cb0 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_recv.h | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_recv.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_RECV_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_RECV_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | |||
32 | #include "gnunet-service-messenger_tunnel.h" | ||
33 | #include "messenger_api_message.h" | ||
34 | |||
35 | /** | ||
36 | * Handles a received info message to change the current member id to the one generated by | ||
37 | * the host connected to. (all current tunnels will be informed about the id change) | ||
38 | * | ||
39 | * @param room Room of the message | ||
40 | * @param tunnel Receiving connection | ||
41 | * @param message INFO-Message | ||
42 | * @param hash Hash of the message | ||
43 | */ | ||
44 | void | ||
45 | recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
46 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
47 | |||
48 | /** | ||
49 | * Handles a received join message to forward all member information to the new member if the message was | ||
50 | * the direct reaction to a previous info message from this peer. | ||
51 | * | ||
52 | * @param room Room of the message | ||
53 | * @param tunnel Receiving connection | ||
54 | * @param message JOIN-Message | ||
55 | * @param hash Hash of the message | ||
56 | */ | ||
57 | void | ||
58 | recv_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
59 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
60 | |||
61 | /** | ||
62 | * Handles a received leave message. | ||
63 | * @see handle_message_leave() | ||
64 | * | ||
65 | * @param room Room of the message | ||
66 | * @param tunnel Receiving connection | ||
67 | * @param message LEAVE-Message | ||
68 | * @param hash Hash of the message | ||
69 | */ | ||
70 | void | ||
71 | recv_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
72 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
73 | |||
74 | /** | ||
75 | * Handles a received name message. | ||
76 | * @see handle_message_name() | ||
77 | * | ||
78 | * @param room Room of the message | ||
79 | * @param tunnel Receiving connection | ||
80 | * @param message NAME-Message | ||
81 | * @param hash Hash of the message | ||
82 | */ | ||
83 | void | ||
84 | recv_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
85 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
86 | |||
87 | /** | ||
88 | * Handles a received key message. | ||
89 | * @see handle_message_key() | ||
90 | * | ||
91 | * @param room Room of the message | ||
92 | * @param tunnel Receiving connection | ||
93 | * @param message KEY-Message | ||
94 | * @param hash Hash of the message | ||
95 | */ | ||
96 | void | ||
97 | recv_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
98 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
99 | |||
100 | /** | ||
101 | * Handles a received peer message to link it to its origin tunnel if the peer identity matches. | ||
102 | * (the peer message and the member id can potentially be linked to the tunnel) | ||
103 | * | ||
104 | * TODO: This handling will only check the one given tunnel! | ||
105 | * | ||
106 | * @param room Room of the message | ||
107 | * @param tunnel Receiving connection | ||
108 | * @param message PEER-Message | ||
109 | * @param hash Hash of the message | ||
110 | */ | ||
111 | void | ||
112 | recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
113 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
114 | |||
115 | /** | ||
116 | * Handles a received id message to change the tunnels linked member id if necessary. | ||
117 | * (the tunnels linked member id will be changed if the sender id is matching) | ||
118 | * | ||
119 | * TODO: This handling will only check the one given tunnel! | ||
120 | * | ||
121 | * @param room Room of the message | ||
122 | * @param tunnel Receiving connection | ||
123 | * @param message ID-Message | ||
124 | * @param hash Hash of the message | ||
125 | */ | ||
126 | void | ||
127 | recv_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
128 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
129 | |||
130 | /** | ||
131 | * Handles a received miss message. | ||
132 | * @see handle_message_miss() | ||
133 | * | ||
134 | * @param room Room of the message | ||
135 | * @param tunnel Receiving connection | ||
136 | * @param message MISS-Message | ||
137 | * @param hash Hash of the message | ||
138 | */ | ||
139 | void | ||
140 | recv_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
141 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
142 | |||
143 | /** | ||
144 | * Handles a received request message by checking for the requested message and forwarding it back | ||
145 | * if the message was found. | ||
146 | * (this can also cause this peer to send a new request instead of only forwarding the received one) | ||
147 | * | ||
148 | * TODO: Requests can cause exponentially more requests! | ||
149 | * | ||
150 | * @param room Room of the message | ||
151 | * @param tunnel Receiving connection | ||
152 | * @param message REQUEST-Message | ||
153 | * @param hash Hash of the message | ||
154 | */ | ||
155 | void | ||
156 | recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
157 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
158 | |||
159 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_RECV_H | ||
diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c new file mode 100644 index 000000000..86cf9b888 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_send.c | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_send.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_send.h" | ||
27 | #include "gnunet-service-messenger_message_handle.h" | ||
28 | |||
29 | void | ||
30 | send_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
31 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
32 | const struct GNUNET_HashCode *hash) | ||
33 | { | ||
34 | if (!tunnel->contact_id) | ||
35 | { | ||
36 | tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
37 | |||
38 | GNUNET_memcpy(tunnel->contact_id, &(message->body.info.unique_id), sizeof(struct GNUNET_ShortHashCode)); | ||
39 | } | ||
40 | else | ||
41 | { | ||
42 | disconnect_tunnel (tunnel); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | void | ||
47 | send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
48 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
49 | const struct GNUNET_HashCode *hash) | ||
50 | { | ||
51 | handle_message_join (room, tunnel, message, hash); | ||
52 | |||
53 | if (room->peer_message) | ||
54 | { | ||
55 | const struct GNUNET_MESSENGER_Message *peer_message = get_room_message (room, handle, room->peer_message, | ||
56 | GNUNET_NO); | ||
57 | |||
58 | if ((peer_message) && (tunnel)) | ||
59 | { | ||
60 | forward_tunnel_message (tunnel, peer_message, room->peer_message); | ||
61 | } | ||
62 | } | ||
63 | } | ||
64 | |||
65 | void | ||
66 | send_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
67 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
68 | const struct GNUNET_HashCode *hash) | ||
69 | { | ||
70 | handle_message_leave (room, tunnel, message, hash); | ||
71 | } | ||
72 | |||
73 | void | ||
74 | send_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
75 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
76 | const struct GNUNET_HashCode *hash) | ||
77 | { | ||
78 | handle_message_name (room, tunnel, message, hash); | ||
79 | } | ||
80 | |||
81 | void | ||
82 | send_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
83 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
84 | const struct GNUNET_HashCode *hash) | ||
85 | { | ||
86 | handle_message_key (room, tunnel, message, hash); | ||
87 | } | ||
88 | |||
89 | void | ||
90 | send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
91 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
92 | const struct GNUNET_HashCode *hash) | ||
93 | { | ||
94 | if (!room->peer_message) | ||
95 | { | ||
96 | room->peer_message = GNUNET_new(struct GNUNET_HashCode); | ||
97 | } | ||
98 | |||
99 | GNUNET_memcpy(room->peer_message, hash, sizeof(struct GNUNET_HashCode)); | ||
100 | |||
101 | handle_message_peer (room, tunnel, message, hash); | ||
102 | } | ||
103 | |||
104 | void | ||
105 | send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
106 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
107 | const struct GNUNET_HashCode *hash) | ||
108 | { | ||
109 | handle_message_id (room, tunnel, message, hash); | ||
110 | } | ||
111 | |||
112 | void | ||
113 | send_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
114 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
115 | const struct GNUNET_HashCode *hash) | ||
116 | { | ||
117 | handle_message_miss (room, tunnel, message, hash); | ||
118 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_message_send.h b/src/messenger/gnunet-service-messenger_message_send.h new file mode 100644 index 000000000..c1096205a --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_send.h | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_send.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_SEND_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_SEND_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | |||
32 | #include "gnunet-service-messenger_tunnel.h" | ||
33 | #include "messenger_api_message.h" | ||
34 | |||
35 | /** | ||
36 | * Handles a sent info message to setup a tunnels linked member id. | ||
37 | * (if a tunnel has already got a member id linked to it, the connection will be closed) | ||
38 | * | ||
39 | * @param room Room of the message | ||
40 | * @param handle Sending handle | ||
41 | * @param tunnel Sending connection (may be NULL) | ||
42 | * @param message INFO-Message | ||
43 | * @param hash Hash of the message | ||
44 | */ | ||
45 | void | ||
46 | send_message_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
47 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
48 | const struct GNUNET_HashCode *hash); | ||
49 | |||
50 | /** | ||
51 | * Handles a sent join message to ensure growth of the decentralized room structure. | ||
52 | * (if the service provides a peer message for this room currently, it will be forwarded) | ||
53 | * | ||
54 | * @param room Room of the message | ||
55 | * @param handle Sending handle | ||
56 | * @param tunnel Sending connection (may be NULL) | ||
57 | * @param message JOIN-Message | ||
58 | * @param hash Hash of the message | ||
59 | */ | ||
60 | void | ||
61 | send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
62 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
63 | const struct GNUNET_HashCode *hash); | ||
64 | |||
65 | /** | ||
66 | * Handles a sent leave message. | ||
67 | * @see handle_message_leave() | ||
68 | * | ||
69 | * @param room Room of the message | ||
70 | * @param handle Sending handle | ||
71 | * @param tunnel Sending connection (may be NULL) | ||
72 | * @param message LEAVE-Message | ||
73 | * @param hash Hash of the message | ||
74 | */ | ||
75 | void | ||
76 | send_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
77 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
78 | const struct GNUNET_HashCode *hash); | ||
79 | |||
80 | /** | ||
81 | * Handles a sent name message. | ||
82 | * @see handle_message_name() | ||
83 | * | ||
84 | * @param room Room of the message | ||
85 | * @param handle Sending handle | ||
86 | * @param tunnel Sending connection (may be NULL) | ||
87 | * @param message NAME-Message | ||
88 | * @param hash Hash of the message | ||
89 | */ | ||
90 | void | ||
91 | send_message_name (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
92 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
93 | const struct GNUNET_HashCode *hash); | ||
94 | |||
95 | /** | ||
96 | * Handles a sent key message. | ||
97 | * @see handle_message_key() | ||
98 | * | ||
99 | * @param room Room of the message | ||
100 | * @param handle Sending handle | ||
101 | * @param tunnel Sending connection (may be NULL) | ||
102 | * @param message KEY-Message | ||
103 | * @param hash Hash of the message | ||
104 | */ | ||
105 | void | ||
106 | send_message_key (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
107 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
108 | const struct GNUNET_HashCode *hash); | ||
109 | |||
110 | /** | ||
111 | * Handles a sent peer message to update the rooms peer message of this service. | ||
112 | * (a set peer message indicates this service being a part of the decentralized room structure) | ||
113 | * | ||
114 | * @param room Room of the message | ||
115 | * @param handle Sending handle | ||
116 | * @param tunnel Sending connection (may be NULL) | ||
117 | * @param message PEER-Message | ||
118 | * @param hash Hash of the message | ||
119 | */ | ||
120 | void | ||
121 | send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
122 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
123 | const struct GNUNET_HashCode *hash); | ||
124 | |||
125 | /** | ||
126 | * Handles a sent id message. | ||
127 | * @see handle_message_id() | ||
128 | * | ||
129 | * @param room Room of the message | ||
130 | * @param handle Sending handle | ||
131 | * @param tunnel Sending connection (may be NULL) | ||
132 | * @param message ID-Message | ||
133 | * @param hash Hash of the message | ||
134 | */ | ||
135 | void | ||
136 | send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
137 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
138 | const struct GNUNET_HashCode *hash); | ||
139 | |||
140 | /** | ||
141 | * Handles a sent miss message. | ||
142 | * @see handle_message_miss() | ||
143 | * | ||
144 | * @param room Room of the message | ||
145 | * @param handle Sending handle | ||
146 | * @param tunnel Sending connection (may be NULL) | ||
147 | * @param message MISS-Message | ||
148 | * @param hash Hash of the message | ||
149 | */ | ||
150 | void | ||
151 | send_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
152 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_MESSENGER_Message *message, | ||
153 | const struct GNUNET_HashCode *hash); | ||
154 | |||
155 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_SEND_H | ||
diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c new file mode 100644 index 000000000..5933d6390 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_store.c | |||
@@ -0,0 +1,282 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_store.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_message_store.h" | ||
27 | #include "messenger_api_message.h" | ||
28 | |||
29 | void | ||
30 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store) | ||
31 | { | ||
32 | store->storage_messages = NULL; | ||
33 | |||
34 | store->entries = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
35 | store->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
36 | } | ||
37 | |||
38 | static int | ||
39 | iterate_destroy_entries (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
40 | { | ||
41 | struct GNUNET_MESSENGER_MessageEntry *entry = value; | ||
42 | |||
43 | GNUNET_free(entry); | ||
44 | |||
45 | return GNUNET_YES; | ||
46 | } | ||
47 | |||
48 | static int | ||
49 | iterate_destroy_messages (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
50 | { | ||
51 | struct GNUNET_MESSENGER_Message *message = value; | ||
52 | |||
53 | destroy_message (message); | ||
54 | |||
55 | return GNUNET_YES; | ||
56 | } | ||
57 | |||
58 | void | ||
59 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store) | ||
60 | { | ||
61 | if (store->storage_messages) | ||
62 | { | ||
63 | GNUNET_DISK_file_close (store->storage_messages); | ||
64 | |||
65 | store->storage_messages = NULL; | ||
66 | } | ||
67 | |||
68 | GNUNET_CONTAINER_multihashmap_iterate (store->entries, iterate_destroy_entries, NULL); | ||
69 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, iterate_destroy_messages, NULL); | ||
70 | |||
71 | GNUNET_CONTAINER_multihashmap_destroy (store->entries); | ||
72 | GNUNET_CONTAINER_multihashmap_destroy (store->messages); | ||
73 | } | ||
74 | |||
75 | struct GNUNET_MESSENGER_MessageEntryStorage | ||
76 | { | ||
77 | struct GNUNET_HashCode hash; | ||
78 | struct GNUNET_MESSENGER_MessageEntry entry; | ||
79 | }; | ||
80 | |||
81 | void | ||
82 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory) | ||
83 | { | ||
84 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
85 | |||
86 | if (store->storage_messages) | ||
87 | GNUNET_DISK_file_close (store->storage_messages); | ||
88 | |||
89 | char *filename; | ||
90 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); | ||
91 | |||
92 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
93 | store->storage_messages = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, permission); | ||
94 | else | ||
95 | store->storage_messages = NULL; | ||
96 | |||
97 | GNUNET_free(filename); | ||
98 | |||
99 | if (!store->storage_messages) | ||
100 | return; | ||
101 | |||
102 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); | ||
103 | |||
104 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | ||
105 | goto free_filename; | ||
106 | |||
107 | struct GNUNET_DISK_FileHandle *entries = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, permission); | ||
108 | |||
109 | if (!entries) | ||
110 | goto free_filename; | ||
111 | |||
112 | struct GNUNET_MESSENGER_MessageEntryStorage storage; | ||
113 | struct GNUNET_MESSENGER_MessageEntry *entry; | ||
114 | |||
115 | do | ||
116 | { | ||
117 | entry = GNUNET_new(struct GNUNET_MESSENGER_MessageEntry); | ||
118 | |||
119 | if (GNUNET_DISK_file_read (entries, &storage, sizeof(storage)) == sizeof(storage)) | ||
120 | { | ||
121 | GNUNET_memcpy(entry, &(storage.entry), sizeof(*entry)); | ||
122 | |||
123 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->entries, &(storage.hash), entry, | ||
124 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
125 | GNUNET_free(entry); | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | GNUNET_free(entry); | ||
130 | |||
131 | entry = NULL; | ||
132 | } | ||
133 | } | ||
134 | while (entry); | ||
135 | |||
136 | GNUNET_DISK_file_close (entries); | ||
137 | |||
138 | free_filename: | ||
139 | GNUNET_free(filename); | ||
140 | } | ||
141 | |||
142 | struct GNUNET_MESSENGER_MessageSave | ||
143 | { | ||
144 | struct GNUNET_MESSENGER_MessageStore *store; | ||
145 | |||
146 | struct GNUNET_DISK_FileHandle *storage_entries; | ||
147 | }; | ||
148 | |||
149 | static int | ||
150 | iterate_save_messages (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
151 | { | ||
152 | struct GNUNET_MESSENGER_MessageSave *save = cls; | ||
153 | |||
154 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (save->store->entries, key)) | ||
155 | return GNUNET_YES; | ||
156 | |||
157 | struct GNUNET_MESSENGER_Message *message = value; | ||
158 | struct GNUNET_MESSENGER_MessageEntryStorage storage; | ||
159 | |||
160 | GNUNET_memcpy(&(storage.hash), key, sizeof(storage.hash)); | ||
161 | |||
162 | storage.entry.length = get_message_size (message); | ||
163 | storage.entry.offset = GNUNET_DISK_file_seek (save->store->storage_messages, 0, GNUNET_DISK_SEEK_END); | ||
164 | |||
165 | if ((GNUNET_SYSERR == storage.entry.offset) || | ||
166 | (sizeof(storage) != GNUNET_DISK_file_write (save->storage_entries, &storage, sizeof(storage)))) | ||
167 | return GNUNET_YES; | ||
168 | |||
169 | char *buffer = GNUNET_malloc(storage.entry.length); | ||
170 | |||
171 | encode_message (message, storage.entry.length, buffer); | ||
172 | |||
173 | GNUNET_DISK_file_write (save->store->storage_messages, buffer, storage.entry.length); | ||
174 | |||
175 | GNUNET_free(buffer); | ||
176 | |||
177 | return GNUNET_YES; | ||
178 | } | ||
179 | |||
180 | void | ||
181 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory) | ||
182 | { | ||
183 | struct GNUNET_MESSENGER_MessageSave save; | ||
184 | |||
185 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
186 | |||
187 | char *filename; | ||
188 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); | ||
189 | |||
190 | save.store = store; | ||
191 | save.storage_entries = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission); | ||
192 | |||
193 | GNUNET_free(filename); | ||
194 | |||
195 | if (!save.storage_entries) | ||
196 | return; | ||
197 | |||
198 | if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage_entries, 0, GNUNET_DISK_SEEK_END)) | ||
199 | goto close_entries; | ||
200 | |||
201 | if (store->storage_messages) | ||
202 | GNUNET_DISK_file_close (store->storage_messages); | ||
203 | |||
204 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); | ||
205 | |||
206 | store->storage_messages = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, | ||
207 | permission); | ||
208 | |||
209 | GNUNET_free(filename); | ||
210 | |||
211 | if (store->storage_messages) | ||
212 | { | ||
213 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, iterate_save_messages, &save); | ||
214 | |||
215 | GNUNET_DISK_file_sync (store->storage_messages); | ||
216 | GNUNET_DISK_file_sync (save.storage_entries); | ||
217 | } | ||
218 | |||
219 | close_entries: | ||
220 | GNUNET_DISK_file_close (save.storage_entries); | ||
221 | } | ||
222 | |||
223 | int | ||
224 | contains_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash) | ||
225 | { | ||
226 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->messages, hash)) | ||
227 | return GNUNET_YES; | ||
228 | |||
229 | return GNUNET_CONTAINER_multihashmap_contains (store->entries, hash); | ||
230 | } | ||
231 | |||
232 | const struct GNUNET_MESSENGER_Message* | ||
233 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash) | ||
234 | { | ||
235 | struct GNUNET_MESSENGER_Message *message = GNUNET_CONTAINER_multihashmap_get (store->messages, hash); | ||
236 | |||
237 | if (message) | ||
238 | return message; | ||
239 | |||
240 | if (!store->storage_messages) | ||
241 | return NULL; | ||
242 | |||
243 | const struct GNUNET_MESSENGER_MessageEntry *entry = GNUNET_CONTAINER_multihashmap_get (store->entries, hash); | ||
244 | |||
245 | if (!entry) | ||
246 | return NULL; | ||
247 | |||
248 | if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages, entry->offset, GNUNET_DISK_SEEK_SET)) | ||
249 | return message; | ||
250 | |||
251 | char *buffer = GNUNET_malloc(entry->length); | ||
252 | |||
253 | if (GNUNET_DISK_file_read (store->storage_messages, buffer, entry->length) != entry->length) | ||
254 | goto free_buffer; | ||
255 | |||
256 | |||
257 | message = create_message (GNUNET_MESSENGER_KIND_UNKNOWN); | ||
258 | |||
259 | if ((GNUNET_YES != decode_message (message, entry->length, buffer)) || (GNUNET_OK | ||
260 | != GNUNET_CONTAINER_multihashmap_put (store->messages, hash, message, | ||
261 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
262 | { | ||
263 | destroy_message (message); | ||
264 | |||
265 | message = NULL; | ||
266 | |||
267 | GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry); | ||
268 | } | ||
269 | |||
270 | free_buffer: | ||
271 | GNUNET_free(buffer); | ||
272 | |||
273 | return message; | ||
274 | } | ||
275 | |||
276 | int | ||
277 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, | ||
278 | struct GNUNET_MESSENGER_Message *message) | ||
279 | { | ||
280 | return GNUNET_CONTAINER_multihashmap_put (store->messages, hash, message, | ||
281 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
282 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_message_store.h b/src/messenger/gnunet-service-messenger_message_store.h new file mode 100644 index 000000000..e58459b21 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_message_store.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_message_store.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_container_lib.h" | ||
31 | #include "gnunet_disk_lib.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_MessageEntry | ||
34 | { | ||
35 | off_t offset; | ||
36 | uint16_t length; | ||
37 | }; | ||
38 | |||
39 | struct GNUNET_MESSENGER_MessageStore | ||
40 | { | ||
41 | struct GNUNET_DISK_FileHandle *storage_messages; | ||
42 | |||
43 | struct GNUNET_CONTAINER_MultiHashMap *entries; | ||
44 | struct GNUNET_CONTAINER_MultiHashMap *messages; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Initializes a message store as fully empty. | ||
49 | * | ||
50 | * @param store Message store | ||
51 | */ | ||
52 | void | ||
53 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
54 | |||
55 | /** | ||
56 | * Clears a message store, wipes its content and deallocates its memory. | ||
57 | * | ||
58 | * @param store Message store | ||
59 | */ | ||
60 | void | ||
61 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store); | ||
62 | |||
63 | /** | ||
64 | * Loads messages from a directory into a message store. | ||
65 | * | ||
66 | * @param store Message store | ||
67 | * @param directory Path to a directory | ||
68 | */ | ||
69 | void | ||
70 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); | ||
71 | |||
72 | /** | ||
73 | * Saves messages from a message store into a directory. | ||
74 | * | ||
75 | * @param store Message store | ||
76 | * @param directory Path to a directory | ||
77 | */ | ||
78 | void | ||
79 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, const char *directory); | ||
80 | |||
81 | /** | ||
82 | * Checks if a message matching a given <i>hash</i> is stored in a message store. The function returns | ||
83 | * GNUNET_YES if a match is found, GNUNET_NO otherwise. | ||
84 | * | ||
85 | * The message has not to be loaded from disk into memory for this check! | ||
86 | * | ||
87 | * @param store Message store | ||
88 | * @param hash Hash of message | ||
89 | * @return GNUNET_YES on match, otherwise GNUNET_NO | ||
90 | */ | ||
91 | int | ||
92 | contains_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); | ||
93 | |||
94 | /** | ||
95 | * Returns the message from a message store matching a given <i>hash</i>. If no matching message is found, | ||
96 | * NULL gets returned. | ||
97 | * | ||
98 | * This function requires the message to be loaded into memory! | ||
99 | * @see contains_store_message() | ||
100 | * | ||
101 | * @param store Message store | ||
102 | * @param hash Hash of message | ||
103 | * @return Message or NULL | ||
104 | */ | ||
105 | const struct GNUNET_MESSENGER_Message* | ||
106 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash); | ||
107 | |||
108 | /** | ||
109 | * Stores a message into the message store. The result indicates if the operation was successful. | ||
110 | * | ||
111 | * @param store Message store | ||
112 | * @param hash Hash of message | ||
113 | * @param message Message | ||
114 | * @return GNUNET_OK on success, otherwise GNUNET_NO | ||
115 | */ | ||
116 | int | ||
117 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash, | ||
118 | struct GNUNET_MESSENGER_Message *message); | ||
119 | |||
120 | #endif //GNUNET_SERVICE_MESSENGER_MESSAGE_STORE_H | ||
diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c new file mode 100644 index 000000000..7383e1d20 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_room.c | |||
@@ -0,0 +1,1051 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_room.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_room.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_message_kind.h" | ||
29 | |||
30 | #include "gnunet-service-messenger_service.h" | ||
31 | #include "gnunet-service-messenger_util.h" | ||
32 | |||
33 | static void | ||
34 | idle_request_room_messages (void *cls); | ||
35 | |||
36 | struct GNUNET_MESSENGER_SrvRoom* | ||
37 | create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key) | ||
38 | { | ||
39 | GNUNET_assert((handle) && (key)); | ||
40 | |||
41 | struct GNUNET_MESSENGER_SrvRoom *room = GNUNET_new(struct GNUNET_MESSENGER_SrvRoom); | ||
42 | |||
43 | room->service = handle->service; | ||
44 | room->host = handle; | ||
45 | room->port = NULL; | ||
46 | |||
47 | GNUNET_memcpy(&(room->key), key, sizeof(struct GNUNET_HashCode)); | ||
48 | |||
49 | room->tunnels = GNUNET_CONTAINER_multipeermap_create (8, GNUNET_NO); | ||
50 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); | ||
51 | room->member_infos = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); | ||
52 | |||
53 | init_message_store (&(room->store)); | ||
54 | room->requested = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
55 | |||
56 | init_list_tunnels (&(room->basement)); | ||
57 | init_list_messages (&(room->last_messages)); | ||
58 | |||
59 | room->peer_message = NULL; | ||
60 | |||
61 | init_list_messages (&(room->handling)); | ||
62 | room->idle = NULL; | ||
63 | |||
64 | room->strict_access = GNUNET_NO; | ||
65 | |||
66 | if (room->service->dir) | ||
67 | load_service_room_and_messages (room->service, room); | ||
68 | |||
69 | room->idle = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, idle_request_room_messages, room); | ||
70 | |||
71 | return room; | ||
72 | } | ||
73 | |||
74 | static int | ||
75 | iterate_destroy_tunnels (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
76 | { | ||
77 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; | ||
78 | destroy_tunnel (tunnel); | ||
79 | return GNUNET_YES; | ||
80 | } | ||
81 | |||
82 | static int | ||
83 | iterate_clear_members (void *cls, const struct GNUNET_ShortHashCode *key, void *value) | ||
84 | { | ||
85 | struct GNUNET_MESSENGER_SrvContact *contact = value; | ||
86 | |||
87 | if (GNUNET_YES == decrease_contact_rc (contact)) | ||
88 | { | ||
89 | struct GNUNET_MESSENGER_SrvRoom *room = cls; | ||
90 | |||
91 | const struct GNUNET_HashCode *id = get_contact_id_from_key (contact); | ||
92 | |||
93 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (room->service->contacts, id, contact)) | ||
94 | destroy_contact (contact); | ||
95 | } | ||
96 | |||
97 | return GNUNET_YES; | ||
98 | } | ||
99 | |||
100 | static int | ||
101 | iterate_destroy_member_infos (void *cls, const struct GNUNET_ShortHashCode *key, void *value) | ||
102 | { | ||
103 | struct GNUNET_MESSENGER_MemberInfo *info = value; | ||
104 | |||
105 | clear_list_messages (&(info->session_messages)); | ||
106 | |||
107 | GNUNET_free(info); | ||
108 | return GNUNET_YES; | ||
109 | } | ||
110 | |||
111 | void | ||
112 | destroy_room (struct GNUNET_MESSENGER_SrvRoom *room) | ||
113 | { | ||
114 | GNUNET_assert(room); | ||
115 | |||
116 | if (room->idle) | ||
117 | { | ||
118 | GNUNET_SCHEDULER_cancel (room->idle); | ||
119 | |||
120 | room->idle = NULL; | ||
121 | } | ||
122 | |||
123 | if (room->port) | ||
124 | GNUNET_CADET_close_port (room->port); | ||
125 | |||
126 | merge_room_last_messages (room, room->host); | ||
127 | |||
128 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_destroy_tunnels, | ||
129 | NULL); | ||
130 | |||
131 | handle_room_messages (room); | ||
132 | |||
133 | if (room->service->dir) | ||
134 | save_service_room_and_messages (room->service, room); | ||
135 | |||
136 | GNUNET_CONTAINER_multishortmap_iterate (room->members, iterate_clear_members, room); | ||
137 | GNUNET_CONTAINER_multishortmap_iterate (room->member_infos, iterate_destroy_member_infos, NULL); | ||
138 | |||
139 | clear_message_store (&(room->store)); | ||
140 | |||
141 | GNUNET_CONTAINER_multihashmap_destroy (room->requested); | ||
142 | |||
143 | GNUNET_CONTAINER_multipeermap_destroy (room->tunnels); | ||
144 | GNUNET_CONTAINER_multishortmap_destroy (room->members); | ||
145 | GNUNET_CONTAINER_multishortmap_destroy (room->member_infos); | ||
146 | |||
147 | clear_list_tunnels (&(room->basement)); | ||
148 | clear_list_messages (&(room->last_messages)); | ||
149 | |||
150 | if (room->peer_message) | ||
151 | GNUNET_free(room->peer_message); | ||
152 | |||
153 | GNUNET_free(room); | ||
154 | } | ||
155 | |||
156 | struct GNUNET_MESSENGER_SrvContact* | ||
157 | get_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id) | ||
158 | { | ||
159 | GNUNET_assert((room) && (room->members)); | ||
160 | |||
161 | return GNUNET_CONTAINER_multishortmap_get (room->members, id); | ||
162 | } | ||
163 | |||
164 | void | ||
165 | add_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id, | ||
166 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
167 | { | ||
168 | struct GNUNET_MESSENGER_SrvContact *contact = get_service_contact_by_pubkey (room->service, pubkey); | ||
169 | |||
170 | if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put (room->members, id, contact, | ||
171 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
172 | increase_contact_rc (contact); | ||
173 | } | ||
174 | |||
175 | struct GNUNET_MESSENGER_MemberInfo* | ||
176 | get_room_member_info (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id) | ||
177 | { | ||
178 | GNUNET_assert((room) && (room->member_infos)); | ||
179 | |||
180 | return GNUNET_CONTAINER_multishortmap_get (room->member_infos, id); | ||
181 | } | ||
182 | |||
183 | struct GNUNET_ShortHashCode* | ||
184 | generate_room_member_id (const struct GNUNET_MESSENGER_SrvRoom *room) | ||
185 | { | ||
186 | struct GNUNET_ShortHashCode *unique_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
187 | |||
188 | GNUNET_assert(room); | ||
189 | |||
190 | if (GNUNET_YES == generate_free_member_id (unique_id, room->members)) | ||
191 | return unique_id; | ||
192 | else | ||
193 | { | ||
194 | GNUNET_free(unique_id); | ||
195 | return NULL; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | const struct GNUNET_ShortHashCode* | ||
200 | get_room_host_id (const struct GNUNET_MESSENGER_SrvRoom *room) | ||
201 | { | ||
202 | GNUNET_assert(room); | ||
203 | |||
204 | return get_handle_member_id (room->host, &(room->key)); | ||
205 | } | ||
206 | |||
207 | void | ||
208 | change_room_host_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *unique_id) | ||
209 | { | ||
210 | GNUNET_assert(room); | ||
211 | |||
212 | change_handle_member_id (room->host, &(room->key), unique_id); | ||
213 | } | ||
214 | |||
215 | static int | ||
216 | send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
217 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
218 | { | ||
219 | if (!handle) | ||
220 | return GNUNET_NO; | ||
221 | |||
222 | merge_room_last_messages (room, handle); | ||
223 | |||
224 | if (!is_tunnel_connected (tunnel)) | ||
225 | return GNUNET_NO; | ||
226 | |||
227 | struct GNUNET_MESSENGER_Message *message = create_message_info (get_handle_ego(handle), room->members); | ||
228 | |||
229 | if (!message) | ||
230 | return GNUNET_NO; | ||
231 | |||
232 | if ((tunnel->peer_message) && (tunnel->contact_id)) | ||
233 | { | ||
234 | GNUNET_memcpy(&(message->body.info.unique_id), &(tunnel->contact_id), sizeof(struct GNUNET_ShortHashCode)); | ||
235 | GNUNET_free(tunnel->contact_id); | ||
236 | |||
237 | tunnel->contact_id = NULL; | ||
238 | } | ||
239 | |||
240 | struct GNUNET_HashCode hash; | ||
241 | |||
242 | send_tunnel_message (tunnel, handle, message, &hash); | ||
243 | destroy_message (message); | ||
244 | |||
245 | if (tunnel->contact_id) | ||
246 | { | ||
247 | GNUNET_free(tunnel->contact_id); | ||
248 | |||
249 | tunnel->contact_id = NULL; | ||
250 | } | ||
251 | |||
252 | return GNUNET_YES; | ||
253 | } | ||
254 | |||
255 | static void* | ||
256 | callback_room_connect (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source) | ||
257 | { | ||
258 | struct GNUNET_MESSENGER_SrvRoom *room = cls; | ||
259 | |||
260 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, source); | ||
261 | |||
262 | if (tunnel) | ||
263 | { | ||
264 | if (GNUNET_YES == bind_tunnel (tunnel, channel)) | ||
265 | { | ||
266 | if (GNUNET_YES == send_room_info (room, room->host, tunnel)) | ||
267 | return tunnel; | ||
268 | else | ||
269 | { | ||
270 | disconnect_tunnel (tunnel); | ||
271 | return NULL; | ||
272 | } | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | delayed_disconnect_channel (channel); | ||
277 | return NULL; | ||
278 | } | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | tunnel = create_tunnel (room, source); | ||
283 | |||
284 | if ((GNUNET_YES == bind_tunnel (tunnel, channel)) && (GNUNET_OK | ||
285 | == GNUNET_CONTAINER_multipeermap_put (room->tunnels, source, tunnel, | ||
286 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
287 | { | ||
288 | if (GNUNET_YES == send_room_info (room, room->host, tunnel)) | ||
289 | return tunnel; | ||
290 | else | ||
291 | { | ||
292 | GNUNET_CONTAINER_multipeermap_remove (room->tunnels, source, tunnel); | ||
293 | |||
294 | disconnect_tunnel (tunnel); | ||
295 | destroy_tunnel (tunnel); | ||
296 | return NULL; | ||
297 | } | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | tunnel->channel = NULL; | ||
302 | destroy_tunnel (tunnel); | ||
303 | |||
304 | delayed_disconnect_channel (channel); | ||
305 | return NULL; | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | |||
310 | static int | ||
311 | join_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
312 | const struct GNUNET_ShortHashCode *member_id) | ||
313 | { | ||
314 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Joining room: %s (%s)\n", GNUNET_h2s(get_room_key(room)), GNUNET_sh2s(member_id)); | ||
315 | |||
316 | struct GNUNET_MESSENGER_Message *message = create_message_join (get_handle_ego(handle)); | ||
317 | |||
318 | if (!message) | ||
319 | { | ||
320 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Your join message could not be created!\n"); | ||
321 | |||
322 | return GNUNET_NO; | ||
323 | } | ||
324 | |||
325 | struct GNUNET_HashCode hash; | ||
326 | |||
327 | send_room_message (room, handle, message, &hash); | ||
328 | destroy_message (message); | ||
329 | |||
330 | struct GNUNET_MESSENGER_MemberInfo *info = GNUNET_new(struct GNUNET_MESSENGER_MemberInfo); | ||
331 | |||
332 | info->access = GNUNET_MESSENGER_MEMBER_ALLOWED; | ||
333 | init_list_messages (&(info->session_messages)); | ||
334 | |||
335 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_put (room->member_infos, member_id, info, | ||
336 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
337 | { | ||
338 | change_handle_member_id (handle, &(room->key), member_id); | ||
339 | |||
340 | add_to_list_messages (&(info->session_messages), &hash); | ||
341 | return GNUNET_YES; | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Your member information could not be registered!\n"); | ||
346 | |||
347 | GNUNET_free(info); | ||
348 | return GNUNET_NO; | ||
349 | } | ||
350 | } | ||
351 | |||
352 | static int | ||
353 | join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) | ||
354 | { | ||
355 | const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, &(room->key)); | ||
356 | |||
357 | struct GNUNET_MESSENGER_MemberInfo *info = GNUNET_CONTAINER_multishortmap_get (room->member_infos, member_id); | ||
358 | |||
359 | if ((!info) && (GNUNET_NO == join_room (room, handle, member_id))) | ||
360 | return GNUNET_NO; | ||
361 | |||
362 | return GNUNET_YES; | ||
363 | } | ||
364 | |||
365 | extern int | ||
366 | check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); | ||
367 | extern void | ||
368 | handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header); | ||
369 | |||
370 | extern void | ||
371 | callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel); | ||
372 | |||
373 | int | ||
374 | open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) | ||
375 | { | ||
376 | if (room->port) | ||
377 | return join_room_locally (room, handle); | ||
378 | |||
379 | struct GNUNET_CADET_Handle *cadet = get_room_cadet (room); | ||
380 | struct GNUNET_HashCode *key = get_room_key (room); | ||
381 | |||
382 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size(tunnel_message, GNUNET_MESSAGE_TYPE_CADET_CLI, | ||
383 | struct GNUNET_MessageHeader, NULL), | ||
384 | GNUNET_MQ_handler_end() }; | ||
385 | |||
386 | room->port = GNUNET_CADET_open_port (cadet, key, callback_room_connect, room, NULL, | ||
387 | callback_tunnel_disconnect, handlers); | ||
388 | |||
389 | const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (handle, &(room->key)); | ||
390 | |||
391 | struct GNUNET_MESSENGER_MemberInfo *info = GNUNET_CONTAINER_multishortmap_get (room->member_infos, member_id); | ||
392 | |||
393 | if ((!info) && (GNUNET_NO == join_room (room, handle, member_id)) && (room->port)) | ||
394 | { | ||
395 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not join the room, therefore it keeps closed!\n"); | ||
396 | |||
397 | GNUNET_CADET_close_port (room->port); | ||
398 | room->port = NULL; | ||
399 | |||
400 | return GNUNET_NO; | ||
401 | } | ||
402 | |||
403 | struct GNUNET_MESSENGER_Message *message = create_message_peer (room->service); | ||
404 | |||
405 | if (message) | ||
406 | { | ||
407 | struct GNUNET_HashCode hash; | ||
408 | |||
409 | send_room_message (room, handle, message, &hash); | ||
410 | destroy_message (message); | ||
411 | } | ||
412 | |||
413 | return (room->port ? GNUNET_YES : GNUNET_NO); | ||
414 | } | ||
415 | |||
416 | int | ||
417 | entry_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
418 | const struct GNUNET_PeerIdentity *door) | ||
419 | { | ||
420 | if (room->peer_message) | ||
421 | { | ||
422 | const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, handle, room->peer_message, GNUNET_NO); | ||
423 | |||
424 | if (0 == GNUNET_memcmp(&(msg->body.peer.peer), door)) | ||
425 | return join_room_locally (room, handle); | ||
426 | } | ||
427 | |||
428 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, door); | ||
429 | |||
430 | if (tunnel) | ||
431 | { | ||
432 | switch (connect_tunnel (tunnel)) | ||
433 | { | ||
434 | case GNUNET_YES: | ||
435 | return GNUNET_YES; | ||
436 | case GNUNET_NO: | ||
437 | return join_room_locally (room, handle); | ||
438 | default: | ||
439 | return GNUNET_NO; | ||
440 | } | ||
441 | } | ||
442 | |||
443 | tunnel = create_tunnel (room, door); | ||
444 | |||
445 | if ((GNUNET_YES == connect_tunnel (tunnel)) && | ||
446 | (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (room->tunnels, door, tunnel, | ||
447 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
448 | return GNUNET_YES; | ||
449 | else | ||
450 | { | ||
451 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not connect to that door!\n"); | ||
452 | |||
453 | destroy_tunnel (tunnel); | ||
454 | return GNUNET_NO; | ||
455 | } | ||
456 | } | ||
457 | |||
458 | struct GNUNET_MESSENGER_SrvTunnelFinder | ||
459 | { | ||
460 | const struct GNUNET_ShortHashCode *needle; | ||
461 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; | ||
462 | }; | ||
463 | |||
464 | static int | ||
465 | iterate_find_tunnel (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) | ||
466 | { | ||
467 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; | ||
468 | struct GNUNET_MESSENGER_SrvTunnelFinder *finder = cls; | ||
469 | |||
470 | if ((tunnel->contact_id) && (0 == GNUNET_memcmp(tunnel->contact_id, finder->needle))) | ||
471 | { | ||
472 | finder->tunnel = tunnel; | ||
473 | return GNUNET_NO; | ||
474 | } | ||
475 | |||
476 | return GNUNET_YES; | ||
477 | } | ||
478 | |||
479 | struct GNUNET_MESSENGER_SrvTunnel* | ||
480 | find_room_tunnel_to (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *contact_id) | ||
481 | { | ||
482 | struct GNUNET_MESSENGER_SrvTunnelFinder finder; | ||
483 | |||
484 | finder.needle = contact_id; | ||
485 | finder.tunnel = NULL; | ||
486 | |||
487 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_find_tunnel, &finder); | ||
488 | |||
489 | return finder.tunnel; | ||
490 | } | ||
491 | |||
492 | struct GNUNET_MQ_Envelope* | ||
493 | pack_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
494 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode) | ||
495 | { | ||
496 | message->header.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | ||
497 | |||
498 | const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, &(room->key)); | ||
499 | |||
500 | GNUNET_assert(id); | ||
501 | |||
502 | GNUNET_memcpy(&(message->header.sender_id), id, sizeof(struct GNUNET_ShortHashCode)); | ||
503 | |||
504 | if (room->last_messages.head) | ||
505 | GNUNET_memcpy(&(message->header.previous), &(room->last_messages.head->hash), sizeof(struct GNUNET_HashCode)); | ||
506 | else | ||
507 | memset (&(message->header.previous), 0, sizeof(struct GNUNET_HashCode)); | ||
508 | |||
509 | return pack_message (message, hash, get_handle_ego (handle), mode); | ||
510 | } | ||
511 | |||
512 | struct GNUNET_MESSENGER_ClosureSendRoom | ||
513 | { | ||
514 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
515 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
516 | struct GNUNET_MESSENGER_SrvTunnel *exclude; | ||
517 | struct GNUNET_MESSENGER_Message *message; | ||
518 | struct GNUNET_HashCode *hash; | ||
519 | int packed; | ||
520 | }; | ||
521 | |||
522 | static int | ||
523 | iterate_send_room_message (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
524 | { | ||
525 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; | ||
526 | |||
527 | if ((!is_tunnel_connected (tunnel)) || (!tunnel->contact_id)) | ||
528 | return GNUNET_YES; | ||
529 | |||
530 | struct GNUNET_MESSENGER_ClosureSendRoom *closure = cls; | ||
531 | |||
532 | if (tunnel == closure->exclude) | ||
533 | return GNUNET_YES; | ||
534 | |||
535 | struct GNUNET_MQ_Envelope *env = NULL; | ||
536 | |||
537 | if (closure->packed == GNUNET_NO) | ||
538 | { | ||
539 | env = pack_room_message (closure->room, closure->handle, closure->message, closure->hash, | ||
540 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | ||
541 | |||
542 | if (env) | ||
543 | { | ||
544 | closure->message = copy_message (closure->message); | ||
545 | closure->packed = GNUNET_YES; | ||
546 | } | ||
547 | } | ||
548 | else | ||
549 | { | ||
550 | env = pack_message (closure->message, NULL, NULL, | ||
551 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | ||
552 | } | ||
553 | |||
554 | if (env) | ||
555 | send_tunnel_envelope (tunnel, closure->handle, env, closure->message, closure->hash); | ||
556 | |||
557 | return GNUNET_YES; | ||
558 | } | ||
559 | |||
560 | void | ||
561 | callback_room_sent (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, | ||
562 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
563 | |||
564 | void | ||
565 | send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
566 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash) | ||
567 | { | ||
568 | struct GNUNET_MESSENGER_ClosureSendRoom closure; | ||
569 | |||
570 | closure.room = room; | ||
571 | closure.handle = handle; | ||
572 | closure.exclude = NULL; | ||
573 | closure.message = message; | ||
574 | closure.hash = hash; | ||
575 | closure.packed = GNUNET_NO; | ||
576 | |||
577 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_send_room_message, &closure); | ||
578 | |||
579 | if ((GNUNET_NO == closure.packed) && (closure.message == message)) | ||
580 | { | ||
581 | pack_room_message (room, handle, message, hash, | ||
582 | GNUNET_MESSENGER_PACK_MODE_UNKNOWN); | ||
583 | |||
584 | callback_room_sent (room, handle, NULL, copy_message (message), hash); | ||
585 | } | ||
586 | } | ||
587 | |||
588 | void | ||
589 | send_room_message_ext (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
590 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, | ||
591 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
592 | { | ||
593 | struct GNUNET_MESSENGER_ClosureSendRoom closure; | ||
594 | |||
595 | closure.room = room; | ||
596 | closure.handle = handle; | ||
597 | closure.exclude = tunnel; | ||
598 | closure.message = message; | ||
599 | closure.hash = hash; | ||
600 | closure.packed = GNUNET_NO; | ||
601 | |||
602 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_send_room_message, &closure); | ||
603 | |||
604 | if ((GNUNET_NO == closure.packed) && (closure.message == message)) | ||
605 | { | ||
606 | pack_room_message (room, handle, message, hash, | ||
607 | GNUNET_MESSENGER_PACK_MODE_UNKNOWN); | ||
608 | |||
609 | callback_room_sent (room, handle, NULL, copy_message (message), hash); | ||
610 | } | ||
611 | } | ||
612 | |||
613 | void | ||
614 | forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
615 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
616 | { | ||
617 | struct GNUNET_MESSENGER_ClosureSendRoom closure; | ||
618 | struct GNUNET_HashCode message_hash; | ||
619 | |||
620 | GNUNET_memcpy(&message_hash, hash, sizeof(struct GNUNET_HashCode)); | ||
621 | |||
622 | closure.room = room; | ||
623 | closure.handle = NULL; | ||
624 | closure.exclude = tunnel; | ||
625 | closure.message = copy_message (message); | ||
626 | closure.hash = &message_hash; | ||
627 | closure.packed = GNUNET_YES; | ||
628 | |||
629 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_send_room_message, &closure); | ||
630 | } | ||
631 | |||
632 | void | ||
633 | merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle) | ||
634 | { | ||
635 | if (!handle) | ||
636 | return; | ||
637 | |||
638 | if (!room->last_messages.head) | ||
639 | return; | ||
640 | |||
641 | while (room->last_messages.head != room->last_messages.tail) | ||
642 | { | ||
643 | struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.tail; | ||
644 | |||
645 | struct GNUNET_MESSENGER_Message *message = create_message_merge (&(element->hash)); | ||
646 | |||
647 | if (message) | ||
648 | { | ||
649 | struct GNUNET_HashCode hash; | ||
650 | |||
651 | send_room_message (room, handle, message, &hash); | ||
652 | destroy_message (message); | ||
653 | } | ||
654 | |||
655 | if (element->prev) | ||
656 | GNUNET_CONTAINER_DLL_remove(room->last_messages.head, room->last_messages.tail, element); | ||
657 | } | ||
658 | } | ||
659 | |||
660 | struct GNUNET_CADET_Handle* | ||
661 | get_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room) | ||
662 | { | ||
663 | return room->service->cadet; | ||
664 | } | ||
665 | |||
666 | struct GNUNET_HashCode* | ||
667 | get_room_key (struct GNUNET_MESSENGER_SrvRoom *room) | ||
668 | { | ||
669 | return &(room->key); | ||
670 | } | ||
671 | |||
672 | const struct GNUNET_MESSENGER_SrvTunnel* | ||
673 | get_room_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer) | ||
674 | { | ||
675 | return GNUNET_CONTAINER_multipeermap_get (room->tunnels, peer); | ||
676 | } | ||
677 | |||
678 | const struct GNUNET_MESSENGER_Message* | ||
679 | get_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
680 | const struct GNUNET_HashCode *hash, int request) | ||
681 | { | ||
682 | const struct GNUNET_MESSENGER_Message *message = get_store_message (&(room->store), hash); | ||
683 | |||
684 | if ((message) || (!handle) || (GNUNET_YES != request) | ||
685 | || (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->requested, hash))) | ||
686 | return message; | ||
687 | |||
688 | struct GNUNET_MESSENGER_Message *request_msg = create_message_request (hash); | ||
689 | |||
690 | if (request_msg) | ||
691 | { | ||
692 | if (GNUNET_CONTAINER_multihashmap_put (room->requested, hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) == GNUNET_OK) | ||
693 | { | ||
694 | struct GNUNET_HashCode request_hash; | ||
695 | |||
696 | send_room_message (room, handle, request_msg, &request_hash); | ||
697 | } | ||
698 | |||
699 | destroy_message (request_msg); | ||
700 | } | ||
701 | |||
702 | return message; | ||
703 | } | ||
704 | |||
705 | void | ||
706 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls) | ||
707 | { | ||
708 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | ||
709 | |||
710 | if (!room->host) | ||
711 | return; | ||
712 | |||
713 | struct GNUNET_PeerIdentity identity; | ||
714 | |||
715 | GNUNET_PEER_resolve (tunnel->peer, &identity); | ||
716 | |||
717 | if (GNUNET_YES == contains_list_tunnels (&(room->basement), &identity)) | ||
718 | { | ||
719 | struct GNUNET_MESSENGER_Message *message = create_message_miss (&identity); | ||
720 | |||
721 | if (message) | ||
722 | { | ||
723 | struct GNUNET_HashCode hash; | ||
724 | |||
725 | send_room_message (room, room->host, message, &hash); | ||
726 | destroy_message (message); | ||
727 | } | ||
728 | } | ||
729 | } | ||
730 | |||
731 | int | ||
732 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, | ||
733 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash) | ||
734 | { | ||
735 | if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind) | ||
736 | return GNUNET_SYSERR; | ||
737 | |||
738 | struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_CONTAINER_multishortmap_get (room->members, | ||
739 | &(message->header.sender_id)); | ||
740 | |||
741 | if (!contact) | ||
742 | { | ||
743 | if (GNUNET_MESSENGER_KIND_INFO == message->header.kind) | ||
744 | contact = get_service_contact_by_pubkey (room->service, &(message->body.info.host_key)); | ||
745 | else if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind) | ||
746 | contact = get_service_contact_by_pubkey (room->service, &(message->body.join.key)); | ||
747 | } | ||
748 | |||
749 | if ((!contact) || (GNUNET_SYSERR == verify_message (message, hash, get_contact_key (contact)))) | ||
750 | return GNUNET_SYSERR; | ||
751 | |||
752 | if (GNUNET_YES == room->strict_access) | ||
753 | { | ||
754 | struct GNUNET_MESSENGER_MemberInfo *info = GNUNET_CONTAINER_multishortmap_get (room->member_infos, | ||
755 | &(message->header.sender_id)); | ||
756 | |||
757 | if ((info) && (GNUNET_MESSENGER_MEMBER_BLOCKED == info->access)) | ||
758 | return GNUNET_SYSERR; | ||
759 | } | ||
760 | |||
761 | if (GNUNET_YES == contains_store_message (&(room->store), hash)) | ||
762 | return GNUNET_NO; | ||
763 | |||
764 | return GNUNET_YES; | ||
765 | } | ||
766 | |||
767 | static void | ||
768 | search_room_for_message (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash) | ||
769 | { | ||
770 | const struct GNUNET_MESSENGER_Message *message = get_room_message (room, room->host, hash, GNUNET_YES); | ||
771 | |||
772 | if (!message) | ||
773 | return; | ||
774 | |||
775 | if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind) | ||
776 | search_room_for_message (room, &(message->body.merge.previous)); | ||
777 | |||
778 | search_room_for_message (room, &(message->header.previous)); | ||
779 | } | ||
780 | |||
781 | static void | ||
782 | idle_request_room_messages (void *cls) | ||
783 | { | ||
784 | struct GNUNET_MESSENGER_SrvRoom *room = cls; | ||
785 | |||
786 | room->idle = NULL; | ||
787 | |||
788 | struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.head; | ||
789 | |||
790 | while (element) | ||
791 | { | ||
792 | search_room_for_message (room, &(element->hash)); | ||
793 | |||
794 | element = element->next; | ||
795 | } | ||
796 | |||
797 | merge_room_last_messages (room, room->host); | ||
798 | |||
799 | room->idle = GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_second_ (), | ||
800 | GNUNET_SCHEDULER_PRIORITY_IDLE, idle_request_room_messages, | ||
801 | cls); | ||
802 | } | ||
803 | |||
804 | void | ||
805 | update_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, | ||
806 | const struct GNUNET_HashCode *hash) | ||
807 | { | ||
808 | struct GNUNET_MESSENGER_ListMessage *element = room->last_messages.head; | ||
809 | struct GNUNET_MESSENGER_ListMessage *merging = NULL; | ||
810 | |||
811 | if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind) | ||
812 | { | ||
813 | merging = room->last_messages.head; | ||
814 | |||
815 | while (merging) | ||
816 | { | ||
817 | if (0 == GNUNET_CRYPTO_hash_cmp (&(merging->hash), &(message->body.merge.previous))) | ||
818 | break; | ||
819 | |||
820 | merging = merging->next; | ||
821 | } | ||
822 | |||
823 | if (merging) | ||
824 | element = merging->next; | ||
825 | } | ||
826 | |||
827 | while (element) | ||
828 | { | ||
829 | if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), &(message->header.previous))) | ||
830 | break; | ||
831 | |||
832 | element = element->next; | ||
833 | } | ||
834 | |||
835 | if ((merging) && (!element)) | ||
836 | { | ||
837 | element = merging; | ||
838 | merging = NULL; | ||
839 | } | ||
840 | |||
841 | if (element) | ||
842 | { | ||
843 | GNUNET_memcpy(&(element->hash), hash, sizeof(struct GNUNET_HashCode)); | ||
844 | |||
845 | if (merging) | ||
846 | GNUNET_CONTAINER_DLL_remove(room->last_messages.head, room->last_messages.tail, merging); | ||
847 | } | ||
848 | else | ||
849 | add_to_list_messages (&(room->last_messages), hash); | ||
850 | |||
851 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (room->requested, hash)) | ||
852 | GNUNET_CONTAINER_multihashmap_remove_all (room->requested, hash); | ||
853 | } | ||
854 | |||
855 | void | ||
856 | switch_room_member_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *old_id, | ||
857 | const struct GNUNET_ShortHashCode *new_id, const struct GNUNET_HashCode *hash) | ||
858 | { | ||
859 | struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_CONTAINER_multishortmap_get (room->members, old_id); | ||
860 | |||
861 | if ((contact) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (room->members, old_id, contact))) | ||
862 | GNUNET_CONTAINER_multishortmap_put (room->members, new_id, contact, | ||
863 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
864 | |||
865 | struct GNUNET_MESSENGER_MemberInfo *info = GNUNET_CONTAINER_multishortmap_get (room->member_infos, old_id); | ||
866 | |||
867 | if ((!info) || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->member_infos, old_id, contact)) | ||
868 | || (GNUNET_YES != GNUNET_CONTAINER_multishortmap_put (room->member_infos, new_id, contact, | ||
869 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
870 | return; | ||
871 | |||
872 | if (hash) | ||
873 | add_to_list_messages (&(info->session_messages), hash); | ||
874 | } | ||
875 | |||
876 | void | ||
877 | rebuild_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room) | ||
878 | { | ||
879 | struct GNUNET_PeerIdentity peer; | ||
880 | size_t src; | ||
881 | |||
882 | if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) || (!find_list_tunnels (&(room->basement), &peer, | ||
883 | &src))) | ||
884 | return; | ||
885 | |||
886 | size_t count = count_of_tunnels (&(room->basement)); | ||
887 | |||
888 | struct GNUNET_MESSENGER_ListTunnel *element = room->basement.head; | ||
889 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; | ||
890 | |||
891 | size_t dst = 0; | ||
892 | |||
893 | while (element) | ||
894 | { | ||
895 | GNUNET_PEER_resolve (element->peer, &peer); | ||
896 | |||
897 | tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, &peer); | ||
898 | |||
899 | if (!tunnel) | ||
900 | { | ||
901 | element = remove_from_list_tunnels (&(room->basement), element); | ||
902 | continue; | ||
903 | } | ||
904 | |||
905 | if (GNUNET_YES == required_connection_between (count, src, dst)) | ||
906 | { | ||
907 | if (GNUNET_SYSERR == connect_tunnel (tunnel)) | ||
908 | { | ||
909 | element = remove_from_list_tunnels (&(room->basement), element); | ||
910 | continue; | ||
911 | } | ||
912 | } | ||
913 | else | ||
914 | disconnect_tunnel (tunnel); | ||
915 | |||
916 | element = element->next; | ||
917 | dst++; | ||
918 | } | ||
919 | } | ||
920 | |||
921 | void | ||
922 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room) | ||
923 | { | ||
924 | while (room->handling.head) | ||
925 | { | ||
926 | struct GNUNET_MESSENGER_ListMessage *element = room->handling.head; | ||
927 | |||
928 | const struct GNUNET_MESSENGER_Message *msg = get_room_message (room, room->host, &(element->hash), GNUNET_NO); | ||
929 | |||
930 | if (msg) | ||
931 | handle_service_message (room->service, room, msg, &(element->hash)); | ||
932 | |||
933 | GNUNET_CONTAINER_DLL_remove(room->handling.head, room->handling.tail, element); | ||
934 | GNUNET_free(element); | ||
935 | } | ||
936 | } | ||
937 | |||
938 | #include "gnunet-service-messenger_message_recv.h" | ||
939 | |||
940 | void | ||
941 | callback_room_recv (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, | ||
942 | const struct GNUNET_HashCode *hash) | ||
943 | { | ||
944 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | ||
945 | |||
946 | if (GNUNET_OK != put_store_message (&(room->store), hash, message)) | ||
947 | return; | ||
948 | |||
949 | update_room_last_messages (room, message, hash); | ||
950 | |||
951 | if (GNUNET_MESSENGER_KIND_INFO != message->header.kind) | ||
952 | forward_room_message (room, tunnel, message, hash); | ||
953 | |||
954 | const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES; | ||
955 | |||
956 | add_to_list_messages (&(room->handling), hash); | ||
957 | |||
958 | switch (message->header.kind) | ||
959 | { | ||
960 | case GNUNET_MESSENGER_KIND_INFO: | ||
961 | recv_message_info (room, tunnel, message, hash); | ||
962 | break; | ||
963 | case GNUNET_MESSENGER_KIND_JOIN: | ||
964 | recv_message_join (room, tunnel, message, hash); | ||
965 | break; | ||
966 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
967 | recv_message_leave (room, tunnel, message, hash); | ||
968 | break; | ||
969 | case GNUNET_MESSENGER_KIND_NAME: | ||
970 | recv_message_name (room, tunnel, message, hash); | ||
971 | break; | ||
972 | case GNUNET_MESSENGER_KIND_KEY: | ||
973 | recv_message_key (room, tunnel, message, hash); | ||
974 | break; | ||
975 | case GNUNET_MESSENGER_KIND_PEER: | ||
976 | recv_message_peer (room, tunnel, message, hash); | ||
977 | break; | ||
978 | case GNUNET_MESSENGER_KIND_ID: | ||
979 | recv_message_id (room, tunnel, message, hash); | ||
980 | break; | ||
981 | case GNUNET_MESSENGER_KIND_MISS: | ||
982 | recv_message_miss (room, tunnel, message, hash); | ||
983 | break; | ||
984 | case GNUNET_MESSENGER_KIND_REQUEST: | ||
985 | recv_message_request (room, tunnel, message, hash); | ||
986 | break; | ||
987 | default: | ||
988 | break; | ||
989 | } | ||
990 | |||
991 | if (GNUNET_YES == start_handle) | ||
992 | handle_room_messages (room); | ||
993 | } | ||
994 | |||
995 | #include "gnunet-service-messenger_message_send.h" | ||
996 | |||
997 | void | ||
998 | callback_room_sent (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, | ||
999 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
1000 | { | ||
1001 | const struct GNUNET_MESSENGER_Message *old_message = get_room_message (room, handle, hash, GNUNET_NO); | ||
1002 | |||
1003 | if ((old_message) || (GNUNET_OK != put_store_message (&(room->store), hash, message))) | ||
1004 | { | ||
1005 | if (old_message != message) | ||
1006 | GNUNET_free(message); | ||
1007 | } | ||
1008 | else | ||
1009 | { | ||
1010 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; // may be NULL | ||
1011 | |||
1012 | update_room_last_messages (room, message, hash); | ||
1013 | |||
1014 | const int start_handle = room->handling.head ? GNUNET_NO : GNUNET_YES; | ||
1015 | |||
1016 | add_to_list_messages (&(room->handling), hash); | ||
1017 | |||
1018 | switch (message->header.kind) | ||
1019 | { | ||
1020 | case GNUNET_MESSENGER_KIND_INFO: | ||
1021 | send_message_info (room, handle, tunnel, message, hash); | ||
1022 | break; | ||
1023 | case GNUNET_MESSENGER_KIND_JOIN: | ||
1024 | send_message_join (room, handle, tunnel, message, hash); | ||
1025 | break; | ||
1026 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
1027 | send_message_leave (room, handle, tunnel, message, hash); | ||
1028 | break; | ||
1029 | case GNUNET_MESSENGER_KIND_NAME: | ||
1030 | send_message_name (room, handle, tunnel, message, hash); | ||
1031 | break; | ||
1032 | case GNUNET_MESSENGER_KIND_KEY: | ||
1033 | send_message_key (room, handle, tunnel, message, hash); | ||
1034 | break; | ||
1035 | case GNUNET_MESSENGER_KIND_PEER: | ||
1036 | send_message_peer (room, handle, tunnel, message, hash); | ||
1037 | break; | ||
1038 | case GNUNET_MESSENGER_KIND_ID: | ||
1039 | send_message_id (room, handle, tunnel, message, hash); | ||
1040 | break; | ||
1041 | case GNUNET_MESSENGER_KIND_MISS: | ||
1042 | send_message_miss (room, handle, tunnel, message, hash); | ||
1043 | break; | ||
1044 | default: | ||
1045 | break; | ||
1046 | } | ||
1047 | |||
1048 | if (GNUNET_YES == start_handle) | ||
1049 | handle_room_messages (room); | ||
1050 | } | ||
1051 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h new file mode 100644 index 000000000..36c9e8cf5 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_room.h | |||
@@ -0,0 +1,378 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_room.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_ROOM_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_ROOM_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_mq_lib.h" | ||
35 | |||
36 | #include "gnunet-service-messenger_contact.h" | ||
37 | |||
38 | #include "gnunet_messenger_service.h" | ||
39 | #include "gnunet-service-messenger_basement.h" | ||
40 | #include "gnunet-service-messenger_handle.h" | ||
41 | #include "gnunet-service-messenger_tunnel.h" | ||
42 | |||
43 | #include "gnunet-service-messenger_list_messages.h" | ||
44 | #include "messenger_api_list_tunnels.h" | ||
45 | |||
46 | #include "gnunet-service-messenger_message_store.h" | ||
47 | #include "messenger_api_ego.h" | ||
48 | |||
49 | enum GNUNET_MESSENGER_MemberAccess | ||
50 | { | ||
51 | GNUNET_MESSENGER_MEMBER_ALLOWED = 1, | ||
52 | GNUNET_MESSENGER_MEMBER_BLOCKED = 1, | ||
53 | |||
54 | GNUNET_MESSENGER_MEMBER_UNKNOWN = 0 | ||
55 | }; | ||
56 | |||
57 | struct GNUNET_MESSENGER_MemberInfo | ||
58 | { | ||
59 | enum GNUNET_MESSENGER_MemberAccess access; | ||
60 | |||
61 | struct GNUNET_MESSENGER_ListMessages session_messages; | ||
62 | }; | ||
63 | |||
64 | struct GNUNET_MESSENGER_SrvRoom | ||
65 | { | ||
66 | struct GNUNET_MESSENGER_Service *service; | ||
67 | struct GNUNET_MESSENGER_SrvHandle *host; | ||
68 | struct GNUNET_CADET_Port *port; | ||
69 | |||
70 | struct GNUNET_HashCode key; | ||
71 | |||
72 | struct GNUNET_CONTAINER_MultiPeerMap *tunnels; | ||
73 | struct GNUNET_CONTAINER_MultiShortmap *members; | ||
74 | struct GNUNET_CONTAINER_MultiShortmap *member_infos; | ||
75 | |||
76 | struct GNUNET_MESSENGER_MessageStore store; | ||
77 | struct GNUNET_CONTAINER_MultiHashMap *requested; | ||
78 | |||
79 | struct GNUNET_MESSENGER_ListTunnels basement; | ||
80 | struct GNUNET_MESSENGER_ListMessages last_messages; | ||
81 | |||
82 | struct GNUNET_HashCode *peer_message; | ||
83 | |||
84 | struct GNUNET_MESSENGER_ListMessages handling; | ||
85 | struct GNUNET_SCHEDULER_Task *idle; | ||
86 | |||
87 | int strict_access; | ||
88 | }; | ||
89 | |||
90 | /** | ||
91 | * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i>. | ||
92 | * | ||
93 | * @param handle Handle | ||
94 | * @param key Key of room | ||
95 | * @return New room | ||
96 | */ | ||
97 | struct GNUNET_MESSENGER_SrvRoom* | ||
98 | create_room (struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key); | ||
99 | |||
100 | /** | ||
101 | * Destroys a room and frees its memory fully. | ||
102 | * | ||
103 | * @param room Room | ||
104 | */ | ||
105 | void | ||
106 | destroy_room (struct GNUNET_MESSENGER_SrvRoom *room); | ||
107 | |||
108 | /** | ||
109 | * Returns the contact of a member in a <i>room</i> identified by a given <i>id</i>. If the <i>room</i> | ||
110 | * does not contain a member with the given <i>id</i>, NULL gets returned. | ||
111 | * | ||
112 | * @param room Room | ||
113 | * @param id Member id | ||
114 | * @return Contact or NULL | ||
115 | */ | ||
116 | struct GNUNET_MESSENGER_SrvContact* | ||
117 | get_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id); | ||
118 | |||
119 | /** | ||
120 | * Adds a contact from the service to a <i>room</i> under a specific <i>id</i> with a given public key. | ||
121 | * | ||
122 | * @param room Room | ||
123 | * @param id Member id | ||
124 | * @param pubkey Public key of EGO | ||
125 | */ | ||
126 | void | ||
127 | add_room_contact (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id, | ||
128 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
129 | |||
130 | /** | ||
131 | * Returns the member information of a member in a <i>room</i> identified by a given <i>id</i>. If the <i>room</i> | ||
132 | * does not contain a member with the given <i>id</i>, NULL gets returned. | ||
133 | * | ||
134 | * @param room Room | ||
135 | * @param id Member id | ||
136 | * @return Member information or NULL | ||
137 | */ | ||
138 | struct GNUNET_MESSENGER_MemberInfo* | ||
139 | get_room_member_info (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *id); | ||
140 | |||
141 | /** | ||
142 | * Tries to generate and allocate a new unique member id checking all current members for possible | ||
143 | * duplicates. If the function fails, NULL gets returned. | ||
144 | * | ||
145 | * @param room Room | ||
146 | * @return New member id or NULL | ||
147 | */ | ||
148 | struct GNUNET_ShortHashCode* | ||
149 | generate_room_member_id (const struct GNUNET_MESSENGER_SrvRoom *room); | ||
150 | |||
151 | /** | ||
152 | * Returns the member id of the member representing the handle currently hosting this <i>room</i>. | ||
153 | * | ||
154 | * @param room Room | ||
155 | * @return Host member id or NULL | ||
156 | */ | ||
157 | const struct GNUNET_ShortHashCode* | ||
158 | get_room_host_id (const struct GNUNET_MESSENGER_SrvRoom *room); | ||
159 | |||
160 | /** | ||
161 | * Changes the member id of the member representing the handle currently hosting this <i>room</i>. | ||
162 | * | ||
163 | * @param room Room | ||
164 | * @param unique_id Unique member id | ||
165 | */ | ||
166 | void | ||
167 | change_room_host_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *unique_id); | ||
168 | |||
169 | /** | ||
170 | * Tries to open a <i>room</i> for a given <i>handle</i>. If the room has already been opened, the handle | ||
171 | * will locally join the room. | ||
172 | * | ||
173 | * Calling this method should result in joining a room and sending a peer message as well for this peer. | ||
174 | * | ||
175 | * If the function returns GNUNET_YES the port for this room is guranteed to be open for incoming connections. | ||
176 | * | ||
177 | * @param room Room | ||
178 | * @param handle Handle | ||
179 | * @return GNUNET_YES on success, GNUNET_NO on failure. | ||
180 | */ | ||
181 | int | ||
182 | open_room (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle); | ||
183 | |||
184 | /** | ||
185 | * Connects a tunnel to a hosting peer of a <i>room</i> through a so called <i>door</i> which is represented by | ||
186 | * a peer identity of a hosting peer. During the connection the handle will join the room as a member, waiting for | ||
187 | * an info message from the selected host. | ||
188 | * | ||
189 | * @param room Room | ||
190 | * @param handle Handle | ||
191 | * @param door Peer identity | ||
192 | * @return GNUNET_YES on success, GNUNET_NO on failure. | ||
193 | */ | ||
194 | int | ||
195 | entry_room_at (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
196 | const struct GNUNET_PeerIdentity *door); | ||
197 | |||
198 | /** | ||
199 | * Returns a tunnel granting a direct connection to a specific member in a <i>room</i>. The member gets identified | ||
200 | * by an <i>id</i>. If no tunnel has been linked to the selected id, NULL gets returned. | ||
201 | * | ||
202 | * @param room Room | ||
203 | * @param contact_id Member id | ||
204 | * @return Tunnel to the member or NULL | ||
205 | */ | ||
206 | struct GNUNET_MESSENGER_SrvTunnel* | ||
207 | find_room_tunnel_to (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *contact_id); | ||
208 | |||
209 | /** | ||
210 | * Packs a <i>message</i> depending on the selected <i>mode</i> into a newly allocated envelope. It will set the | ||
211 | * timestamp of the message, the sender id and the previous messages hash automatically before packing. The message | ||
212 | * will be signed by the handles EGO. | ||
213 | * | ||
214 | * If the optional <i>hash</i> parameter is a valid pointer, its value will be overriden by the signed messages hash. | ||
215 | * | ||
216 | * If <i>mode</i> is set to GNUNET_MESSENGER_PACK_MODE_ENVELOPE, the function returns a valid envelope to send | ||
217 | * through a message queue, otherwise NULL. | ||
218 | * | ||
219 | * @param room Room | ||
220 | * @param handle Handle | ||
221 | * @param message Message | ||
222 | * @param[out] hash Hash of message | ||
223 | * @param mode Packing mode | ||
224 | * @return New envelope or NULL | ||
225 | */ | ||
226 | struct GNUNET_MQ_Envelope* | ||
227 | pack_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
228 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, int mode); | ||
229 | |||
230 | /** | ||
231 | * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i>. The <i>hash</i> parameter will be | ||
232 | * updated with the hash-value resulting from the sent message. | ||
233 | * | ||
234 | * The function handles packing the message automatically and will call linked message-events locally even if | ||
235 | * the message won't be sent to another peer. | ||
236 | * | ||
237 | * @param room Room | ||
238 | * @param handle Handle | ||
239 | * @param message Message | ||
240 | * @param[out] hash Hash of message | ||
241 | */ | ||
242 | void | ||
243 | send_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
244 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash); | ||
245 | |||
246 | /** | ||
247 | * Sends a <i>message</i> from a given <i>handle</i> into a <i>room</i> excluding one specific <i>tunnel</i>. | ||
248 | * The <i>hash</i> parameter will be updated with the hash-value resulting from the sent message. | ||
249 | * | ||
250 | * The function handles packing the message automatically and will call linked message-events locally even if | ||
251 | * the message won't be sent to another peer. | ||
252 | * | ||
253 | * @param room Room | ||
254 | * @param handle Handle | ||
255 | * @param message Message | ||
256 | * @param[out] hash Hash of message | ||
257 | * @param tunnel Tunnel | ||
258 | */ | ||
259 | void | ||
260 | send_room_message_ext (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
261 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, | ||
262 | struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
263 | |||
264 | /** | ||
265 | * Forwards a <i>message</i> with a given <i>hash</i> to a specific <i>tunnel</i> inside of a <i>room</i>. | ||
266 | * | ||
267 | * @param room Room | ||
268 | * @param tunnel Tunnel | ||
269 | * @param message Message | ||
270 | * @param hash Hash of message | ||
271 | */ | ||
272 | void | ||
273 | forward_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvTunnel *tunnel, | ||
274 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
275 | |||
276 | /** | ||
277 | * Reduces all current forks inside of the message history of a <i>room</i> to one remaining last message | ||
278 | * by merging them down. All merge messages will be sent from a given <i>handle</i>. | ||
279 | * | ||
280 | * @param room Room | ||
281 | * @param handle Handle | ||
282 | */ | ||
283 | void | ||
284 | merge_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle); | ||
285 | |||
286 | /** | ||
287 | * Returns the CADET handle from a rooms service. | ||
288 | * | ||
289 | * @param room Room | ||
290 | * @return CADET handle | ||
291 | */ | ||
292 | struct GNUNET_CADET_Handle* | ||
293 | get_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room); | ||
294 | |||
295 | /** | ||
296 | * Returns the shared secret you need to access a <i>room</i>. | ||
297 | * | ||
298 | * @param room Room | ||
299 | * @return Shared secret | ||
300 | */ | ||
301 | struct GNUNET_HashCode* | ||
302 | get_room_key (struct GNUNET_MESSENGER_SrvRoom *room); | ||
303 | |||
304 | /** | ||
305 | * Returns a tunnel inside of a <i>room</i> leading towards a given <i>peer</i> if such a tunnel exists, | ||
306 | * otherwise NULL. | ||
307 | * | ||
308 | * @param room Room | ||
309 | * @param peer Peer identity | ||
310 | * @return Tunnel or NULL | ||
311 | */ | ||
312 | const struct GNUNET_MESSENGER_SrvTunnel* | ||
313 | get_room_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *peer); | ||
314 | |||
315 | /** | ||
316 | * Returns a message from a <i>room</i> identified by a given <i>hash</i>. If no matching message is | ||
317 | * found and <i>request</i> is set to GNUNET_YES, the <i>handle</i> will request the missing message | ||
318 | * automatically. | ||
319 | * | ||
320 | * The function uses the optimized check for a message via its hash from the message store. | ||
321 | * @see contains_store_message() | ||
322 | * | ||
323 | * If a message is missing independent of the following request, NULL gets returned instead of the | ||
324 | * matching message. | ||
325 | * | ||
326 | * @param room Room | ||
327 | * @param handle Handle | ||
328 | * @param hash Hash of message | ||
329 | * @param request Flag to request a message | ||
330 | * @return Message or NULL | ||
331 | */ | ||
332 | const struct GNUNET_MESSENGER_Message* | ||
333 | get_room_message (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
334 | const struct GNUNET_HashCode *hash, int request); | ||
335 | |||
336 | /** | ||
337 | * Updates the last messages of a <i>room</i> by replacing them if the previous hash of a given <i>message</i> | ||
338 | * matches with one of the latest messages. | ||
339 | * | ||
340 | * @param room Room | ||
341 | * @param message Message | ||
342 | * @param hash Hash of message | ||
343 | */ | ||
344 | void | ||
345 | update_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_Message *message, | ||
346 | const struct GNUNET_HashCode *hash); | ||
347 | |||
348 | /** | ||
349 | * Changes an id of a current member from an old id to a new one and adds optionally the <i>hash</i> of an | ||
350 | * id message to the members information. | ||
351 | * | ||
352 | * @param room Room | ||
353 | * @param old_id Old member id | ||
354 | * @param new_id New member id | ||
355 | * @param hash Hash of id message | ||
356 | */ | ||
357 | void | ||
358 | switch_room_member_id (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *old_id, | ||
359 | const struct GNUNET_ShortHashCode *new_id, const struct GNUNET_HashCode *hash); | ||
360 | |||
361 | /** | ||
362 | * Rebuilds the decentralized structure for a <i>room</i> by ensuring all required connections are made | ||
363 | * depending on the amount of peers and this peers index in the list of them. | ||
364 | * | ||
365 | * @param room Room | ||
366 | */ | ||
367 | void | ||
368 | rebuild_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room); | ||
369 | |||
370 | /** | ||
371 | * Handles all queued up messages of a room to handle in correct order. | ||
372 | * | ||
373 | * @param room Room | ||
374 | */ | ||
375 | void | ||
376 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room); | ||
377 | |||
378 | #endif //GNUNET_SERVICE_MESSENGER_ROOM_H | ||
diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c new file mode 100644 index 000000000..963314fd8 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_service.c | |||
@@ -0,0 +1,516 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_service.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_service.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_message_kind.h" | ||
29 | |||
30 | #include "gnunet-service-messenger.h" | ||
31 | #include "gnunet-service-messenger_util.h" | ||
32 | |||
33 | static void | ||
34 | callback_shutdown_service (void *cls) | ||
35 | { | ||
36 | struct GNUNET_MESSENGER_Service *service = cls; | ||
37 | |||
38 | if (service) | ||
39 | { | ||
40 | service->shutdown = NULL; | ||
41 | |||
42 | destroy_service (service); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | static void | ||
47 | callback_update_ego (void *cls, | ||
48 | struct GNUNET_IDENTITY_Ego *ego, | ||
49 | void **ctx, | ||
50 | const char *identifier) | ||
51 | { | ||
52 | if ((!ego) || (!identifier)) | ||
53 | return; | ||
54 | |||
55 | struct GNUNET_MESSENGER_Service *service = cls; | ||
56 | |||
57 | update_service_ego(service, identifier, GNUNET_IDENTITY_ego_get_private_key(ego)); | ||
58 | } | ||
59 | |||
60 | struct GNUNET_MESSENGER_Service* | ||
61 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle) | ||
62 | { | ||
63 | struct GNUNET_MESSENGER_Service *service = GNUNET_new(struct GNUNET_MESSENGER_Service); | ||
64 | |||
65 | service->config = config; | ||
66 | service->service = service_handle; | ||
67 | |||
68 | service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, service); | ||
69 | |||
70 | service->dir = NULL; | ||
71 | |||
72 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config, | ||
73 | GNUNET_MESSENGER_SERVICE_NAME, | ||
74 | "MESSENGER_DIR", &(service->dir))) | ||
75 | { | ||
76 | if (service->dir) | ||
77 | GNUNET_free(service->dir); | ||
78 | |||
79 | service->dir = NULL; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | if ((GNUNET_YES != GNUNET_DISK_directory_test (service->dir, GNUNET_YES)) && (GNUNET_OK | ||
84 | != GNUNET_DISK_directory_create (service->dir))) | ||
85 | { | ||
86 | GNUNET_free(service->dir); | ||
87 | |||
88 | service->dir = NULL; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | service->cadet = GNUNET_CADET_connect (service->config); | ||
93 | service->identity = GNUNET_IDENTITY_connect (service->config, &callback_update_ego, service); | ||
94 | |||
95 | service->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
96 | |||
97 | init_list_handles (&(service->handles)); | ||
98 | |||
99 | service->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
100 | service->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
101 | |||
102 | return service; | ||
103 | } | ||
104 | |||
105 | static int | ||
106 | iterate_destroy_egos (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
107 | { | ||
108 | struct GNUNET_MESSENGER_Ego *ego = value; | ||
109 | GNUNET_free(ego); | ||
110 | return GNUNET_YES; | ||
111 | } | ||
112 | |||
113 | static int | ||
114 | iterate_destroy_rooms (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
115 | { | ||
116 | struct GNUNET_MESSENGER_SrvRoom *room = value; | ||
117 | destroy_room (room); | ||
118 | return GNUNET_YES; | ||
119 | } | ||
120 | |||
121 | static int | ||
122 | iterate_destroy_contacts (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
123 | { | ||
124 | struct GNUNET_MESSENGER_SrvContact *contact = value; | ||
125 | destroy_contact (contact); | ||
126 | return GNUNET_YES; | ||
127 | } | ||
128 | |||
129 | void | ||
130 | destroy_service (struct GNUNET_MESSENGER_Service *service) | ||
131 | { | ||
132 | if (service->shutdown) | ||
133 | { | ||
134 | GNUNET_SCHEDULER_cancel (service->shutdown); | ||
135 | |||
136 | service->shutdown = NULL; | ||
137 | } | ||
138 | |||
139 | GNUNET_CONTAINER_multihashmap_iterate (service->egos, iterate_destroy_egos, NULL); | ||
140 | |||
141 | clear_list_handles (&(service->handles)); | ||
142 | |||
143 | GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, NULL); | ||
144 | GNUNET_CONTAINER_multihashmap_iterate (service->contacts, iterate_destroy_contacts, NULL); | ||
145 | |||
146 | GNUNET_CONTAINER_multihashmap_destroy (service->egos); | ||
147 | GNUNET_CONTAINER_multihashmap_destroy (service->rooms); | ||
148 | GNUNET_CONTAINER_multihashmap_destroy (service->contacts); | ||
149 | |||
150 | if (service->cadet) | ||
151 | { | ||
152 | GNUNET_CADET_disconnect (service->cadet); | ||
153 | |||
154 | service->cadet = NULL; | ||
155 | } | ||
156 | |||
157 | if (service->identity) | ||
158 | { | ||
159 | GNUNET_IDENTITY_disconnect (service->identity); | ||
160 | |||
161 | service->identity = NULL; | ||
162 | } | ||
163 | |||
164 | if (service->dir) | ||
165 | { | ||
166 | GNUNET_free(service->dir); | ||
167 | |||
168 | service->dir = NULL; | ||
169 | } | ||
170 | |||
171 | GNUNET_SERVICE_shutdown (service->service); | ||
172 | |||
173 | GNUNET_free(service); | ||
174 | } | ||
175 | |||
176 | struct GNUNET_MESSENGER_Ego* | ||
177 | lookup_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier) | ||
178 | { | ||
179 | GNUNET_assert(identifier); | ||
180 | |||
181 | struct GNUNET_HashCode hash; | ||
182 | |||
183 | GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash); | ||
184 | return GNUNET_CONTAINER_multihashmap_get(service->egos, &hash); | ||
185 | } | ||
186 | |||
187 | void | ||
188 | update_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier, | ||
189 | const struct GNUNET_IDENTITY_PrivateKey* key) | ||
190 | { | ||
191 | GNUNET_assert((identifier) && (key)); | ||
192 | |||
193 | struct GNUNET_HashCode hash; | ||
194 | |||
195 | GNUNET_CRYPTO_hash(identifier, strlen(identifier), &hash); | ||
196 | |||
197 | struct GNUNET_MESSENGER_Ego* ego = GNUNET_CONTAINER_multihashmap_get(service->egos, &hash); | ||
198 | |||
199 | if (!ego) | ||
200 | { | ||
201 | ego = GNUNET_new(struct GNUNET_MESSENGER_Ego); | ||
202 | GNUNET_CONTAINER_multihashmap_put(service->egos, &hash, ego, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
203 | } | ||
204 | |||
205 | GNUNET_memcpy(&(ego->priv), key, sizeof(*key)); | ||
206 | |||
207 | if (GNUNET_OK != GNUNET_IDENTITY_key_get_public(key, &(ego->pub))) | ||
208 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n"); | ||
209 | } | ||
210 | |||
211 | struct GNUNET_MESSENGER_SrvHandle* | ||
212 | add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq) | ||
213 | { | ||
214 | struct GNUNET_MESSENGER_SrvHandle *handle = create_handle (service, mq); | ||
215 | |||
216 | if (handle) | ||
217 | { | ||
218 | add_list_handle (&(service->handles), handle); | ||
219 | } | ||
220 | |||
221 | return handle; | ||
222 | } | ||
223 | |||
224 | void | ||
225 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle) | ||
226 | { | ||
227 | if (!handle) | ||
228 | return; | ||
229 | |||
230 | if (GNUNET_YES == remove_list_handle (&(service->handles), handle)) | ||
231 | destroy_handle (handle); | ||
232 | } | ||
233 | |||
234 | int | ||
235 | get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer) | ||
236 | { | ||
237 | return GNUNET_CRYPTO_get_peer_identity (service->config, peer); | ||
238 | } | ||
239 | |||
240 | struct GNUNET_MESSENGER_SrvContact* | ||
241 | get_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
242 | { | ||
243 | struct GNUNET_HashCode hash; | ||
244 | |||
245 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | ||
246 | |||
247 | struct GNUNET_MESSENGER_SrvContact *contact = GNUNET_CONTAINER_multihashmap_get (service->contacts, &hash); | ||
248 | |||
249 | if (contact) | ||
250 | return contact; | ||
251 | |||
252 | contact = create_contact (pubkey); | ||
253 | |||
254 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->contacts, &hash, contact, | ||
255 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
256 | return contact; | ||
257 | |||
258 | destroy_contact (contact); | ||
259 | return NULL; | ||
260 | } | ||
261 | |||
262 | void | ||
263 | swap_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, | ||
264 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
265 | { | ||
266 | const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact); | ||
267 | |||
268 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (service->contacts, hash, contact)) | ||
269 | { | ||
270 | GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey)); | ||
271 | |||
272 | hash = get_contact_id_from_key (contact); | ||
273 | |||
274 | GNUNET_CONTAINER_multihashmap_put (service->contacts, hash, contact, | ||
275 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | struct GNUNET_ShortHashCode* | ||
280 | generate_service_new_member_id (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key) | ||
281 | { | ||
282 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | ||
283 | |||
284 | if (room) | ||
285 | { | ||
286 | return generate_room_member_id (room); | ||
287 | } | ||
288 | else | ||
289 | { | ||
290 | struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
291 | generate_free_member_id (random_id, NULL); | ||
292 | return random_id; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | struct GNUNET_MESSENGER_SrvRoom* | ||
297 | get_service_room (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key) | ||
298 | { | ||
299 | return GNUNET_CONTAINER_multihashmap_get (service->rooms, key); | ||
300 | } | ||
301 | |||
302 | int | ||
303 | open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
304 | const struct GNUNET_HashCode *key) | ||
305 | { | ||
306 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | ||
307 | |||
308 | if (room) | ||
309 | return open_room (room, handle); | ||
310 | |||
311 | room = create_room (handle, key); | ||
312 | |||
313 | if ((GNUNET_YES == open_room (room, handle)) && (GNUNET_OK | ||
314 | == GNUNET_CONTAINER_multihashmap_put (service->rooms, key, room, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
315 | return GNUNET_YES; | ||
316 | |||
317 | destroy_room (room); | ||
318 | return GNUNET_NO; | ||
319 | } | ||
320 | |||
321 | int | ||
322 | entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
323 | const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key) | ||
324 | { | ||
325 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | ||
326 | |||
327 | if (room) | ||
328 | { | ||
329 | if (GNUNET_YES == entry_room_at (room, handle, door)) | ||
330 | return GNUNET_YES; | ||
331 | else | ||
332 | return GNUNET_NO; | ||
333 | } | ||
334 | |||
335 | room = create_room (handle, key); | ||
336 | |||
337 | if ((GNUNET_YES == entry_room_at (room, handle, door)) && (GNUNET_OK | ||
338 | == GNUNET_CONTAINER_multihashmap_put (service->rooms, key, room, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
339 | { | ||
340 | return GNUNET_YES; | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | destroy_room (room); | ||
345 | return GNUNET_NO; | ||
346 | } | ||
347 | |||
348 | } | ||
349 | |||
350 | int | ||
351 | close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
352 | const struct GNUNET_HashCode *key) | ||
353 | { | ||
354 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | ||
355 | |||
356 | if (!room) | ||
357 | return GNUNET_NO; | ||
358 | |||
359 | struct GNUNET_MESSENGER_Message *message = create_message_leave (); | ||
360 | |||
361 | if (message) | ||
362 | { | ||
363 | struct GNUNET_HashCode hash; | ||
364 | |||
365 | send_room_message (room, handle, message, &hash); | ||
366 | destroy_message (message); | ||
367 | } | ||
368 | |||
369 | const struct GNUNET_ShortHashCode *id = get_handle_member_id (handle, key); | ||
370 | |||
371 | GNUNET_assert(id); | ||
372 | |||
373 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (handle->member_ids, key, id)) | ||
374 | return GNUNET_NO; | ||
375 | |||
376 | struct GNUNET_MESSENGER_SrvHandle *member_handle = (struct GNUNET_MESSENGER_SrvHandle*) find_list_handle_by_member ( | ||
377 | &(service->handles), key); | ||
378 | |||
379 | if (!member_handle) | ||
380 | { | ||
381 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room)) | ||
382 | { | ||
383 | destroy_room (room); | ||
384 | return GNUNET_YES; | ||
385 | } | ||
386 | else | ||
387 | return GNUNET_NO; | ||
388 | } | ||
389 | |||
390 | if (room->host == handle) | ||
391 | room->host = member_handle; | ||
392 | |||
393 | return GNUNET_YES; | ||
394 | } | ||
395 | |||
396 | static void | ||
397 | get_room_data_subdir (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, char **dir) | ||
398 | { | ||
399 | GNUNET_asprintf (dir, "%s%s%c%s%c", service->dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (&(room->key)), DIR_SEPARATOR); | ||
400 | } | ||
401 | |||
402 | void | ||
403 | load_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room) | ||
404 | { | ||
405 | char *room_dir; | ||
406 | get_room_data_subdir (service, room, &room_dir); | ||
407 | |||
408 | if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES)) | ||
409 | { | ||
410 | load_message_store (&room->store, room_dir); | ||
411 | |||
412 | char *config_file; | ||
413 | GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg"); | ||
414 | |||
415 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | ||
416 | |||
417 | if ((GNUNET_YES == GNUNET_DISK_file_test (config_file)) && (GNUNET_OK | ||
418 | == GNUNET_CONFIGURATION_parse (cfg, config_file))) | ||
419 | { | ||
420 | unsigned long long access; | ||
421 | |||
422 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "room", "access-rule", &access)) | ||
423 | room->strict_access = (int) (access); | ||
424 | |||
425 | char *message_string; | ||
426 | |||
427 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "room", "last-message", &message_string)) && (message_string)) | ||
428 | { | ||
429 | struct GNUNET_HashCode hash; | ||
430 | |||
431 | GNUNET_CRYPTO_hash_from_string(message_string, &hash); | ||
432 | |||
433 | const struct GNUNET_MESSENGER_Message *message = get_room_message (room, room->host, &hash, GNUNET_NO); | ||
434 | |||
435 | if (message) | ||
436 | update_room_last_messages (room, message, &hash); | ||
437 | |||
438 | GNUNET_free(message_string); | ||
439 | } | ||
440 | } | ||
441 | |||
442 | GNUNET_CONFIGURATION_destroy (cfg); | ||
443 | |||
444 | GNUNET_free(config_file); | ||
445 | } | ||
446 | |||
447 | GNUNET_free(room_dir); | ||
448 | } | ||
449 | |||
450 | void | ||
451 | save_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room) | ||
452 | { | ||
453 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (service->rooms, &(room->key))) | ||
454 | { | ||
455 | return; | ||
456 | } | ||
457 | |||
458 | char *room_dir; | ||
459 | get_room_data_subdir (service, room, &room_dir); | ||
460 | |||
461 | if ((GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_NO)) || (GNUNET_OK | ||
462 | == GNUNET_DISK_directory_create (room_dir))) | ||
463 | { | ||
464 | save_message_store (&room->store, room_dir); | ||
465 | |||
466 | char *config_file; | ||
467 | GNUNET_asprintf (&config_file, "%s%s", room_dir, "room.cfg"); | ||
468 | |||
469 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | ||
470 | |||
471 | GNUNET_CONFIGURATION_set_value_number (cfg, "room", "access-rule", room->strict_access); | ||
472 | |||
473 | if (room->last_messages.head) | ||
474 | GNUNET_CONFIGURATION_set_value_string (cfg, "room", "last-message", | ||
475 | GNUNET_h2s_full (&(room->last_messages.head->hash))); | ||
476 | |||
477 | GNUNET_CONFIGURATION_write (cfg, config_file); | ||
478 | GNUNET_CONFIGURATION_destroy (cfg); | ||
479 | |||
480 | GNUNET_free(config_file); | ||
481 | } | ||
482 | |||
483 | GNUNET_free(room_dir); | ||
484 | } | ||
485 | |||
486 | void | ||
487 | handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, | ||
488 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
489 | { | ||
490 | struct GNUNET_MESSENGER_ListHandle *element = service->handles.head; | ||
491 | |||
492 | const uint16_t length = get_message_size (message); | ||
493 | |||
494 | while (element) | ||
495 | { | ||
496 | struct GNUNET_MESSENGER_SrvHandle *handle = (struct GNUNET_MESSENGER_SrvHandle*) element->handle; | ||
497 | |||
498 | if ((handle->mq) && (get_handle_member_id (handle, &(room->key)))) | ||
499 | { | ||
500 | struct GNUNET_MESSENGER_RecvMessage *msg; | ||
501 | struct GNUNET_MQ_Envelope *env; | ||
502 | |||
503 | env = GNUNET_MQ_msg_extra(msg, length, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE); | ||
504 | |||
505 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
506 | GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash)); | ||
507 | |||
508 | char *buffer = ((char*) msg) + sizeof(*msg); | ||
509 | encode_message (message, length, buffer); | ||
510 | |||
511 | GNUNET_MQ_send (handle->mq, env); | ||
512 | } | ||
513 | |||
514 | element = element->next; | ||
515 | } | ||
516 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_service.h b/src/messenger/gnunet-service-messenger_service.h new file mode 100644 index 000000000..246c74771 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_service.h | |||
@@ -0,0 +1,259 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_service.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_SERVICE_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_SERVICE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_configuration_lib.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | #include "gnunet_container_lib.h" | ||
33 | #include "gnunet_disk_lib.h" | ||
34 | #include "gnunet_identity_service.h" | ||
35 | |||
36 | #include "messenger_api_ego.h" | ||
37 | |||
38 | #include "gnunet-service-messenger_list_handles.h" | ||
39 | |||
40 | #include "gnunet-service-messenger_contact.h" | ||
41 | #include "gnunet-service-messenger_room.h" | ||
42 | |||
43 | struct GNUNET_MESSENGER_Service | ||
44 | { | ||
45 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
46 | struct GNUNET_SERVICE_Handle *service; | ||
47 | |||
48 | struct GNUNET_SCHEDULER_Task *shutdown; | ||
49 | |||
50 | char *dir; | ||
51 | |||
52 | struct GNUNET_CADET_Handle *cadet; | ||
53 | struct GNUNET_IDENTITY_Handle *identity; | ||
54 | |||
55 | struct GNUNET_CONTAINER_MultiHashMap *egos; | ||
56 | |||
57 | struct GNUNET_MESSENGER_ListHandles handles; | ||
58 | |||
59 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *rooms; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Creates and allocates a new service using a given <i>config</i> and a GNUnet service handle. | ||
65 | * | ||
66 | * @param config Configuration | ||
67 | * @param service_handle GNUnet service handle | ||
68 | * @return New service | ||
69 | */ | ||
70 | struct GNUNET_MESSENGER_Service* | ||
71 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, struct GNUNET_SERVICE_Handle *service_handle); | ||
72 | |||
73 | /** | ||
74 | * Destroys a <i>service</i> and frees its memory fully. | ||
75 | * | ||
76 | * @param service Service | ||
77 | */ | ||
78 | void | ||
79 | destroy_service (struct GNUNET_MESSENGER_Service *service); | ||
80 | |||
81 | /** | ||
82 | * Lookups an EGO which was registered to a <i>service</i> under | ||
83 | * a specific <i>identifier</i>. | ||
84 | * | ||
85 | * @param service Service | ||
86 | * @param identifier Identifier string | ||
87 | * @return EGO or NULL | ||
88 | */ | ||
89 | struct GNUNET_MESSENGER_Ego* | ||
90 | lookup_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier); | ||
91 | |||
92 | /** | ||
93 | * Updates the registration of an EGO to a <i>service</i> under | ||
94 | * a specific <i>identifier</i> with a new <i>key</i>. | ||
95 | * | ||
96 | * @param service Service | ||
97 | * @param identifier Identifier string | ||
98 | * @param key Private EGO key | ||
99 | */ | ||
100 | void | ||
101 | update_service_ego (struct GNUNET_MESSENGER_Service *service, const char *identifier, | ||
102 | const struct GNUNET_IDENTITY_PrivateKey* key); | ||
103 | |||
104 | /** | ||
105 | * Creates and adds a new handle to a <i>service</i> using a given message queue. | ||
106 | * | ||
107 | * @param service Service | ||
108 | * @param mq Message queue | ||
109 | * @return New handle | ||
110 | */ | ||
111 | struct GNUNET_MESSENGER_SrvHandle* | ||
112 | add_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq); | ||
113 | |||
114 | /** | ||
115 | * Removes a <i>handle</i> from a <i>service</i> and destroys it. | ||
116 | * | ||
117 | * @param service Service | ||
118 | * @param handle Handle | ||
119 | */ | ||
120 | void | ||
121 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle); | ||
122 | |||
123 | /** | ||
124 | * Tries to write the peer identity of the peer running a <i>service</i> on to the <i>peer</i> | ||
125 | * parameter. The functions returns GNUNET_OK on success, otherwise GNUNET_SYSERR. | ||
126 | * | ||
127 | * @param service Service | ||
128 | * @param[out] peer Peer identity | ||
129 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
130 | */ | ||
131 | int | ||
132 | get_service_peer_identity (const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer); | ||
133 | |||
134 | /** | ||
135 | * Returns a contact of a <i>service</i> identified by a given public key. If no matching contact exists, | ||
136 | * it will tried to create one with the specific public key. If the function still fails to do so, | ||
137 | * NULL gets returned. | ||
138 | * | ||
139 | * @param service Service | ||
140 | * @param pubkey Public key of EGO | ||
141 | * @return Contact | ||
142 | */ | ||
143 | struct GNUNET_MESSENGER_SrvContact* | ||
144 | get_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
145 | |||
146 | /** | ||
147 | * Changes the public key for a <i>contact</i> known to a <i>service</i> to a specific public key and | ||
148 | * updates local map entries to access the contact by its updated key. | ||
149 | * | ||
150 | * @param service Service | ||
151 | * @param contact Contact | ||
152 | * @param pubkey Public key of EGO | ||
153 | */ | ||
154 | void | ||
155 | swap_service_contact_by_pubkey (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvContact *contact, | ||
156 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
157 | |||
158 | /** | ||
159 | * Tries to generate and allocate a new unique member id for a given room of a service identified by its <i>key</i>. | ||
160 | * If the generation fails caused by too many tries of duplicates, it returns NULL. | ||
161 | * | ||
162 | * @param service Service | ||
163 | * @param key Key of room | ||
164 | * @return Newly generated member id or NULL | ||
165 | */ | ||
166 | struct GNUNET_ShortHashCode* | ||
167 | generate_service_new_member_id (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key); | ||
168 | |||
169 | /** | ||
170 | * Returns the room identified by a given <i>key</i> for a <i>service</i>. If the service doesn't know any room | ||
171 | * using the given key, NULL gets returned. | ||
172 | * | ||
173 | * @param service Service | ||
174 | * @param key Key of room | ||
175 | * @return Room or NULL | ||
176 | */ | ||
177 | struct GNUNET_MESSENGER_SrvRoom* | ||
178 | get_service_room (struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key); | ||
179 | |||
180 | /** | ||
181 | * Tries to open a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will be | ||
182 | * created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
183 | * | ||
184 | * @param service Service | ||
185 | * @param handle Handle | ||
186 | * @param key Key of room | ||
187 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
188 | */ | ||
189 | int | ||
190 | open_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
191 | const struct GNUNET_HashCode *key); | ||
192 | |||
193 | /** | ||
194 | * Tries to enter a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will | ||
195 | * be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
196 | * | ||
197 | * The room will be entered through the peer identitied by the peer identity provided as <i>door</i> parameter and | ||
198 | * a new connection will be made. | ||
199 | * | ||
200 | * @param service Service | ||
201 | * @param handle Handle | ||
202 | * @param door Peer identity | ||
203 | * @param key Key of room | ||
204 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
205 | */ | ||
206 | int | ||
207 | entry_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
208 | const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key); | ||
209 | |||
210 | /** | ||
211 | * Tries to close a room using a given <i>key</i> for a <i>service</i> by a specific <i>handle</i>. The room will | ||
212 | * be created if necessary. If the function is successful, it returns GNUNET_YES, otherwise GNUNET_NO. | ||
213 | * | ||
214 | * If the specific handle is currently the host of the room for this service, a new handle which is a member will | ||
215 | * take its place. Otherwise the room will be destroyed for this service. | ||
216 | * | ||
217 | * @param service Service | ||
218 | * @param handle Handle | ||
219 | * @param key Key of room | ||
220 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
221 | */ | ||
222 | int | ||
223 | close_service_room (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, | ||
224 | const struct GNUNET_HashCode *key); | ||
225 | |||
226 | /** | ||
227 | * Loads the local configuration for a given <i>room</i> of a <i>service</i> which contains the last messages hash | ||
228 | * and the ruleset for general access of new members. | ||
229 | * | ||
230 | * @param service Service | ||
231 | * @param room Room | ||
232 | */ | ||
233 | void | ||
234 | load_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room); | ||
235 | |||
236 | /** | ||
237 | * Saves the configuration for a given <i>room</i> of a <i>service</i> which contains the last messages hash | ||
238 | * and the ruleset for general access of new members locally. | ||
239 | * | ||
240 | * @param service Service | ||
241 | * @param room Room | ||
242 | */ | ||
243 | void | ||
244 | save_service_room_and_messages (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room); | ||
245 | |||
246 | /** | ||
247 | * Sends a received or sent <i>message</i> with a given <i>hash</i> to each handle of a <i>service</i> which | ||
248 | * is currently member of a specific <i>room</i> for handling it in the client API. | ||
249 | * | ||
250 | * @param service Service | ||
251 | * @param room Room | ||
252 | * @param message Message | ||
253 | * @param hash Hash of message | ||
254 | */ | ||
255 | void | ||
256 | handle_service_message (struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvRoom *room, | ||
257 | const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
258 | |||
259 | #endif //GNUNET_SERVICE_MESSENGER_SERVICE_H | ||
diff --git a/src/messenger/gnunet-service-messenger_tunnel.c b/src/messenger/gnunet-service-messenger_tunnel.c new file mode 100644 index 000000000..df9e5c4c7 --- /dev/null +++ b/src/messenger/gnunet-service-messenger_tunnel.c | |||
@@ -0,0 +1,300 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_tunnel.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_tunnel.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_handle.h" | ||
29 | #include "gnunet-service-messenger_util.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_SrvTunnel* | ||
32 | create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door) | ||
33 | { | ||
34 | GNUNET_assert((room) && (door)); | ||
35 | |||
36 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_new(struct GNUNET_MESSENGER_SrvTunnel); | ||
37 | |||
38 | tunnel->room = room; | ||
39 | tunnel->channel = NULL; | ||
40 | |||
41 | tunnel->peer = GNUNET_PEER_intern (door); | ||
42 | tunnel->contact_id = NULL; | ||
43 | |||
44 | tunnel->peer_message = NULL; | ||
45 | tunnel->last_message = NULL; | ||
46 | |||
47 | return tunnel; | ||
48 | } | ||
49 | |||
50 | void | ||
51 | destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
52 | { | ||
53 | GNUNET_assert(tunnel); | ||
54 | |||
55 | if (tunnel->channel) | ||
56 | GNUNET_CADET_channel_destroy (tunnel->channel); | ||
57 | |||
58 | GNUNET_PEER_change_rc (tunnel->peer, -1); | ||
59 | |||
60 | if (tunnel->contact_id) | ||
61 | GNUNET_free(tunnel->contact_id); | ||
62 | |||
63 | if (tunnel->peer_message) | ||
64 | GNUNET_free(tunnel->peer_message); | ||
65 | |||
66 | if (tunnel->last_message) | ||
67 | GNUNET_free(tunnel->last_message); | ||
68 | |||
69 | GNUNET_free(tunnel); | ||
70 | } | ||
71 | |||
72 | int | ||
73 | bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel) | ||
74 | { | ||
75 | GNUNET_assert(tunnel); | ||
76 | |||
77 | if (tunnel->channel) | ||
78 | { | ||
79 | if (tunnel->contact_id) | ||
80 | return GNUNET_NO; | ||
81 | |||
82 | delayed_disconnect_channel (tunnel->channel); | ||
83 | } | ||
84 | |||
85 | tunnel->channel = channel; | ||
86 | |||
87 | return GNUNET_YES; | ||
88 | } | ||
89 | |||
90 | extern void | ||
91 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, void *cls); | ||
92 | |||
93 | void | ||
94 | callback_tunnel_disconnect (void *cls, const struct GNUNET_CADET_Channel *channel) | ||
95 | { | ||
96 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | ||
97 | |||
98 | if (tunnel) | ||
99 | { | ||
100 | tunnel->channel = NULL; | ||
101 | |||
102 | callback_room_disconnect (tunnel->room, cls); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | extern int | ||
107 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, | ||
108 | struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash); | ||
109 | |||
110 | int | ||
111 | check_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | ||
112 | { | ||
113 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | ||
114 | |||
115 | if (!tunnel) | ||
116 | return GNUNET_NO; | ||
117 | |||
118 | const uint16_t length = ntohs (header->size) - sizeof(*header); | ||
119 | const char *buffer = (const char*) &header[1]; | ||
120 | |||
121 | struct GNUNET_MESSENGER_Message message; | ||
122 | |||
123 | if (length < sizeof(message.header)) | ||
124 | return GNUNET_NO; | ||
125 | |||
126 | if (GNUNET_YES != decode_message (&message, length, buffer)) | ||
127 | return GNUNET_NO; | ||
128 | |||
129 | struct GNUNET_HashCode hash; | ||
130 | hash_message (length, buffer, &hash); | ||
131 | |||
132 | int result = callback_verify_room_message (tunnel->room, cls, &message, &hash); | ||
133 | |||
134 | if (GNUNET_MESSENGER_KIND_PEER == message.header.kind) | ||
135 | { | ||
136 | struct GNUNET_PeerIdentity identity; | ||
137 | |||
138 | GNUNET_PEER_resolve (tunnel->peer, &identity); | ||
139 | |||
140 | if (0 == GNUNET_memcmp(&(message.body.peer.peer), &(identity))) | ||
141 | { | ||
142 | if (tunnel->contact_id) | ||
143 | { | ||
144 | if (0 != GNUNET_memcmp(tunnel->contact_id, &(message.header.sender_id))) | ||
145 | result = GNUNET_SYSERR; | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | tunnel->contact_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
150 | |||
151 | GNUNET_memcpy(tunnel->contact_id, &(message.header.sender_id), sizeof(struct GNUNET_ShortHashCode)); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return (result == GNUNET_YES ? GNUNET_OK : GNUNET_NO); | ||
157 | } | ||
158 | |||
159 | extern void | ||
160 | callback_room_recv (struct GNUNET_MESSENGER_SrvRoom *room, void *cls, struct GNUNET_MESSENGER_Message *message, | ||
161 | const struct GNUNET_HashCode *hash); | ||
162 | |||
163 | void | ||
164 | handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | ||
165 | { | ||
166 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | ||
167 | |||
168 | const uint16_t length = ntohs (header->size) - sizeof(*header); | ||
169 | const char *buffer = (const char*) &header[1]; | ||
170 | |||
171 | struct GNUNET_MESSENGER_Message message; | ||
172 | struct GNUNET_HashCode hash; | ||
173 | |||
174 | decode_message (&message, length, buffer); | ||
175 | hash_message (length, buffer, &hash); | ||
176 | |||
177 | if (tunnel) | ||
178 | { | ||
179 | if (!tunnel->last_message) | ||
180 | tunnel->last_message = GNUNET_new(struct GNUNET_HashCode); | ||
181 | |||
182 | GNUNET_memcpy(tunnel->last_message, &hash, sizeof(struct GNUNET_HashCode)); | ||
183 | |||
184 | callback_room_recv (tunnel->room, cls, copy_message (&message), &hash); | ||
185 | } | ||
186 | |||
187 | GNUNET_CADET_receive_done (tunnel->channel); | ||
188 | } | ||
189 | |||
190 | int | ||
191 | connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
192 | { | ||
193 | GNUNET_assert(tunnel); | ||
194 | |||
195 | if (tunnel->channel) | ||
196 | return GNUNET_NO; | ||
197 | |||
198 | const struct GNUNET_PeerIdentity *door = GNUNET_PEER_resolve2 (tunnel->peer); | ||
199 | |||
200 | struct GNUNET_CADET_Handle *cadet = get_room_cadet (tunnel->room); | ||
201 | struct GNUNET_HashCode *key = get_room_key (tunnel->room); | ||
202 | |||
203 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size(tunnel_message, GNUNET_MESSAGE_TYPE_CADET_CLI, | ||
204 | struct GNUNET_MessageHeader, NULL), | ||
205 | GNUNET_MQ_handler_end() }; | ||
206 | |||
207 | tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, key, NULL, callback_tunnel_disconnect, handlers); | ||
208 | |||
209 | return GNUNET_YES; | ||
210 | } | ||
211 | |||
212 | void | ||
213 | disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
214 | { | ||
215 | if (tunnel->channel) | ||
216 | { | ||
217 | delayed_disconnect_channel (tunnel->channel); | ||
218 | |||
219 | tunnel->channel = NULL; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | int | ||
224 | is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
225 | { | ||
226 | return (tunnel->channel ? GNUNET_YES : GNUNET_NO); | ||
227 | } | ||
228 | |||
229 | struct GNUNET_MESSENGER_MessageSent | ||
230 | { | ||
231 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; | ||
232 | struct GNUNET_HashCode hash; | ||
233 | }; | ||
234 | |||
235 | extern void | ||
236 | callback_room_sent (struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, void *cls, | ||
237 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
238 | |||
239 | static void | ||
240 | callback_tunnel_sent (void *cls) | ||
241 | { | ||
242 | struct GNUNET_MESSENGER_MessageSent *sent = cls; | ||
243 | |||
244 | if (sent->tunnel) | ||
245 | { | ||
246 | if (!sent->tunnel->last_message) | ||
247 | sent->tunnel->last_message = GNUNET_new(struct GNUNET_HashCode); | ||
248 | |||
249 | GNUNET_memcpy(sent->tunnel->last_message, &(sent->hash), sizeof(struct GNUNET_HashCode)); | ||
250 | } | ||
251 | |||
252 | GNUNET_free(sent); | ||
253 | } | ||
254 | |||
255 | void | ||
256 | send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, | ||
257 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash) | ||
258 | { | ||
259 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (tunnel->channel); | ||
260 | |||
261 | struct GNUNET_MESSENGER_MessageSent *sent = GNUNET_new(struct GNUNET_MESSENGER_MessageSent); | ||
262 | |||
263 | GNUNET_memcpy(&(sent->hash), hash, sizeof(struct GNUNET_HashCode)); | ||
264 | |||
265 | sent->tunnel = tunnel; | ||
266 | |||
267 | GNUNET_MQ_notify_sent (env, callback_tunnel_sent, sent); | ||
268 | GNUNET_MQ_send (mq, env); | ||
269 | |||
270 | callback_room_sent (tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle, tunnel, message, hash); | ||
271 | } | ||
272 | |||
273 | void | ||
274 | send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message, | ||
275 | struct GNUNET_HashCode *hash) | ||
276 | { | ||
277 | struct GNUNET_MQ_Envelope *env = pack_room_message (tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle, | ||
278 | message, hash, | ||
279 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | ||
280 | |||
281 | if (env) | ||
282 | send_tunnel_envelope (tunnel, handle, env, copy_message (message), hash); | ||
283 | } | ||
284 | |||
285 | void | ||
286 | forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, | ||
287 | const struct GNUNET_HashCode *hash) | ||
288 | { | ||
289 | struct GNUNET_MESSENGER_Message *clone = copy_message (message); | ||
290 | struct GNUNET_MQ_Envelope *env = pack_message (clone, NULL, NULL, GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | ||
291 | |||
292 | if (env) | ||
293 | send_tunnel_envelope (tunnel, NULL, env, clone, hash); | ||
294 | } | ||
295 | |||
296 | const struct GNUNET_HashCode* | ||
297 | get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) | ||
298 | { | ||
299 | return tunnel->peer_message; | ||
300 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_tunnel.h b/src/messenger/gnunet-service-messenger_tunnel.h new file mode 100644 index 000000000..e6efb226d --- /dev/null +++ b/src/messenger/gnunet-service-messenger_tunnel.h | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_tunnel.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_TUNNEL_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_TUNNEL_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_peer_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | |||
34 | #include "gnunet-service-messenger_room.h" | ||
35 | |||
36 | struct GNUNET_MESSENGER_SrvTunnel | ||
37 | { | ||
38 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
39 | struct GNUNET_CADET_Channel *channel; | ||
40 | |||
41 | GNUNET_PEER_Id peer; | ||
42 | struct GNUNET_ShortHashCode *contact_id; | ||
43 | |||
44 | struct GNUNET_HashCode *peer_message; | ||
45 | struct GNUNET_HashCode *last_message; | ||
46 | }; | ||
47 | |||
48 | /** | ||
49 | * Creates and allocates a tunnel of a <i>room</i> to a specific peer identity. | ||
50 | * | ||
51 | * @param room Room | ||
52 | * @param door Peer identity | ||
53 | * @return New tunnel | ||
54 | */ | ||
55 | struct GNUNET_MESSENGER_SrvTunnel* | ||
56 | create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_PeerIdentity *door); | ||
57 | |||
58 | /** | ||
59 | * Destroys a <i>tunnel</i> and frees its memory fully. | ||
60 | * | ||
61 | * @param tunnel | ||
62 | */ | ||
63 | void | ||
64 | destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
65 | |||
66 | /** | ||
67 | * Binds a CADET <i>channel</i> to a <i>tunnel</i> on returns GNUNET_YES only if | ||
68 | * the bounds channel was replaced successfully, otherwise GNUNET_NO gets returned. | ||
69 | * | ||
70 | * @param tunnel Tunnel | ||
71 | * @param channel CADET channel | ||
72 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
73 | */ | ||
74 | int | ||
75 | bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, struct GNUNET_CADET_Channel *channel); | ||
76 | |||
77 | /** | ||
78 | * Tries to connect a <i>tunnel</i> by creating a new CADET channel and binding it. | ||
79 | * The function returns GNUNET_YES on success, otherwise GNUNET_NO. | ||
80 | * | ||
81 | * @param tunnel Tunnel | ||
82 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
83 | */ | ||
84 | int | ||
85 | connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
86 | |||
87 | /** | ||
88 | * Disconnects and unbinds a channel from a <i>tunnel</i>. The actual disconnection | ||
89 | * will be asynchronous. | ||
90 | * | ||
91 | * @param tunnel Tunnel | ||
92 | */ | ||
93 | void | ||
94 | disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
95 | |||
96 | /** | ||
97 | * Returns the status of a currently bound channel of a <i>tunnel</i>. | ||
98 | * | ||
99 | * @param tunnel Tunnel | ||
100 | * @return GNUNET_YES or GNUNET_NO | ||
101 | */ | ||
102 | int | ||
103 | is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
104 | |||
105 | /** | ||
106 | * Sends an envelope containing a <i>message</i> with a given <i>hash</i> through | ||
107 | * a <i>tunnel</i> by a given <i>handle</i>. | ||
108 | * | ||
109 | * @param tunnel Tunnel | ||
110 | * @param handle Handle | ||
111 | * @param env Envelope | ||
112 | * @param message Message | ||
113 | * @param hash Hash of message | ||
114 | */ | ||
115 | void | ||
116 | send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MQ_Envelope *env, | ||
117 | struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash); | ||
118 | |||
119 | /** | ||
120 | * Sends a <i>message</i> by packing it automatically into an envelope and passing it | ||
121 | * through the <i>tunnel</i>. The used <i>handle</i> will sign the message and | ||
122 | * the <i>hash</i> will be calculated and stored. | ||
123 | * | ||
124 | * @param tunnel Tunnel | ||
125 | * @param handle Handle | ||
126 | * @param[out] message Message | ||
127 | * @param[out] hash Hash of message | ||
128 | */ | ||
129 | void | ||
130 | send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, void *handle, struct GNUNET_MESSENGER_Message *message, | ||
131 | struct GNUNET_HashCode *hash); | ||
132 | |||
133 | /** | ||
134 | * Forwards a given <i>message</i> with a known <i>hash</i> through a <i>tunnel</i>. | ||
135 | * | ||
136 | * @param tunnel Tunnel | ||
137 | * @param message Message | ||
138 | * @param hash Hash of message | ||
139 | */ | ||
140 | void | ||
141 | forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, const struct GNUNET_MESSENGER_Message *message, | ||
142 | const struct GNUNET_HashCode *hash); | ||
143 | |||
144 | /** | ||
145 | * Returns the hash of the latest peer message published through a given <i>tunnel</i> | ||
146 | * and matching the tunnels peer identity. If no peer message has been linked to the tunnel | ||
147 | * yet, NULL gets returned. | ||
148 | * | ||
149 | * @param tunnel Tunnel | ||
150 | * @return Hash of peer message or NULL | ||
151 | */ | ||
152 | const struct GNUNET_HashCode* | ||
153 | get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel); | ||
154 | |||
155 | #endif //GNUNET_SERVICE_MESSENGER_TUNNEL_H | ||
diff --git a/src/messenger/gnunet-service-messenger_util.c b/src/messenger/gnunet-service-messenger_util.c new file mode 100644 index 000000000..94fc9469d --- /dev/null +++ b/src/messenger/gnunet-service-messenger_util.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_util.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet-service-messenger_util.h" | ||
27 | |||
28 | static void | ||
29 | callback_close_channel (void *cls) | ||
30 | { | ||
31 | struct GNUNET_CADET_Channel *channel = cls; | ||
32 | |||
33 | if (channel) | ||
34 | GNUNET_CADET_channel_destroy (channel); | ||
35 | } | ||
36 | |||
37 | void | ||
38 | delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel) | ||
39 | { | ||
40 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_URGENT, | ||
41 | callback_close_channel, channel); | ||
42 | } | ||
43 | |||
44 | int | ||
45 | generate_free_member_id (struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members) | ||
46 | { | ||
47 | size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (members) : 0); | ||
48 | |||
49 | do | ||
50 | { | ||
51 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, id, sizeof(struct GNUNET_ShortHashCode)); | ||
52 | |||
53 | if ((members) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (members, id))) | ||
54 | counter--; | ||
55 | else | ||
56 | break; | ||
57 | } | ||
58 | while (counter > 0); | ||
59 | |||
60 | if (counter) | ||
61 | return GNUNET_YES; | ||
62 | |||
63 | return GNUNET_NO; | ||
64 | } | ||
diff --git a/src/messenger/gnunet-service-messenger_util.h b/src/messenger/gnunet-service-messenger_util.h new file mode 100644 index 000000000..20f8f0afe --- /dev/null +++ b/src/messenger/gnunet-service-messenger_util.h | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/gnunet-service-messenger_util.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_SERVICE_MESSENGER_UTIL_H | ||
27 | #define GNUNET_SERVICE_MESSENGER_UTIL_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | |||
34 | /** | ||
35 | * Starts an urgent task to close a CADET channel asynchronously. | ||
36 | * | ||
37 | * @param channel Channel | ||
38 | */ | ||
39 | void | ||
40 | delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel); | ||
41 | |||
42 | /** | ||
43 | * Tries to generate an unused member id and store it into the <i>id</i> parameter. A map containing all currently | ||
44 | * used member ids is used to check against. | ||
45 | * | ||
46 | * @param[out] id New member id | ||
47 | * @param members Map of member ids | ||
48 | * @return GNUNET_YES on success, GNUNET_NO on failure | ||
49 | */ | ||
50 | int | ||
51 | generate_free_member_id (struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members); | ||
52 | |||
53 | #endif //GNUNET_SERVICE_MESSENGER_UTIL_H | ||
diff --git a/src/messenger/messenger.conf.in b/src/messenger/messenger.conf.in new file mode 100644 index 000000000..59e11b166 --- /dev/null +++ b/src/messenger/messenger.conf.in | |||
@@ -0,0 +1,13 @@ | |||
1 | [messenger] | ||
2 | START_ON_DEMAND = YES | ||
3 | PORT = 2097 | ||
4 | HOSTNAME = localhost | ||
5 | BINARY = gnunet-service-messenger | ||
6 | ACCEPT_FROM = 127.0.0.1; | ||
7 | ACCEPT_FROM6 = ::1; | ||
8 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-messenger.sock | ||
9 | UNIX_MATCH_UID = NO | ||
10 | UNIX_MATCH_GID = YES | ||
11 | |||
12 | # Directory to store messages and contacts | ||
13 | MESSENGER_DIR = $GNUNET_DATA_HOME/messenger/ \ No newline at end of file | ||
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c new file mode 100644 index 000000000..6401b18d7 --- /dev/null +++ b/src/messenger/messenger_api.c | |||
@@ -0,0 +1,568 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "gnunet_messenger_service.h" | ||
27 | |||
28 | #include "gnunet-service-messenger.h" | ||
29 | |||
30 | #include "messenger_api_handle.h" | ||
31 | #include "messenger_api_message.h" | ||
32 | |||
33 | const char* | ||
34 | GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind) | ||
35 | { | ||
36 | switch (kind) | ||
37 | { | ||
38 | case GNUNET_MESSENGER_KIND_INFO: | ||
39 | return "INFO"; | ||
40 | case GNUNET_MESSENGER_KIND_JOIN: | ||
41 | return "JOIN"; | ||
42 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
43 | return "LEAVE"; | ||
44 | case GNUNET_MESSENGER_KIND_NAME: | ||
45 | return "NAME"; | ||
46 | case GNUNET_MESSENGER_KIND_KEY: | ||
47 | return "KEY"; | ||
48 | case GNUNET_MESSENGER_KIND_PEER: | ||
49 | return "PEER"; | ||
50 | case GNUNET_MESSENGER_KIND_ID: | ||
51 | return "ID"; | ||
52 | case GNUNET_MESSENGER_KIND_MISS: | ||
53 | return "MISS"; | ||
54 | case GNUNET_MESSENGER_KIND_MERGE: | ||
55 | return "MERGE"; | ||
56 | case GNUNET_MESSENGER_KIND_REQUEST: | ||
57 | return "REQUEST"; | ||
58 | case GNUNET_MESSENGER_KIND_INVITE: | ||
59 | return "INVITE"; | ||
60 | case GNUNET_MESSENGER_KIND_TEXT: | ||
61 | return "TEXT"; | ||
62 | case GNUNET_MESSENGER_KIND_FILE: | ||
63 | return "FILE"; | ||
64 | default: | ||
65 | return "UNKNOWN"; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | static int | ||
70 | check_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) | ||
71 | { | ||
72 | GNUNET_MQ_check_zero_termination(msg); | ||
73 | return GNUNET_OK; | ||
74 | } | ||
75 | |||
76 | static void | ||
77 | handle_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg) | ||
78 | { | ||
79 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
80 | |||
81 | const char *name = ((const char*) msg) + sizeof(*msg); | ||
82 | |||
83 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set name of handle: %s\n", name); | ||
84 | |||
85 | set_handle_name (handle, strlen(name) > 0? name : NULL); | ||
86 | } | ||
87 | |||
88 | static void | ||
89 | handle_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg) | ||
90 | { | ||
91 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
92 | |||
93 | const struct GNUNET_IDENTITY_PublicKey *pubkey = &(msg->pubkey); | ||
94 | |||
95 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set key of handle: %s\n", GNUNET_IDENTITY_public_key_to_string (pubkey)); | ||
96 | |||
97 | set_handle_key (handle, pubkey); | ||
98 | |||
99 | if (handle->identity_callback) | ||
100 | handle->identity_callback (handle->identity_cls, handle); | ||
101 | } | ||
102 | |||
103 | static void | ||
104 | handle_member_id (void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg) | ||
105 | { | ||
106 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
107 | |||
108 | const struct GNUNET_HashCode *key = &(msg->key); | ||
109 | const struct GNUNET_ShortHashCode *id = &(msg->id); | ||
110 | |||
111 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set id of handle in room: %s\n", GNUNET_h2s (key)); | ||
112 | |||
113 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
114 | |||
115 | if (room) | ||
116 | { | ||
117 | if (!room->contact_id) | ||
118 | room->contact_id = GNUNET_new(struct GNUNET_ShortHashCode); | ||
119 | |||
120 | GNUNET_memcpy(room->contact_id, id, sizeof(*id)); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | static void | ||
125 | handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
126 | { | ||
127 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
128 | |||
129 | const struct GNUNET_HashCode *key = &(msg->key); | ||
130 | |||
131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key)); | ||
132 | |||
133 | open_handle_room (handle, key); | ||
134 | } | ||
135 | |||
136 | static void | ||
137 | handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
138 | { | ||
139 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
140 | |||
141 | const struct GNUNET_PeerIdentity *door = &(msg->door); | ||
142 | const struct GNUNET_HashCode *key = &(msg->key); | ||
143 | |||
144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key)); | ||
145 | |||
146 | entry_handle_room_at (handle, door, key); | ||
147 | } | ||
148 | |||
149 | static void | ||
150 | handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg) | ||
151 | { | ||
152 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
153 | |||
154 | const struct GNUNET_HashCode *key = &(msg->key); | ||
155 | |||
156 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key)); | ||
157 | |||
158 | close_handle_room (handle, key); | ||
159 | } | ||
160 | |||
161 | static int | ||
162 | check_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) | ||
163 | { | ||
164 | const uint16_t full_length = ntohs (msg->header.size) - sizeof(msg->header); | ||
165 | |||
166 | if (full_length < sizeof(msg->hash)) | ||
167 | return GNUNET_NO; | ||
168 | |||
169 | const uint16_t length = full_length - sizeof(msg->hash); | ||
170 | const char *buffer = ((const char*) msg) + sizeof(*msg); | ||
171 | |||
172 | struct GNUNET_MESSENGER_Message message; | ||
173 | |||
174 | if (length < sizeof(message.header)) | ||
175 | return GNUNET_NO; | ||
176 | |||
177 | if (GNUNET_YES != decode_message (&message, length, buffer)) | ||
178 | return GNUNET_NO; | ||
179 | |||
180 | return GNUNET_OK; | ||
181 | } | ||
182 | |||
183 | static void | ||
184 | handle_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg) | ||
185 | { | ||
186 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
187 | |||
188 | const struct GNUNET_HashCode *key = &(msg->key); | ||
189 | const struct GNUNET_HashCode *hash = &(msg->hash); | ||
190 | |||
191 | const char *buffer = ((const char*) msg) + sizeof(*msg); | ||
192 | |||
193 | const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); | ||
194 | |||
195 | struct GNUNET_MESSENGER_Message message; | ||
196 | decode_message (&message, length, buffer); | ||
197 | |||
198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", GNUNET_MESSENGER_name_of_kind (message.header.kind)); | ||
199 | |||
200 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
201 | |||
202 | if (room) | ||
203 | { | ||
204 | handle_room_message (room, &message, hash); | ||
205 | |||
206 | if (handle->msg_callback) | ||
207 | handle->msg_callback (handle->msg_cls, room, &message, hash); | ||
208 | } | ||
209 | else | ||
210 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESSENGER ERROR: Room not found\n"); | ||
211 | } | ||
212 | |||
213 | static void | ||
214 | reconnect (struct GNUNET_MESSENGER_Handle *handle); | ||
215 | |||
216 | static void | ||
217 | send_open_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room) | ||
218 | { | ||
219 | struct GNUNET_MESSENGER_RoomMessage *msg; | ||
220 | struct GNUNET_MQ_Envelope *env; | ||
221 | |||
222 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); | ||
223 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
224 | GNUNET_MQ_send (handle->mq, env); | ||
225 | } | ||
226 | |||
227 | static void | ||
228 | send_entry_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, | ||
229 | const struct GNUNET_PeerIdentity *door) | ||
230 | { | ||
231 | struct GNUNET_MESSENGER_RoomMessage *msg; | ||
232 | struct GNUNET_MQ_Envelope *env; | ||
233 | |||
234 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); | ||
235 | GNUNET_memcpy(&(msg->door), door, sizeof(*door)); | ||
236 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
237 | GNUNET_MQ_send (handle->mq, env); | ||
238 | } | ||
239 | |||
240 | static void | ||
241 | send_close_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room) | ||
242 | { | ||
243 | struct GNUNET_MESSENGER_RoomMessage *msg; | ||
244 | struct GNUNET_MQ_Envelope *env; | ||
245 | |||
246 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); | ||
247 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
248 | GNUNET_MQ_send (handle->mq, env); | ||
249 | } | ||
250 | |||
251 | static int | ||
252 | iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
253 | { | ||
254 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
255 | struct GNUNET_MESSENGER_Room *room = value; | ||
256 | |||
257 | if (GNUNET_YES == room->opened) | ||
258 | send_open_room (handle, room); | ||
259 | |||
260 | struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head; | ||
261 | |||
262 | struct GNUNET_PeerIdentity door; | ||
263 | |||
264 | while (entry) | ||
265 | { | ||
266 | GNUNET_PEER_resolve (entry->peer, &door); | ||
267 | |||
268 | send_entry_room (handle, room, &door); | ||
269 | |||
270 | entry = entry->next; | ||
271 | } | ||
272 | |||
273 | return GNUNET_YES; | ||
274 | } | ||
275 | |||
276 | static void | ||
277 | callback_reconnect (void *cls) | ||
278 | { | ||
279 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
280 | |||
281 | handle->reconnect_task = NULL; | ||
282 | handle->reconnect_time = GNUNET_TIME_STD_BACKOFF(handle->reconnect_time) | ||
283 | ; | ||
284 | |||
285 | reconnect (handle); | ||
286 | |||
287 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_reset_room, handle); | ||
288 | } | ||
289 | |||
290 | static int | ||
291 | iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
292 | { | ||
293 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
294 | struct GNUNET_MESSENGER_Room *room = value; | ||
295 | |||
296 | send_close_room (handle, room); | ||
297 | |||
298 | return GNUNET_YES; | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | callback_mq_error (void *cls, enum GNUNET_MQ_Error error) | ||
303 | { | ||
304 | struct GNUNET_MESSENGER_Handle *handle = cls; | ||
305 | |||
306 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error); | ||
307 | |||
308 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_close_room, handle); | ||
309 | |||
310 | if (handle->mq) | ||
311 | { | ||
312 | GNUNET_MQ_destroy (handle->mq); | ||
313 | handle->mq = NULL; | ||
314 | } | ||
315 | |||
316 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time, &callback_reconnect, handle); | ||
317 | } | ||
318 | |||
319 | static void | ||
320 | reconnect (struct GNUNET_MESSENGER_Handle *handle) | ||
321 | { | ||
322 | const struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size( | ||
323 | get_name, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME, struct GNUNET_MESSENGER_NameMessage, handle), | ||
324 | GNUNET_MQ_hd_fixed_size( | ||
325 | get_key, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY, | ||
326 | struct GNUNET_MESSENGER_KeyMessage, handle), | ||
327 | GNUNET_MQ_hd_fixed_size( | ||
328 | member_id, | ||
329 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, | ||
330 | struct GNUNET_MESSENGER_MemberMessage, handle), | ||
331 | GNUNET_MQ_hd_fixed_size(room_open, | ||
332 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, | ||
333 | struct GNUNET_MESSENGER_RoomMessage, | ||
334 | handle), | ||
335 | GNUNET_MQ_hd_fixed_size(room_entry, | ||
336 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, | ||
337 | struct GNUNET_MESSENGER_RoomMessage, | ||
338 | handle), | ||
339 | GNUNET_MQ_hd_fixed_size(room_close, | ||
340 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, | ||
341 | struct GNUNET_MESSENGER_RoomMessage, | ||
342 | handle), | ||
343 | GNUNET_MQ_hd_var_size( | ||
344 | recv_message, | ||
345 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, | ||
346 | struct GNUNET_MESSENGER_RecvMessage, handle), | ||
347 | GNUNET_MQ_handler_end() }; | ||
348 | |||
349 | handle->mq = GNUNET_CLIENT_connect (handle->cfg, | ||
350 | GNUNET_MESSENGER_SERVICE_NAME, | ||
351 | handlers, &callback_mq_error, handle); | ||
352 | } | ||
353 | |||
354 | struct GNUNET_MESSENGER_Handle* | ||
355 | GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, | ||
356 | GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, | ||
357 | GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) | ||
358 | { | ||
359 | struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, identity_callback, identity_cls, msg_callback, msg_cls); | ||
360 | |||
361 | reconnect (handle); | ||
362 | |||
363 | if (handle->mq) | ||
364 | { | ||
365 | const uint16_t name_len = name ? strlen (name) : 0; | ||
366 | |||
367 | struct GNUNET_MESSENGER_CreateMessage *msg; | ||
368 | struct GNUNET_MQ_Envelope *env; | ||
369 | |||
370 | env = GNUNET_MQ_msg_extra(msg, name_len + 1, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE); | ||
371 | |||
372 | char *extra = ((char*) msg) + sizeof(*msg); | ||
373 | |||
374 | if (name_len) | ||
375 | GNUNET_memcpy(extra, name, name_len); | ||
376 | |||
377 | extra[name_len] = '\0'; | ||
378 | |||
379 | GNUNET_MQ_send (handle->mq, env); | ||
380 | return handle; | ||
381 | } | ||
382 | else | ||
383 | { | ||
384 | destroy_handle (handle); | ||
385 | return NULL; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | int | ||
390 | GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle) | ||
391 | { | ||
392 | if ((!handle) || (!get_handle_name(handle))) | ||
393 | return GNUNET_SYSERR; | ||
394 | |||
395 | struct GNUNET_MESSENGER_UpdateMessage *msg; | ||
396 | struct GNUNET_MQ_Envelope *env; | ||
397 | |||
398 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE); | ||
399 | GNUNET_MQ_send (handle->mq, env); | ||
400 | return GNUNET_OK; | ||
401 | } | ||
402 | |||
403 | void | ||
404 | GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) | ||
405 | { | ||
406 | if (!handle) | ||
407 | return; | ||
408 | |||
409 | struct GNUNET_MESSENGER_DestroyMessage *msg; | ||
410 | struct GNUNET_MQ_Envelope *env; | ||
411 | |||
412 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY); | ||
413 | GNUNET_MQ_send (handle->mq, env); | ||
414 | |||
415 | destroy_handle (handle); | ||
416 | } | ||
417 | |||
418 | const char* | ||
419 | GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle) | ||
420 | { | ||
421 | if (!handle) | ||
422 | return NULL; | ||
423 | |||
424 | return get_handle_name (handle); | ||
425 | } | ||
426 | |||
427 | int | ||
428 | GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) | ||
429 | { | ||
430 | if (!handle) | ||
431 | return GNUNET_SYSERR; | ||
432 | |||
433 | const uint16_t name_len = name ? strlen (name) : 0; | ||
434 | |||
435 | struct GNUNET_MESSENGER_NameMessage *msg; | ||
436 | struct GNUNET_MQ_Envelope *env; | ||
437 | |||
438 | env = GNUNET_MQ_msg_extra(msg, name_len + 1, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME); | ||
439 | |||
440 | char *extra = ((char*) msg) + sizeof(*msg); | ||
441 | |||
442 | if (name_len) | ||
443 | GNUNET_memcpy(extra, name, name_len); | ||
444 | |||
445 | extra[name_len] = '\0'; | ||
446 | |||
447 | GNUNET_MQ_send (handle->mq, env); | ||
448 | return GNUNET_YES; | ||
449 | } | ||
450 | |||
451 | const struct GNUNET_IDENTITY_PublicKey* | ||
452 | GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle) | ||
453 | { | ||
454 | if (!handle) | ||
455 | return NULL; | ||
456 | |||
457 | return get_handle_key (handle); | ||
458 | } | ||
459 | |||
460 | struct GNUNET_MESSENGER_Room* | ||
461 | GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | ||
462 | { | ||
463 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
464 | |||
465 | if (!room) | ||
466 | { | ||
467 | room = create_room (handle, key); | ||
468 | |||
469 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, | ||
470 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
471 | { | ||
472 | destroy_room (room); | ||
473 | return NULL; | ||
474 | } | ||
475 | } | ||
476 | |||
477 | send_open_room (handle, room); | ||
478 | return room; | ||
479 | } | ||
480 | |||
481 | struct GNUNET_MESSENGER_Room* | ||
482 | GNUNET_MESSENGER_entry_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | ||
483 | const struct GNUNET_HashCode *key) | ||
484 | { | ||
485 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
486 | |||
487 | if (!room) | ||
488 | { | ||
489 | room = create_room (handle, key); | ||
490 | |||
491 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, | ||
492 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
493 | { | ||
494 | destroy_room (room); | ||
495 | return NULL; | ||
496 | } | ||
497 | } | ||
498 | |||
499 | send_entry_room (handle, room, door); | ||
500 | return room; | ||
501 | } | ||
502 | |||
503 | void | ||
504 | GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) | ||
505 | { | ||
506 | send_close_room (room->handle, room); | ||
507 | } | ||
508 | |||
509 | struct GNUNET_MESSENGER_Contact* | ||
510 | GNUNET_MESSENGER_get_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id) | ||
511 | { | ||
512 | return GNUNET_CONTAINER_multishortmap_get (room->members, id); | ||
513 | } | ||
514 | |||
515 | const char* | ||
516 | GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact) | ||
517 | { | ||
518 | if (!contact) | ||
519 | return NULL; | ||
520 | |||
521 | return get_contact_name (contact); | ||
522 | } | ||
523 | |||
524 | const struct GNUNET_IDENTITY_PublicKey* | ||
525 | GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact) | ||
526 | { | ||
527 | if (!contact) | ||
528 | return NULL; | ||
529 | |||
530 | return get_contact_key (contact); | ||
531 | } | ||
532 | |||
533 | void | ||
534 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message) | ||
535 | { | ||
536 | const uint16_t length = get_message_size (message); | ||
537 | |||
538 | struct GNUNET_MESSENGER_SendMessage *msg; | ||
539 | struct GNUNET_MQ_Envelope *env; | ||
540 | |||
541 | env = GNUNET_MQ_msg_extra(msg, length, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE); | ||
542 | |||
543 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
544 | |||
545 | char *buffer = ((char*) msg) + sizeof(*msg); | ||
546 | encode_message (message, length, buffer); | ||
547 | |||
548 | GNUNET_MQ_send (room->handle->mq, env); | ||
549 | } | ||
550 | |||
551 | const struct GNUNET_MESSENGER_Message* | ||
552 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) | ||
553 | { | ||
554 | const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash); | ||
555 | |||
556 | if (!message) | ||
557 | { | ||
558 | struct GNUNET_MESSENGER_RecvMessage *msg; | ||
559 | struct GNUNET_MQ_Envelope *env; | ||
560 | |||
561 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); | ||
562 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key)); | ||
563 | GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash)); | ||
564 | GNUNET_MQ_send (room->handle->mq, env); | ||
565 | } | ||
566 | |||
567 | return message; | ||
568 | } | ||
diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c new file mode 100644 index 000000000..9a242aa00 --- /dev/null +++ b/src/messenger/messenger_api_contact.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_contact.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_contact.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_Contact* | ||
29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | ||
30 | { | ||
31 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); | ||
32 | |||
33 | contact->name = NULL; | ||
34 | |||
35 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | ||
36 | |||
37 | return contact; | ||
38 | } | ||
39 | |||
40 | void | ||
41 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | ||
42 | { | ||
43 | if (contact->name) | ||
44 | GNUNET_free(contact->name); | ||
45 | |||
46 | GNUNET_free(contact); | ||
47 | } | ||
48 | |||
49 | const char* | ||
50 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | ||
51 | { | ||
52 | return contact->name; | ||
53 | } | ||
54 | |||
55 | void | ||
56 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name) | ||
57 | { | ||
58 | if (contact->name) | ||
59 | GNUNET_free(contact->name); | ||
60 | |||
61 | contact->name = name? GNUNET_strdup(name) : NULL; | ||
62 | } | ||
63 | |||
64 | const struct GNUNET_IDENTITY_PublicKey* | ||
65 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | ||
66 | { | ||
67 | return &(contact->public_key); | ||
68 | } | ||
69 | |||
70 | const struct GNUNET_HashCode* | ||
71 | get_contact_id_from_key (const struct GNUNET_MESSENGER_Contact *contact) | ||
72 | { | ||
73 | static struct GNUNET_HashCode id; | ||
74 | |||
75 | GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id); | ||
76 | |||
77 | return &id; | ||
78 | } | ||
diff --git a/src/messenger/messenger_api_contact.h b/src/messenger/messenger_api_contact.h new file mode 100644 index 000000000..0673b9b85 --- /dev/null +++ b/src/messenger/messenger_api_contact.h | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_contact.h | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_CONTACT_H | ||
27 | #define GNUNET_MESSENGER_API_CONTACT_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | #include "gnunet_identity_service.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_Contact | ||
34 | { | ||
35 | char *name; | ||
36 | |||
37 | struct GNUNET_IDENTITY_PublicKey public_key; | ||
38 | }; | ||
39 | |||
40 | /** | ||
41 | * Creates and allocates a new contact with a given public <i>key</i> from an EGO. | ||
42 | * | ||
43 | * @param key Public key | ||
44 | * @return New contact | ||
45 | */ | ||
46 | struct GNUNET_MESSENGER_Contact* | ||
47 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key); | ||
48 | |||
49 | /** | ||
50 | * Destroys a contact and frees its memory fully. | ||
51 | * | ||
52 | * @param contact Contact | ||
53 | */ | ||
54 | void | ||
55 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact); | ||
56 | |||
57 | /** | ||
58 | * Returns the current name of a given <i>contact</i> or NULL if no valid name was assigned yet. | ||
59 | * | ||
60 | * @param contact Contact | ||
61 | * @return Name of the contact or NULL | ||
62 | */ | ||
63 | const char* | ||
64 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact); | ||
65 | |||
66 | /** | ||
67 | * Changes the current name of a given <i>contact</i> by copying it from the parameter <i>name</i>. | ||
68 | * | ||
69 | * @param contact Contact | ||
70 | * @param name Valid name (may not be NULL!) | ||
71 | */ | ||
72 | void | ||
73 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name); | ||
74 | |||
75 | /** | ||
76 | * Returns the public key of a given <i>contact</i>. | ||
77 | * | ||
78 | * @param contact Contact | ||
79 | * @return Public key of the contact | ||
80 | */ | ||
81 | const struct GNUNET_IDENTITY_PublicKey* | ||
82 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact); | ||
83 | |||
84 | /** | ||
85 | * Returns the resulting hashcode of the public key from a given <i>contact</i>. | ||
86 | * | ||
87 | * @param contact Contact | ||
88 | * @return Hash of the contacts public key | ||
89 | */ | ||
90 | const struct GNUNET_HashCode* | ||
91 | get_contact_id_from_key (const struct GNUNET_MESSENGER_Contact *contact); | ||
92 | |||
93 | #endif //GNUNET_MESSENGER_API_CONTACT_H | ||
diff --git a/src/messenger/messenger_api_ego.h b/src/messenger/messenger_api_ego.h new file mode 100644 index 000000000..c60eeac50 --- /dev/null +++ b/src/messenger/messenger_api_ego.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_ego.h | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_EGO_H | ||
27 | #define GNUNET_MESSENGER_API_EGO_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_identity_service.h" | ||
31 | |||
32 | struct GNUNET_MESSENGER_Ego | ||
33 | { | ||
34 | struct GNUNET_IDENTITY_PrivateKey priv; | ||
35 | struct GNUNET_IDENTITY_PublicKey pub; | ||
36 | }; | ||
37 | |||
38 | #endif //GNUNET_MESSENGER_API_EGO_H | ||
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c new file mode 100644 index 000000000..20ef77254 --- /dev/null +++ b/src/messenger/messenger_api_handle.c | |||
@@ -0,0 +1,213 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_handle.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_handle.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_Handle* | ||
29 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, | ||
30 | void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls) | ||
31 | { | ||
32 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new(struct GNUNET_MESSENGER_Handle); | ||
33 | |||
34 | handle->cfg = cfg; | ||
35 | handle->mq = NULL; | ||
36 | |||
37 | handle->identity_callback = identity_callback; | ||
38 | handle->identity_cls = identity_cls; | ||
39 | |||
40 | handle->msg_callback = msg_callback; | ||
41 | handle->msg_cls = msg_cls; | ||
42 | |||
43 | handle->name = NULL; | ||
44 | handle->pubkey = NULL; | ||
45 | |||
46 | handle->reconnect_time = GNUNET_TIME_relative_get_zero_ (); | ||
47 | handle->reconnect_task = NULL; | ||
48 | |||
49 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
50 | handle->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
51 | |||
52 | return handle; | ||
53 | } | ||
54 | |||
55 | static int | ||
56 | iterate_destroy_room (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
57 | { | ||
58 | struct GNUNET_MESSENGER_Room *room = value; | ||
59 | |||
60 | destroy_room (room); | ||
61 | |||
62 | return GNUNET_YES; | ||
63 | } | ||
64 | |||
65 | static int | ||
66 | iterate_destroy_contact (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
67 | { | ||
68 | struct GNUNET_MESSENGER_Contact *contact = value; | ||
69 | |||
70 | destroy_contact (contact); | ||
71 | |||
72 | return GNUNET_YES; | ||
73 | } | ||
74 | |||
75 | void | ||
76 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | ||
77 | { | ||
78 | if (handle->reconnect_task) | ||
79 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | ||
80 | |||
81 | if (handle->mq) | ||
82 | GNUNET_MQ_destroy (handle->mq); | ||
83 | |||
84 | if (handle->name) | ||
85 | GNUNET_free(handle->name); | ||
86 | |||
87 | if (handle->pubkey) | ||
88 | GNUNET_free(handle->pubkey); | ||
89 | |||
90 | if (handle->rooms) | ||
91 | { | ||
92 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, NULL); | ||
93 | |||
94 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); | ||
95 | } | ||
96 | |||
97 | if (handle->contacts) | ||
98 | { | ||
99 | GNUNET_CONTAINER_multihashmap_iterate (handle->contacts, iterate_destroy_contact, NULL); | ||
100 | |||
101 | GNUNET_CONTAINER_multihashmap_destroy (handle->contacts); | ||
102 | } | ||
103 | |||
104 | GNUNET_free(handle->name); | ||
105 | } | ||
106 | |||
107 | void | ||
108 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name) | ||
109 | { | ||
110 | if (handle->name) | ||
111 | GNUNET_free(handle->name); | ||
112 | |||
113 | handle->name = name? GNUNET_strdup(name) : NULL; | ||
114 | } | ||
115 | |||
116 | const char* | ||
117 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) | ||
118 | { | ||
119 | return handle->name; | ||
120 | } | ||
121 | |||
122 | void | ||
123 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
124 | { | ||
125 | if (!handle->pubkey) | ||
126 | handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); | ||
127 | |||
128 | GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey)); | ||
129 | } | ||
130 | |||
131 | const struct GNUNET_IDENTITY_PublicKey* | ||
132 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) | ||
133 | { | ||
134 | if (!handle->pubkey) | ||
135 | { | ||
136 | struct GNUNET_IDENTITY_Ego *anonymous = GNUNET_IDENTITY_ego_get_anonymous (); | ||
137 | static struct GNUNET_IDENTITY_PublicKey pubkey; | ||
138 | |||
139 | GNUNET_IDENTITY_ego_get_public_key (anonymous, &pubkey); | ||
140 | |||
141 | return &pubkey; | ||
142 | } | ||
143 | |||
144 | return handle->pubkey; | ||
145 | } | ||
146 | |||
147 | struct GNUNET_MESSENGER_Contact* | ||
148 | get_handle_contact_by_pubkey (const struct GNUNET_MESSENGER_Handle *handle, | ||
149 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
150 | { | ||
151 | struct GNUNET_HashCode hash; | ||
152 | |||
153 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | ||
154 | |||
155 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get (handle->contacts, &hash); | ||
156 | |||
157 | if (contact) | ||
158 | return contact; | ||
159 | |||
160 | contact = create_contact (pubkey); | ||
161 | |||
162 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->contacts, &hash, contact, | ||
163 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
164 | return contact; | ||
165 | |||
166 | destroy_contact (contact); | ||
167 | return NULL; | ||
168 | } | ||
169 | |||
170 | void | ||
171 | swap_handle_contact_by_pubkey (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Contact *contact, | ||
172 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | ||
173 | { | ||
174 | const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact); | ||
175 | |||
176 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->contacts, hash, contact)) | ||
177 | { | ||
178 | GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey)); | ||
179 | |||
180 | hash = get_contact_id_from_key (contact); | ||
181 | |||
182 | GNUNET_CONTAINER_multihashmap_put (handle->contacts, hash, contact, | ||
183 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | void | ||
188 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | ||
189 | { | ||
190 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
191 | |||
192 | if (room) | ||
193 | room->opened = GNUNET_YES; | ||
194 | } | ||
195 | |||
196 | void | ||
197 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | ||
198 | const struct GNUNET_HashCode *key) | ||
199 | { | ||
200 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
201 | |||
202 | if (room) | ||
203 | add_to_list_tunnels (&(room->entries), door); | ||
204 | } | ||
205 | |||
206 | void | ||
207 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | ||
208 | { | ||
209 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | ||
210 | |||
211 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) | ||
212 | destroy_room (room); | ||
213 | } | ||
diff --git a/src/messenger/messenger_api_handle.h b/src/messenger/messenger_api_handle.h new file mode 100644 index 000000000..d6cde0106 --- /dev/null +++ b/src/messenger/messenger_api_handle.h | |||
@@ -0,0 +1,174 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_handle.h | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_HANDLE_H | ||
27 | #define GNUNET_MESSENGER_API_HANDLE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_cadet_service.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | #include "gnunet_crypto_lib.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_peer_lib.h" | ||
35 | |||
36 | #include "gnunet_messenger_service.h" | ||
37 | |||
38 | #include "messenger_api_contact.h" | ||
39 | #include "messenger_api_room.h" | ||
40 | |||
41 | struct GNUNET_MESSENGER_Handle | ||
42 | { | ||
43 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
44 | |||
45 | struct GNUNET_MQ_Handle *mq; | ||
46 | |||
47 | GNUNET_MESSENGER_IdentityCallback identity_callback; | ||
48 | void *identity_cls; | ||
49 | |||
50 | GNUNET_MESSENGER_MessageCallback msg_callback; | ||
51 | void *msg_cls; | ||
52 | |||
53 | char *name; | ||
54 | struct GNUNET_IDENTITY_PublicKey *pubkey; | ||
55 | |||
56 | struct GNUNET_TIME_Relative reconnect_time; | ||
57 | struct GNUNET_SCHEDULER_Task *reconnect_task; | ||
58 | |||
59 | struct GNUNET_CONTAINER_MultiHashMap *rooms; | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * Creates and allocates a new handle using a given configuration and a custom message callback | ||
65 | * with a given closure for the client API. | ||
66 | * | ||
67 | * @param cfg Configuration | ||
68 | * @param msg_callback Message callback | ||
69 | * @param msg_cls Closure | ||
70 | * @return New handle | ||
71 | */ | ||
72 | struct GNUNET_MESSENGER_Handle* | ||
73 | create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, | ||
74 | void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls); | ||
75 | |||
76 | /** | ||
77 | * Destroys a <i>handle</i> and frees its memory fully from the client API. | ||
78 | * | ||
79 | * @param handle Handle | ||
80 | */ | ||
81 | void | ||
82 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle); | ||
83 | |||
84 | /** | ||
85 | * Sets the name of a <i>handle</i> to a specific <i>name</i>. | ||
86 | * | ||
87 | * @param handle Handle | ||
88 | * @param name New name | ||
89 | */ | ||
90 | void | ||
91 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name); | ||
92 | |||
93 | /** | ||
94 | * Returns the current name of a given <i>handle</i> or NULL if no valid name was assigned yet. | ||
95 | * | ||
96 | * @param handle Handle | ||
97 | * @return Name of the handle or NULL | ||
98 | */ | ||
99 | const char* | ||
100 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle); | ||
101 | |||
102 | /** | ||
103 | * Sets the public key of a given <i>handle</i> to a specific public key. | ||
104 | * | ||
105 | * @param handle Handle | ||
106 | * @param pubkey Public key | ||
107 | */ | ||
108 | void | ||
109 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
110 | |||
111 | /** | ||
112 | * Returns the public key of a given <i>handle</i>. | ||
113 | * | ||
114 | * @param handle Handle | ||
115 | * @return Public key of the handle | ||
116 | */ | ||
117 | const struct GNUNET_IDENTITY_PublicKey* | ||
118 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle); | ||
119 | |||
120 | /** | ||
121 | * Returns a contact known to a <i>handle</i> identified by a given public key. If not matching | ||
122 | * contact is found, NULL gets returned. | ||
123 | * | ||
124 | * @param handle Handle | ||
125 | * @param pubkey Public key of EGO | ||
126 | * @return Contact or NULL | ||
127 | */ | ||
128 | struct GNUNET_MESSENGER_Contact* | ||
129 | get_handle_contact_by_pubkey (const struct GNUNET_MESSENGER_Handle *handle, | ||
130 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
131 | |||
132 | /** | ||
133 | * Changes the public key for a <i>contact</i> known to a <i>handle</i> to a specific public key and | ||
134 | * updates local map entries to access the contact by its updated key. | ||
135 | * | ||
136 | * @param handle Handle | ||
137 | * @param contact Contact | ||
138 | * @param pubkey Public key of EGO | ||
139 | */ | ||
140 | void | ||
141 | swap_handle_contact_by_pubkey (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Contact *contact, | ||
142 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | ||
143 | |||
144 | /** | ||
145 | * Marks a room known to a <i>handle</i> identified by a given <i>key</i> as open. | ||
146 | * | ||
147 | * @param handle Handle | ||
148 | * @param key Key of room | ||
149 | */ | ||
150 | void | ||
151 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
152 | |||
153 | /** | ||
154 | * Adds a tunnel for a room known to a <i>handle</i> identified by a given <i>key</i> to a | ||
155 | * list of opened connections. | ||
156 | * | ||
157 | * @param handle Handle | ||
158 | * @param door Peer identity | ||
159 | * @param key Key of room | ||
160 | */ | ||
161 | void | ||
162 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, | ||
163 | const struct GNUNET_HashCode *key); | ||
164 | |||
165 | /** | ||
166 | * Destroys and so implicitly closes a room known to a <i>handle</i> identified by a given <i>key</i>. | ||
167 | * | ||
168 | * @param handle Handle | ||
169 | * @param key Key of room | ||
170 | */ | ||
171 | void | ||
172 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
173 | |||
174 | #endif //GNUNET_MESSENGER_API_HANDLE_H | ||
diff --git a/src/messenger/messenger_api_list_tunnels.c b/src/messenger/messenger_api_list_tunnels.c new file mode 100644 index 000000000..13d8c1906 --- /dev/null +++ b/src/messenger/messenger_api_list_tunnels.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_list_tunnels.c | ||
23 | * @brief messenger api: client and service implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_list_tunnels.h" | ||
27 | |||
28 | void | ||
29 | init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) | ||
30 | { | ||
31 | GNUNET_assert(tunnels); | ||
32 | |||
33 | tunnels->head = NULL; | ||
34 | tunnels->tail = NULL; | ||
35 | } | ||
36 | |||
37 | void | ||
38 | clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) | ||
39 | { | ||
40 | GNUNET_assert(tunnels); | ||
41 | |||
42 | struct GNUNET_MESSENGER_ListTunnel *element; | ||
43 | |||
44 | for (element = tunnels->head; element; element = tunnels->head) | ||
45 | { | ||
46 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | ||
47 | GNUNET_PEER_change_rc (element->peer, -1); | ||
48 | GNUNET_free(element); | ||
49 | } | ||
50 | |||
51 | tunnels->head = NULL; | ||
52 | tunnels->tail = NULL; | ||
53 | } | ||
54 | |||
55 | static int | ||
56 | compare_list_tunnels (void *cls, struct GNUNET_MESSENGER_ListTunnel *element0, | ||
57 | struct GNUNET_MESSENGER_ListTunnel *element1) | ||
58 | { | ||
59 | return ((int) element0->peer) - ((int) element1->peer); | ||
60 | } | ||
61 | |||
62 | void | ||
63 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer) | ||
64 | { | ||
65 | struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new(struct GNUNET_MESSENGER_ListTunnel); | ||
66 | |||
67 | element->peer = GNUNET_PEER_intern (peer); | ||
68 | |||
69 | GNUNET_CONTAINER_DLL_insert_sorted(struct GNUNET_MESSENGER_ListTunnel, compare_list_tunnels, NULL, tunnels->head, | ||
70 | tunnels->tail, element); | ||
71 | } | ||
72 | |||
73 | struct GNUNET_MESSENGER_ListTunnel* | ||
74 | find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index) | ||
75 | { | ||
76 | struct GNUNET_MESSENGER_ListTunnel *element; | ||
77 | struct GNUNET_PeerIdentity pid; | ||
78 | |||
79 | if (index) | ||
80 | *index = 0; | ||
81 | |||
82 | for (element = tunnels->head; element; element = element->next) | ||
83 | { | ||
84 | GNUNET_PEER_resolve (element->peer, &pid); | ||
85 | |||
86 | if (0 == GNUNET_memcmp(&pid, peer)) | ||
87 | return element; | ||
88 | |||
89 | if (index) | ||
90 | (*index) = (*index) + 1; | ||
91 | } | ||
92 | |||
93 | return NULL; | ||
94 | } | ||
95 | |||
96 | int | ||
97 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer) | ||
98 | { | ||
99 | return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES : GNUNET_NO; | ||
100 | } | ||
101 | |||
102 | struct GNUNET_MESSENGER_ListTunnel* | ||
103 | remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element) | ||
104 | { | ||
105 | struct GNUNET_MESSENGER_ListTunnel *next = element->next; | ||
106 | |||
107 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | ||
108 | GNUNET_PEER_change_rc (element->peer, -1); | ||
109 | GNUNET_free(element); | ||
110 | |||
111 | return next; | ||
112 | } | ||
diff --git a/src/messenger/messenger_api_list_tunnels.h b/src/messenger/messenger_api_list_tunnels.h new file mode 100644 index 000000000..0240fceb8 --- /dev/null +++ b/src/messenger/messenger_api_list_tunnels.h | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_list_tunnels.h | ||
23 | * @brief messenger api: client and service implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_LIST_TUNNELS_H | ||
27 | #define GNUNET_MESSENGER_API_LIST_TUNNELS_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_peer_lib.h" | ||
31 | #include "gnunet_container_lib.h" | ||
32 | |||
33 | struct GNUNET_MESSENGER_ListTunnel | ||
34 | { | ||
35 | struct GNUNET_MESSENGER_ListTunnel *prev; | ||
36 | struct GNUNET_MESSENGER_ListTunnel *next; | ||
37 | |||
38 | GNUNET_PEER_Id peer; | ||
39 | }; | ||
40 | |||
41 | struct GNUNET_MESSENGER_ListTunnels | ||
42 | { | ||
43 | struct GNUNET_MESSENGER_ListTunnel *head; | ||
44 | struct GNUNET_MESSENGER_ListTunnel *tail; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * Initializes list of tunnels peer identities as empty list. | ||
49 | * | ||
50 | * @param tunnels List of peer identities | ||
51 | */ | ||
52 | void | ||
53 | init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels); | ||
54 | |||
55 | /** | ||
56 | * Clears the list of tunnels peer identities. | ||
57 | * | ||
58 | * @param tunnels List of peer identities | ||
59 | */ | ||
60 | void | ||
61 | clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels); | ||
62 | |||
63 | /** | ||
64 | * Adds a specific <i>peer</i> from a tunnel to the end of the list. | ||
65 | * | ||
66 | * @param tunnels List of peer identities | ||
67 | * @param peer Peer identity of tunnel | ||
68 | */ | ||
69 | void | ||
70 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer); | ||
71 | |||
72 | /** | ||
73 | * Searches linearly through the list of tunnels peer identities for matching a | ||
74 | * specific <i>peer</i> identity and returns the matching element of the list. | ||
75 | * | ||
76 | * If no matching element is found, NULL gets returned. | ||
77 | * | ||
78 | * If <i>index</i> is not NULL, <i>index</i> will be overriden with the numeric index of | ||
79 | * the found element in the list. If no matching element is found, <i>index</i> will | ||
80 | * contain the total amount of elements in the list. | ||
81 | * | ||
82 | * @param tunnels List of peer identities | ||
83 | * @param peer Peer identity of tunnel | ||
84 | * @param[out] index Index of found element (optional) | ||
85 | * @return Element in the list with matching peer identity | ||
86 | */ | ||
87 | struct GNUNET_MESSENGER_ListTunnel* | ||
88 | find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index); | ||
89 | |||
90 | /** | ||
91 | * Tests linearly if the list of tunnels peer identities contains a specific | ||
92 | * <i>peer</i> identity and returns GNUNET_YES on success, otherwise GNUNET_NO. | ||
93 | * | ||
94 | * @param tunnels List of peer identities | ||
95 | * @param peer Peer identity of tunnel | ||
96 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
97 | */ | ||
98 | int | ||
99 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer); | ||
100 | |||
101 | /** | ||
102 | * Removes a specific <i>element</i> from the list of tunnels peer identities and returns | ||
103 | * the next element in the list. | ||
104 | * | ||
105 | * @param tunnels List of peer identities | ||
106 | * @param element Element of the list | ||
107 | * @return Next element in the list | ||
108 | */ | ||
109 | struct GNUNET_MESSENGER_ListTunnel* | ||
110 | remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element); | ||
111 | |||
112 | #endif //GNUNET_MESSENGER_API_LIST_TUNNELS_H | ||
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c new file mode 100644 index 000000000..fdab60eef --- /dev/null +++ b/src/messenger/messenger_api_message.c | |||
@@ -0,0 +1,602 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_message.c | ||
23 | * @brief messenger api: client and service implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_message.h" | ||
27 | |||
28 | struct GNUNET_MESSENGER_MessageSignature | ||
29 | { | ||
30 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
31 | struct GNUNET_HashCode hash; | ||
32 | }; | ||
33 | |||
34 | struct GNUNET_MESSENGER_ShortMessage | ||
35 | { | ||
36 | enum GNUNET_MESSENGER_MessageKind kind; | ||
37 | struct GNUNET_MESSENGER_MessageBody body; | ||
38 | }; | ||
39 | |||
40 | struct GNUNET_MESSENGER_Message* | ||
41 | create_message (enum GNUNET_MESSENGER_MessageKind kind) | ||
42 | { | ||
43 | struct GNUNET_MESSENGER_Message *message = GNUNET_new(struct GNUNET_MESSENGER_Message); | ||
44 | |||
45 | message->header.kind = kind; | ||
46 | |||
47 | switch (message->header.kind) | ||
48 | { | ||
49 | case GNUNET_MESSENGER_KIND_NAME: | ||
50 | message->body.name.name = NULL; | ||
51 | break; | ||
52 | case GNUNET_MESSENGER_KIND_TEXT: | ||
53 | message->body.text.text = NULL; | ||
54 | break; | ||
55 | case GNUNET_MESSENGER_KIND_FILE: | ||
56 | message->body.file.uri = NULL; | ||
57 | break; | ||
58 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
59 | message->body.private.length = 0; | ||
60 | message->body.private.data = NULL; | ||
61 | break; | ||
62 | default: | ||
63 | break; | ||
64 | } | ||
65 | |||
66 | return message; | ||
67 | } | ||
68 | |||
69 | struct GNUNET_MESSENGER_Message* | ||
70 | copy_message (const struct GNUNET_MESSENGER_Message *message) | ||
71 | { | ||
72 | struct GNUNET_MESSENGER_Message *copy = GNUNET_new(struct GNUNET_MESSENGER_Message); | ||
73 | |||
74 | GNUNET_memcpy(copy, message, sizeof(struct GNUNET_MESSENGER_Message)); | ||
75 | |||
76 | switch (message->header.kind) | ||
77 | { | ||
78 | case GNUNET_MESSENGER_KIND_NAME: | ||
79 | copy->body.name.name = GNUNET_strdup(message->body.name.name); | ||
80 | break; | ||
81 | case GNUNET_MESSENGER_KIND_TEXT: | ||
82 | copy->body.text.text = GNUNET_strdup(message->body.text.text); | ||
83 | break; | ||
84 | case GNUNET_MESSENGER_KIND_FILE: | ||
85 | copy->body.file.uri = GNUNET_strdup(message->body.file.uri); | ||
86 | break; | ||
87 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
88 | copy->body.private.data = copy->body.private.length ? GNUNET_malloc(copy->body.private.length) : NULL; | ||
89 | |||
90 | if (copy->body.private.data) | ||
91 | { | ||
92 | GNUNET_memcpy(copy->body.private.data, message->body.private.data, copy->body.private.length); | ||
93 | } | ||
94 | |||
95 | break; | ||
96 | default: | ||
97 | break; | ||
98 | } | ||
99 | |||
100 | return copy; | ||
101 | } | ||
102 | |||
103 | static void | ||
104 | destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body) | ||
105 | { | ||
106 | switch (kind) | ||
107 | { | ||
108 | case GNUNET_MESSENGER_KIND_NAME: | ||
109 | GNUNET_free(body->name.name); | ||
110 | break; | ||
111 | case GNUNET_MESSENGER_KIND_TEXT: | ||
112 | GNUNET_free(body->text.text); | ||
113 | break; | ||
114 | case GNUNET_MESSENGER_KIND_FILE: | ||
115 | GNUNET_free(body->file.uri); | ||
116 | break; | ||
117 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
118 | GNUNET_free(body->private.data); | ||
119 | break; | ||
120 | default: | ||
121 | break; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | void | ||
126 | destroy_message (struct GNUNET_MESSENGER_Message *message) | ||
127 | { | ||
128 | destroy_message_body (message->header.kind, &(message->body)); | ||
129 | |||
130 | GNUNET_free(message); | ||
131 | } | ||
132 | |||
133 | static void | ||
134 | fold_short_message (const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened) | ||
135 | { | ||
136 | shortened->kind = message->header.kind; | ||
137 | |||
138 | GNUNET_memcpy(&(shortened->body), &(message->body), sizeof(struct GNUNET_MESSENGER_MessageBody)); | ||
139 | } | ||
140 | |||
141 | static void | ||
142 | unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message) | ||
143 | { | ||
144 | destroy_message_body (message->header.kind, &(message->body)); | ||
145 | |||
146 | message->header.kind = shortened->kind; | ||
147 | |||
148 | GNUNET_memcpy(&(message->body), &(shortened->body), sizeof(struct GNUNET_MESSENGER_MessageBody)); | ||
149 | } | ||
150 | |||
151 | #define member_size(type, member) sizeof(((type*) NULL)->member) | ||
152 | |||
153 | static uint16_t | ||
154 | get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | ||
155 | { | ||
156 | uint16_t length = 0; | ||
157 | |||
158 | switch (kind) | ||
159 | { | ||
160 | case GNUNET_MESSENGER_KIND_INFO: | ||
161 | length += member_size(struct GNUNET_MESSENGER_Message, body.info.host_key); | ||
162 | length += member_size(struct GNUNET_MESSENGER_Message, body.info.unique_id); | ||
163 | break; | ||
164 | case GNUNET_MESSENGER_KIND_JOIN: | ||
165 | length += member_size(struct GNUNET_MESSENGER_Message, body.join.key); | ||
166 | break; | ||
167 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
168 | break; | ||
169 | case GNUNET_MESSENGER_KIND_NAME: | ||
170 | break; | ||
171 | case GNUNET_MESSENGER_KIND_KEY: | ||
172 | length += member_size(struct GNUNET_MESSENGER_Message, body.key.key); | ||
173 | break; | ||
174 | case GNUNET_MESSENGER_KIND_PEER: | ||
175 | length += member_size(struct GNUNET_MESSENGER_Message, body.peer.peer); | ||
176 | break; | ||
177 | case GNUNET_MESSENGER_KIND_ID: | ||
178 | length += member_size(struct GNUNET_MESSENGER_Message, body.id.id); | ||
179 | break; | ||
180 | case GNUNET_MESSENGER_KIND_MISS: | ||
181 | length += member_size(struct GNUNET_MESSENGER_Message, body.miss.peer); | ||
182 | break; | ||
183 | case GNUNET_MESSENGER_KIND_MERGE: | ||
184 | length += member_size(struct GNUNET_MESSENGER_Message, body.merge.previous); | ||
185 | break; | ||
186 | case GNUNET_MESSENGER_KIND_REQUEST: | ||
187 | length += member_size(struct GNUNET_MESSENGER_Message, body.request.hash); | ||
188 | break; | ||
189 | case GNUNET_MESSENGER_KIND_INVITE: | ||
190 | length += member_size(struct GNUNET_MESSENGER_Message, body.invite.door); | ||
191 | length += member_size(struct GNUNET_MESSENGER_Message, body.invite.key); | ||
192 | break; | ||
193 | case GNUNET_MESSENGER_KIND_TEXT: | ||
194 | break; | ||
195 | case GNUNET_MESSENGER_KIND_FILE: | ||
196 | length += member_size(struct GNUNET_MESSENGER_Message, body.file.key); | ||
197 | length += member_size(struct GNUNET_MESSENGER_Message, body.file.hash); | ||
198 | length += NAME_MAX; | ||
199 | break; | ||
200 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
201 | length += member_size(struct GNUNET_MESSENGER_Message, body.private.key); | ||
202 | break; | ||
203 | default: | ||
204 | break; | ||
205 | } | ||
206 | |||
207 | return length; | ||
208 | } | ||
209 | |||
210 | uint16_t | ||
211 | get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | ||
212 | { | ||
213 | uint16_t length = 0; | ||
214 | |||
215 | length += member_size(struct GNUNET_MESSENGER_Message, header.signature); | ||
216 | length += member_size(struct GNUNET_MESSENGER_Message, header.timestamp); | ||
217 | length += member_size(struct GNUNET_MESSENGER_Message, header.sender_id); | ||
218 | length += member_size(struct GNUNET_MESSENGER_Message, header.previous); | ||
219 | length += member_size(struct GNUNET_MESSENGER_Message, header.kind); | ||
220 | |||
221 | return length + get_message_body_kind_size (kind); | ||
222 | } | ||
223 | |||
224 | static uint16_t | ||
225 | get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body) | ||
226 | { | ||
227 | uint16_t length = 0; | ||
228 | |||
229 | switch (kind) | ||
230 | { | ||
231 | case GNUNET_MESSENGER_KIND_NAME: | ||
232 | length += (body->name.name? strlen (body->name.name) : 0); | ||
233 | break; | ||
234 | case GNUNET_MESSENGER_KIND_TEXT: | ||
235 | length += strlen (body->text.text); | ||
236 | break; | ||
237 | case GNUNET_MESSENGER_KIND_FILE: | ||
238 | length += strlen (body->file.uri); | ||
239 | break; | ||
240 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
241 | length += body->private.length; | ||
242 | break; | ||
243 | default: | ||
244 | break; | ||
245 | } | ||
246 | |||
247 | return length; | ||
248 | } | ||
249 | |||
250 | uint16_t | ||
251 | get_message_size (const struct GNUNET_MESSENGER_Message *message) | ||
252 | { | ||
253 | return get_message_kind_size (message->header.kind) + get_message_body_size (message->header.kind, &(message->body)); | ||
254 | } | ||
255 | |||
256 | static uint16_t | ||
257 | get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message) | ||
258 | { | ||
259 | if (message) | ||
260 | return sizeof(message->kind) + get_message_body_kind_size (message->kind) | ||
261 | + get_message_body_size (message->kind, &(message->body)); | ||
262 | else | ||
263 | return sizeof(message->kind); | ||
264 | } | ||
265 | |||
266 | #define min(x, y) (x < y? x : y) | ||
267 | |||
268 | #define encode_step_ext(dst, offset, src, size) do { \ | ||
269 | GNUNET_memcpy(dst + offset, src, size); \ | ||
270 | offset += size; \ | ||
271 | } while (0) | ||
272 | |||
273 | #define encode_step(dst, offset, src) do { \ | ||
274 | encode_step_ext(dst, offset, src, sizeof(*src)); \ | ||
275 | } while(0) | ||
276 | |||
277 | static void | ||
278 | encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, | ||
279 | uint16_t length, char *buffer, uint16_t offset) | ||
280 | { | ||
281 | switch (kind) | ||
282 | { | ||
283 | case GNUNET_MESSENGER_KIND_INFO: | ||
284 | encode_step(buffer, offset, &(body->info.host_key)); | ||
285 | encode_step(buffer, offset, &(body->info.unique_id)); | ||
286 | break; | ||
287 | case GNUNET_MESSENGER_KIND_JOIN: | ||
288 | encode_step(buffer, offset, &(body->join.key)); | ||
289 | break; | ||
290 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
291 | break; | ||
292 | case GNUNET_MESSENGER_KIND_NAME: | ||
293 | if (body->name.name) | ||
294 | encode_step_ext(buffer, offset, body->name.name, min(length - offset, strlen(body->name.name))); | ||
295 | break; | ||
296 | case GNUNET_MESSENGER_KIND_KEY: | ||
297 | encode_step(buffer, offset, &(body->key.key)); | ||
298 | break; | ||
299 | case GNUNET_MESSENGER_KIND_PEER: | ||
300 | encode_step(buffer, offset, &(body->peer.peer)); | ||
301 | break; | ||
302 | case GNUNET_MESSENGER_KIND_ID: | ||
303 | encode_step(buffer, offset, &(body->id.id)); | ||
304 | break; | ||
305 | case GNUNET_MESSENGER_KIND_MISS: | ||
306 | encode_step(buffer, offset, &(body->miss.peer)); | ||
307 | break; | ||
308 | case GNUNET_MESSENGER_KIND_MERGE: | ||
309 | encode_step(buffer, offset, &(body->merge.previous)); | ||
310 | break; | ||
311 | case GNUNET_MESSENGER_KIND_REQUEST: | ||
312 | encode_step(buffer, offset, &(body->request.hash)); | ||
313 | break; | ||
314 | case GNUNET_MESSENGER_KIND_INVITE: | ||
315 | encode_step(buffer, offset, &(body->invite.door)); | ||
316 | encode_step(buffer, offset, &(body->invite.key)); | ||
317 | break; | ||
318 | case GNUNET_MESSENGER_KIND_TEXT: | ||
319 | encode_step_ext(buffer, offset, body->text.text, min(length - offset, strlen(body->text.text))); | ||
320 | break; | ||
321 | case GNUNET_MESSENGER_KIND_FILE: | ||
322 | encode_step(buffer, offset, &(body->file.key)); | ||
323 | encode_step(buffer, offset, &(body->file.hash)); | ||
324 | encode_step_ext(buffer, offset, body->file.name, NAME_MAX); | ||
325 | encode_step_ext(buffer, offset, body->file.uri, min(length - offset, strlen(body->file.uri))); | ||
326 | break; | ||
327 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
328 | encode_step(buffer, offset, &(body->private.key)); | ||
329 | encode_step_ext(buffer, offset, body->private.data, min(length - offset, body->private.length)); | ||
330 | break; | ||
331 | default: | ||
332 | break; | ||
333 | } | ||
334 | } | ||
335 | |||
336 | void | ||
337 | encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer) | ||
338 | { | ||
339 | uint16_t offset = 0; | ||
340 | |||
341 | encode_step(buffer, offset, &(message->header.signature)); | ||
342 | encode_step(buffer, offset, &(message->header.timestamp)); | ||
343 | encode_step(buffer, offset, &(message->header.sender_id)); | ||
344 | encode_step(buffer, offset, &(message->header.previous)); | ||
345 | encode_step(buffer, offset, &(message->header.kind)); | ||
346 | |||
347 | encode_message_body (message->header.kind, &(message->body), length, buffer, offset); | ||
348 | } | ||
349 | |||
350 | static void | ||
351 | encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer) | ||
352 | { | ||
353 | uint16_t offset = 0; | ||
354 | |||
355 | encode_step(buffer, offset, &(message->kind)); | ||
356 | |||
357 | encode_message_body (message->kind, &(message->body), length, buffer, offset); | ||
358 | } | ||
359 | |||
360 | #define decode_step_ext(src, offset, dst, size) do { \ | ||
361 | GNUNET_memcpy(dst, src + offset, size); \ | ||
362 | offset += size; \ | ||
363 | } while (0) | ||
364 | |||
365 | #define decode_step(src, offset, dst) do { \ | ||
366 | decode_step_ext(src, offset, dst, sizeof(*dst)); \ | ||
367 | } while (0) | ||
368 | |||
369 | #define decode_step_malloc(src, offset, dst, size, zero) do { \ | ||
370 | dst = GNUNET_malloc(size + zero); \ | ||
371 | if (zero) dst[size] = 0; \ | ||
372 | decode_step_ext(src, offset, dst, size); \ | ||
373 | } while (0) | ||
374 | |||
375 | static void | ||
376 | decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, | ||
377 | uint16_t length, const char *buffer, uint16_t offset) | ||
378 | { | ||
379 | switch (*kind) | ||
380 | { | ||
381 | case GNUNET_MESSENGER_KIND_INFO: | ||
382 | decode_step(buffer, offset, &(body->info.host_key)); | ||
383 | decode_step(buffer, offset, &(body->info.unique_id)); | ||
384 | break; | ||
385 | case GNUNET_MESSENGER_KIND_JOIN: | ||
386 | decode_step(buffer, offset, &(body->join.key)); | ||
387 | break; | ||
388 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
389 | break; | ||
390 | case GNUNET_MESSENGER_KIND_NAME: | ||
391 | if (length - offset > 0) | ||
392 | decode_step_malloc(buffer, offset, body->name.name, length - offset, 1); | ||
393 | else | ||
394 | body->name.name = NULL; | ||
395 | break; | ||
396 | case GNUNET_MESSENGER_KIND_KEY: | ||
397 | decode_step(buffer, offset, &(body->key.key)); | ||
398 | break; | ||
399 | case GNUNET_MESSENGER_KIND_PEER: | ||
400 | decode_step(buffer, offset, &(body->peer.peer)); | ||
401 | break; | ||
402 | case GNUNET_MESSENGER_KIND_ID: | ||
403 | decode_step(buffer, offset, &(body->id.id)); | ||
404 | break; | ||
405 | case GNUNET_MESSENGER_KIND_MISS: | ||
406 | decode_step(buffer, offset, &(body->miss.peer)); | ||
407 | break; | ||
408 | case GNUNET_MESSENGER_KIND_MERGE: | ||
409 | decode_step(buffer, offset, &(body->merge.previous)); | ||
410 | break; | ||
411 | case GNUNET_MESSENGER_KIND_REQUEST: | ||
412 | decode_step(buffer, offset, &(body->request.hash)); | ||
413 | break; | ||
414 | case GNUNET_MESSENGER_KIND_INVITE: | ||
415 | decode_step(buffer, offset, &(body->invite.door)); | ||
416 | decode_step(buffer, offset, &(body->invite.key)); | ||
417 | break; | ||
418 | case GNUNET_MESSENGER_KIND_TEXT: | ||
419 | decode_step_malloc(buffer, offset, body->text.text, length - offset, 1); | ||
420 | break; | ||
421 | case GNUNET_MESSENGER_KIND_FILE: | ||
422 | decode_step(buffer, offset, &(body->file.key)); | ||
423 | decode_step(buffer, offset, &(body->file.hash)); | ||
424 | decode_step_ext(buffer, offset, body->file.name, NAME_MAX); | ||
425 | decode_step_malloc(buffer, offset, body->file.uri, length - offset, 1); | ||
426 | break; | ||
427 | case GNUNET_MESSENGER_KIND_PRIVATE: | ||
428 | decode_step(buffer, offset, &(body->private.key)); | ||
429 | |||
430 | body->private.length = (length - offset); | ||
431 | decode_step_malloc(buffer, offset, body->private.data, length - offset, 0); | ||
432 | break; | ||
433 | default: | ||
434 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; | ||
435 | break; | ||
436 | } | ||
437 | } | ||
438 | |||
439 | int | ||
440 | decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer) | ||
441 | { | ||
442 | uint16_t offset = 0; | ||
443 | |||
444 | if (length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN)) | ||
445 | return GNUNET_NO; | ||
446 | |||
447 | decode_step(buffer, offset, &(message->header.signature)); | ||
448 | decode_step(buffer, offset, &(message->header.timestamp)); | ||
449 | decode_step(buffer, offset, &(message->header.sender_id)); | ||
450 | decode_step(buffer, offset, &(message->header.previous)); | ||
451 | decode_step(buffer, offset, &(message->header.kind)); | ||
452 | |||
453 | if (length < get_message_kind_size (message->header.kind)) | ||
454 | return GNUNET_NO; | ||
455 | |||
456 | decode_message_body (&(message->header.kind), &(message->body), length, buffer, offset); | ||
457 | |||
458 | return GNUNET_YES; | ||
459 | } | ||
460 | |||
461 | static int | ||
462 | decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer) | ||
463 | { | ||
464 | uint16_t offset = 0; | ||
465 | |||
466 | if (length < get_short_message_size (NULL)) | ||
467 | return GNUNET_NO; | ||
468 | |||
469 | decode_step(buffer, offset, &(message->kind)); | ||
470 | |||
471 | if (length < get_short_message_size (message)) | ||
472 | return GNUNET_NO; | ||
473 | |||
474 | decode_message_body (&(message->kind), &(message->body), length, buffer, offset); | ||
475 | |||
476 | return GNUNET_YES; | ||
477 | } | ||
478 | |||
479 | void | ||
480 | hash_message (uint16_t length, const char *buffer, struct GNUNET_HashCode *hash) | ||
481 | { | ||
482 | GNUNET_CRYPTO_hash (buffer + sizeof(struct GNUNET_CRYPTO_EcdsaSignature), | ||
483 | length - sizeof(struct GNUNET_CRYPTO_EcdsaSignature), hash); | ||
484 | } | ||
485 | |||
486 | void | ||
487 | sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, | ||
488 | const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego) | ||
489 | { | ||
490 | struct GNUNET_MESSENGER_MessageSignature signature; | ||
491 | |||
492 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | ||
493 | signature.purpose.size = htonl (sizeof(signature)); | ||
494 | |||
495 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | ||
496 | |||
497 | GNUNET_IDENTITY_sign(&(ego->priv), &signature, &(message->header.signature)); | ||
498 | GNUNET_memcpy(buffer, &(message->header.signature), sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | ||
499 | } | ||
500 | |||
501 | int | ||
502 | verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, | ||
503 | const struct GNUNET_IDENTITY_PublicKey *key) | ||
504 | { | ||
505 | struct GNUNET_MESSENGER_MessageSignature signature; | ||
506 | |||
507 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | ||
508 | signature.purpose.size = htonl (sizeof(signature)); | ||
509 | |||
510 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | ||
511 | |||
512 | return GNUNET_IDENTITY_signature_verify(GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature, | ||
513 | &(message->header.signature), key); | ||
514 | } | ||
515 | |||
516 | int | ||
517 | encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key) | ||
518 | { | ||
519 | struct GNUNET_MESSENGER_ShortMessage shortened; | ||
520 | |||
521 | fold_short_message (message, &shortened); | ||
522 | |||
523 | const uint16_t length = get_short_message_size (&shortened); | ||
524 | |||
525 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; | ||
526 | message->body.private.data = GNUNET_malloc(length); | ||
527 | |||
528 | encode_short_message (&shortened, length, message->body.private.data); | ||
529 | |||
530 | if (GNUNET_IDENTITY_encrypt (message->body.private.data, length, key, &(message->body.private.key), | ||
531 | message->body.private.data) | ||
532 | == length) | ||
533 | { | ||
534 | destroy_message_body (shortened.kind, &(shortened.body)); | ||
535 | return GNUNET_YES; | ||
536 | } | ||
537 | else | ||
538 | { | ||
539 | unfold_short_message (&shortened, message); | ||
540 | return GNUNET_NO; | ||
541 | } | ||
542 | } | ||
543 | |||
544 | int | ||
545 | decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key) | ||
546 | { | ||
547 | if (message->body.private.length != GNUNET_IDENTITY_decrypt (message->body.private.data, | ||
548 | message->body.private.length, key, | ||
549 | &(message->body.private.key), | ||
550 | message->body.private.data)) | ||
551 | return GNUNET_NO; | ||
552 | |||
553 | struct GNUNET_MESSENGER_ShortMessage shortened; | ||
554 | |||
555 | if (GNUNET_YES != decode_short_message (&shortened, message->body.private.length, message->body.private.data)) | ||
556 | return GNUNET_NO; | ||
557 | |||
558 | unfold_short_message (&shortened, message); | ||
559 | return GNUNET_YES; | ||
560 | } | ||
561 | |||
562 | struct GNUNET_MQ_Envelope* | ||
563 | pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, | ||
564 | const struct GNUNET_MESSENGER_Ego *ego, int mode) | ||
565 | { | ||
566 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Packing message: %u\n", message->header.kind); | ||
567 | |||
568 | struct GNUNET_MessageHeader *header; | ||
569 | |||
570 | uint16_t length = get_message_size (message); | ||
571 | |||
572 | struct GNUNET_MQ_Envelope *env; | ||
573 | char *buffer; | ||
574 | |||
575 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE == mode) | ||
576 | { | ||
577 | env = GNUNET_MQ_msg_extra(header, length, GNUNET_MESSAGE_TYPE_CADET_CLI); | ||
578 | |||
579 | buffer = (char*) &(header[1]); | ||
580 | } | ||
581 | else | ||
582 | { | ||
583 | env = NULL; | ||
584 | |||
585 | buffer = GNUNET_malloc(length); | ||
586 | } | ||
587 | |||
588 | encode_message (message, length, buffer); | ||
589 | |||
590 | if (hash) | ||
591 | { | ||
592 | hash_message (length, buffer, hash); | ||
593 | |||
594 | if (ego) | ||
595 | sign_message (message, length, buffer, hash, ego); | ||
596 | } | ||
597 | |||
598 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE != mode) | ||
599 | GNUNET_free(buffer); | ||
600 | |||
601 | return env; | ||
602 | } | ||
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h new file mode 100644 index 000000000..0f0a97e9c --- /dev/null +++ b/src/messenger/messenger_api_message.h | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_message.h | ||
23 | * @brief messenger api: client and service implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_MESSAGE_H | ||
27 | #define GNUNET_MESSENGER_API_MESSAGE_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_crypto_lib.h" | ||
31 | #include "gnunet_identity_service.h" | ||
32 | #include "gnunet_mq_lib.h" | ||
33 | #include "gnunet_signatures.h" | ||
34 | |||
35 | #include "gnunet_messenger_service.h" | ||
36 | |||
37 | #include "messenger_api_ego.h" | ||
38 | |||
39 | /** | ||
40 | * Creates and allocates a new message with a specific <i>kind</i>. | ||
41 | * | ||
42 | * @param kind Kind of message | ||
43 | * @return New message | ||
44 | */ | ||
45 | struct GNUNET_MESSENGER_Message* | ||
46 | create_message (enum GNUNET_MESSENGER_MessageKind kind); | ||
47 | |||
48 | /** | ||
49 | * Creates and allocates a copy of a given <i>message</i>. | ||
50 | * | ||
51 | * @param message Message | ||
52 | * @return New message | ||
53 | */ | ||
54 | struct GNUNET_MESSENGER_Message* | ||
55 | copy_message (const struct GNUNET_MESSENGER_Message *message); | ||
56 | |||
57 | /** | ||
58 | * Destroys a message and frees its memory fully. | ||
59 | * | ||
60 | * @param message Message | ||
61 | */ | ||
62 | void | ||
63 | destroy_message (struct GNUNET_MESSENGER_Message *message); | ||
64 | |||
65 | /** | ||
66 | * Returns the minimal size in bytes to encode a message of a specific <i>kind</i>. | ||
67 | * | ||
68 | * @param kind Kind of message | ||
69 | * @return Minimal size to encode | ||
70 | */ | ||
71 | uint16_t | ||
72 | get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind); | ||
73 | |||
74 | /** | ||
75 | * Returns the exact size in bytes to encode a given <i>message</i>. | ||
76 | * | ||
77 | * @param message Message | ||
78 | * @return Size to encode | ||
79 | */ | ||
80 | uint16_t | ||
81 | get_message_size (const struct GNUNET_MESSENGER_Message *message); | ||
82 | |||
83 | /** | ||
84 | * Encodes a given <i>message</i> into a <i>buffer</i> of a maximal <i>length</i> in bytes. | ||
85 | * | ||
86 | * @param message Message | ||
87 | * @param length Maximal length to encode | ||
88 | * @param[out] buffer Buffer | ||
89 | */ | ||
90 | void | ||
91 | encode_message (const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer); | ||
92 | |||
93 | /** | ||
94 | * Decodes a <i>message</i> from a given <i>buffer</i> of a maximal <i>length</i> in bytes. | ||
95 | * | ||
96 | * If the buffer is too small for a message of its decoded kind the function fails with | ||
97 | * resulting GNUNET_NO after decoding only the messages header. | ||
98 | * | ||
99 | * On success the function returns GNUNET_YES. | ||
100 | * | ||
101 | * @param[out] message Message | ||
102 | * @param length Maximal length to decode | ||
103 | * @param buffer Buffer | ||
104 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
105 | */ | ||
106 | int | ||
107 | decode_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer); | ||
108 | |||
109 | /** | ||
110 | * Calculates a <i>hash</i> of a given <i>buffer</i> of a <i>length</i> in bytes. | ||
111 | * | ||
112 | * @param length Length of buffer | ||
113 | * @param buffer Buffer | ||
114 | * @param[out] hash Hash | ||
115 | */ | ||
116 | void | ||
117 | hash_message (uint16_t length, const char *buffer, struct GNUNET_HashCode *hash); | ||
118 | |||
119 | /** | ||
120 | * Signs the <i>hash</i> of a <i>message</i> with a given <i>ego</i> and writes the signature | ||
121 | * into the <i>buffer</i> as well. | ||
122 | * | ||
123 | * @param[out] message Message | ||
124 | * @param length Length of buffer | ||
125 | * @param[out] buffer Buffer | ||
126 | * @param hash Hash of message | ||
127 | * @param ego EGO | ||
128 | */ | ||
129 | void | ||
130 | sign_message (struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, | ||
131 | const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Ego *ego); | ||
132 | |||
133 | /** | ||
134 | * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific | ||
135 | * public key. The function returns GNUNET_OK if the signature was valid, otherwise | ||
136 | * GNUNET_SYSERR. | ||
137 | * | ||
138 | * @param message Message | ||
139 | * @param hash Hash of message | ||
140 | * @param key Public key of EGO | ||
141 | * @return GNUNET_OK on success, otherwise GNUNET_SYSERR | ||
142 | */ | ||
143 | int | ||
144 | verify_message (const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, | ||
145 | const struct GNUNET_IDENTITY_PublicKey *key); | ||
146 | |||
147 | /** | ||
148 | * Encrypts a <i>message</i> using a given public <i>key</i> and replaces its body | ||
149 | * and kind with the now private encrypted <i>message</i>. The function returns | ||
150 | * GNUNET_YES if the operation succeeded, otherwise GNUNET_NO. | ||
151 | * | ||
152 | * @param message Message | ||
153 | * @param key Public key of EGO | ||
154 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
155 | */ | ||
156 | int | ||
157 | encrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PublicKey *key); | ||
158 | |||
159 | /** | ||
160 | * Decrypts a private <i>message</i> using a given private <i>key</i> and replaces its body | ||
161 | * and kind with the inner encrypted message. The function returns GNUNET_YES if the | ||
162 | * operation succeeded, otherwise GNUNET_NO. | ||
163 | * | ||
164 | * @param message Message | ||
165 | * @param key Private key of EGO | ||
166 | * @return GNUNET_YES on success, otherwise GNUNET_NO | ||
167 | */ | ||
168 | int | ||
169 | decrypt_message (struct GNUNET_MESSENGER_Message *message, const struct GNUNET_IDENTITY_PrivateKey *key); | ||
170 | |||
171 | #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 | ||
172 | #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 | ||
173 | |||
174 | /** | ||
175 | * Encodes the <i>message</i> to pack it into a newly allocated envelope if <i>mode</i> | ||
176 | * is equal to GNUNET_MESSENGER_PACK_MODE_ENVELOPE. Independent of the mode the message | ||
177 | * will be hashed if <i>hash</i> is not NULL and it will be signed if the <i>ego</i> is | ||
178 | * not NULL. | ||
179 | * | ||
180 | * @param[out] message Message | ||
181 | * @param[out] hash Hash of message | ||
182 | * @param ego EGO to sign | ||
183 | * @param mode Mode of packing | ||
184 | * @return Envelope or NULL | ||
185 | */ | ||
186 | struct GNUNET_MQ_Envelope* | ||
187 | pack_message (struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, | ||
188 | const struct GNUNET_MESSENGER_Ego *ego, int mode); | ||
189 | |||
190 | #endif //GNUNET_MESSENGER_API_MESSAGE_H | ||
diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c new file mode 100644 index 000000000..5fedf1a78 --- /dev/null +++ b/src/messenger/messenger_api_room.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_room.c | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_room.h" | ||
27 | |||
28 | #include "messenger_api_handle.h" | ||
29 | |||
30 | struct GNUNET_MESSENGER_Room* | ||
31 | create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key) | ||
32 | { | ||
33 | struct GNUNET_MESSENGER_Room *room = GNUNET_new(struct GNUNET_MESSENGER_Room); | ||
34 | |||
35 | room->handle = handle; | ||
36 | GNUNET_memcpy(&(room->key), key, sizeof(*key)); | ||
37 | |||
38 | room->opened = GNUNET_NO; | ||
39 | room->contact_id = NULL; | ||
40 | |||
41 | room->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); | ||
42 | |||
43 | init_list_tunnels (&(room->entries)); | ||
44 | |||
45 | room->messages = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | ||
46 | |||
47 | return room; | ||
48 | } | ||
49 | |||
50 | static int | ||
51 | iterate_destroy_message (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
52 | { | ||
53 | struct GNUNET_MESSENGER_Message *message = value; | ||
54 | |||
55 | destroy_message (message); | ||
56 | |||
57 | return GNUNET_YES; | ||
58 | } | ||
59 | |||
60 | void | ||
61 | destroy_room (struct GNUNET_MESSENGER_Room *room) | ||
62 | { | ||
63 | if (room->members) | ||
64 | GNUNET_CONTAINER_multishortmap_destroy (room->members); | ||
65 | |||
66 | clear_list_tunnels (&(room->entries)); | ||
67 | |||
68 | if (room->messages) | ||
69 | { | ||
70 | GNUNET_CONTAINER_multihashmap_iterate (room->messages, iterate_destroy_message, NULL); | ||
71 | |||
72 | GNUNET_CONTAINER_multihashmap_destroy (room->messages); | ||
73 | } | ||
74 | |||
75 | if (room->contact_id) | ||
76 | GNUNET_free(room->contact_id); | ||
77 | |||
78 | GNUNET_free(room); | ||
79 | } | ||
80 | |||
81 | const struct GNUNET_MESSENGER_Message* | ||
82 | get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash) | ||
83 | { | ||
84 | return GNUNET_CONTAINER_multihashmap_get (room->messages, hash); | ||
85 | } | ||
86 | |||
87 | static void | ||
88 | handle_join_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
89 | const struct GNUNET_HashCode *hash) | ||
90 | { | ||
91 | struct GNUNET_MESSENGER_Contact *contact = get_handle_contact_by_pubkey (room->handle, &(message->body.join.key)); | ||
92 | |||
93 | if (contact) | ||
94 | GNUNET_CONTAINER_multishortmap_put (room->members, &(message->header.sender_id), contact, | ||
95 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
96 | } | ||
97 | |||
98 | static void | ||
99 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
100 | const struct GNUNET_HashCode *hash) | ||
101 | { | ||
102 | GNUNET_CONTAINER_multishortmap_remove_all (room->members, &(message->header.sender_id)); | ||
103 | } | ||
104 | |||
105 | static void | ||
106 | handle_name_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
107 | const struct GNUNET_HashCode *hash) | ||
108 | { | ||
109 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multishortmap_get (room->members, | ||
110 | &(message->header.sender_id)); | ||
111 | |||
112 | if (contact) | ||
113 | set_contact_name (contact, message->body.name.name); | ||
114 | } | ||
115 | |||
116 | static void | ||
117 | handle_key_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
118 | const struct GNUNET_HashCode *hash) | ||
119 | { | ||
120 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multishortmap_get (room->members, | ||
121 | &(message->header.sender_id)); | ||
122 | |||
123 | if (contact) | ||
124 | swap_handle_contact_by_pubkey (room->handle, contact, &(message->body.key.key)); | ||
125 | } | ||
126 | |||
127 | static void | ||
128 | handle_id_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
129 | const struct GNUNET_HashCode *hash) | ||
130 | { | ||
131 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multishortmap_get (room->members, | ||
132 | &(message->header.sender_id)); | ||
133 | |||
134 | if ((contact) && (GNUNET_OK | ||
135 | == GNUNET_CONTAINER_multishortmap_put (room->members, &(message->body.id.id), contact, | ||
136 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | ||
137 | GNUNET_CONTAINER_multishortmap_remove (room->members, &(message->header.sender_id), contact); | ||
138 | } | ||
139 | |||
140 | static void | ||
141 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
142 | const struct GNUNET_HashCode *hash) | ||
143 | { | ||
144 | if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id))) | ||
145 | { | ||
146 | struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (&(room->entries), &(message->body.miss.peer), NULL); | ||
147 | |||
148 | if (match) | ||
149 | remove_from_list_tunnels (&(room->entries), match); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | void | ||
154 | handle_room_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
155 | const struct GNUNET_HashCode *hash) | ||
156 | { | ||
157 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) | ||
158 | return; | ||
159 | |||
160 | switch (message->header.kind) | ||
161 | { | ||
162 | case GNUNET_MESSENGER_KIND_JOIN: | ||
163 | handle_join_message (room, message, hash); | ||
164 | break; | ||
165 | case GNUNET_MESSENGER_KIND_LEAVE: | ||
166 | handle_leave_message (room, message, hash); | ||
167 | break; | ||
168 | case GNUNET_MESSENGER_KIND_NAME: | ||
169 | handle_name_message (room, message, hash); | ||
170 | break; | ||
171 | case GNUNET_MESSENGER_KIND_KEY: | ||
172 | handle_key_message (room, message, hash); | ||
173 | break; | ||
174 | case GNUNET_MESSENGER_KIND_ID: | ||
175 | handle_id_message (room, message, hash); | ||
176 | break; | ||
177 | case GNUNET_MESSENGER_KIND_MISS: | ||
178 | handle_miss_message (room, message, hash); | ||
179 | break; | ||
180 | default: | ||
181 | break; | ||
182 | } | ||
183 | |||
184 | struct GNUNET_MESSENGER_Message *clone = copy_message (message); | ||
185 | |||
186 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, clone, | ||
187 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
188 | destroy_message (clone); | ||
189 | } | ||
diff --git a/src/messenger/messenger_api_room.h b/src/messenger/messenger_api_room.h new file mode 100644 index 000000000..0038128d8 --- /dev/null +++ b/src/messenger/messenger_api_room.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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/messenger_api_room.h | ||
23 | * @brief messenger api: client implementation of GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #ifndef GNUNET_MESSENGER_API_ROOM_H | ||
27 | #define GNUNET_MESSENGER_API_ROOM_H | ||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_container_lib.h" | ||
31 | #include "gnunet_crypto_lib.h" | ||
32 | |||
33 | #include "gnunet_messenger_service.h" | ||
34 | |||
35 | #include "messenger_api_list_tunnels.h" | ||
36 | #include "messenger_api_contact.h" | ||
37 | #include "messenger_api_message.h" | ||
38 | |||
39 | struct GNUNET_MESSENGER_Room | ||
40 | { | ||
41 | struct GNUNET_MESSENGER_Handle *handle; | ||
42 | struct GNUNET_HashCode key; | ||
43 | |||
44 | int opened; | ||
45 | |||
46 | struct GNUNET_ShortHashCode *contact_id; | ||
47 | |||
48 | struct GNUNET_CONTAINER_MultiShortmap *members; | ||
49 | struct GNUNET_MESSENGER_ListTunnels entries; | ||
50 | |||
51 | struct GNUNET_CONTAINER_MultiHashMap *messages; | ||
52 | }; | ||
53 | |||
54 | /** | ||
55 | * Creates and allocates a new room for a <i>handle</i> with a given <i>key</i> for the client API. | ||
56 | * | ||
57 | * @param handle Handle | ||
58 | * @param key Key of room | ||
59 | * @return New room | ||
60 | */ | ||
61 | struct GNUNET_MESSENGER_Room* | ||
62 | create_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key); | ||
63 | |||
64 | /** | ||
65 | * Destroys a room and frees its memory fully from the client API. | ||
66 | * | ||
67 | * @param room Room | ||
68 | */ | ||
69 | void | ||
70 | destroy_room (struct GNUNET_MESSENGER_Room *room); | ||
71 | |||
72 | /** | ||
73 | * Returns a message locally stored from a map for a given <i>hash</i> in a <i>room</i>. If no matching | ||
74 | * message is found, NULL gets returned. | ||
75 | * | ||
76 | * @param room Room | ||
77 | * @param hash Hash of message | ||
78 | * @return Message or NULL | ||
79 | */ | ||
80 | const struct GNUNET_MESSENGER_Message* | ||
81 | get_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash); | ||
82 | |||
83 | /** | ||
84 | * Handles a <i>message</i> with a given <i>hash</i> in a <i>room</i> for the client API to update | ||
85 | * members and its information. The function also stores the message in map locally for access afterwards. | ||
86 | * | ||
87 | * @param room Room | ||
88 | * @param message Message | ||
89 | * @param hash Hash of message | ||
90 | */ | ||
91 | void | ||
92 | handle_room_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
93 | const struct GNUNET_HashCode *hash); | ||
94 | |||
95 | #endif //GNUNET_MESSENGER_API_ROOM_H | ||
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c new file mode 100644 index 000000000..b42dfe6d9 --- /dev/null +++ b/src/messenger/test_messenger.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | * @file messenger/test_messenger.c | ||
22 | * @author Tobias Frisch | ||
23 | * @brief Test for the messenger service using cadet API. | ||
24 | */ | ||
25 | #include <stdio.h> | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "gnunet_messenger_service.h" | ||
30 | |||
31 | /** | ||
32 | * How long until we really give up on a particular testcase portion? | ||
33 | */ | ||
34 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
35 | 60) | ||
36 | |||
37 | /** | ||
38 | * How long until we give up on any particular operation (and retry)? | ||
39 | */ | ||
40 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
41 | |||
42 | #define TESTER_NAME "tester" | ||
43 | |||
44 | static int status = 1; | ||
45 | |||
46 | static struct GNUNET_SCHEDULER_Task *die_task = NULL; | ||
47 | static struct GNUNET_SCHEDULER_Task *op_task = NULL; | ||
48 | |||
49 | struct GNUNET_MESSENGER_Handle *messenger = NULL; | ||
50 | |||
51 | static void | ||
52 | end (void *cls) | ||
53 | { | ||
54 | die_task = NULL; | ||
55 | |||
56 | if (op_task) | ||
57 | { | ||
58 | GNUNET_SCHEDULER_cancel (op_task); | ||
59 | op_task = NULL; | ||
60 | } | ||
61 | |||
62 | if (messenger) | ||
63 | { | ||
64 | GNUNET_MESSENGER_disconnect(messenger); | ||
65 | messenger = NULL; | ||
66 | } | ||
67 | |||
68 | status = 0; | ||
69 | } | ||
70 | |||
71 | |||
72 | static void | ||
73 | end_badly (void *cls) | ||
74 | { | ||
75 | fprintf (stderr, "Testcase failed (timeout).\n"); | ||
76 | |||
77 | end (NULL); | ||
78 | status = 1; | ||
79 | } | ||
80 | |||
81 | static void | ||
82 | end_operation (void *cls) | ||
83 | { | ||
84 | op_task = NULL; | ||
85 | |||
86 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls? (const char*) cls : "unknown"); | ||
87 | |||
88 | if (die_task) | ||
89 | GNUNET_SCHEDULER_cancel (die_task); | ||
90 | |||
91 | end (NULL); | ||
92 | status = 1; | ||
93 | } | ||
94 | |||
95 | static int identity_counter = 0; | ||
96 | |||
97 | /** | ||
98 | * Function called when an identity is retrieved. | ||
99 | * | ||
100 | * @param cls Closure | ||
101 | * @param handle Handle of messenger service | ||
102 | */ | ||
103 | static void | ||
104 | on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
105 | { | ||
106 | if (op_task) | ||
107 | { | ||
108 | GNUNET_SCHEDULER_cancel (op_task); | ||
109 | op_task = NULL; | ||
110 | } | ||
111 | |||
112 | const char* name = GNUNET_MESSENGER_get_name(handle); | ||
113 | |||
114 | if (0 != strcmp(name, TESTER_NAME)) | ||
115 | { | ||
116 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); | ||
121 | struct GNUNET_IDENTITY_PublicKey anonymous_key; | ||
122 | |||
123 | GNUNET_IDENTITY_ego_get_public_key(ego, &anonymous_key); | ||
124 | |||
125 | const struct GNUNET_IDENTITY_PublicKey* key = GNUNET_MESSENGER_get_key(handle); | ||
126 | |||
127 | if (((!identity_counter) && (0 != GNUNET_memcmp(key, (&anonymous_key)))) || | ||
128 | ((identity_counter) && (0 == GNUNET_memcmp(key, (&anonymous_key))))) | ||
129 | { | ||
130 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | if (identity_counter) { | ||
135 | GNUNET_MESSENGER_disconnect(handle); | ||
136 | |||
137 | op_task = NULL; | ||
138 | messenger = NULL; | ||
139 | |||
140 | if (die_task) | ||
141 | GNUNET_SCHEDULER_cancel (die_task); | ||
142 | |||
143 | die_task = GNUNET_SCHEDULER_add_now (&end, NULL); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | GNUNET_MESSENGER_update(messenger); | ||
148 | identity_counter++; | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * Main function for testcase. | ||
153 | * | ||
154 | * @param cls Closure | ||
155 | * @param cfg Configuration | ||
156 | * @param peer Peer for testing | ||
157 | */ | ||
158 | static void | ||
159 | run (void *cls, | ||
160 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
161 | struct GNUNET_TESTING_Peer *peer) | ||
162 | { | ||
163 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | ||
164 | |||
165 | identity_counter = 0; | ||
166 | |||
167 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | ||
168 | messenger = GNUNET_MESSENGER_connect(cfg, TESTER_NAME, &on_identity, NULL, NULL, NULL); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * The main function. | ||
173 | * | ||
174 | * @param argc number of arguments from the command line | ||
175 | * @param argv command line arguments | ||
176 | * @return 0 ok, 1 on error | ||
177 | */ | ||
178 | int | ||
179 | main(int argc, char **argv) | ||
180 | { | ||
181 | if (0 != GNUNET_TESTING_peer_run("test-messenger", | ||
182 | "test_messenger_api.conf", | ||
183 | &run, NULL)) | ||
184 | return 1; | ||
185 | |||
186 | return status; | ||
187 | } | ||
diff --git a/src/messenger/test_messenger_anonymous.c b/src/messenger/test_messenger_anonymous.c new file mode 100644 index 000000000..e2057acc4 --- /dev/null +++ b/src/messenger/test_messenger_anonymous.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | * @file messenger/test_messenger_anonymous.c | ||
22 | * @author Tobias Frisch | ||
23 | * @brief Test for the messenger service using cadet API. | ||
24 | */ | ||
25 | #include <stdio.h> | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "gnunet_messenger_service.h" | ||
30 | |||
31 | /** | ||
32 | * How long until we really give up on a particular testcase portion? | ||
33 | */ | ||
34 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
35 | 60) | ||
36 | |||
37 | /** | ||
38 | * How long until we give up on any particular operation (and retry)? | ||
39 | */ | ||
40 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
41 | |||
42 | static int status = 1; | ||
43 | |||
44 | static struct GNUNET_SCHEDULER_Task *die_task = NULL; | ||
45 | static struct GNUNET_SCHEDULER_Task *op_task = NULL; | ||
46 | |||
47 | struct GNUNET_MESSENGER_Handle *messenger = NULL; | ||
48 | |||
49 | static void | ||
50 | end (void *cls) | ||
51 | { | ||
52 | die_task = NULL; | ||
53 | |||
54 | if (op_task) | ||
55 | { | ||
56 | GNUNET_SCHEDULER_cancel (op_task); | ||
57 | op_task = NULL; | ||
58 | } | ||
59 | |||
60 | if (messenger) | ||
61 | { | ||
62 | GNUNET_MESSENGER_disconnect(messenger); | ||
63 | messenger = NULL; | ||
64 | } | ||
65 | |||
66 | status = 0; | ||
67 | } | ||
68 | |||
69 | |||
70 | static void | ||
71 | end_badly (void *cls) | ||
72 | { | ||
73 | fprintf (stderr, "Testcase failed (timeout).\n"); | ||
74 | |||
75 | end (NULL); | ||
76 | status = 1; | ||
77 | } | ||
78 | |||
79 | static void | ||
80 | end_operation (void *cls) | ||
81 | { | ||
82 | op_task = NULL; | ||
83 | |||
84 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls? (const char*) cls : "unknown"); | ||
85 | |||
86 | if (die_task) | ||
87 | GNUNET_SCHEDULER_cancel (die_task); | ||
88 | |||
89 | end (NULL); | ||
90 | status = 1; | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Function called when an identity is retrieved. | ||
95 | * | ||
96 | * @param cls Closure | ||
97 | * @param handle Handle of messenger service | ||
98 | */ | ||
99 | static void | ||
100 | on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
101 | { | ||
102 | if (op_task) | ||
103 | { | ||
104 | GNUNET_SCHEDULER_cancel (op_task); | ||
105 | op_task = NULL; | ||
106 | } | ||
107 | |||
108 | const char* name = GNUNET_MESSENGER_get_name(handle); | ||
109 | |||
110 | if (NULL != name) | ||
111 | { | ||
112 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name-anonymous"); | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | if (GNUNET_SYSERR != GNUNET_MESSENGER_update(handle)) | ||
117 | { | ||
118 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "update-fail"); | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); | ||
123 | struct GNUNET_IDENTITY_PublicKey anonymous_key; | ||
124 | |||
125 | GNUNET_IDENTITY_ego_get_public_key(ego, &anonymous_key); | ||
126 | |||
127 | const struct GNUNET_IDENTITY_PublicKey* key = GNUNET_MESSENGER_get_key(handle); | ||
128 | |||
129 | if (0 != GNUNET_memcmp(key, (&anonymous_key))) | ||
130 | { | ||
131 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key-anonymous"); | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | GNUNET_MESSENGER_disconnect(handle); | ||
136 | |||
137 | messenger = NULL; | ||
138 | |||
139 | if (die_task) | ||
140 | GNUNET_SCHEDULER_cancel (die_task); | ||
141 | |||
142 | die_task = GNUNET_SCHEDULER_add_now (&end, NULL); | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * Main function for testcase. | ||
147 | * | ||
148 | * @param cls Closure | ||
149 | * @param cfg Configuration | ||
150 | * @param peer Peer for testing | ||
151 | */ | ||
152 | static void | ||
153 | run (void *cls, | ||
154 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
155 | struct GNUNET_TESTING_Peer *peer) | ||
156 | { | ||
157 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | ||
158 | |||
159 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | ||
160 | messenger = GNUNET_MESSENGER_connect(cfg, NULL, &on_identity, NULL, NULL, NULL); | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * The main function. | ||
165 | * | ||
166 | * @param argc number of arguments from the command line | ||
167 | * @param argv command line arguments | ||
168 | * @return 0 ok, 1 on error | ||
169 | */ | ||
170 | int | ||
171 | main(int argc, char **argv) | ||
172 | { | ||
173 | if (0 != GNUNET_TESTING_peer_run("test-messenger", | ||
174 | "test_messenger_api.conf", | ||
175 | &run, NULL)) | ||
176 | return 1; | ||
177 | |||
178 | return status; | ||
179 | } | ||
diff --git a/src/messenger/test_messenger_comm0.c b/src/messenger/test_messenger_comm0.c new file mode 100644 index 000000000..631b5b2c9 --- /dev/null +++ b/src/messenger/test_messenger_comm0.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | * @file messenger/test_messenger_comm0.c | ||
22 | * @author Tobias Frisch | ||
23 | * @brief Test for the messenger service using cadet API. | ||
24 | */ | ||
25 | #include <stdio.h> | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testbed_logger_service.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_messenger_service.h" | ||
32 | |||
33 | /** | ||
34 | * How long until we really give up on a particular testcase portion? | ||
35 | */ | ||
36 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
37 | 60) | ||
38 | |||
39 | /** | ||
40 | * How long until we give up on any particular operation (and retry)? | ||
41 | */ | ||
42 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
43 | |||
44 | static int status = 1; | ||
45 | |||
46 | static struct GNUNET_SCHEDULER_Task *die_task = NULL; | ||
47 | static struct GNUNET_SCHEDULER_Task *op_task = NULL; | ||
48 | |||
49 | static void | ||
50 | end (void *cls) | ||
51 | { | ||
52 | die_task = NULL; | ||
53 | |||
54 | if (op_task) | ||
55 | { | ||
56 | GNUNET_SCHEDULER_cancel (op_task); | ||
57 | op_task = NULL; | ||
58 | } | ||
59 | |||
60 | GNUNET_SCHEDULER_shutdown (); | ||
61 | status = 0; | ||
62 | } | ||
63 | |||
64 | |||
65 | static void | ||
66 | end_badly (void *cls) | ||
67 | { | ||
68 | fprintf (stderr, "Testcase failed (timeout).\n"); | ||
69 | |||
70 | end (NULL); | ||
71 | status = 1; | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | end_operation (void *cls) | ||
76 | { | ||
77 | op_task = NULL; | ||
78 | |||
79 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls? (const char*) cls : "unknown"); | ||
80 | |||
81 | if (die_task) | ||
82 | GNUNET_SCHEDULER_cancel (die_task); | ||
83 | |||
84 | end (NULL); | ||
85 | status = 1; | ||
86 | } | ||
87 | |||
88 | static void | ||
89 | end_error (void *cls) | ||
90 | { | ||
91 | op_task = NULL; | ||
92 | |||
93 | fprintf (stderr, "Testcase failed (error: '%s').\n", cls? (const char*) cls : "unknown"); | ||
94 | GNUNET_free(cls); | ||
95 | |||
96 | if (die_task) | ||
97 | GNUNET_SCHEDULER_cancel (die_task); | ||
98 | |||
99 | end (NULL); | ||
100 | status = 1; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * Function called whenever a message is received or sent. | ||
105 | * | ||
106 | * @param cls Closure | ||
107 | * @param room Room | ||
108 | * @param message Message | ||
109 | * @param hash Hash of message | ||
110 | */ | ||
111 | static void | ||
112 | on_message (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, | ||
113 | const struct GNUNET_HashCode *hash) | ||
114 | { | ||
115 | // TODO | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * Function called when an identity is retrieved. | ||
120 | * | ||
121 | * @param cls Closure | ||
122 | * @param handle Handle of messenger service | ||
123 | */ | ||
124 | static void | ||
125 | on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
126 | { | ||
127 | // TODO | ||
128 | } | ||
129 | |||
130 | static void | ||
131 | on_peer (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | ||
132 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
133 | const char *emsg) | ||
134 | { | ||
135 | if (emsg) | ||
136 | { | ||
137 | op_task = GNUNET_SCHEDULER_add_now (&end_error, GNUNET_strdup(emsg)); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | if (pinfo->pit != GNUNET_TESTBED_PIT_CONFIGURATION) | ||
142 | { | ||
143 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "config"); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | struct GNUNET_MESSENGER_Handle *handle; | ||
148 | struct GNUNET_MESSENGER_Room *room; | ||
149 | |||
150 | fprintf (stderr, "MSG: connect\n"); | ||
151 | |||
152 | handle = GNUNET_MESSENGER_connect(pinfo->result.cfg, "tester", &on_identity, NULL, &on_message, NULL); | ||
153 | |||
154 | struct GNUNET_HashCode hash; | ||
155 | GNUNET_CRYPTO_hash("test", 4, &hash); | ||
156 | |||
157 | fprintf (stderr, "MSG: open\n"); | ||
158 | |||
159 | room = GNUNET_MESSENGER_open_room(handle, &hash); | ||
160 | |||
161 | fprintf (stderr, "MSG: close\n"); | ||
162 | |||
163 | GNUNET_MESSENGER_close_room(room); | ||
164 | |||
165 | fprintf (stderr, "MSG: disconnect\n"); | ||
166 | |||
167 | GNUNET_MESSENGER_disconnect(handle); | ||
168 | |||
169 | GNUNET_TESTBED_operation_done(op); | ||
170 | |||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Main function for a peer of the testcase. | ||
175 | * | ||
176 | * @param cls Closure | ||
177 | * @param event Information about the event | ||
178 | */ | ||
179 | static void | ||
180 | run (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | ||
181 | { | ||
182 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | ||
183 | { | ||
184 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "start"); | ||
185 | return; | ||
186 | } | ||
187 | |||
188 | GNUNET_TESTBED_peer_get_information(event->details.peer_start.peer, | ||
189 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
190 | on_peer, event->details.peer_start.peer); | ||
191 | |||
192 | fprintf (stderr, "MSG: barrier\n"); | ||
193 | |||
194 | GNUNET_TESTBED_barrier_wait("exit", NULL, NULL); | ||
195 | |||
196 | fprintf (stderr, "MSG: exit\n"); | ||
197 | } | ||
198 | |||
199 | static void | ||
200 | exit_status (void *cls, const char *name, | ||
201 | struct GNUNET_TESTBED_Barrier *barrier, | ||
202 | enum GNUNET_TESTBED_BarrierStatus status, | ||
203 | const char *emsg) | ||
204 | { | ||
205 | if (emsg) | ||
206 | { | ||
207 | op_task = GNUNET_SCHEDULER_add_now (&end_error, GNUNET_strdup(emsg)); | ||
208 | return; | ||
209 | } | ||
210 | |||
211 | if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status) | ||
212 | { | ||
213 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "exit"); | ||
214 | return; | ||
215 | } | ||
216 | else if (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status) | ||
217 | GNUNET_SCHEDULER_add_now(&end, NULL); | ||
218 | } | ||
219 | |||
220 | static void | ||
221 | init (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, | ||
222 | struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, | ||
223 | unsigned int links_failed) | ||
224 | { | ||
225 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | ||
226 | |||
227 | struct GNUNET_TESTBED_Controller *controller; | ||
228 | |||
229 | controller = GNUNET_TESTBED_run_get_controller_handle(h); | ||
230 | |||
231 | GNUNET_TESTBED_barrier_init(controller, "exit", num_peers, exit_status, NULL); | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * The main function. | ||
236 | * | ||
237 | * @param argc number of arguments from the command line | ||
238 | * @param argv command line arguments | ||
239 | * @return 0 ok, 1 on error | ||
240 | */ | ||
241 | int | ||
242 | main(int argc, char **argv) | ||
243 | { | ||
244 | if (GNUNET_OK != GNUNET_TESTBED_test_run("test-messenger-comm0", | ||
245 | "test_messenger_api.conf", | ||
246 | 2, 0, | ||
247 | &run, NULL, | ||
248 | &init, NULL)) | ||
249 | return 1; | ||
250 | |||
251 | return status; | ||
252 | } | ||
diff --git a/src/my/my_query_helper.c b/src/my/my_query_helper.c index 526e57b8b..97ea04fd1 100644 --- a/src/my/my_query_helper.c +++ b/src/my/my_query_helper.c | |||
@@ -280,14 +280,14 @@ my_conv_rsa_public_key (void *cls, | |||
280 | MYSQL_BIND *qbind) | 280 | MYSQL_BIND *qbind) |
281 | { | 281 | { |
282 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; | 282 | const struct GNUNET_CRYPTO_RsaPublicKey *rsa = qp->data; |
283 | char *buf; | 283 | void *buf; |
284 | size_t buf_size; | 284 | size_t buf_size; |
285 | 285 | ||
286 | (void) cls; | 286 | (void) cls; |
287 | GNUNET_assert (1 == qp->num_params); | 287 | GNUNET_assert (1 == qp->num_params); |
288 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, | 288 | buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa, |
289 | &buf); | 289 | &buf); |
290 | qbind->buffer = (void *) buf; | 290 | qbind->buffer = buf; |
291 | qbind->buffer_length = buf_size; | 291 | qbind->buffer_length = buf_size; |
292 | qbind->buffer_type = MYSQL_TYPE_BLOB; | 292 | qbind->buffer_type = MYSQL_TYPE_BLOB; |
293 | return 1; | 293 | return 1; |
@@ -332,14 +332,14 @@ my_conv_rsa_signature (void *cls, | |||
332 | MYSQL_BIND *qbind) | 332 | MYSQL_BIND *qbind) |
333 | { | 333 | { |
334 | const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data; | 334 | const struct GNUNET_CRYPTO_RsaSignature *sig = qp->data; |
335 | char *buf; | 335 | void *buf; |
336 | size_t buf_size; | 336 | size_t buf_size; |
337 | 337 | ||
338 | (void) cls; | 338 | (void) cls; |
339 | GNUNET_assert (1 == qp->num_params); | 339 | GNUNET_assert (1 == qp->num_params); |
340 | buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, | 340 | buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig, |
341 | &buf); | 341 | &buf); |
342 | qbind->buffer = (void *) buf; | 342 | qbind->buffer = buf; |
343 | qbind->buffer_length = buf_size; | 343 | qbind->buffer_length = buf_size; |
344 | qbind->buffer_type = MYSQL_TYPE_BLOB; | 344 | qbind->buffer_type = MYSQL_TYPE_BLOB; |
345 | return 1; | 345 | return 1; |
diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am index 5e80ea4c5..836a6b5d9 100644 --- a/src/namecache/Makefile.am +++ b/src/namecache/Makefile.am | |||
@@ -65,6 +65,7 @@ libgnunetnamecache_la_SOURCES = \ | |||
65 | namecache.h | 65 | namecache.h |
66 | libgnunetnamecache_la_LIBADD = \ | 66 | libgnunetnamecache_la_LIBADD = \ |
67 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 67 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
68 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
68 | $(top_builddir)/src/util/libgnunetutil.la \ | 69 | $(top_builddir)/src/util/libgnunetutil.la \ |
69 | $(GN_LIBINTL) | 70 | $(GN_LIBINTL) |
70 | libgnunetnamecache_la_LDFLAGS = \ | 71 | libgnunetnamecache_la_LDFLAGS = \ |
@@ -82,6 +83,7 @@ gnunet_namecache_SOURCES = \ | |||
82 | gnunet-namecache.c | 83 | gnunet-namecache.c |
83 | gnunet_namecache_LDADD = \ | 84 | gnunet_namecache_LDADD = \ |
84 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 85 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
86 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
85 | $(top_builddir)/src/util/libgnunetutil.la \ | 87 | $(top_builddir)/src/util/libgnunetutil.la \ |
86 | libgnunetnamecache.la \ | 88 | libgnunetnamecache.la \ |
87 | $(GN_LIBINTL) | 89 | $(GN_LIBINTL) |
@@ -91,6 +93,7 @@ gnunet_service_namecache_SOURCES = \ | |||
91 | 93 | ||
92 | gnunet_service_namecache_LDADD = \ | 94 | gnunet_service_namecache_LDADD = \ |
93 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 95 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
96 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
94 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 97 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
95 | $(top_builddir)/src/util/libgnunetutil.la \ | 98 | $(top_builddir)/src/util/libgnunetutil.la \ |
96 | libgnunetnamecache.la \ | 99 | libgnunetnamecache.la \ |
@@ -107,6 +110,8 @@ libgnunet_plugin_namecache_flat_la_SOURCES = \ | |||
107 | libgnunet_plugin_namecache_flat_la_LIBADD = \ | 110 | libgnunet_plugin_namecache_flat_la_LIBADD = \ |
108 | libgnunetnamecache.la \ | 111 | libgnunetnamecache.la \ |
109 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 112 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
113 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
114 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
110 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | 115 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ |
111 | $(LTLIBINTL) | 116 | $(LTLIBINTL) |
112 | libgnunet_plugin_namecache_flat_la_LDFLAGS = \ | 117 | libgnunet_plugin_namecache_flat_la_LDFLAGS = \ |
@@ -118,6 +123,8 @@ libgnunet_plugin_namecache_sqlite_la_LIBADD = \ | |||
118 | libgnunetnamecache.la \ | 123 | libgnunetnamecache.la \ |
119 | $(top_builddir)/src/sq/libgnunetsq.la \ | 124 | $(top_builddir)/src/sq/libgnunetsq.la \ |
120 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 125 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
126 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
127 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
121 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ | 128 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ |
122 | $(LTLIBINTL) | 129 | $(LTLIBINTL) |
123 | libgnunet_plugin_namecache_sqlite_la_LDFLAGS = \ | 130 | libgnunet_plugin_namecache_sqlite_la_LDFLAGS = \ |
@@ -130,6 +137,8 @@ libgnunet_plugin_namecache_postgres_la_LIBADD = \ | |||
130 | libgnunetnamecache.la \ | 137 | libgnunetnamecache.la \ |
131 | $(top_builddir)/src/pq/libgnunetpq.la \ | 138 | $(top_builddir)/src/pq/libgnunetpq.la \ |
132 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 139 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
140 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
141 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
133 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ | 142 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ |
134 | $(LTLIBINTL) | 143 | $(LTLIBINTL) |
135 | libgnunet_plugin_namecache_postgres_la_LDFLAGS = \ | 144 | libgnunet_plugin_namecache_postgres_la_LDFLAGS = \ |
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c index 2e3c733e6..19f2a5766 100644 --- a/src/namecache/gnunet-namecache.c +++ b/src/namecache/gnunet-namecache.c | |||
@@ -51,7 +51,7 @@ static char *name; | |||
51 | /** | 51 | /** |
52 | * Public key of the zone to look in. | 52 | * Public key of the zone to look in. |
53 | */ | 53 | */ |
54 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 54 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Public key of the zone to look in, in ASCII. | 57 | * Public key of the zone to look in, in ASCII. |
@@ -177,7 +177,7 @@ run (void *cls, | |||
177 | } | 177 | } |
178 | 178 | ||
179 | if (GNUNET_OK != | 179 | if (GNUNET_OK != |
180 | GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey)) | 180 | GNUNET_IDENTITY_public_key_from_string (pkey, &pubkey)) |
181 | { | 181 | { |
182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); | 182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); |
183 | GNUNET_SCHEDULER_shutdown (); | 183 | GNUNET_SCHEDULER_shutdown (); |
diff --git a/src/namecache/gnunet-service-namecache.c b/src/namecache/gnunet-service-namecache.c index 7cf216ce3..07bf30de9 100644 --- a/src/namecache/gnunet-service-namecache.c +++ b/src/namecache/gnunet-service-namecache.c | |||
@@ -184,40 +184,24 @@ handle_lookup_block_it (void *cls, | |||
184 | struct LookupBlockContext *lnc = cls; | 184 | struct LookupBlockContext *lnc = cls; |
185 | struct GNUNET_MQ_Envelope *env; | 185 | struct GNUNET_MQ_Envelope *env; |
186 | struct LookupBlockResponseMessage *r; | 186 | struct LookupBlockResponseMessage *r; |
187 | size_t esize; | ||
188 | size_t bsize; | 187 | size_t bsize; |
189 | 188 | ||
190 | bsize = ntohl (block->purpose.size); | 189 | bsize = GNUNET_GNSRECORD_block_get_size (block); |
191 | if (bsize < | ||
192 | (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(struct | ||
193 | GNUNET_TIME_AbsoluteNBO))) | ||
194 | { | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
196 | "Malformed block."); | ||
197 | lnc->status = GNUNET_SYSERR; | ||
198 | return; | ||
199 | } | ||
200 | esize = ntohl (block->purpose.size) | ||
201 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
202 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
203 | env = GNUNET_MQ_msg_extra (r, | 190 | env = GNUNET_MQ_msg_extra (r, |
204 | esize, | 191 | bsize, |
205 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); | 192 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); |
206 | r->gns_header.r_id = htonl (lnc->request_id); | 193 | r->gns_header.r_id = htonl (lnc->request_id); |
207 | r->expire = block->expiration_time; | ||
208 | r->signature = block->signature; | ||
209 | r->derived_key = block->derived_key; | ||
210 | GNUNET_memcpy (&r[1], | 194 | GNUNET_memcpy (&r[1], |
211 | &block[1], | 195 | block, |
212 | esize); | 196 | bsize); |
213 | GNUNET_STATISTICS_update (statistics, | 197 | GNUNET_STATISTICS_update (statistics, |
214 | "blocks found in cache", | 198 | "blocks found in cache", |
215 | 1, | 199 | 1, |
216 | GNUNET_NO); | 200 | GNUNET_NO); |
201 | r->expire = GNUNET_TIME_absolute_hton ( | ||
202 | GNUNET_GNSRECORD_block_get_expiration (block)); | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
218 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message with expiration time %s\n", | 204 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n"); |
219 | GNUNET_STRINGS_absolute_time_to_string ( | ||
220 | GNUNET_TIME_absolute_ntoh (r->expire))); | ||
221 | GNUNET_MQ_send (lnc->nc->mq, | 205 | GNUNET_MQ_send (lnc->nc->mq, |
222 | env); | 206 | env); |
223 | } | 207 | } |
@@ -314,20 +298,11 @@ handle_block_cache (void *cls, | |||
314 | GNUNET_NO); | 298 | GNUNET_NO); |
315 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct | 299 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct |
316 | BlockCacheMessage); | 300 | BlockCacheMessage); |
317 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) + esize); | 301 | block = GNUNET_malloc (esize); |
318 | block->signature = rp_msg->signature; | 302 | memcpy (block, &rp_msg[1], esize); |
319 | block->derived_key = rp_msg->derived_key; | ||
320 | block->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
321 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
322 | + esize); | ||
323 | block->expiration_time = rp_msg->expire; | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Received NAMECACHE_BLOCK_CACHE message with expiration time %s\n", | 304 | "Received NAMECACHE_BLOCK_CACHE message with type %u\n", |
326 | GNUNET_STRINGS_absolute_time_to_string ( | 305 | htonl (block->type)); |
327 | GNUNET_TIME_absolute_ntoh (block->expiration_time))); | ||
328 | GNUNET_memcpy (&block[1], | ||
329 | &rp_msg[1], | ||
330 | esize); | ||
331 | res = GSN_database->cache_block (GSN_database->cls, | 306 | res = GSN_database->cache_block (GSN_database->cls, |
332 | block); | 307 | block); |
333 | GNUNET_free (block); | 308 | GNUNET_free (block); |
diff --git a/src/namecache/namecache.h b/src/namecache/namecache.h index 1657662c2..43c8cf85f 100644 --- a/src/namecache/namecache.h +++ b/src/namecache/namecache.h | |||
@@ -92,7 +92,7 @@ struct LookupBlockResponseMessage | |||
92 | /** | 92 | /** |
93 | * Derived public key. | 93 | * Derived public key. |
94 | */ | 94 | */ |
95 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | 95 | struct GNUNET_IDENTITY_PublicKey derived_key; |
96 | 96 | ||
97 | /* follwed by encrypted block data */ | 97 | /* follwed by encrypted block data */ |
98 | }; | 98 | }; |
@@ -121,7 +121,7 @@ struct BlockCacheMessage | |||
121 | /** | 121 | /** |
122 | * Derived public key. | 122 | * Derived public key. |
123 | */ | 123 | */ |
124 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | 124 | struct GNUNET_IDENTITY_PublicKey derived_key; |
125 | 125 | ||
126 | /* follwed by encrypted block data */ | 126 | /* follwed by encrypted block data */ |
127 | }; | 127 | }; |
diff --git a/src/namecache/namecache_api.c b/src/namecache/namecache_api.c index 0c904c9ed..fdbf142a7 100644 --- a/src/namecache/namecache_api.c +++ b/src/namecache/namecache_api.c | |||
@@ -225,19 +225,11 @@ handle_lookup_block_response (void *cls, | |||
225 | size = ntohs (msg->gns_header.header.size) | 225 | size = ntohs (msg->gns_header.header.size) |
226 | - sizeof(struct LookupBlockResponseMessage); | 226 | - sizeof(struct LookupBlockResponseMessage); |
227 | { | 227 | { |
228 | char buf[size + sizeof(struct GNUNET_GNSRECORD_Block)] GNUNET_ALIGN; | 228 | char buf[size] GNUNET_ALIGN; |
229 | struct GNUNET_GNSRECORD_Block *block; | 229 | struct GNUNET_GNSRECORD_Block *block; |
230 | 230 | ||
231 | block = (struct GNUNET_GNSRECORD_Block *) buf; | 231 | block = (struct GNUNET_GNSRECORD_Block *) buf; |
232 | block->signature = msg->signature; | 232 | GNUNET_memcpy (block, |
233 | block->derived_key = msg->derived_key; | ||
234 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
235 | block->purpose.size = htonl (size | ||
236 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
237 | + sizeof(struct | ||
238 | GNUNET_CRYPTO_EccSignaturePurpose)); | ||
239 | block->expiration_time = msg->expire; | ||
240 | GNUNET_memcpy (&block[1], | ||
241 | &msg[1], | 233 | &msg[1], |
242 | size); | 234 | size); |
243 | if (GNUNET_OK != | 235 | if (GNUNET_OK != |
@@ -483,11 +475,7 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
483 | 475 | ||
484 | if (NULL == h->mq) | 476 | if (NULL == h->mq) |
485 | return NULL; | 477 | return NULL; |
486 | blen = ntohl (block->purpose.size); | 478 | blen = GNUNET_GNSRECORD_block_get_size (block); |
487 | GNUNET_assert (blen > (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
488 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))); | ||
489 | blen -= (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
490 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
491 | rid = get_op_id (h); | 479 | rid = get_op_id (h); |
492 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); | 480 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); |
493 | qe->nsh = h; | 481 | qe->nsh = h; |
@@ -502,11 +490,8 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
502 | blen, | 490 | blen, |
503 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); | 491 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); |
504 | msg->gns_header.r_id = htonl (rid); | 492 | msg->gns_header.r_id = htonl (rid); |
505 | msg->expire = block->expiration_time; | ||
506 | msg->signature = block->signature; | ||
507 | msg->derived_key = block->derived_key; | ||
508 | GNUNET_memcpy (&msg[1], | 493 | GNUNET_memcpy (&msg[1], |
509 | &block[1], | 494 | block, |
510 | blen); | 495 | blen); |
511 | GNUNET_MQ_send (h->mq, | 496 | GNUNET_MQ_send (h->mq, |
512 | env); | 497 | env); |
diff --git a/src/namecache/plugin_namecache_flat.c b/src/namecache/plugin_namecache_flat.c index 24f4f2570..eb7800051 100644 --- a/src/namecache/plugin_namecache_flat.c +++ b/src/namecache/plugin_namecache_flat.c | |||
@@ -207,10 +207,7 @@ store_and_free_entries (void *cls, | |||
207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; | 207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; |
208 | size_t block_size; | 208 | size_t block_size; |
209 | 209 | ||
210 | block_size = ntohl (entry->block->purpose.size) | 210 | block_size = GNUNET_GNSRECORD_block_get_size (entry->block); |
211 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
212 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
213 | |||
214 | GNUNET_STRINGS_base64_encode ((char *) entry->block, | 211 | GNUNET_STRINGS_base64_encode ((char *) entry->block, |
215 | block_size, | 212 | block_size, |
216 | &block_b64); | 213 | &block_b64); |
@@ -277,7 +274,7 @@ expire_blocks (void *cls, | |||
277 | struct GNUNET_TIME_Absolute expiration; | 274 | struct GNUNET_TIME_Absolute expiration; |
278 | 275 | ||
279 | now = GNUNET_TIME_absolute_get (); | 276 | now = GNUNET_TIME_absolute_get (); |
280 | expiration = GNUNET_TIME_absolute_ntoh (entry->block->expiration_time); | 277 | expiration = GNUNET_GNSRECORD_block_get_expiration (entry->block); |
281 | 278 | ||
282 | if (0 == GNUNET_TIME_absolute_get_difference (now, | 279 | if (0 == GNUNET_TIME_absolute_get_difference (now, |
283 | expiration).rel_value_us) | 280 | expiration).rel_value_us) |
@@ -319,12 +316,9 @@ namecache_cache_block (void *cls, | |||
319 | size_t block_size; | 316 | size_t block_size; |
320 | 317 | ||
321 | namecache_expire_blocks (plugin); | 318 | namecache_expire_blocks (plugin); |
322 | GNUNET_CRYPTO_hash (&block->derived_key, | 319 | GNUNET_GNSRECORD_query_from_block (block, |
323 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 320 | &query); |
324 | &query); | 321 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
325 | block_size = ntohl (block->purpose.size) | ||
326 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
327 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
328 | if (block_size > 64 * 65536) | 322 | if (block_size > 64 * 65536) |
329 | { | 323 | { |
330 | GNUNET_break (0); | 324 | GNUNET_break (0); |
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c index 0e947e9c5..ae0f71a1f 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -64,15 +64,13 @@ database_setup (struct Plugin *plugin) | |||
64 | " query BYTEA NOT NULL DEFAULT ''," | 64 | " query BYTEA NOT NULL DEFAULT ''," |
65 | " block BYTEA NOT NULL DEFAULT ''," | 65 | " block BYTEA NOT NULL DEFAULT ''," |
66 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 66 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
67 | ")" | 67 | ")"); |
68 | "WITH OIDS"); | ||
69 | struct GNUNET_PQ_ExecuteStatement es_default = | 68 | struct GNUNET_PQ_ExecuteStatement es_default = |
70 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" | 69 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" |
71 | " query BYTEA NOT NULL DEFAULT ''," | 70 | " query BYTEA NOT NULL DEFAULT ''," |
72 | " block BYTEA NOT NULL DEFAULT ''," | 71 | " block BYTEA NOT NULL DEFAULT ''," |
73 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 72 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
74 | ")" | 73 | ")"); |
75 | "WITH OIDS"); | ||
76 | const struct GNUNET_PQ_ExecuteStatement *cr; | 74 | const struct GNUNET_PQ_ExecuteStatement *cr; |
77 | 75 | ||
78 | if (GNUNET_YES == | 76 | if (GNUNET_YES == |
@@ -155,11 +153,11 @@ namecache_postgres_expire_blocks (struct Plugin *plugin) | |||
155 | static void | 153 | static void |
156 | delete_old_block (struct Plugin *plugin, | 154 | delete_old_block (struct Plugin *plugin, |
157 | const struct GNUNET_HashCode *query, | 155 | const struct GNUNET_HashCode *query, |
158 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | 156 | struct GNUNET_TIME_Absolute expiration_time) |
159 | { | 157 | { |
160 | struct GNUNET_PQ_QueryParam params[] = { | 158 | struct GNUNET_PQ_QueryParam params[] = { |
161 | GNUNET_PQ_query_param_auto_from_type (query), | 159 | GNUNET_PQ_query_param_auto_from_type (query), |
162 | GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time), | 160 | GNUNET_PQ_query_param_absolute_time (&expiration_time), |
163 | GNUNET_PQ_query_param_end | 161 | GNUNET_PQ_query_param_end |
164 | }; | 162 | }; |
165 | enum GNUNET_DB_QueryStatus res; | 163 | enum GNUNET_DB_QueryStatus res; |
@@ -184,21 +182,20 @@ namecache_postgres_cache_block (void *cls, | |||
184 | { | 182 | { |
185 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
186 | struct GNUNET_HashCode query; | 184 | struct GNUNET_HashCode query; |
187 | size_t block_size = ntohl (block->purpose.size) | 185 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
188 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 186 | struct GNUNET_TIME_Absolute exp; |
189 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 187 | exp = GNUNET_GNSRECORD_block_get_expiration (block); |
190 | struct GNUNET_PQ_QueryParam params[] = { | 188 | struct GNUNET_PQ_QueryParam params[] = { |
191 | GNUNET_PQ_query_param_auto_from_type (&query), | 189 | GNUNET_PQ_query_param_auto_from_type (&query), |
192 | GNUNET_PQ_query_param_fixed_size (block, block_size), | 190 | GNUNET_PQ_query_param_fixed_size (block, block_size), |
193 | GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time), | 191 | GNUNET_PQ_query_param_absolute_time (&exp), |
194 | GNUNET_PQ_query_param_end | 192 | GNUNET_PQ_query_param_end |
195 | }; | 193 | }; |
196 | enum GNUNET_DB_QueryStatus res; | 194 | enum GNUNET_DB_QueryStatus res; |
197 | 195 | ||
198 | namecache_postgres_expire_blocks (plugin); | 196 | namecache_postgres_expire_blocks (plugin); |
199 | GNUNET_CRYPTO_hash (&block->derived_key, | 197 | GNUNET_GNSRECORD_query_from_block (block, |
200 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 198 | &query); |
201 | &query); | ||
202 | if (block_size > 64 * 65536) | 199 | if (block_size > 64 * 65536) |
203 | { | 200 | { |
204 | GNUNET_break (0); | 201 | GNUNET_break (0); |
@@ -206,7 +203,7 @@ namecache_postgres_cache_block (void *cls, | |||
206 | } | 203 | } |
207 | delete_old_block (plugin, | 204 | delete_old_block (plugin, |
208 | &query, | 205 | &query, |
209 | block->expiration_time); | 206 | exp); |
210 | 207 | ||
211 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 208 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
212 | "cache_block", | 209 | "cache_block", |
@@ -265,10 +262,7 @@ namecache_postgres_lookup_block (void *cls, | |||
265 | "Ending iteration (no more results)\n"); | 262 | "Ending iteration (no more results)\n"); |
266 | return GNUNET_NO; | 263 | return GNUNET_NO; |
267 | } | 264 | } |
268 | if ((bsize < sizeof(*block)) || | 265 | if ((bsize < sizeof(*block))) |
269 | (bsize != ntohl (block->purpose.size) | ||
270 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
271 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))) | ||
272 | { | 266 | { |
273 | GNUNET_break (0); | 267 | GNUNET_break (0); |
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 268 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/namecache/plugin_namecache_sqlite.c b/src/namecache/plugin_namecache_sqlite.c index c9d79ba2d..82008c837 100644 --- a/src/namecache/plugin_namecache_sqlite.c +++ b/src/namecache/plugin_namecache_sqlite.c | |||
@@ -332,9 +332,7 @@ namecache_sqlite_cache_block (void *cls, | |||
332 | struct Plugin *plugin = cls; | 332 | struct Plugin *plugin = cls; |
333 | struct GNUNET_HashCode query; | 333 | struct GNUNET_HashCode query; |
334 | struct GNUNET_TIME_Absolute expiration; | 334 | struct GNUNET_TIME_Absolute expiration; |
335 | size_t block_size = ntohl (block->purpose.size) | 335 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
336 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
337 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
338 | struct GNUNET_SQ_QueryParam del_params[] = { | 336 | struct GNUNET_SQ_QueryParam del_params[] = { |
339 | GNUNET_SQ_query_param_auto_from_type (&query), | 337 | GNUNET_SQ_query_param_auto_from_type (&query), |
340 | GNUNET_SQ_query_param_absolute_time (&expiration), | 338 | GNUNET_SQ_query_param_absolute_time (&expiration), |
@@ -356,10 +354,9 @@ namecache_sqlite_cache_block (void *cls, | |||
356 | last_expire = GNUNET_TIME_absolute_get (); | 354 | last_expire = GNUNET_TIME_absolute_get (); |
357 | namecache_sqlite_expire_blocks (plugin); | 355 | namecache_sqlite_expire_blocks (plugin); |
358 | } | 356 | } |
359 | GNUNET_CRYPTO_hash (&block->derived_key, | 357 | GNUNET_assert (GNUNET_OK == |
360 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 358 | GNUNET_GNSRECORD_query_from_block (block, &query)); |
361 | &query); | 359 | expiration = GNUNET_GNSRECORD_block_get_expiration (block); |
362 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
364 | "Caching new version of block %s (expires %s)\n", | 361 | "Caching new version of block %s (expires %s)\n", |
365 | GNUNET_h2s (&query), | 362 | GNUNET_h2s (&query), |
@@ -498,10 +495,7 @@ namecache_sqlite_lookup_block (void *cls, | |||
498 | GNUNET_break (0); | 495 | GNUNET_break (0); |
499 | ret = GNUNET_SYSERR; | 496 | ret = GNUNET_SYSERR; |
500 | } | 497 | } |
501 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block)) || | 498 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block))) |
502 | (ntohl (block->purpose.size) | ||
503 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
504 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) != block_size)) | ||
505 | { | 499 | { |
506 | GNUNET_break (0); | 500 | GNUNET_break (0); |
507 | GNUNET_SQ_cleanup_result (rs); | 501 | GNUNET_SQ_cleanup_result (rs); |
diff --git a/src/namecache/test_namecache_api_cache_block.c b/src/namecache/test_namecache_api_cache_block.c index 12b72d93b..310c4de42 100644 --- a/src/namecache/test_namecache_api_cache_block.c +++ b/src/namecache/test_namecache_api_cache_block.c | |||
@@ -39,9 +39,9 @@ static struct GNUNET_NAMECACHE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
45 | 45 | ||
46 | static int res; | 46 | static int res; |
47 | 47 | ||
@@ -172,23 +172,13 @@ run (void *cls, | |||
172 | { | 172 | { |
173 | struct GNUNET_GNSRECORD_Data rd; | 173 | struct GNUNET_GNSRECORD_Data rd; |
174 | struct GNUNET_GNSRECORD_Block *block; | 174 | struct GNUNET_GNSRECORD_Block *block; |
175 | char *hostkey_file; | ||
176 | const char *name = "dummy.dummy.gnunet"; | 175 | const char *name = "dummy.dummy.gnunet"; |
177 | 176 | ||
178 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 177 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
179 | &endbadly, NULL); | 178 | &endbadly, NULL); |
180 | GNUNET_asprintf (&hostkey_file, | 179 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
181 | "zonefiles%s%s", | 180 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
182 | DIR_SEPARATOR_STR, | 181 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); |
183 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", | ||
185 | hostkey_file); | ||
186 | GNUNET_assert (GNUNET_SYSERR != | ||
187 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
188 | GNUNET_YES, | ||
189 | &privkey)); | ||
190 | GNUNET_free (hostkey_file); | ||
191 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); | ||
192 | 182 | ||
193 | 183 | ||
194 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; | 184 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 40ac64197..3a92f98c9 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -131,6 +131,7 @@ libgnunet_plugin_rest_namestore_la_LIBADD = \ | |||
131 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 131 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
132 | $(top_builddir)/src/json/libgnunetjson.la \ | 132 | $(top_builddir)/src/json/libgnunetjson.la \ |
133 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 133 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
134 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecordjson.la \ | ||
134 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | 135 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ |
135 | $(LTLIBINTL) -ljansson $(MHD_LIBS) | 136 | $(LTLIBINTL) -ljansson $(MHD_LIBS) |
136 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ | 137 | libgnunet_plugin_rest_namestore_la_LDFLAGS = \ |
@@ -144,6 +145,7 @@ libgnunetnamestore_la_SOURCES = \ | |||
144 | namestore.h | 145 | namestore.h |
145 | libgnunetnamestore_la_LIBADD = \ | 146 | libgnunetnamestore_la_LIBADD = \ |
146 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 147 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
148 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
147 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 149 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
148 | $(top_builddir)/src/util/libgnunetutil.la \ | 150 | $(top_builddir)/src/util/libgnunetutil.la \ |
149 | $(GN_LIBINTL) | 151 | $(GN_LIBINTL) |
@@ -190,6 +192,7 @@ gnunet_service_namestore_SOURCES = \ | |||
190 | gnunet_service_namestore_LDADD = \ | 192 | gnunet_service_namestore_LDADD = \ |
191 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ | 193 | $(top_builddir)/src/namecache/libgnunetnamecache.la \ |
192 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 194 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
195 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
193 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 196 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
194 | $(top_builddir)/src/util/libgnunetutil.la \ | 197 | $(top_builddir)/src/util/libgnunetutil.la \ |
195 | libgnunetnamestore.la \ | 198 | libgnunetnamestore.la \ |
@@ -200,7 +203,8 @@ gnunet_service_namestore_LDADD = \ | |||
200 | libgnunet_plugin_namestore_flat_la_SOURCES = \ | 203 | libgnunet_plugin_namestore_flat_la_SOURCES = \ |
201 | plugin_namestore_flat.c | 204 | plugin_namestore_flat.c |
202 | libgnunet_plugin_namestore_flat_la_LIBADD = \ | 205 | libgnunet_plugin_namestore_flat_la_LIBADD = \ |
203 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 206 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
207 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
204 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 208 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
205 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | 209 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ |
206 | $(LTLIBINTL) | 210 | $(LTLIBINTL) |
@@ -212,6 +216,7 @@ libgnunet_plugin_namestore_sqlite_la_SOURCES = \ | |||
212 | plugin_namestore_sqlite.c | 216 | plugin_namestore_sqlite.c |
213 | libgnunet_plugin_namestore_sqlite_la_LIBADD = \ | 217 | libgnunet_plugin_namestore_sqlite_la_LIBADD = \ |
214 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 218 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
219 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
215 | $(top_builddir)/src/sq/libgnunetsq.la \ | 220 | $(top_builddir)/src/sq/libgnunetsq.la \ |
216 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 221 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
217 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ | 222 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ |
@@ -223,6 +228,7 @@ libgnunet_plugin_namestore_postgres_la_SOURCES = \ | |||
223 | plugin_namestore_postgres.c | 228 | plugin_namestore_postgres.c |
224 | libgnunet_plugin_namestore_postgres_la_LIBADD = \ | 229 | libgnunet_plugin_namestore_postgres_la_LIBADD = \ |
225 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 230 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
231 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
226 | $(top_builddir)/src/pq/libgnunetpq.la \ | 232 | $(top_builddir)/src/pq/libgnunetpq.la \ |
227 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 233 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
228 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ | 234 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ |
@@ -236,6 +242,7 @@ test_namestore_api_store_flat_LDADD = \ | |||
236 | $(top_builddir)/src/testing/libgnunettesting.la \ | 242 | $(top_builddir)/src/testing/libgnunettesting.la \ |
237 | $(top_builddir)/src/util/libgnunetutil.la \ | 243 | $(top_builddir)/src/util/libgnunetutil.la \ |
238 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 244 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
245 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
239 | libgnunetnamestore.la | 246 | libgnunetnamestore.la |
240 | 247 | ||
241 | test_namestore_api_store_sqlite_SOURCES = \ | 248 | test_namestore_api_store_sqlite_SOURCES = \ |
@@ -244,6 +251,7 @@ test_namestore_api_store_sqlite_LDADD = \ | |||
244 | $(top_builddir)/src/testing/libgnunettesting.la \ | 251 | $(top_builddir)/src/testing/libgnunettesting.la \ |
245 | $(top_builddir)/src/util/libgnunetutil.la \ | 252 | $(top_builddir)/src/util/libgnunetutil.la \ |
246 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 253 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
254 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
247 | libgnunetnamestore.la | 255 | libgnunetnamestore.la |
248 | 256 | ||
249 | test_namestore_api_store_postgres_SOURCES = \ | 257 | test_namestore_api_store_postgres_SOURCES = \ |
@@ -252,6 +260,7 @@ test_namestore_api_store_postgres_LDADD = \ | |||
252 | $(top_builddir)/src/testing/libgnunettesting.la \ | 260 | $(top_builddir)/src/testing/libgnunettesting.la \ |
253 | $(top_builddir)/src/util/libgnunetutil.la \ | 261 | $(top_builddir)/src/util/libgnunetutil.la \ |
254 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 262 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
263 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
255 | libgnunetnamestore.la | 264 | libgnunetnamestore.la |
256 | 265 | ||
257 | test_namestore_api_store_update_flat_SOURCES = \ | 266 | test_namestore_api_store_update_flat_SOURCES = \ |
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 34641d22e..22d108067 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -164,7 +164,7 @@ struct Request | |||
164 | */ | 164 | */ |
165 | char public_key[128]; | 165 | char public_key[128]; |
166 | 166 | ||
167 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 167 | struct GNUNET_IDENTITY_PublicKey pub; |
168 | }; | 168 | }; |
169 | 169 | ||
170 | /** | 170 | /** |
@@ -211,7 +211,7 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
211 | /** | 211 | /** |
212 | * Private key for the fcfsd zone. | 212 | * Private key for the fcfsd zone. |
213 | */ | 213 | */ |
214 | static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey; | 214 | static struct GNUNET_IDENTITY_PrivateKey fcfs_zone_pkey; |
215 | 215 | ||
216 | /** | 216 | /** |
217 | * Connection to identity service. | 217 | * Connection to identity service. |
@@ -306,7 +306,6 @@ zone_iteration_end (void *cls) | |||
306 | /* return static form */ | 306 | /* return static form */ |
307 | GNUNET_asprintf (&full_page, | 307 | GNUNET_asprintf (&full_page, |
308 | ZONEINFO_PAGE, | 308 | ZONEINFO_PAGE, |
309 | zr->zoneinfo, | ||
310 | zr->zoneinfo); | 309 | zr->zoneinfo); |
311 | response = MHD_create_response_from_buffer (strlen (full_page), | 310 | response = MHD_create_response_from_buffer (strlen (full_page), |
312 | (void *) full_page, | 311 | (void *) full_page, |
@@ -332,7 +331,7 @@ zone_iteration_end (void *cls) | |||
332 | */ | 331 | */ |
333 | static void | 332 | static void |
334 | iterate_cb (void *cls, | 333 | iterate_cb (void *cls, |
335 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 334 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
336 | const char *name, | 335 | const char *name, |
337 | unsigned int rd_len, | 336 | unsigned int rd_len, |
338 | const struct GNUNET_GNSRECORD_Data *rd) | 337 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -350,7 +349,8 @@ iterate_cb (void *cls, | |||
350 | return; | 349 | return; |
351 | } | 350 | } |
352 | 351 | ||
353 | if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) | 352 | if ((GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) && |
353 | (GNUNET_GNSRECORD_TYPE_EDKEY != rd->record_type)) | ||
354 | { | 354 | { |
355 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, | 355 | GNUNET_NAMESTORE_zone_iterator_next (zr->list_it, |
356 | 1); | 356 | 1); |
@@ -615,13 +615,14 @@ zone_to_name_error (void *cls) | |||
615 | */ | 615 | */ |
616 | static void | 616 | static void |
617 | zone_to_name_cb (void *cls, | 617 | zone_to_name_cb (void *cls, |
618 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 618 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
619 | const char *name, | 619 | const char *name, |
620 | unsigned int rd_count, | 620 | unsigned int rd_count, |
621 | const struct GNUNET_GNSRECORD_Data *rd) | 621 | const struct GNUNET_GNSRECORD_Data *rd) |
622 | { | 622 | { |
623 | struct Request *request = cls; | 623 | struct Request *request = cls; |
624 | struct GNUNET_GNSRECORD_Data r; | 624 | struct GNUNET_GNSRECORD_Data r; |
625 | char *rdata; | ||
625 | 626 | ||
626 | (void) rd; | 627 | (void) rd; |
627 | (void) zone_key; | 628 | (void) zone_key; |
@@ -636,10 +637,21 @@ zone_to_name_cb (void *cls, | |||
636 | run_httpd_now (); | 637 | run_httpd_now (); |
637 | return; | 638 | return; |
638 | } | 639 | } |
639 | r.data = &request->pub; | 640 | if (GNUNET_OK != GNUNET_GNSRECORD_data_from_identity (&request->pub, |
640 | r.data_size = sizeof(request->pub); | 641 | &rdata, |
642 | &r.data_size, | ||
643 | &r.record_type)) | ||
644 | { | ||
645 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
646 | _ ("Error creating record data.\n")); | ||
647 | request->phase = RP_FAIL; | ||
648 | MHD_resume_connection (request->con); | ||
649 | run_httpd_now (); | ||
650 | return; | ||
651 | } | ||
652 | |||
653 | r.data = rdata; | ||
641 | r.expiration_time = UINT64_MAX; | 654 | r.expiration_time = UINT64_MAX; |
642 | r.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
643 | r.flags = GNUNET_GNSRECORD_RF_NONE; | 655 | r.flags = GNUNET_GNSRECORD_RF_NONE; |
644 | request->qe = GNUNET_NAMESTORE_records_store (ns, | 656 | request->qe = GNUNET_NAMESTORE_records_store (ns, |
645 | &fcfs_zone_pkey, | 657 | &fcfs_zone_pkey, |
@@ -647,6 +659,7 @@ zone_to_name_cb (void *cls, | |||
647 | 1, &r, | 659 | 1, &r, |
648 | &put_continuation, | 660 | &put_continuation, |
649 | request); | 661 | request); |
662 | GNUNET_free (rdata); | ||
650 | } | 663 | } |
651 | 664 | ||
652 | 665 | ||
@@ -677,7 +690,7 @@ lookup_it_error (void *cls) | |||
677 | */ | 690 | */ |
678 | static void | 691 | static void |
679 | lookup_it_processor (void *cls, | 692 | lookup_it_processor (void *cls, |
680 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, | 693 | const struct GNUNET_IDENTITY_PrivateKey *zonekey, |
681 | const char *label, | 694 | const char *label, |
682 | unsigned int rd_count, | 695 | unsigned int rd_count, |
683 | const struct GNUNET_GNSRECORD_Data *rd) | 696 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -712,9 +725,8 @@ lookup_it_finished (void *cls) | |||
712 | return; | 725 | return; |
713 | } | 726 | } |
714 | if (GNUNET_OK != | 727 | if (GNUNET_OK != |
715 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | 728 | GNUNET_IDENTITY_public_key_from_string (request->public_key, |
716 | strlen (request->public_key), | 729 | &request->pub)) |
717 | &request->pub)) | ||
718 | { | 730 | { |
719 | GNUNET_break (0); | 731 | GNUNET_break (0); |
720 | request->phase = RP_FAIL; | 732 | request->phase = RP_FAIL; |
@@ -767,7 +779,7 @@ create_response (void *cls, | |||
767 | { | 779 | { |
768 | struct MHD_Response *response; | 780 | struct MHD_Response *response; |
769 | struct Request *request; | 781 | struct Request *request; |
770 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 782 | struct GNUNET_IDENTITY_PublicKey pub; |
771 | MHD_RESULT ret; | 783 | MHD_RESULT ret; |
772 | 784 | ||
773 | (void) cls; | 785 | (void) cls; |
@@ -822,10 +834,8 @@ create_response (void *cls, | |||
822 | request->pp = NULL; | 834 | request->pp = NULL; |
823 | } | 835 | } |
824 | if (GNUNET_OK != | 836 | if (GNUNET_OK != |
825 | GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key, | 837 | GNUNET_IDENTITY_public_key_from_string (request->public_key, |
826 | strlen ( | 838 | &pub)) |
827 | request->public_key), | ||
828 | &pub)) | ||
829 | { | 839 | { |
830 | /* parse error */ | 840 | /* parse error */ |
831 | return fill_s_reply ("Failed to parse given public key", | 841 | return fill_s_reply ("Failed to parse given public key", |
@@ -1211,7 +1221,8 @@ main (int argc, | |||
1211 | options, | 1221 | options, |
1212 | &run, NULL)) ? 0 : 1; | 1222 | &run, NULL)) ? 0 : 1; |
1213 | GNUNET_free_nz ((void *) argv); | 1223 | GNUNET_free_nz ((void *) argv); |
1214 | GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); | 1224 | // FIXME |
1225 | // GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey); | ||
1215 | return ret; | 1226 | return ret; |
1216 | } | 1227 | } |
1217 | 1228 | ||
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 07d045b90..92d2cf627 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -59,7 +59,7 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
59 | /** | 59 | /** |
60 | * Private key for the our zone. | 60 | * Private key for the our zone. |
61 | */ | 61 | */ |
62 | static struct GNUNET_CRYPTO_EcdsaPrivateKey zone_pkey; | 62 | static struct GNUNET_IDENTITY_PrivateKey zone_pkey; |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Handle to identity lookup. | 65 | * Handle to identity lookup. |
@@ -496,7 +496,7 @@ display_record (const char *rname, | |||
496 | */ | 496 | */ |
497 | static void | 497 | static void |
498 | display_record_iterator (void *cls, | 498 | display_record_iterator (void *cls, |
499 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 499 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
500 | const char *rname, | 500 | const char *rname, |
501 | unsigned int rd_len, | 501 | unsigned int rd_len, |
502 | const struct GNUNET_GNSRECORD_Data *rd) | 502 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -519,7 +519,7 @@ display_record_iterator (void *cls, | |||
519 | */ | 519 | */ |
520 | static void | 520 | static void |
521 | display_record_monitor (void *cls, | 521 | display_record_monitor (void *cls, |
522 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 522 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
523 | const char *rname, | 523 | const char *rname, |
524 | unsigned int rd_len, | 524 | unsigned int rd_len, |
525 | const struct GNUNET_GNSRECORD_Data *rd) | 525 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -542,7 +542,7 @@ display_record_monitor (void *cls, | |||
542 | */ | 542 | */ |
543 | static void | 543 | static void |
544 | display_record_lookup (void *cls, | 544 | display_record_lookup (void *cls, |
545 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 545 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
546 | const char *rname, | 546 | const char *rname, |
547 | unsigned int rd_len, | 547 | unsigned int rd_len, |
548 | const struct GNUNET_GNSRECORD_Data *rd) | 548 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -622,7 +622,7 @@ add_error_cb (void *cls) | |||
622 | */ | 622 | */ |
623 | static void | 623 | static void |
624 | get_existing_record (void *cls, | 624 | get_existing_record (void *cls, |
625 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 625 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
626 | const char *rec_name, | 626 | const char *rec_name, |
627 | unsigned int rd_count, | 627 | unsigned int rd_count, |
628 | const struct GNUNET_GNSRECORD_Data *rd) | 628 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -661,11 +661,11 @@ get_existing_record (void *cls, | |||
661 | return; | 661 | return; |
662 | 662 | ||
663 | case GNUNET_GNSRECORD_TYPE_PKEY: | 663 | case GNUNET_GNSRECORD_TYPE_PKEY: |
664 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
664 | fprintf ( | 665 | fprintf ( |
665 | stderr, | 666 | stderr, |
666 | _ ( | 667 | _ ( |
667 | "A %s record exists already under `%s', no other records can be added.\n"), | 668 | "A zone key record exists already under `%s', no other records can be added.\n"), |
668 | "PKEY", | ||
669 | rec_name); | 669 | rec_name); |
670 | ret = 1; | 670 | ret = 1; |
671 | test_finished (); | 671 | test_finished (); |
@@ -703,13 +703,13 @@ get_existing_record (void *cls, | |||
703 | break; | 703 | break; |
704 | 704 | ||
705 | case GNUNET_GNSRECORD_TYPE_PKEY: | 705 | case GNUNET_GNSRECORD_TYPE_PKEY: |
706 | case GNUNET_GNSRECORD_TYPE_EDKEY: | ||
706 | if (0 != rd_count) | 707 | if (0 != rd_count) |
707 | { | 708 | { |
708 | fprintf (stderr, | 709 | fprintf (stderr, |
709 | _ ( | 710 | _ ( |
710 | "Records already exist under `%s', cannot add `%s' record.\n"), | 711 | "Records already exist under `%s', cannot add record.\n"), |
711 | rec_name, | 712 | rec_name); |
712 | "PKEY"); | ||
713 | ret = 1; | 713 | ret = 1; |
714 | test_finished (); | 714 | test_finished (); |
715 | return; | 715 | return; |
@@ -781,7 +781,7 @@ reverse_error_cb (void *cls) | |||
781 | */ | 781 | */ |
782 | static void | 782 | static void |
783 | handle_reverse_lookup (void *cls, | 783 | handle_reverse_lookup (void *cls, |
784 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 784 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
785 | const char *label, | 785 | const char *label, |
786 | unsigned int rd_count, | 786 | unsigned int rd_count, |
787 | const struct GNUNET_GNSRECORD_Data *rd) | 787 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -826,7 +826,7 @@ del_lookup_error_cb (void *cls) | |||
826 | */ | 826 | */ |
827 | static void | 827 | static void |
828 | del_monitor (void *cls, | 828 | del_monitor (void *cls, |
829 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 829 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
830 | const char *label, | 830 | const char *label, |
831 | unsigned int rd_count, | 831 | unsigned int rd_count, |
832 | const struct GNUNET_GNSRECORD_Data *rd) | 832 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1187,12 +1187,11 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1187 | } | 1187 | } |
1188 | if (NULL != reverse_pkey) | 1188 | if (NULL != reverse_pkey) |
1189 | { | 1189 | { |
1190 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 1190 | struct GNUNET_IDENTITY_PublicKey pubkey; |
1191 | 1191 | ||
1192 | if (GNUNET_OK != | 1192 | if (GNUNET_OK != |
1193 | GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_pkey, | 1193 | GNUNET_IDENTITY_public_key_from_string (reverse_pkey, |
1194 | strlen (reverse_pkey), | 1194 | &pubkey)) |
1195 | &pubkey)) | ||
1196 | { | 1195 | { |
1197 | fprintf (stderr, | 1196 | fprintf (stderr, |
1198 | _ ("Invalid public key for reverse lookup `%s'\n"), | 1197 | _ ("Invalid public key for reverse lookup `%s'\n"), |
@@ -1211,12 +1210,12 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1211 | { | 1210 | { |
1212 | char sh[105]; | 1211 | char sh[105]; |
1213 | char sname[64]; | 1212 | char sname[64]; |
1214 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1213 | struct GNUNET_IDENTITY_PublicKey pkey; |
1215 | 1214 | ||
1216 | GNUNET_STRINGS_utf8_tolower (uri, uri); | 1215 | GNUNET_STRINGS_utf8_tolower (uri, uri); |
1217 | if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) || | 1216 | if ((2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname))) || |
1218 | (GNUNET_OK != | 1217 | (GNUNET_OK != |
1219 | GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey))) | 1218 | GNUNET_IDENTITY_public_key_from_string (sh, &pkey))) |
1220 | { | 1219 | { |
1221 | fprintf (stderr, _ ("Invalid URI `%s'\n"), uri); | 1220 | fprintf (stderr, _ ("Invalid URI `%s'\n"), uri); |
1222 | GNUNET_SCHEDULER_shutdown (); | 1221 | GNUNET_SCHEDULER_shutdown (); |
@@ -1242,8 +1241,8 @@ run_with_zone_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1242 | } | 1241 | } |
1243 | memset (&rd, 0, sizeof(rd)); | 1242 | memset (&rd, 0, sizeof(rd)); |
1244 | rd.data = &pkey; | 1243 | rd.data = &pkey; |
1245 | rd.data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | 1244 | rd.data_size = GNUNET_IDENTITY_key_get_length (&pkey); |
1246 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 1245 | rd.record_type = ntohl (pkey.type); |
1247 | rd.expiration_time = etime; | 1246 | rd.expiration_time = etime; |
1248 | if (GNUNET_YES == etime_is_rel) | 1247 | if (GNUNET_YES == etime_is_rel) |
1249 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1248 | rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
@@ -1704,11 +1703,13 @@ main (int argc, char *const *argv) | |||
1704 | NULL))) | 1703 | NULL))) |
1705 | { | 1704 | { |
1706 | GNUNET_free_nz ((void *) argv); | 1705 | GNUNET_free_nz ((void *) argv); |
1707 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1706 | //FIXME |
1707 | //GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | ||
1708 | return lret; | 1708 | return lret; |
1709 | } | 1709 | } |
1710 | GNUNET_free_nz ((void *) argv); | 1710 | GNUNET_free_nz ((void *) argv); |
1711 | GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | 1711 | //FIXME |
1712 | //GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey); | ||
1712 | return ret; | 1713 | return ret; |
1713 | } | 1714 | } |
1714 | 1715 | ||
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index b24bb2952..d6774b37b 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -82,7 +82,7 @@ struct ZoneIteration | |||
82 | /** | 82 | /** |
83 | * Key of the zone we are iterating over. | 83 | * Key of the zone we are iterating over. |
84 | */ | 84 | */ |
85 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 85 | struct GNUNET_IDENTITY_PrivateKey zone; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Last sequence number in the zone iteration used to address next | 88 | * Last sequence number in the zone iteration used to address next |
@@ -174,7 +174,7 @@ struct ZoneMonitor | |||
174 | /** | 174 | /** |
175 | * Private key of the zone. | 175 | * Private key of the zone. |
176 | */ | 176 | */ |
177 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 177 | struct GNUNET_IDENTITY_PrivateKey zone; |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * Task active during initial iteration. | 180 | * Task active during initial iteration. |
@@ -314,7 +314,7 @@ struct NickCache | |||
314 | /** | 314 | /** |
315 | * Zone the cache entry is for. | 315 | * Zone the cache entry is for. |
316 | */ | 316 | */ |
317 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 317 | struct GNUNET_IDENTITY_PrivateKey zone; |
318 | 318 | ||
319 | /** | 319 | /** |
320 | * Cached record data. | 320 | * Cached record data. |
@@ -336,7 +336,7 @@ static struct NickCache nick_cache[NC_SIZE]; | |||
336 | /** | 336 | /** |
337 | * Public key of all zeros. | 337 | * Public key of all zeros. |
338 | */ | 338 | */ |
339 | static const struct GNUNET_CRYPTO_EcdsaPrivateKey zero; | 339 | static const struct GNUNET_IDENTITY_PrivateKey zero; |
340 | 340 | ||
341 | /** | 341 | /** |
342 | * Configuration handle. | 342 | * Configuration handle. |
@@ -481,7 +481,7 @@ free_store_activity (struct StoreActivity *sa) | |||
481 | static void | 481 | static void |
482 | lookup_nick_it (void *cls, | 482 | lookup_nick_it (void *cls, |
483 | uint64_t seq, | 483 | uint64_t seq, |
484 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 484 | const struct GNUNET_IDENTITY_PrivateKey *private_key, |
485 | const char *label, | 485 | const char *label, |
486 | unsigned int rd_count, | 486 | unsigned int rd_count, |
487 | const struct GNUNET_GNSRECORD_Data *rd) | 487 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -521,7 +521,7 @@ lookup_nick_it (void *cls, | |||
521 | * @param nick nick entry to cache | 521 | * @param nick nick entry to cache |
522 | */ | 522 | */ |
523 | static void | 523 | static void |
524 | cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 524 | cache_nick (const struct GNUNET_IDENTITY_PrivateKey *zone, |
525 | const struct GNUNET_GNSRECORD_Data *nick) | 525 | const struct GNUNET_GNSRECORD_Data *nick) |
526 | { | 526 | { |
527 | struct NickCache *oldest; | 527 | struct NickCache *oldest; |
@@ -564,9 +564,9 @@ cache_nick (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
564 | * @return NULL if no NICK record was found | 564 | * @return NULL if no NICK record was found |
565 | */ | 565 | */ |
566 | static struct GNUNET_GNSRECORD_Data * | 566 | static struct GNUNET_GNSRECORD_Data * |
567 | get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | 567 | get_nick_record (const struct GNUNET_IDENTITY_PrivateKey *zone) |
568 | { | 568 | { |
569 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 569 | struct GNUNET_IDENTITY_PublicKey pub; |
570 | struct GNUNET_GNSRECORD_Data *nick; | 570 | struct GNUNET_GNSRECORD_Data *nick; |
571 | int res; | 571 | int res; |
572 | 572 | ||
@@ -606,7 +606,7 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
606 | __LINE__); | 606 | __LINE__); |
607 | if (1 == do_log) | 607 | if (1 == do_log) |
608 | { | 608 | { |
609 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); | 609 | GNUNET_IDENTITY_key_get_public (zone, &pub); |
610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
611 | "No nick name set for zone `%s'\n", | 611 | "No nick name set for zone `%s'\n", |
612 | GNUNET_GNSRECORD_z2s (&pub)); | 612 | GNUNET_GNSRECORD_z2s (&pub)); |
@@ -720,7 +720,7 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
720 | static void | 720 | static void |
721 | send_lookup_response (struct NamestoreClient *nc, | 721 | send_lookup_response (struct NamestoreClient *nc, |
722 | uint32_t request_id, | 722 | uint32_t request_id, |
723 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 723 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
724 | const char *name, | 724 | const char *name, |
725 | unsigned int rd_count, | 725 | unsigned int rd_count, |
726 | const struct GNUNET_GNSRECORD_Data *rd) | 726 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -899,14 +899,14 @@ static void | |||
899 | refresh_block (struct NamestoreClient *nc, | 899 | refresh_block (struct NamestoreClient *nc, |
900 | struct ZoneIteration *zi, | 900 | struct ZoneIteration *zi, |
901 | uint32_t rid, | 901 | uint32_t rid, |
902 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 902 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
903 | const char *name, | 903 | const char *name, |
904 | unsigned int rd_count, | 904 | unsigned int rd_count, |
905 | const struct GNUNET_GNSRECORD_Data *rd) | 905 | const struct GNUNET_GNSRECORD_Data *rd) |
906 | { | 906 | { |
907 | struct GNUNET_GNSRECORD_Block *block; | 907 | struct GNUNET_GNSRECORD_Block *block; |
908 | struct CacheOperation *cop; | 908 | struct CacheOperation *cop; |
909 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 909 | struct GNUNET_IDENTITY_PublicKey pkey; |
910 | struct GNUNET_GNSRECORD_Data *nick; | 910 | struct GNUNET_GNSRECORD_Data *nick; |
911 | struct GNUNET_GNSRECORD_Data *res; | 911 | struct GNUNET_GNSRECORD_Data *res; |
912 | unsigned int res_count; | 912 | unsigned int res_count; |
@@ -946,7 +946,7 @@ refresh_block (struct NamestoreClient *nc, | |||
946 | block = | 946 | block = |
947 | GNUNET_GNSRECORD_block_create (zone_key, exp_time, name, res, res_count); | 947 | GNUNET_GNSRECORD_block_create (zone_key, exp_time, name, res, res_count); |
948 | GNUNET_assert (NULL != block); | 948 | GNUNET_assert (NULL != block); |
949 | GNUNET_CRYPTO_ecdsa_key_get_public (zone_key, &pkey); | 949 | GNUNET_IDENTITY_key_get_public (zone_key, &pkey); |
950 | GNUNET_log ( | 950 | GNUNET_log ( |
951 | GNUNET_ERROR_TYPE_DEBUG, | 951 | GNUNET_ERROR_TYPE_DEBUG, |
952 | "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n", | 952 | "Caching block for label `%s' with %u records and expiration %s in zone `%s' in namecache\n", |
@@ -1214,7 +1214,7 @@ struct RecordLookupContext | |||
1214 | static void | 1214 | static void |
1215 | lookup_it (void *cls, | 1215 | lookup_it (void *cls, |
1216 | uint64_t seq, | 1216 | uint64_t seq, |
1217 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 1217 | const struct GNUNET_IDENTITY_PrivateKey *private_key, |
1218 | const char *label, | 1218 | const char *label, |
1219 | unsigned int rd_count, | 1219 | unsigned int rd_count, |
1220 | const struct GNUNET_GNSRECORD_Data *rd) | 1220 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1605,7 +1605,7 @@ struct ZoneToNameCtx | |||
1605 | static void | 1605 | static void |
1606 | handle_zone_to_name_it (void *cls, | 1606 | handle_zone_to_name_it (void *cls, |
1607 | uint64_t seq, | 1607 | uint64_t seq, |
1608 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1608 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
1609 | const char *name, | 1609 | const char *name, |
1610 | unsigned int rd_count, | 1610 | unsigned int rd_count, |
1611 | const struct GNUNET_GNSRECORD_Data *rd) | 1611 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1738,7 +1738,7 @@ struct ZoneIterationProcResult | |||
1738 | static void | 1738 | static void |
1739 | zone_iterate_proc (void *cls, | 1739 | zone_iterate_proc (void *cls, |
1740 | uint64_t seq, | 1740 | uint64_t seq, |
1741 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1741 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
1742 | const char *name, | 1742 | const char *name, |
1743 | unsigned int rd_count, | 1743 | unsigned int rd_count, |
1744 | const struct GNUNET_GNSRECORD_Data *rd) | 1744 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -2009,7 +2009,7 @@ monitor_iteration_next (void *cls); | |||
2009 | static void | 2009 | static void |
2010 | monitor_iterate_cb (void *cls, | 2010 | monitor_iterate_cb (void *cls, |
2011 | uint64_t seq, | 2011 | uint64_t seq, |
2012 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 2012 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
2013 | const char *name, | 2013 | const char *name, |
2014 | unsigned int rd_count, | 2014 | unsigned int rd_count, |
2015 | const struct GNUNET_GNSRECORD_Data *rd) | 2015 | const struct GNUNET_GNSRECORD_Data *rd) |
diff --git a/src/namestore/gnunet-zoneimport.c b/src/namestore/gnunet-zoneimport.c index 5b4e41475..ce62b52d5 100644 --- a/src/namestore/gnunet-zoneimport.c +++ b/src/namestore/gnunet-zoneimport.c | |||
@@ -96,7 +96,7 @@ struct Zone | |||
96 | /** | 96 | /** |
97 | * Private key of the zone. | 97 | * Private key of the zone. |
98 | */ | 98 | */ |
99 | struct GNUNET_CRYPTO_EcdsaPrivateKey key; | 99 | struct GNUNET_IDENTITY_PrivateKey key; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | 102 | ||
@@ -1405,7 +1405,7 @@ ns_lookup_error_cb (void *cls) | |||
1405 | */ | 1405 | */ |
1406 | static void | 1406 | static void |
1407 | ns_lookup_result_cb (void *cls, | 1407 | ns_lookup_result_cb (void *cls, |
1408 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 1408 | const struct GNUNET_IDENTITY_PrivateKey *key, |
1409 | const char *label, | 1409 | const char *label, |
1410 | unsigned int rd_count, | 1410 | unsigned int rd_count, |
1411 | const struct GNUNET_GNSRECORD_Data *rd) | 1411 | const struct GNUNET_GNSRECORD_Data *rd) |
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 6f45ab1c1..fd9a8ed47 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -90,7 +90,7 @@ struct RecordStoreMessage | |||
90 | /** | 90 | /** |
91 | * The private key of the authority. | 91 | * The private key of the authority. |
92 | */ | 92 | */ |
93 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 93 | struct GNUNET_IDENTITY_PrivateKey private_key; |
94 | 94 | ||
95 | /* followed by: | 95 | /* followed by: |
96 | * name with length name_len | 96 | * name with length name_len |
@@ -134,7 +134,7 @@ struct LabelLookupMessage | |||
134 | /** | 134 | /** |
135 | * The private key of the zone to look up in | 135 | * The private key of the zone to look up in |
136 | */ | 136 | */ |
137 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 137 | struct GNUNET_IDENTITY_PrivateKey zone; |
138 | 138 | ||
139 | /* followed by: | 139 | /* followed by: |
140 | * name with length name_len | 140 | * name with length name_len |
@@ -176,7 +176,7 @@ struct LabelLookupResponseMessage | |||
176 | /** | 176 | /** |
177 | * The private key of the authority. | 177 | * The private key of the authority. |
178 | */ | 178 | */ |
179 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 179 | struct GNUNET_IDENTITY_PrivateKey private_key; |
180 | 180 | ||
181 | /* followed by: | 181 | /* followed by: |
182 | * name with length name_len | 182 | * name with length name_len |
@@ -198,12 +198,12 @@ struct ZoneToNameMessage | |||
198 | /** | 198 | /** |
199 | * The private key of the zone to look up in | 199 | * The private key of the zone to look up in |
200 | */ | 200 | */ |
201 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 201 | struct GNUNET_IDENTITY_PrivateKey zone; |
202 | 202 | ||
203 | /** | 203 | /** |
204 | * The public key of the target zone | 204 | * The public key of the target zone |
205 | */ | 205 | */ |
206 | struct GNUNET_CRYPTO_EcdsaPublicKey value_zone; | 206 | struct GNUNET_IDENTITY_PublicKey value_zone; |
207 | }; | 207 | }; |
208 | 208 | ||
209 | 209 | ||
@@ -241,7 +241,7 @@ struct ZoneToNameResponseMessage | |||
241 | /** | 241 | /** |
242 | * The private key of the zone that contained the name. | 242 | * The private key of the zone that contained the name. |
243 | */ | 243 | */ |
244 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 244 | struct GNUNET_IDENTITY_PrivateKey zone; |
245 | 245 | ||
246 | /* followed by: | 246 | /* followed by: |
247 | * name with length name_len | 247 | * name with length name_len |
@@ -283,7 +283,7 @@ struct RecordResultMessage | |||
283 | /** | 283 | /** |
284 | * The private key of the authority. | 284 | * The private key of the authority. |
285 | */ | 285 | */ |
286 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 286 | struct GNUNET_IDENTITY_PrivateKey private_key; |
287 | 287 | ||
288 | /* followed by: | 288 | /* followed by: |
289 | * name with length name_len | 289 | * name with length name_len |
@@ -311,7 +311,7 @@ struct ZoneMonitorStartMessage | |||
311 | /** | 311 | /** |
312 | * Zone key. | 312 | * Zone key. |
313 | */ | 313 | */ |
314 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 314 | struct GNUNET_IDENTITY_PrivateKey zone; |
315 | }; | 315 | }; |
316 | 316 | ||
317 | 317 | ||
@@ -352,7 +352,7 @@ struct ZoneIterationStartMessage | |||
352 | /** | 352 | /** |
353 | * Zone key. All zeros for "all zones". | 353 | * Zone key. All zeros for "all zones". |
354 | */ | 354 | */ |
355 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 355 | struct GNUNET_IDENTITY_PrivateKey zone; |
356 | }; | 356 | }; |
357 | 357 | ||
358 | 358 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index f383f8b4a..c845b5019 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -174,7 +174,7 @@ struct GNUNET_NAMESTORE_ZoneIterator | |||
174 | /** | 174 | /** |
175 | * Private key of the zone. | 175 | * Private key of the zone. |
176 | */ | 176 | */ |
177 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 177 | struct GNUNET_IDENTITY_PrivateKey zone; |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * The operation id this zone iteration operation has | 180 | * The operation id this zone iteration operation has |
@@ -493,7 +493,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) | |||
493 | static int | 493 | static int |
494 | check_record_result (void *cls, const struct RecordResultMessage *msg) | 494 | check_record_result (void *cls, const struct RecordResultMessage *msg) |
495 | { | 495 | { |
496 | static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy; | 496 | static struct GNUNET_IDENTITY_PrivateKey priv_dummy; |
497 | const char *name; | 497 | const char *name; |
498 | size_t msg_len; | 498 | size_t msg_len; |
499 | size_t name_len; | 499 | size_t name_len; |
@@ -981,7 +981,7 @@ warn_delay (void *cls) | |||
981 | struct GNUNET_NAMESTORE_QueueEntry * | 981 | struct GNUNET_NAMESTORE_QueueEntry * |
982 | GNUNET_NAMESTORE_records_store ( | 982 | GNUNET_NAMESTORE_records_store ( |
983 | struct GNUNET_NAMESTORE_Handle *h, | 983 | struct GNUNET_NAMESTORE_Handle *h, |
984 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 984 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
985 | const char *label, | 985 | const char *label, |
986 | unsigned int rd_count, | 986 | unsigned int rd_count, |
987 | const struct GNUNET_GNSRECORD_Data *rd, | 987 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -1080,7 +1080,7 @@ GNUNET_NAMESTORE_records_store ( | |||
1080 | struct GNUNET_NAMESTORE_QueueEntry * | 1080 | struct GNUNET_NAMESTORE_QueueEntry * |
1081 | GNUNET_NAMESTORE_records_lookup ( | 1081 | GNUNET_NAMESTORE_records_lookup ( |
1082 | struct GNUNET_NAMESTORE_Handle *h, | 1082 | struct GNUNET_NAMESTORE_Handle *h, |
1083 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1083 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1084 | const char *label, | 1084 | const char *label, |
1085 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1085 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1086 | void *error_cb_cls, | 1086 | void *error_cb_cls, |
@@ -1140,8 +1140,8 @@ GNUNET_NAMESTORE_records_lookup ( | |||
1140 | struct GNUNET_NAMESTORE_QueueEntry * | 1140 | struct GNUNET_NAMESTORE_QueueEntry * |
1141 | GNUNET_NAMESTORE_zone_to_name ( | 1141 | GNUNET_NAMESTORE_zone_to_name ( |
1142 | struct GNUNET_NAMESTORE_Handle *h, | 1142 | struct GNUNET_NAMESTORE_Handle *h, |
1143 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1143 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1144 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 1144 | const struct GNUNET_IDENTITY_PublicKey *value_zone, |
1145 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1145 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1146 | void *error_cb_cls, | 1146 | void *error_cb_cls, |
1147 | GNUNET_NAMESTORE_RecordMonitor proc, | 1147 | GNUNET_NAMESTORE_RecordMonitor proc, |
@@ -1196,7 +1196,7 @@ GNUNET_NAMESTORE_zone_to_name ( | |||
1196 | struct GNUNET_NAMESTORE_ZoneIterator * | 1196 | struct GNUNET_NAMESTORE_ZoneIterator * |
1197 | GNUNET_NAMESTORE_zone_iteration_start ( | 1197 | GNUNET_NAMESTORE_zone_iteration_start ( |
1198 | struct GNUNET_NAMESTORE_Handle *h, | 1198 | struct GNUNET_NAMESTORE_Handle *h, |
1199 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1199 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1200 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1200 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1201 | void *error_cb_cls, | 1201 | void *error_cb_cls, |
1202 | GNUNET_NAMESTORE_RecordMonitor proc, | 1202 | GNUNET_NAMESTORE_RecordMonitor proc, |
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 9dc955544..6670e54ce 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -82,7 +82,7 @@ struct GNUNET_NAMESTORE_ZoneMonitor | |||
82 | /** | 82 | /** |
83 | * Monitored zone. | 83 | * Monitored zone. |
84 | */ | 84 | */ |
85 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 85 | struct GNUNET_IDENTITY_PrivateKey zone; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Do we first iterate over all existing records? | 88 | * Do we first iterate over all existing records? |
@@ -302,7 +302,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
302 | struct GNUNET_NAMESTORE_ZoneMonitor * | 302 | struct GNUNET_NAMESTORE_ZoneMonitor * |
303 | GNUNET_NAMESTORE_zone_monitor_start ( | 303 | GNUNET_NAMESTORE_zone_monitor_start ( |
304 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 304 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
305 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 305 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
306 | int iterate_first, | 306 | int iterate_first, |
307 | GNUNET_SCHEDULER_TaskCallback error_cb, | 307 | GNUNET_SCHEDULER_TaskCallback error_cb, |
308 | void *error_cb_cls, | 308 | void *error_cb_cls, |
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c index c1012de62..f46a1c523 100644 --- a/src/namestore/perf_namestore_api_zone_iteration.c +++ b/src/namestore/perf_namestore_api_zone_iteration.c | |||
@@ -64,7 +64,7 @@ static struct GNUNET_SCHEDULER_Task *timeout_task; | |||
64 | 64 | ||
65 | static struct GNUNET_SCHEDULER_Task *t; | 65 | static struct GNUNET_SCHEDULER_Task *t; |
66 | 66 | ||
67 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 67 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
68 | 68 | ||
69 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 69 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
70 | 70 | ||
@@ -188,7 +188,7 @@ fail_cb (void *cls) | |||
188 | 188 | ||
189 | static void | 189 | static void |
190 | zone_proc (void *cls, | 190 | zone_proc (void *cls, |
191 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 191 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
192 | const char *label, | 192 | const char *label, |
193 | unsigned int rd_count, | 193 | unsigned int rd_count, |
194 | const struct GNUNET_GNSRECORD_Data *rd) | 194 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -341,7 +341,8 @@ run (void *cls, | |||
341 | NULL); | 341 | NULL); |
342 | nsh = GNUNET_NAMESTORE_connect (cfg); | 342 | nsh = GNUNET_NAMESTORE_connect (cfg); |
343 | GNUNET_assert (NULL != nsh); | 343 | GNUNET_assert (NULL != nsh); |
344 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 344 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
345 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
345 | start = GNUNET_TIME_absolute_get (); | 346 | start = GNUNET_TIME_absolute_get (); |
346 | t = GNUNET_SCHEDULER_add_now (&publish_record, | 347 | t = GNUNET_SCHEDULER_add_now (&publish_record, |
347 | NULL); | 348 | NULL); |
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c index 60b24df67..9ccc90cfd 100644 --- a/src/namestore/plugin_namestore_flat.c +++ b/src/namestore/plugin_namestore_flat.c | |||
@@ -54,7 +54,7 @@ struct FlatFileEntry | |||
54 | /** | 54 | /** |
55 | * Entry zone | 55 | * Entry zone |
56 | */ | 56 | */ |
57 | struct GNUNET_CRYPTO_EcdsaPrivateKey private_key; | 57 | struct GNUNET_IDENTITY_PrivateKey private_key; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Record cound | 60 | * Record cound |
@@ -86,7 +86,7 @@ struct FlatFileEntry | |||
86 | * @param h[out] initialized hash | 86 | * @param h[out] initialized hash |
87 | */ | 87 | */ |
88 | static void | 88 | static void |
89 | hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 89 | hash_pkey_and_label (const struct GNUNET_IDENTITY_PrivateKey *pkey, |
90 | const char *label, | 90 | const char *label, |
91 | struct GNUNET_HashCode *h) | 91 | struct GNUNET_HashCode *h) |
92 | { | 92 | { |
@@ -95,14 +95,14 @@ hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | |||
95 | size_t key_len; | 95 | size_t key_len; |
96 | 96 | ||
97 | label_len = strlen (label); | 97 | label_len = strlen (label); |
98 | key_len = label_len + sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey); | 98 | key_len = label_len + sizeof(struct GNUNET_IDENTITY_PrivateKey); |
99 | key = GNUNET_malloc (key_len); | 99 | key = GNUNET_malloc (key_len); |
100 | GNUNET_memcpy (key, | 100 | GNUNET_memcpy (key, |
101 | label, | 101 | label, |
102 | label_len); | 102 | label_len); |
103 | GNUNET_memcpy (key + label_len, | 103 | GNUNET_memcpy (key + label_len, |
104 | pkey, | 104 | pkey, |
105 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | 105 | sizeof(struct GNUNET_IDENTITY_PrivateKey)); |
106 | GNUNET_CRYPTO_hash (key, | 106 | GNUNET_CRYPTO_hash (key, |
107 | key_len, | 107 | key_len, |
108 | h); | 108 | h); |
@@ -296,7 +296,7 @@ database_setup (struct Plugin *plugin) | |||
296 | GNUNET_free (record_data); | 296 | GNUNET_free (record_data); |
297 | 297 | ||
298 | { | 298 | { |
299 | struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; | 299 | struct GNUNET_IDENTITY_PrivateKey *private_key; |
300 | 300 | ||
301 | GNUNET_STRINGS_base64_decode (zone_private_key, | 301 | GNUNET_STRINGS_base64_decode (zone_private_key, |
302 | strlen (zone_private_key), | 302 | strlen (zone_private_key), |
@@ -345,7 +345,7 @@ store_and_free_entries (void *cls, | |||
345 | 345 | ||
346 | (void) key; | 346 | (void) key; |
347 | GNUNET_STRINGS_base64_encode (&entry->private_key, | 347 | GNUNET_STRINGS_base64_encode (&entry->private_key, |
348 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), | 348 | sizeof(struct GNUNET_IDENTITY_PrivateKey), |
349 | &zone_private_key); | 349 | &zone_private_key); |
350 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, | 350 | data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count, |
351 | entry->record_data); | 351 | entry->record_data); |
@@ -452,7 +452,7 @@ database_shutdown (struct Plugin *plugin) | |||
452 | static int | 452 | static int |
453 | namestore_flat_store_records (void *cls, | 453 | namestore_flat_store_records (void *cls, |
454 | const struct | 454 | const struct |
455 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 455 | GNUNET_IDENTITY_PrivateKey *zone_key, |
456 | const char *label, | 456 | const char *label, |
457 | unsigned int rd_count, | 457 | unsigned int rd_count, |
458 | const struct GNUNET_GNSRECORD_Data *rd) | 458 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -482,7 +482,7 @@ namestore_flat_store_records (void *cls, | |||
482 | strlen (label)); | 482 | strlen (label)); |
483 | GNUNET_memcpy (&entry->private_key, | 483 | GNUNET_memcpy (&entry->private_key, |
484 | zone_key, | 484 | zone_key, |
485 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey)); | 485 | sizeof(struct GNUNET_IDENTITY_PrivateKey)); |
486 | entry->rvalue = rvalue; | 486 | entry->rvalue = rvalue; |
487 | entry->record_count = rd_count; | 487 | entry->record_count = rd_count; |
488 | entry->record_data = GNUNET_new_array (rd_count, | 488 | entry->record_data = GNUNET_new_array (rd_count, |
@@ -517,7 +517,7 @@ namestore_flat_store_records (void *cls, | |||
517 | */ | 517 | */ |
518 | static int | 518 | static int |
519 | namestore_flat_lookup_records (void *cls, | 519 | namestore_flat_lookup_records (void *cls, |
520 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 520 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
521 | const char *label, | 521 | const char *label, |
522 | GNUNET_NAMESTORE_RecordIterator iter, | 522 | GNUNET_NAMESTORE_RecordIterator iter, |
523 | void *iter_cls) | 523 | void *iter_cls) |
@@ -574,7 +574,7 @@ struct IterateContext | |||
574 | /** | 574 | /** |
575 | * Target zone. | 575 | * Target zone. |
576 | */ | 576 | */ |
577 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; | 577 | const struct GNUNET_IDENTITY_PrivateKey *zone; |
578 | 578 | ||
579 | /** | 579 | /** |
580 | * Function to call on each record. | 580 | * Function to call on each record. |
@@ -647,7 +647,7 @@ iterate_zones (void *cls, | |||
647 | static int | 647 | static int |
648 | namestore_flat_iterate_records (void *cls, | 648 | namestore_flat_iterate_records (void *cls, |
649 | const struct | 649 | const struct |
650 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 650 | GNUNET_IDENTITY_PrivateKey *zone, |
651 | uint64_t serial, | 651 | uint64_t serial, |
652 | uint64_t limit, | 652 | uint64_t limit, |
653 | GNUNET_NAMESTORE_RecordIterator iter, | 653 | GNUNET_NAMESTORE_RecordIterator iter, |
@@ -674,8 +674,8 @@ namestore_flat_iterate_records (void *cls, | |||
674 | */ | 674 | */ |
675 | struct ZoneToNameContext | 675 | struct ZoneToNameContext |
676 | { | 676 | { |
677 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone; | 677 | const struct GNUNET_IDENTITY_PrivateKey *zone; |
678 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone; | 678 | const struct GNUNET_IDENTITY_PublicKey *value_zone; |
679 | GNUNET_NAMESTORE_RecordIterator iter; | 679 | GNUNET_NAMESTORE_RecordIterator iter; |
680 | void *iter_cls; | 680 | void *iter_cls; |
681 | 681 | ||
@@ -698,11 +698,14 @@ zone_to_name (void *cls, | |||
698 | 698 | ||
699 | for (unsigned int i = 0; i < entry->record_count; i++) | 699 | for (unsigned int i = 0; i < entry->record_count; i++) |
700 | { | 700 | { |
701 | if (GNUNET_GNSRECORD_TYPE_PKEY != entry->record_data[i].record_type) | 701 | if (GNUNET_NO == |
702 | GNUNET_GNSRECORD_is_zonekey_type (entry->record_data[i].record_type)) | ||
703 | continue; | ||
704 | if (ztn->value_zone->type != entry->record_data[i].record_type) | ||
702 | continue; | 705 | continue; |
703 | if (0 == memcmp (ztn->value_zone, | 706 | if (0 == memcmp (ztn->value_zone, |
704 | entry->record_data[i].data, | 707 | entry->record_data[i].data, |
705 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 708 | entry->record_data[i].data_size)) |
706 | { | 709 | { |
707 | ztn->iter (ztn->iter_cls, | 710 | ztn->iter (ztn->iter_cls, |
708 | i + 1, /* zero is illegal! */ | 711 | i + 1, /* zero is illegal! */ |
@@ -730,9 +733,9 @@ zone_to_name (void *cls, | |||
730 | */ | 733 | */ |
731 | static int | 734 | static int |
732 | namestore_flat_zone_to_name (void *cls, | 735 | namestore_flat_zone_to_name (void *cls, |
733 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 736 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
734 | const struct | 737 | const struct |
735 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 738 | GNUNET_IDENTITY_PublicKey *value_zone, |
736 | GNUNET_NAMESTORE_RecordIterator iter, | 739 | GNUNET_NAMESTORE_RecordIterator iter, |
737 | void *iter_cls) | 740 | void *iter_cls) |
738 | { | 741 | { |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 01dddde9e..bdbaf96b3 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -73,8 +73,7 @@ database_setup (struct Plugin *plugin) | |||
73 | " record_data BYTEA NOT NULL DEFAULT ''," | 73 | " record_data BYTEA NOT NULL DEFAULT ''," |
74 | " label TEXT NOT NULL DEFAULT ''," | 74 | " label TEXT NOT NULL DEFAULT ''," |
75 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | 75 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" |
76 | ")" | 76 | ")"); |
77 | "WITH OIDS"); | ||
78 | struct GNUNET_PQ_ExecuteStatement es_default = | 77 | struct GNUNET_PQ_ExecuteStatement es_default = |
79 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" | 78 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" |
80 | " seq BIGSERIAL PRIMARY KEY," | 79 | " seq BIGSERIAL PRIMARY KEY," |
@@ -85,8 +84,7 @@ database_setup (struct Plugin *plugin) | |||
85 | " record_data BYTEA NOT NULL DEFAULT ''," | 84 | " record_data BYTEA NOT NULL DEFAULT ''," |
86 | " label TEXT NOT NULL DEFAULT ''," | 85 | " label TEXT NOT NULL DEFAULT ''," |
87 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" | 86 | " CONSTRAINT zl UNIQUE (zone_private_key,label)" |
88 | ")" | 87 | ")"); |
89 | "WITH OIDS"); | ||
90 | const struct GNUNET_PQ_ExecuteStatement *cr; | 88 | const struct GNUNET_PQ_ExecuteStatement *cr; |
91 | struct GNUNET_PQ_ExecuteStatement sc = GNUNET_PQ_EXECUTE_STATEMENT_END; | 89 | struct GNUNET_PQ_ExecuteStatement sc = GNUNET_PQ_EXECUTE_STATEMENT_END; |
92 | 90 | ||
@@ -182,13 +180,13 @@ database_setup (struct Plugin *plugin) | |||
182 | static int | 180 | static int |
183 | namestore_postgres_store_records (void *cls, | 181 | namestore_postgres_store_records (void *cls, |
184 | const struct | 182 | const struct |
185 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 183 | GNUNET_IDENTITY_PrivateKey *zone_key, |
186 | const char *label, | 184 | const char *label, |
187 | unsigned int rd_count, | 185 | unsigned int rd_count, |
188 | const struct GNUNET_GNSRECORD_Data *rd) | 186 | const struct GNUNET_GNSRECORD_Data *rd) |
189 | { | 187 | { |
190 | struct Plugin *plugin = cls; | 188 | struct Plugin *plugin = cls; |
191 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 189 | struct GNUNET_IDENTITY_PublicKey pkey; |
192 | uint64_t rvalue; | 190 | uint64_t rvalue; |
193 | uint32_t rd_count32 = (uint32_t) rd_count; | 191 | uint32_t rd_count32 = (uint32_t) rd_count; |
194 | ssize_t data_size; | 192 | ssize_t data_size; |
@@ -197,13 +195,14 @@ namestore_postgres_store_records (void *cls, | |||
197 | 0, | 195 | 0, |
198 | sizeof(pkey)); | 196 | sizeof(pkey)); |
199 | for (unsigned int i = 0; i < rd_count; i++) | 197 | for (unsigned int i = 0; i < rd_count; i++) |
200 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) | 198 | if (GNUNET_YES == |
199 | GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type)) | ||
201 | { | 200 | { |
202 | GNUNET_break (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == | 201 | GNUNET_break (GNUNET_OK == |
203 | rd[i].data_size); | 202 | GNUNET_GNSRECORD_identity_from_data (rd[i].data, |
204 | GNUNET_memcpy (&pkey, | 203 | rd[i].data_size, |
205 | rd[i].data, | 204 | rd[i].record_type, |
206 | rd[i].data_size); | 205 | &pkey)); |
207 | break; | 206 | break; |
208 | } | 207 | } |
209 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 208 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -298,7 +297,7 @@ struct ParserContext | |||
298 | /** | 297 | /** |
299 | * Zone key, NULL if part of record. | 298 | * Zone key, NULL if part of record. |
300 | */ | 299 | */ |
301 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; | 300 | const struct GNUNET_IDENTITY_PrivateKey *zone_key; |
302 | 301 | ||
303 | /** | 302 | /** |
304 | * Number of results still to return (counted down by | 303 | * Number of results still to return (counted down by |
@@ -332,7 +331,7 @@ parse_result_call_iterator (void *cls, | |||
332 | size_t data_size; | 331 | size_t data_size; |
333 | uint32_t record_count; | 332 | uint32_t record_count; |
334 | char *label; | 333 | char *label; |
335 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | 334 | struct GNUNET_IDENTITY_PrivateKey zk; |
336 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { | 335 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { |
337 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | 336 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), |
338 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | 337 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), |
@@ -409,7 +408,7 @@ parse_result_call_iterator (void *cls, | |||
409 | static int | 408 | static int |
410 | namestore_postgres_lookup_records (void *cls, | 409 | namestore_postgres_lookup_records (void *cls, |
411 | const struct | 410 | const struct |
412 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 411 | GNUNET_IDENTITY_PrivateKey *zone, |
413 | const char *label, | 412 | const char *label, |
414 | GNUNET_NAMESTORE_RecordIterator iter, | 413 | GNUNET_NAMESTORE_RecordIterator iter, |
415 | void *iter_cls) | 414 | void *iter_cls) |
@@ -459,7 +458,7 @@ namestore_postgres_lookup_records (void *cls, | |||
459 | static int | 458 | static int |
460 | namestore_postgres_iterate_records (void *cls, | 459 | namestore_postgres_iterate_records (void *cls, |
461 | const struct | 460 | const struct |
462 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 461 | GNUNET_IDENTITY_PrivateKey *zone, |
463 | uint64_t serial, | 462 | uint64_t serial, |
464 | uint64_t limit, | 463 | uint64_t limit, |
465 | GNUNET_NAMESTORE_RecordIterator iter, | 464 | GNUNET_NAMESTORE_RecordIterator iter, |
@@ -526,9 +525,9 @@ namestore_postgres_iterate_records (void *cls, | |||
526 | static int | 525 | static int |
527 | namestore_postgres_zone_to_name (void *cls, | 526 | namestore_postgres_zone_to_name (void *cls, |
528 | const struct | 527 | const struct |
529 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 528 | GNUNET_IDENTITY_PrivateKey *zone, |
530 | const struct | 529 | const struct |
531 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 530 | GNUNET_IDENTITY_PublicKey *value_zone, |
532 | GNUNET_NAMESTORE_RecordIterator iter, | 531 | GNUNET_NAMESTORE_RecordIterator iter, |
533 | void *iter_cls) | 532 | void *iter_cls) |
534 | { | 533 | { |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 45fb782f7..7cb9b7ed0 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -314,14 +314,14 @@ database_shutdown (struct Plugin *plugin) | |||
314 | static int | 314 | static int |
315 | namestore_sqlite_store_records (void *cls, | 315 | namestore_sqlite_store_records (void *cls, |
316 | const struct | 316 | const struct |
317 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 317 | GNUNET_IDENTITY_PrivateKey *zone_key, |
318 | const char *label, | 318 | const char *label, |
319 | unsigned int rd_count, | 319 | unsigned int rd_count, |
320 | const struct GNUNET_GNSRECORD_Data *rd) | 320 | const struct GNUNET_GNSRECORD_Data *rd) |
321 | { | 321 | { |
322 | struct Plugin *plugin = cls; | 322 | struct Plugin *plugin = cls; |
323 | int n; | 323 | int n; |
324 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 324 | struct GNUNET_IDENTITY_PublicKey pkey; |
325 | uint64_t rvalue; | 325 | uint64_t rvalue; |
326 | ssize_t data_size; | 326 | ssize_t data_size; |
327 | 327 | ||
@@ -329,13 +329,13 @@ namestore_sqlite_store_records (void *cls, | |||
329 | 0, | 329 | 0, |
330 | sizeof(pkey)); | 330 | sizeof(pkey)); |
331 | for (unsigned int i = 0; i < rd_count; i++) | 331 | for (unsigned int i = 0; i < rd_count; i++) |
332 | if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type) | 332 | if (GNUNET_YES == GNUNET_GNSRECORD_is_zonekey_type (rd[i].record_type)) |
333 | { | 333 | { |
334 | GNUNET_break (sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) == | 334 | GNUNET_break (GNUNET_YES == |
335 | rd[i].data_size); | 335 | GNUNET_GNSRECORD_identity_from_data (rd[i].data, |
336 | GNUNET_memcpy (&pkey, | 336 | rd[i].data_size, |
337 | rd[i].data, | 337 | rd[i].record_type, |
338 | rd[i].data_size); | 338 | &pkey)); |
339 | break; | 339 | break; |
340 | } | 340 | } |
341 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 341 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -461,7 +461,7 @@ static int | |||
461 | get_records_and_call_iterator (struct Plugin *plugin, | 461 | get_records_and_call_iterator (struct Plugin *plugin, |
462 | sqlite3_stmt *stmt, | 462 | sqlite3_stmt *stmt, |
463 | const struct | 463 | const struct |
464 | GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 464 | GNUNET_IDENTITY_PrivateKey *zone_key, |
465 | uint64_t limit, | 465 | uint64_t limit, |
466 | GNUNET_NAMESTORE_RecordIterator iter, | 466 | GNUNET_NAMESTORE_RecordIterator iter, |
467 | void *iter_cls) | 467 | void *iter_cls) |
@@ -496,7 +496,7 @@ get_records_and_call_iterator (struct Plugin *plugin, | |||
496 | size_t data_size; | 496 | size_t data_size; |
497 | void *data; | 497 | void *data; |
498 | char *label; | 498 | char *label; |
499 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | 499 | struct GNUNET_IDENTITY_PrivateKey zk; |
500 | struct GNUNET_SQ_ResultSpec rs[] = { | 500 | struct GNUNET_SQ_ResultSpec rs[] = { |
501 | GNUNET_SQ_result_spec_uint64 (&seq), | 501 | GNUNET_SQ_result_spec_uint64 (&seq), |
502 | GNUNET_SQ_result_spec_uint32 (&record_count), | 502 | GNUNET_SQ_result_spec_uint32 (&record_count), |
@@ -578,7 +578,7 @@ get_records_and_call_iterator (struct Plugin *plugin, | |||
578 | static int | 578 | static int |
579 | namestore_sqlite_lookup_records (void *cls, | 579 | namestore_sqlite_lookup_records (void *cls, |
580 | const struct | 580 | const struct |
581 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 581 | GNUNET_IDENTITY_PrivateKey *zone, |
582 | const char *label, | 582 | const char *label, |
583 | GNUNET_NAMESTORE_RecordIterator iter, | 583 | GNUNET_NAMESTORE_RecordIterator iter, |
584 | void *iter_cls) | 584 | void *iter_cls) |
@@ -629,7 +629,7 @@ namestore_sqlite_lookup_records (void *cls, | |||
629 | static int | 629 | static int |
630 | namestore_sqlite_iterate_records (void *cls, | 630 | namestore_sqlite_iterate_records (void *cls, |
631 | const struct | 631 | const struct |
632 | GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 632 | GNUNET_IDENTITY_PrivateKey *zone, |
633 | uint64_t serial, | 633 | uint64_t serial, |
634 | uint64_t limit, | 634 | uint64_t limit, |
635 | GNUNET_NAMESTORE_RecordIterator iter, | 635 | GNUNET_NAMESTORE_RecordIterator iter, |
@@ -695,9 +695,9 @@ namestore_sqlite_iterate_records (void *cls, | |||
695 | */ | 695 | */ |
696 | static int | 696 | static int |
697 | namestore_sqlite_zone_to_name (void *cls, | 697 | namestore_sqlite_zone_to_name (void *cls, |
698 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 698 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
699 | const struct | 699 | const struct |
700 | GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 700 | GNUNET_IDENTITY_PublicKey *value_zone, |
701 | GNUNET_NAMESTORE_RecordIterator iter, | 701 | GNUNET_NAMESTORE_RecordIterator iter, |
702 | void *iter_cls) | 702 | void *iter_cls) |
703 | { | 703 | { |
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 9354b9896..edcbeb874 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "gnunet_namestore_service.h" | 30 | #include "gnunet_namestore_service.h" |
31 | #include "gnunet_identity_service.h" | 31 | #include "gnunet_identity_service.h" |
32 | #include "gnunet_rest_lib.h" | 32 | #include "gnunet_rest_lib.h" |
33 | #include "gnunet_json_lib.h" | 33 | #include "gnunet_gnsrecord_json_lib.h" |
34 | #include "microhttpd.h" | 34 | #include "microhttpd.h" |
35 | #include <jansson.h> | 35 | #include <jansson.h> |
36 | 36 | ||
@@ -214,7 +214,7 @@ struct RequestHandle | |||
214 | /** | 214 | /** |
215 | * Private key for the zone | 215 | * Private key for the zone |
216 | */ | 216 | */ |
217 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey; | 217 | const struct GNUNET_IDENTITY_PrivateKey *zone_pkey; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * IDENTITY Operation | 220 | * IDENTITY Operation |
@@ -510,7 +510,7 @@ namestore_list_finished (void *cls) | |||
510 | */ | 510 | */ |
511 | static void | 511 | static void |
512 | namestore_list_iteration (void *cls, | 512 | namestore_list_iteration (void *cls, |
513 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 513 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
514 | const char *rname, | 514 | const char *rname, |
515 | unsigned int rd_len, | 515 | unsigned int rd_len, |
516 | const struct GNUNET_GNSRECORD_Data *rd) | 516 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -535,9 +535,9 @@ namestore_list_iteration (void *cls, | |||
535 | /** Only add if not empty **/ | 535 | /** Only add if not empty **/ |
536 | if (j > 0) | 536 | if (j > 0) |
537 | { | 537 | { |
538 | record_obj = GNUNET_JSON_from_gnsrecord (rname, | 538 | record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname, |
539 | rd_filtered, | 539 | rd_filtered, |
540 | j); | 540 | j); |
541 | json_array_append_new (handle->resp_object, record_obj); | 541 | json_array_append_new (handle->resp_object, record_obj); |
542 | } | 542 | } |
543 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); | 543 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); |
@@ -561,7 +561,7 @@ ns_lookup_error_cb (void *cls) | |||
561 | 561 | ||
562 | static void | 562 | static void |
563 | ns_get_lookup_cb (void *cls, | 563 | ns_get_lookup_cb (void *cls, |
564 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 564 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
565 | const char *label, | 565 | const char *label, |
566 | unsigned int rd_len, | 566 | unsigned int rd_len, |
567 | const struct GNUNET_GNSRECORD_Data *rd) | 567 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -587,9 +587,9 @@ ns_get_lookup_cb (void *cls, | |||
587 | /** Only add if not empty **/ | 587 | /** Only add if not empty **/ |
588 | if (j > 0) | 588 | if (j > 0) |
589 | { | 589 | { |
590 | record_obj = GNUNET_JSON_from_gnsrecord (label, | 590 | record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label, |
591 | rd_filtered, | 591 | rd_filtered, |
592 | j); | 592 | j); |
593 | json_array_append_new (handle->resp_object, record_obj); | 593 | json_array_append_new (handle->resp_object, record_obj); |
594 | } | 594 | } |
595 | GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle); | 595 | GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle); |
@@ -689,7 +689,7 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
689 | 689 | ||
690 | static void | 690 | static void |
691 | ns_lookup_cb (void *cls, | 691 | ns_lookup_cb (void *cls, |
692 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 692 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
693 | const char *label, | 693 | const char *label, |
694 | unsigned int rd_count, | 694 | unsigned int rd_count, |
695 | const struct GNUNET_GNSRECORD_Data *rd) | 695 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -755,7 +755,7 @@ namestore_add_or_update (struct GNUNET_REST_RequestHandle *con_handle, | |||
755 | handle->rest_handle->data_size); | 755 | handle->rest_handle->data_size); |
756 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 756 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); |
757 | struct GNUNET_JSON_Specification gnsspec[] = | 757 | struct GNUNET_JSON_Specification gnsspec[] = |
758 | { GNUNET_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count, | 758 | { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&handle->rd, &handle->rd_count, |
759 | &handle->record_name), | 759 | &handle->record_name), |
760 | GNUNET_JSON_spec_end () }; | 760 | GNUNET_JSON_spec_end () }; |
761 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) | 761 | if (GNUNET_OK != GNUNET_JSON_parse (data_js, gnsspec, NULL, NULL)) |
@@ -946,7 +946,7 @@ list_ego (void *cls, | |||
946 | const char *identifier) | 946 | const char *identifier) |
947 | { | 947 | { |
948 | struct EgoEntry *ego_entry; | 948 | struct EgoEntry *ego_entry; |
949 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 949 | struct GNUNET_IDENTITY_PublicKey pk; |
950 | 950 | ||
951 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) | 951 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
952 | { | 952 | { |
@@ -957,7 +957,7 @@ list_ego (void *cls, | |||
957 | { | 957 | { |
958 | ego_entry = GNUNET_new (struct EgoEntry); | 958 | ego_entry = GNUNET_new (struct EgoEntry); |
959 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 959 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
960 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 960 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
961 | ego_entry->ego = ego; | 961 | ego_entry->ego = ego; |
962 | ego_entry->identifier = GNUNET_strdup (identifier); | 962 | ego_entry->identifier = GNUNET_strdup (identifier); |
963 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 963 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
@@ -983,7 +983,7 @@ list_ego (void *cls, | |||
983 | /* Add */ | 983 | /* Add */ |
984 | ego_entry = GNUNET_new (struct EgoEntry); | 984 | ego_entry = GNUNET_new (struct EgoEntry); |
985 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 985 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
986 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 986 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
987 | ego_entry->ego = ego; | 987 | ego_entry->ego = ego; |
988 | ego_entry->identifier = GNUNET_strdup (identifier); | 988 | ego_entry->identifier = GNUNET_strdup (identifier); |
989 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 989 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
diff --git a/src/namestore/test_namestore_api_lookup_nick.c b/src/namestore/test_namestore_api_lookup_nick.c index 14fe7fc70..6ce969c9b 100644 --- a/src/namestore/test_namestore_api_lookup_nick.c +++ b/src/namestore/test_namestore_api_lookup_nick.c | |||
@@ -41,9 +41,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
41 | 41 | ||
42 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 42 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 44 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
45 | 45 | ||
46 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 46 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
47 | 47 | ||
48 | static int res; | 48 | static int res; |
49 | 49 | ||
@@ -98,7 +98,7 @@ end (void *cls) | |||
98 | 98 | ||
99 | static void | 99 | static void |
100 | lookup_it (void *cls, | 100 | lookup_it (void *cls, |
101 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 101 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
102 | const char *label, | 102 | const char *label, |
103 | unsigned int rd_count, | 103 | unsigned int rd_count, |
104 | const struct GNUNET_GNSRECORD_Data *rd) | 104 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -288,8 +288,9 @@ run (void *cls, | |||
288 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 288 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
289 | &endbadly, | 289 | &endbadly, |
290 | NULL); | 290 | NULL); |
291 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 291 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
292 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 292 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
293 | GNUNET_IDENTITY_key_get_public (&privkey, | ||
293 | &pubkey); | 294 | &pubkey); |
294 | 295 | ||
295 | nsh = GNUNET_NAMESTORE_connect (cfg); | 296 | nsh = GNUNET_NAMESTORE_connect (cfg); |
diff --git a/src/namestore/test_namestore_api_lookup_private.c b/src/namestore/test_namestore_api_lookup_private.c index d0ad726cc..67cf54582 100644 --- a/src/namestore/test_namestore_api_lookup_private.c +++ b/src/namestore/test_namestore_api_lookup_private.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 41 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 43 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
44 | 44 | ||
45 | static int res; | 45 | static int res; |
46 | 46 | ||
@@ -91,7 +91,7 @@ end (void *cls) | |||
91 | 91 | ||
92 | static void | 92 | static void |
93 | lookup_it (void *cls, | 93 | lookup_it (void *cls, |
94 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 94 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
95 | const char *label, | 95 | const char *label, |
96 | unsigned int rd_count, | 96 | unsigned int rd_count, |
97 | const struct GNUNET_GNSRECORD_Data *rd) | 97 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -187,8 +187,9 @@ run (void *cls, | |||
187 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 187 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
188 | &endbadly, | 188 | &endbadly, |
189 | NULL); | 189 | NULL); |
190 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 190 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
191 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); | 191 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
192 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); | ||
192 | 193 | ||
193 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | 194 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
194 | rd.record_type = TEST_RECORD_TYPE; | 195 | rd.record_type = TEST_RECORD_TYPE; |
diff --git a/src/namestore/test_namestore_api_lookup_public.c b/src/namestore/test_namestore_api_lookup_public.c index 039c7cbf6..5e3e7bbd8 100644 --- a/src/namestore/test_namestore_api_lookup_public.c +++ b/src/namestore/test_namestore_api_lookup_public.c | |||
@@ -42,9 +42,9 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 45 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 47 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
48 | 48 | ||
49 | static int res; | 49 | static int res; |
50 | 50 | ||
@@ -163,7 +163,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
163 | { | 163 | { |
164 | const char *name = cls; | 164 | const char *name = cls; |
165 | struct GNUNET_HashCode derived_hash; | 165 | struct GNUNET_HashCode derived_hash; |
166 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 166 | struct GNUNET_IDENTITY_PublicKey pubkey; |
167 | 167 | ||
168 | nsqe = NULL; | 168 | nsqe = NULL; |
169 | GNUNET_assert (NULL != cls); | 169 | GNUNET_assert (NULL != cls); |
@@ -173,8 +173,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
173 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 173 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
174 | 174 | ||
175 | /* Create derived hash */ | 175 | /* Create derived hash */ |
176 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 176 | GNUNET_IDENTITY_key_get_public (&privkey, |
177 | &pubkey); | 177 | &pubkey); |
178 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); | 178 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, name, &derived_hash); |
179 | 179 | ||
180 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, | 180 | ncqe = GNUNET_NAMECACHE_lookup_block (nch, &derived_hash, |
@@ -193,9 +193,10 @@ run (void *cls, | |||
193 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 193 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
194 | &endbadly, | 194 | &endbadly, |
195 | NULL); | 195 | NULL); |
196 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 196 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
197 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 197 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
198 | &pubkey); | 198 | GNUNET_IDENTITY_key_get_public (&privkey, |
199 | &pubkey); | ||
199 | 200 | ||
200 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 201 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
201 | rd.record_type = TEST_RECORD_TYPE; | 202 | rd.record_type = TEST_RECORD_TYPE; |
diff --git a/src/namestore/test_namestore_api_lookup_shadow.c b/src/namestore/test_namestore_api_lookup_shadow.c index d399d903a..79fa4c9c6 100644 --- a/src/namestore/test_namestore_api_lookup_shadow.c +++ b/src/namestore/test_namestore_api_lookup_shadow.c | |||
@@ -44,9 +44,9 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
44 | 44 | ||
45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 45 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 47 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
48 | 48 | ||
49 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 49 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
50 | 50 | ||
51 | static int res; | 51 | static int res; |
52 | 52 | ||
@@ -195,7 +195,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
195 | { | 195 | { |
196 | const char *name = cls; | 196 | const char *name = cls; |
197 | struct GNUNET_HashCode derived_hash; | 197 | struct GNUNET_HashCode derived_hash; |
198 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 198 | struct GNUNET_IDENTITY_PublicKey pubkey; |
199 | 199 | ||
200 | nsqe = NULL; | 200 | nsqe = NULL; |
201 | GNUNET_assert (NULL != cls); | 201 | GNUNET_assert (NULL != cls); |
@@ -205,8 +205,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
205 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 205 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
206 | 206 | ||
207 | /* Create derived hash */ | 207 | /* Create derived hash */ |
208 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 208 | GNUNET_IDENTITY_key_get_public (&privkey, |
209 | &pubkey); | 209 | &pubkey); |
210 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, | 210 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, |
211 | name, | 211 | name, |
212 | &derived_hash); | 212 | &derived_hash); |
@@ -228,9 +228,10 @@ run (void *cls, | |||
228 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 228 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
229 | &endbadly, | 229 | &endbadly, |
230 | NULL); | 230 | NULL); |
231 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 231 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
232 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 232 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
233 | &pubkey); | 233 | GNUNET_IDENTITY_key_get_public (&privkey, |
234 | &pubkey); | ||
234 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 235 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
235 | rd.record_type = TEST_RECORD_TYPE; | 236 | rd.record_type = TEST_RECORD_TYPE; |
236 | rd.data_size = TEST_RECORD_DATALEN; | 237 | rd.data_size = TEST_RECORD_DATALEN; |
diff --git a/src/namestore/test_namestore_api_lookup_shadow_filter.c b/src/namestore/test_namestore_api_lookup_shadow_filter.c index 40dbeb90f..4fc197750 100644 --- a/src/namestore/test_namestore_api_lookup_shadow_filter.c +++ b/src/namestore/test_namestore_api_lookup_shadow_filter.c | |||
@@ -48,9 +48,9 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; | |||
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; | 49 | static struct GNUNET_SCHEDULER_Task *delayed_lookup_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 51 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
52 | 52 | ||
53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 53 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
54 | 54 | ||
55 | static int res; | 55 | static int res; |
56 | 56 | ||
@@ -66,7 +66,7 @@ static struct GNUNET_TIME_Absolute record_expiration; | |||
66 | 66 | ||
67 | static struct GNUNET_HashCode derived_hash; | 67 | static struct GNUNET_HashCode derived_hash; |
68 | 68 | ||
69 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 69 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
70 | 70 | ||
71 | 71 | ||
72 | static void | 72 | static void |
@@ -267,8 +267,8 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
267 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); | 267 | (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); |
268 | 268 | ||
269 | /* Create derived hash */ | 269 | /* Create derived hash */ |
270 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 270 | GNUNET_IDENTITY_key_get_public (&privkey, |
271 | &pubkey); | 271 | &pubkey); |
272 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); | 272 | GNUNET_GNSRECORD_query_from_public_key (&pubkey, TEST_NAME, &derived_hash); |
273 | 273 | ||
274 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) | 274 | if (0 == GNUNET_TIME_absolute_get_remaining (record_expiration).rel_value_us) |
@@ -297,9 +297,10 @@ run (void *cls, | |||
297 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 297 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
298 | &endbadly, | 298 | &endbadly, |
299 | NULL); | 299 | NULL); |
300 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 300 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
301 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 301 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
302 | &pubkey); | 302 | GNUNET_IDENTITY_key_get_public (&privkey, |
303 | &pubkey); | ||
303 | 304 | ||
304 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 305 | record_expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
305 | EXPIRATION); | 306 | EXPIRATION); |
diff --git a/src/namestore/test_namestore_api_monitoring.c b/src/namestore/test_namestore_api_monitoring.c index 3f1be1403..df0c38608 100644 --- a/src/namestore/test_namestore_api_monitoring.c +++ b/src/namestore/test_namestore_api_monitoring.c | |||
@@ -37,9 +37,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
37 | 37 | ||
38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 40 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 44 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
45 | 45 | ||
@@ -133,7 +133,7 @@ end (void *cls) | |||
133 | 133 | ||
134 | static void | 134 | static void |
135 | zone_proc (void *cls, | 135 | zone_proc (void *cls, |
136 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 136 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
137 | const char *name, | 137 | const char *name, |
138 | unsigned int rd_count, | 138 | unsigned int rd_count, |
139 | const struct GNUNET_GNSRECORD_Data *rd) | 139 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -273,7 +273,8 @@ run (void *cls, | |||
273 | struct GNUNET_TESTING_Peer *peer) | 273 | struct GNUNET_TESTING_Peer *peer) |
274 | { | 274 | { |
275 | res = 1; | 275 | res = 1; |
276 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 276 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
277 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
277 | /* Start monitoring */ | 278 | /* Start monitoring */ |
278 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, | 279 | zm = GNUNET_NAMESTORE_zone_monitor_start (cfg, |
279 | &privkey, | 280 | &privkey, |
@@ -304,7 +305,8 @@ run (void *cls, | |||
304 | return; | 305 | return; |
305 | } | 306 | } |
306 | 307 | ||
307 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); | 308 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
309 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); | ||
308 | 310 | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
310 | "Created record 3\n"); | 312 | "Created record 3\n"); |
diff --git a/src/namestore/test_namestore_api_monitoring_existing.c b/src/namestore/test_namestore_api_monitoring_existing.c index 728fcc25e..366f5739f 100644 --- a/src/namestore/test_namestore_api_monitoring_existing.c +++ b/src/namestore/test_namestore_api_monitoring_existing.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 41 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 43 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 45 | static struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
46 | 46 | ||
@@ -129,7 +129,7 @@ end (void *cls) | |||
129 | 129 | ||
130 | static void | 130 | static void |
131 | zone_proc (void *cls, | 131 | zone_proc (void *cls, |
132 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 132 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
133 | const char *name, | 133 | const char *name, |
134 | unsigned int rd_count, | 134 | unsigned int rd_count, |
135 | const struct GNUNET_GNSRECORD_Data *rd) | 135 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -302,8 +302,10 @@ run (void *cls, | |||
302 | struct GNUNET_TESTING_Peer *peer) | 302 | struct GNUNET_TESTING_Peer *peer) |
303 | { | 303 | { |
304 | res = 1; | 304 | res = 1; |
305 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 305 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
306 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); | 306 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
307 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
308 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); | ||
307 | 309 | ||
308 | cfg = mycfg; | 310 | cfg = mycfg; |
309 | GNUNET_SCHEDULER_add_shutdown (&end, | 311 | GNUNET_SCHEDULER_add_shutdown (&end, |
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index e575821e8..b6254e531 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c | |||
@@ -39,9 +39,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
45 | 45 | ||
46 | static int res; | 46 | static int res; |
47 | 47 | ||
@@ -158,9 +158,10 @@ run (void *cls, | |||
158 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 158 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
159 | &endbadly, | 159 | &endbadly, |
160 | NULL); | 160 | NULL); |
161 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 161 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
162 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 162 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
163 | &pubkey); | 163 | GNUNET_IDENTITY_key_get_public (&privkey, |
164 | &pubkey); | ||
164 | 165 | ||
165 | removed = GNUNET_NO; | 166 | removed = GNUNET_NO; |
166 | 167 | ||
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index 75e1cc3ed..e66992909 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 41 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 43 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
44 | 44 | ||
45 | static int res; | 45 | static int res; |
46 | 46 | ||
@@ -132,8 +132,9 @@ run (void *cls, | |||
132 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 132 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
133 | &endbadly, | 133 | &endbadly, |
134 | NULL); | 134 | NULL); |
135 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 135 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
136 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); | 136 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
137 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); | ||
137 | 138 | ||
138 | nsh = GNUNET_NAMESTORE_connect (cfg); | 139 | nsh = GNUNET_NAMESTORE_connect (cfg); |
139 | GNUNET_break (NULL != nsh); | 140 | GNUNET_break (NULL != nsh); |
diff --git a/src/namestore/test_namestore_api_store.c b/src/namestore/test_namestore_api_store.c index 9223b56a3..e0b7daa5d 100644 --- a/src/namestore/test_namestore_api_store.c +++ b/src/namestore/test_namestore_api_store.c | |||
@@ -39,9 +39,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
45 | 45 | ||
46 | static int res; | 46 | static int res; |
47 | 47 | ||
@@ -113,8 +113,9 @@ run (void *cls, | |||
113 | 113 | ||
114 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 114 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
115 | &endbadly, NULL); | 115 | &endbadly, NULL); |
116 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 116 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
117 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); | 117 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
118 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); | ||
118 | 119 | ||
119 | 120 | ||
120 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | 121 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
diff --git a/src/namestore/test_namestore_api_store_update.c b/src/namestore/test_namestore_api_store_update.c index 7a5a69a6c..5c169734a 100644 --- a/src/namestore/test_namestore_api_store_update.c +++ b/src/namestore/test_namestore_api_store_update.c | |||
@@ -48,9 +48,9 @@ static struct GNUNET_NAMECACHE_Handle *nch; | |||
48 | 48 | ||
49 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 49 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
50 | 50 | ||
51 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 51 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
52 | 52 | ||
53 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 53 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
54 | 54 | ||
55 | static int res; | 55 | static int res; |
56 | 56 | ||
@@ -246,9 +246,10 @@ run (void *cls, | |||
246 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 246 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
247 | &endbadly, | 247 | &endbadly, |
248 | NULL); | 248 | NULL); |
249 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 249 | memset (&privkey, 0, sizeof (privkey)); |
250 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 250 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
251 | &pubkey); | 251 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
252 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); | ||
252 | rd.flags = GNUNET_GNSRECORD_RF_NONE; | 253 | rd.flags = GNUNET_GNSRECORD_RF_NONE; |
253 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; | 254 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 1000000000; |
254 | rd.record_type = TEST_RECORD_TYPE; | 255 | rd.record_type = TEST_RECORD_TYPE; |
@@ -291,7 +292,7 @@ main (int argc, | |||
291 | SETUP_CFG (plugin_name, cfg_name); | 292 | SETUP_CFG (plugin_name, cfg_name); |
292 | res = 1; | 293 | res = 1; |
293 | if (0 != | 294 | if (0 != |
294 | GNUNET_TESTING_peer_run ("test-namestore-api-store-update", | 295 | GNUNET_TESTING_peer_run ("test--store-update", |
295 | cfg_name, | 296 | cfg_name, |
296 | &run, | 297 | &run, |
297 | NULL)) | 298 | NULL)) |
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 5d02b9e49..55ca901e2 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -37,9 +37,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
37 | 37 | ||
38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 38 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
39 | 39 | ||
40 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 40 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
43 | 43 | ||
44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 44 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
45 | 45 | ||
@@ -142,7 +142,7 @@ fail_cb (void *cls) | |||
142 | 142 | ||
143 | static void | 143 | static void |
144 | zone_proc (void *cls, | 144 | zone_proc (void *cls, |
145 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 145 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
146 | const char *label, | 146 | const char *label, |
147 | unsigned int rd_count, | 147 | unsigned int rd_count, |
148 | const struct GNUNET_GNSRECORD_Data *rd) | 148 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -331,7 +331,7 @@ create_record (unsigned int count) | |||
331 | */ | 331 | */ |
332 | static void | 332 | static void |
333 | empty_zone_proc (void *cls, | 333 | empty_zone_proc (void *cls, |
334 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 334 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
335 | const char *label, | 335 | const char *label, |
336 | unsigned int rd_count, | 336 | unsigned int rd_count, |
337 | const struct GNUNET_GNSRECORD_Data *rd) | 337 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -362,34 +362,11 @@ empty_zone_proc (void *cls, | |||
362 | static void | 362 | static void |
363 | empty_zone_end (void *cls) | 363 | empty_zone_end (void *cls) |
364 | { | 364 | { |
365 | char *hostkey_file; | ||
366 | |||
367 | zi = NULL; | 365 | zi = NULL; |
368 | GNUNET_asprintf (&hostkey_file, | 366 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
369 | "zonefiles%s%s", | 367 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
370 | DIR_SEPARATOR_STR, | 368 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
371 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 369 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); |
372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
373 | "Using zonekey file `%s' \n", | ||
374 | hostkey_file); | ||
375 | GNUNET_assert (GNUNET_SYSERR != | ||
376 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
377 | GNUNET_YES, | ||
378 | &privkey)); | ||
379 | GNUNET_free (hostkey_file); | ||
380 | |||
381 | GNUNET_asprintf (&hostkey_file, | ||
382 | "zonefiles%s%s", | ||
383 | DIR_SEPARATOR_STR, | ||
384 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
386 | "Using zonekey file `%s' \n", | ||
387 | hostkey_file); | ||
388 | GNUNET_assert (GNUNET_SYSERR != | ||
389 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
390 | GNUNET_YES, | ||
391 | &privkey2)); | ||
392 | GNUNET_free (hostkey_file); | ||
393 | 370 | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); | 371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); |
395 | 372 | ||
diff --git a/src/namestore/test_namestore_api_zone_iteration_nick.c b/src/namestore/test_namestore_api_zone_iteration_nick.c index 4e54a05d2..c203a63a6 100644 --- a/src/namestore/test_namestore_api_zone_iteration_nick.c +++ b/src/namestore/test_namestore_api_zone_iteration_nick.c | |||
@@ -38,9 +38,9 @@ | |||
38 | 38 | ||
39 | static struct GNUNET_NAMESTORE_Handle *nsh; | 39 | static struct GNUNET_NAMESTORE_Handle *nsh; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 41 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 43 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
46 | 46 | ||
@@ -153,7 +153,7 @@ zone_proc_end (void *cls) | |||
153 | 153 | ||
154 | static void | 154 | static void |
155 | zone_proc (void *cls, | 155 | zone_proc (void *cls, |
156 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 156 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
157 | const char *label, | 157 | const char *label, |
158 | unsigned int rd_count, | 158 | unsigned int rd_count, |
159 | const struct GNUNET_GNSRECORD_Data *rd) | 159 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -345,7 +345,7 @@ nick_1_cont (void *cls, int32_t success, const char *emsg) | |||
345 | */ | 345 | */ |
346 | static void | 346 | static void |
347 | empty_zone_proc (void *cls, | 347 | empty_zone_proc (void *cls, |
348 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 348 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
349 | const char *label, | 349 | const char *label, |
350 | unsigned int rd_count, | 350 | unsigned int rd_count, |
351 | const struct GNUNET_GNSRECORD_Data *rd) | 351 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -379,8 +379,10 @@ empty_zone_end (void *cls) | |||
379 | struct GNUNET_GNSRECORD_Data rd; | 379 | struct GNUNET_GNSRECORD_Data rd; |
380 | 380 | ||
381 | zi = NULL; | 381 | zi = NULL; |
382 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 382 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
383 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); | 383 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
384 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
385 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); | ||
384 | 386 | ||
385 | memset (&rd, 0, sizeof(rd)); | 387 | memset (&rd, 0, sizeof(rd)); |
386 | rd.data = ZONE_NICK_1; | 388 | rd.data = ZONE_NICK_1; |
diff --git a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c index 30920713f..70097a69e 100644 --- a/src/namestore/test_namestore_api_zone_iteration_specific_zone.c +++ b/src/namestore/test_namestore_api_zone_iteration_specific_zone.c | |||
@@ -38,9 +38,9 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
38 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 39 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
40 | 40 | ||
41 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 41 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
42 | 42 | ||
43 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 43 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
44 | 44 | ||
45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 45 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
46 | 46 | ||
@@ -124,7 +124,7 @@ fail_cb (void *cls) | |||
124 | 124 | ||
125 | static void | 125 | static void |
126 | zone_proc (void *cls, | 126 | zone_proc (void *cls, |
127 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 127 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
128 | const char *label, | 128 | const char *label, |
129 | unsigned int rd_count, | 129 | unsigned int rd_count, |
130 | const struct GNUNET_GNSRECORD_Data *rd) | 130 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -309,7 +309,7 @@ create_record (unsigned int count) | |||
309 | */ | 309 | */ |
310 | static void | 310 | static void |
311 | empty_zone_proc (void *cls, | 311 | empty_zone_proc (void *cls, |
312 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 312 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
313 | const char *label, | 313 | const char *label, |
314 | unsigned int rd_count, | 314 | unsigned int rd_count, |
315 | const struct GNUNET_GNSRECORD_Data *rd) | 315 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -341,8 +341,10 @@ static void | |||
341 | empty_zone_proc_end (void *cls) | 341 | empty_zone_proc_end (void *cls) |
342 | { | 342 | { |
343 | zi = NULL; | 343 | zi = NULL; |
344 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 344 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
345 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2); | 345 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
346 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
347 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); | ||
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
347 | "Created record 1\n"); | 349 | "Created record 1\n"); |
348 | GNUNET_asprintf (&s_name_1, | 350 | GNUNET_asprintf (&s_name_1, |
diff --git a/src/namestore/test_namestore_api_zone_iteration_stop.c b/src/namestore/test_namestore_api_zone_iteration_stop.c index bdcdd1706..71b36ba09 100644 --- a/src/namestore/test_namestore_api_zone_iteration_stop.c +++ b/src/namestore/test_namestore_api_zone_iteration_stop.c | |||
@@ -34,9 +34,9 @@ | |||
34 | 34 | ||
35 | static struct GNUNET_NAMESTORE_Handle *nsh; | 35 | static struct GNUNET_NAMESTORE_Handle *nsh; |
36 | 36 | ||
37 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 37 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
38 | 38 | ||
39 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey2; | 39 | static struct GNUNET_IDENTITY_PrivateKey privkey2; |
40 | 40 | ||
41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; | 41 | static struct GNUNET_NAMESTORE_ZoneIterator *zi; |
42 | 42 | ||
@@ -112,7 +112,7 @@ fail_cb (void *cls) | |||
112 | 112 | ||
113 | static void | 113 | static void |
114 | zone_proc (void *cls, | 114 | zone_proc (void *cls, |
115 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 115 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
116 | const char *label, | 116 | const char *label, |
117 | unsigned int rd_count, | 117 | unsigned int rd_count, |
118 | const struct GNUNET_GNSRECORD_Data *rd) | 118 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -318,7 +318,7 @@ create_record (unsigned int count) | |||
318 | */ | 318 | */ |
319 | static void | 319 | static void |
320 | empty_zone_proc (void *cls, | 320 | empty_zone_proc (void *cls, |
321 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 321 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
322 | const char *label, | 322 | const char *label, |
323 | unsigned int rd_count, | 323 | unsigned int rd_count, |
324 | const struct GNUNET_GNSRECORD_Data *rd) | 324 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -347,34 +347,13 @@ empty_zone_proc (void *cls, | |||
347 | static void | 347 | static void |
348 | empty_zone_proc_end (void *cls) | 348 | empty_zone_proc_end (void *cls) |
349 | { | 349 | { |
350 | char *hostkey_file; | ||
351 | |||
352 | GNUNET_assert (nsh == cls); | 350 | GNUNET_assert (nsh == cls); |
353 | zi = NULL; | 351 | zi = NULL; |
354 | GNUNET_asprintf (&hostkey_file, | 352 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
355 | "zonefiles%s%s", | 353 | privkey2.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
356 | DIR_SEPARATOR_STR, | 354 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
357 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | 355 | GNUNET_CRYPTO_ecdsa_key_create (&privkey2.ecdsa_key); |
358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | |
359 | "Using zonekey file `%s' \n", | ||
360 | hostkey_file); | ||
361 | GNUNET_assert (GNUNET_SYSERR | ||
362 | != GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
363 | GNUNET_YES, | ||
364 | &privkey)); | ||
365 | GNUNET_free (hostkey_file); | ||
366 | GNUNET_asprintf (&hostkey_file, | ||
367 | "zonefiles%s%s", | ||
368 | DIR_SEPARATOR_STR, | ||
369 | "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); | ||
370 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
371 | "Using zonekey file `%s'\n", | ||
372 | hostkey_file); | ||
373 | GNUNET_assert (GNUNET_SYSERR != | ||
374 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
375 | GNUNET_YES, | ||
376 | &privkey2)); | ||
377 | GNUNET_free (hostkey_file); | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
379 | "Created record 1\n"); | 358 | "Created record 1\n"); |
380 | 359 | ||
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c index 94cc5c285..3fd10e4a1 100644 --- a/src/namestore/test_namestore_api_zone_to_name.c +++ b/src/namestore/test_namestore_api_zone_to_name.c | |||
@@ -42,11 +42,11 @@ static struct GNUNET_NAMESTORE_Handle *nsh; | |||
42 | 42 | ||
43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 43 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
44 | 44 | ||
45 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 45 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
46 | 46 | ||
47 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 47 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
48 | 48 | ||
49 | static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value; | 49 | static struct GNUNET_IDENTITY_PublicKey s_zone_value; |
50 | 50 | ||
51 | static char *s_name; | 51 | static char *s_name; |
52 | 52 | ||
@@ -92,7 +92,7 @@ end (void *cls) | |||
92 | 92 | ||
93 | static void | 93 | static void |
94 | zone_to_name_proc (void *cls, | 94 | zone_to_name_proc (void *cls, |
95 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 95 | const struct GNUNET_IDENTITY_PrivateKey *zone_key, |
96 | const char *n, | 96 | const char *n, |
97 | unsigned int rd_count, | 97 | unsigned int rd_count, |
98 | const struct GNUNET_GNSRECORD_Data *rd) | 98 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -203,20 +203,22 @@ run (void *cls, | |||
203 | GNUNET_SCHEDULER_add_shutdown (&end, | 203 | GNUNET_SCHEDULER_add_shutdown (&end, |
204 | NULL); | 204 | NULL); |
205 | GNUNET_asprintf (&s_name, "dummy"); | 205 | GNUNET_asprintf (&s_name, "dummy"); |
206 | GNUNET_CRYPTO_ecdsa_key_create (&privkey); | 206 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
207 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
207 | /* get public key */ | 208 | /* get public key */ |
208 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, | 209 | GNUNET_IDENTITY_key_get_public (&privkey, |
209 | &pubkey); | 210 | &pubkey); |
210 | 211 | ||
211 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 212 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
212 | &s_zone_value, | 213 | &s_zone_value, |
213 | sizeof(s_zone_value)); | 214 | sizeof(s_zone_value)); |
215 | s_zone_value.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
214 | { | 216 | { |
215 | struct GNUNET_GNSRECORD_Data rd; | 217 | struct GNUNET_GNSRECORD_Data rd; |
216 | 218 | ||
217 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; | 219 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us; |
218 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 220 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; |
219 | rd.data_size = sizeof(s_zone_value); | 221 | rd.data_size = GNUNET_IDENTITY_key_get_length (&s_zone_value); |
220 | rd.data = &s_zone_value; | 222 | rd.data = &s_zone_value; |
221 | rd.flags = 0; | 223 | rd.flags = 0; |
222 | 224 | ||
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index 0f9ce97e4..baea0e444 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -85,14 +85,14 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
85 | static void | 85 | static void |
86 | test_record (void *cls, | 86 | test_record (void *cls, |
87 | uint64_t seq, | 87 | uint64_t seq, |
88 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 88 | const struct GNUNET_IDENTITY_PrivateKey *private_key, |
89 | const char *label, | 89 | const char *label, |
90 | unsigned int rd_count, | 90 | unsigned int rd_count, |
91 | const struct GNUNET_GNSRECORD_Data *rd) | 91 | const struct GNUNET_GNSRECORD_Data *rd) |
92 | { | 92 | { |
93 | int *idp = cls; | 93 | int *idp = cls; |
94 | int id = *idp; | 94 | int id = *idp; |
95 | struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; | 95 | struct GNUNET_IDENTITY_PrivateKey tzone_private_key; |
96 | char tname[64]; | 96 | char tname[64]; |
97 | unsigned int trd_count = 1 + (id % 1024); | 97 | unsigned int trd_count = 1 + (id % 1024); |
98 | 98 | ||
@@ -123,7 +123,7 @@ get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | |||
123 | static void | 123 | static void |
124 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 124 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) |
125 | { | 125 | { |
126 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; | 126 | struct GNUNET_IDENTITY_PrivateKey zone_private_key; |
127 | char label[64]; | 127 | char label[64]; |
128 | unsigned int rd_count = 1 + (id % 1024); | 128 | unsigned int rd_count = 1 + (id % 1024); |
129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; | 129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |
diff --git a/src/namestore/test_plugin_rest_namestore.sh b/src/namestore/test_plugin_rest_namestore.sh index 12a7fa50c..8a45cebf5 100755 --- a/src/namestore/test_plugin_rest_namestore.sh +++ b/src/namestore/test_plugin_rest_namestore.sh | |||
@@ -84,14 +84,15 @@ gnunet-identity -C $TEST_ID -c test_namestore_api.conf | |||
84 | test="$(gnunet-namestore -D -z $TEST_ID -c test_namestore_api.conf)" | 84 | test="$(gnunet-namestore -D -z $TEST_ID -c test_namestore_api.conf)" |
85 | name=$TEST_ID | 85 | name=$TEST_ID |
86 | public="$(gnunet-identity -d -c test_namestore_api.conf | grep $TEST_ID | awk 'NR==1{print $3}')" | 86 | public="$(gnunet-identity -d -c test_namestore_api.conf | grep $TEST_ID | awk 'NR==1{print $3}')" |
87 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf | 87 | echo "$name $public" |
88 | valgrind gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf | ||
88 | #curl_get "${namestore_link}" "HTTP/1.1 200 OK" | 89 | #curl_get "${namestore_link}" "HTTP/1.1 200 OK" |
89 | curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" | 90 | curl_get "${namestore_link}/$name" "HTTP/1.1 200 OK" |
90 | curl_get "${namestore_link}/$public" "error" | 91 | curl_get "${namestore_link}/$public" "error" |
91 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf | 92 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf |
92 | 93 | ||
93 | #Test POST with NAME | 94 | #Test POST with NAME |
94 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content" | 95 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204 No Content" |
95 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 96 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
96 | 97 | ||
97 | # invalid values | 98 | # invalid values |
@@ -106,29 +107,29 @@ curl_post "${namestore_link}/$name" '{"data": [{"record_type":"PKEY", "expiratio | |||
106 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 107 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
107 | 108 | ||
108 | #expirations | 109 | #expirations |
109 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"0d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" | 110 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"0d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" |
110 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 111 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
111 | 112 | ||
112 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"10000d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" | 113 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"10000d","private": false, "relative_expiration": true, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "HTTP/1.1 204" |
113 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 114 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
114 | 115 | ||
115 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"now","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" | 116 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"now","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" |
116 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 117 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
117 | 118 | ||
118 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time_missing":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" | 119 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time_missing":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":"test_entry"}' "error" |
119 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 120 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
120 | 121 | ||
121 | #record_name | 122 | #record_name |
122 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":""}' "error" | 123 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name":""}' "error" |
123 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 124 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
124 | curl_post "${namestore_link}/$name" '{"data": [{"value":"HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name_missing":"test_entry"}' "error" | 125 | curl_post "${namestore_link}/$name" '{"data": [{"value":"000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8", "record_type":"PKEY", "expiration_time":"1d","private": false, "relative_expiration": false, "supplemental": false, "shadow": false}],"record_name_missing":"test_entry"}' "error" |
125 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 | 126 | gnunet-namestore -z $name -d -n "test_entry" -c test_namestore_api.conf > /dev/null 2>&1 |
126 | 127 | ||
127 | #Test DELETE | 128 | #Test DELETE |
128 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf | 129 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf |
129 | curl_delete "${namestore_link}/$name/test_entry" "HTTP/1.1 204" | 130 | curl_delete "${namestore_link}/$name/test_entry" "HTTP/1.1 204" |
130 | curl_delete "${namestore_link}/$name/test_entry" "error" | 131 | curl_delete "${namestore_link}/$name/test_entry" "error" |
131 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "HVX38H2CB7WJM0WCPWT9CFX6GASMYJVR65RN75SJSSKAYVYXHMRG" -t "PKEY" -c test_namestore_api.conf | 132 | gnunet-namestore -z $name -p -a -n "test_entry" -e "1d" -V "000G006WVZ8HQ5YTVFNX09HK0VJVVQ9ZCBYDSCH3ERT04N5ZRBKEB82EP8" -t "PKEY" -c test_namestore_api.conf |
132 | curl_delete "${namestore_link}/$public/test_entry" "error" | 133 | curl_delete "${namestore_link}/$public/test_entry" "error" |
133 | 134 | ||
134 | gnunet-arm -e -c test_namestore_api.conf | 135 | gnunet-arm -e -c test_namestore_api.conf |
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c index 81a16b245..f653a716e 100644 --- a/src/nse/gnunet-nse-profiler.c +++ b/src/nse/gnunet-nse-profiler.c | |||
@@ -317,7 +317,7 @@ handle_estimate (void *cls, | |||
317 | } | 317 | } |
318 | size = GNUNET_snprintf (output_buffer, | 318 | size = GNUNET_snprintf (output_buffer, |
319 | sizeof(output_buffer), | 319 | sizeof(output_buffer), |
320 | "%p %llu %llu %f %f %f\n", | 320 | "%p %u %llu %f %f %f\n", |
321 | peer, | 321 | peer, |
322 | peers_running, | 322 | peers_running, |
323 | (unsigned long long) timestamp.abs_value_us, | 323 | (unsigned long long) timestamp.abs_value_us, |
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 739249a93..987c7c3a0 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -338,9 +338,9 @@ print_address (void *cls, | |||
338 | ar->pc = pc; | 338 | ar->pc = pc; |
339 | ar->expiration = expiration; | 339 | ar->expiration = expiration; |
340 | GNUNET_asprintf (&ar->result, | 340 | GNUNET_asprintf (&ar->result, |
341 | "%s:%u:%u", | 341 | "%s:%lu:%u", |
342 | address->transport_name, | 342 | address->transport_name, |
343 | address->address_length, | 343 | (unsigned long) address->address_length, |
344 | address->local_info); | 344 | address->local_info); |
345 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, | 345 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, |
346 | address, | 346 | address, |
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c index 99cec7e58..4bbc7442e 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/peerinfo-tool/plugin_rest_peerinfo.c | |||
@@ -554,9 +554,9 @@ print_address (void *cls, | |||
554 | ar->pc = pc; | 554 | ar->pc = pc; |
555 | ar->expiration = expiration; | 555 | ar->expiration = expiration; |
556 | GNUNET_asprintf (&ar->result, | 556 | GNUNET_asprintf (&ar->result, |
557 | "%s:%u:%u", | 557 | "%s:%lu:%u", |
558 | address->transport_name, | 558 | address->transport_name, |
559 | address->address_length, | 559 | (unsigned long) address->address_length, |
560 | address->local_info); | 560 | address->local_info); |
561 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, | 561 | ar->atsc = GNUNET_TRANSPORT_address_to_string (cfg, |
562 | address, | 562 | address, |
diff --git a/src/pq/pq.c b/src/pq/pq.c index eca097e58..e9c960e33 100644 --- a/src/pq/pq.c +++ b/src/pq/pq.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016, 2017, 2019 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016, 2017, 2019, 2020 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 |
@@ -27,14 +27,7 @@ | |||
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "pq.h" | 28 | #include "pq.h" |
29 | 29 | ||
30 | /** | 30 | |
31 | * Execute a prepared statement. | ||
32 | * | ||
33 | * @param db database handle | ||
34 | * @param name name of the prepared statement | ||
35 | * @param params parameters to the statement | ||
36 | * @return postgres result | ||
37 | */ | ||
38 | PGresult * | 31 | PGresult * |
39 | GNUNET_PQ_exec_prepared (struct GNUNET_PQ_Context *db, | 32 | GNUNET_PQ_exec_prepared (struct GNUNET_PQ_Context *db, |
40 | const char *name, | 33 | const char *name, |
@@ -120,12 +113,6 @@ GNUNET_PQ_exec_prepared (struct GNUNET_PQ_Context *db, | |||
120 | } | 113 | } |
121 | 114 | ||
122 | 115 | ||
123 | /** | ||
124 | * Free all memory that was allocated in @a rs during | ||
125 | * #GNUNET_PQ_extract_result(). | ||
126 | * | ||
127 | * @param rs reult specification to clean up | ||
128 | */ | ||
129 | void | 116 | void |
130 | GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs) | 117 | GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs) |
131 | { | 118 | { |
@@ -136,17 +123,6 @@ GNUNET_PQ_cleanup_result (struct GNUNET_PQ_ResultSpec *rs) | |||
136 | } | 123 | } |
137 | 124 | ||
138 | 125 | ||
139 | /** | ||
140 | * Extract results from a query result according to the given | ||
141 | * specification. | ||
142 | * | ||
143 | * @param result result to process | ||
144 | * @param[in,out] rs result specification to extract for | ||
145 | * @param row row from the result to extract | ||
146 | * @return | ||
147 | * #GNUNET_YES if all results could be extracted | ||
148 | * #GNUNET_SYSERR if a result was invalid (non-existing field) | ||
149 | */ | ||
150 | int | 126 | int |
151 | GNUNET_PQ_extract_result (PGresult *result, | 127 | GNUNET_PQ_extract_result (PGresult *result, |
152 | struct GNUNET_PQ_ResultSpec *rs, | 128 | struct GNUNET_PQ_ResultSpec *rs, |
@@ -160,6 +136,23 @@ GNUNET_PQ_extract_result (PGresult *result, | |||
160 | int ret; | 136 | int ret; |
161 | 137 | ||
162 | spec = &rs[i]; | 138 | spec = &rs[i]; |
139 | if (spec->is_nullable) | ||
140 | { | ||
141 | int fnum; | ||
142 | |||
143 | fnum = PQfnumber (result, | ||
144 | spec->fname); | ||
145 | if (PQgetisnull (result, | ||
146 | row, | ||
147 | fnum)) | ||
148 | { | ||
149 | if (NULL != spec->is_null) | ||
150 | *spec->is_null = true; | ||
151 | continue; | ||
152 | } | ||
153 | if (NULL != spec->is_null) | ||
154 | *spec->is_null = false; | ||
155 | } | ||
163 | ret = spec->conv (spec->cls, | 156 | ret = spec->conv (spec->cls, |
164 | result, | 157 | result, |
165 | row, | 158 | row, |
diff --git a/src/pq/pq_eval.c b/src/pq/pq_eval.c index 5bcf8ca0e..8d8b5b0f2 100644 --- a/src/pq/pq_eval.c +++ b/src/pq/pq_eval.c | |||
@@ -263,6 +263,7 @@ GNUNET_PQ_eval_prepared_singleton_select (struct GNUNET_PQ_Context *db, | |||
263 | { | 263 | { |
264 | PGresult *result; | 264 | PGresult *result; |
265 | enum GNUNET_DB_QueryStatus qs; | 265 | enum GNUNET_DB_QueryStatus qs; |
266 | int ntuples; | ||
266 | 267 | ||
267 | result = GNUNET_PQ_exec_prepared (db, | 268 | result = GNUNET_PQ_exec_prepared (db, |
268 | statement_name, | 269 | statement_name, |
@@ -277,12 +278,13 @@ GNUNET_PQ_eval_prepared_singleton_select (struct GNUNET_PQ_Context *db, | |||
277 | PQclear (result); | 278 | PQclear (result); |
278 | return qs; | 279 | return qs; |
279 | } | 280 | } |
280 | if (0 == PQntuples (result)) | 281 | ntuples = PQntuples (result); |
282 | if (0 == ntuples) | ||
281 | { | 283 | { |
282 | PQclear (result); | 284 | PQclear (result); |
283 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; | 285 | return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; |
284 | } | 286 | } |
285 | if (1 != PQntuples (result)) | 287 | if (1 != ntuples) |
286 | { | 288 | { |
287 | /* more than one result, but there must be at most one */ | 289 | /* more than one result, but there must be at most one */ |
288 | GNUNET_break (0); | 290 | GNUNET_break (0); |
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c index a36848f3a..cee84d203 100644 --- a/src/pq/pq_query_helper.c +++ b/src/pq/pq_query_helper.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016, 2020 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 |
@@ -42,6 +42,56 @@ | |||
42 | * @return -1 on error, number of offsets used in @a scratch otherwise | 42 | * @return -1 on error, number of offsets used in @a scratch otherwise |
43 | */ | 43 | */ |
44 | static int | 44 | static int |
45 | qconv_null (void *cls, | ||
46 | const void *data, | ||
47 | size_t data_len, | ||
48 | void *param_values[], | ||
49 | int param_lengths[], | ||
50 | int param_formats[], | ||
51 | unsigned int param_length, | ||
52 | void *scratch[], | ||
53 | unsigned int scratch_length) | ||
54 | { | ||
55 | (void) scratch; | ||
56 | (void) scratch_length; | ||
57 | (void) data; | ||
58 | (void) data_len; | ||
59 | GNUNET_break (NULL == cls); | ||
60 | if (1 != param_length) | ||
61 | return -1; | ||
62 | param_values[0] = NULL; | ||
63 | param_lengths[0] = 0; | ||
64 | param_formats[0] = 1; | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | |||
69 | struct GNUNET_PQ_QueryParam | ||
70 | GNUNET_PQ_query_param_null (void) | ||
71 | { | ||
72 | struct GNUNET_PQ_QueryParam res = { | ||
73 | &qconv_null, NULL, NULL, 0, 1 | ||
74 | }; | ||
75 | |||
76 | return res; | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Function called to convert input argument into SQL parameters. | ||
82 | * | ||
83 | * @param cls closure | ||
84 | * @param data pointer to input argument | ||
85 | * @param data_len number of bytes in @a data (if applicable) | ||
86 | * @param[out] param_values SQL data to set | ||
87 | * @param[out] param_lengths SQL length data to set | ||
88 | * @param[out] param_formats SQL format data to set | ||
89 | * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays | ||
90 | * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc() | ||
91 | * @param scratch_length number of entries left in @a scratch | ||
92 | * @return -1 on error, number of offsets used in @a scratch otherwise | ||
93 | */ | ||
94 | static int | ||
45 | qconv_fixed (void *cls, | 95 | qconv_fixed (void *cls, |
46 | const void *data, | 96 | const void *data, |
47 | size_t data_len, | 97 | size_t data_len, |
@@ -64,33 +114,23 @@ qconv_fixed (void *cls, | |||
64 | } | 114 | } |
65 | 115 | ||
66 | 116 | ||
67 | /** | ||
68 | * Generate query parameter for a buffer @a ptr of | ||
69 | * @a ptr_size bytes. | ||
70 | * | ||
71 | * @param ptr pointer to the query parameter to pass | ||
72 | * @oaran ptr_size number of bytes in @a ptr | ||
73 | */ | ||
74 | struct GNUNET_PQ_QueryParam | 117 | struct GNUNET_PQ_QueryParam |
75 | GNUNET_PQ_query_param_fixed_size (const void *ptr, | 118 | GNUNET_PQ_query_param_fixed_size (const void *ptr, |
76 | size_t ptr_size) | 119 | size_t ptr_size) |
77 | { | 120 | { |
78 | struct GNUNET_PQ_QueryParam res = | 121 | struct GNUNET_PQ_QueryParam res = { |
79 | { &qconv_fixed, NULL, ptr, ptr_size, 1 }; | 122 | &qconv_fixed, NULL, ptr, ptr_size, 1 |
123 | }; | ||
80 | 124 | ||
81 | return res; | 125 | return res; |
82 | } | 126 | } |
83 | 127 | ||
84 | 128 | ||
85 | /** | ||
86 | * Generate query parameter for a string. | ||
87 | * | ||
88 | * @param ptr pointer to the string query parameter to pass | ||
89 | */ | ||
90 | struct GNUNET_PQ_QueryParam | 129 | struct GNUNET_PQ_QueryParam |
91 | GNUNET_PQ_query_param_string (const char *ptr) | 130 | GNUNET_PQ_query_param_string (const char *ptr) |
92 | { | 131 | { |
93 | return GNUNET_PQ_query_param_fixed_size (ptr, strlen (ptr)); | 132 | return GNUNET_PQ_query_param_fixed_size (ptr, |
133 | strlen (ptr)); | ||
94 | } | 134 | } |
95 | 135 | ||
96 | 136 | ||
@@ -137,11 +177,6 @@ qconv_uint16 (void *cls, | |||
137 | } | 177 | } |
138 | 178 | ||
139 | 179 | ||
140 | /** | ||
141 | * Generate query parameter for an uint16_t in host byte order. | ||
142 | * | ||
143 | * @param x pointer to the query parameter to pass | ||
144 | */ | ||
145 | struct GNUNET_PQ_QueryParam | 180 | struct GNUNET_PQ_QueryParam |
146 | GNUNET_PQ_query_param_uint16 (const uint16_t *x) | 181 | GNUNET_PQ_query_param_uint16 (const uint16_t *x) |
147 | { | 182 | { |
@@ -195,11 +230,6 @@ qconv_uint32 (void *cls, | |||
195 | } | 230 | } |
196 | 231 | ||
197 | 232 | ||
198 | /** | ||
199 | * Generate query parameter for an uint32_t in host byte order. | ||
200 | * | ||
201 | * @param x pointer to the query parameter to pass | ||
202 | */ | ||
203 | struct GNUNET_PQ_QueryParam | 233 | struct GNUNET_PQ_QueryParam |
204 | GNUNET_PQ_query_param_uint32 (const uint32_t *x) | 234 | GNUNET_PQ_query_param_uint32 (const uint32_t *x) |
205 | { | 235 | { |
@@ -253,11 +283,6 @@ qconv_uint64 (void *cls, | |||
253 | } | 283 | } |
254 | 284 | ||
255 | 285 | ||
256 | /** | ||
257 | * Generate query parameter for an uint64_t in host byte order. | ||
258 | * | ||
259 | * @param x pointer to the query parameter to pass | ||
260 | */ | ||
261 | struct GNUNET_PQ_QueryParam | 286 | struct GNUNET_PQ_QueryParam |
262 | GNUNET_PQ_query_param_uint64 (const uint64_t *x) | 287 | GNUNET_PQ_query_param_uint64 (const uint64_t *x) |
263 | { | 288 | { |
@@ -310,13 +335,6 @@ qconv_rsa_public_key (void *cls, | |||
310 | } | 335 | } |
311 | 336 | ||
312 | 337 | ||
313 | /** | ||
314 | * Generate query parameter for an RSA public key. The | ||
315 | * database must contain a BLOB type in the respective position. | ||
316 | * | ||
317 | * @param x the query parameter to pass | ||
318 | * @return array entry for the query parameters to use | ||
319 | */ | ||
320 | struct GNUNET_PQ_QueryParam | 338 | struct GNUNET_PQ_QueryParam |
321 | GNUNET_PQ_query_param_rsa_public_key (const struct | 339 | GNUNET_PQ_query_param_rsa_public_key (const struct |
322 | GNUNET_CRYPTO_RsaPublicKey *x) | 340 | GNUNET_CRYPTO_RsaPublicKey *x) |
@@ -370,13 +388,6 @@ qconv_rsa_signature (void *cls, | |||
370 | } | 388 | } |
371 | 389 | ||
372 | 390 | ||
373 | /** | ||
374 | * Generate query parameter for an RSA signature. The | ||
375 | * database must contain a BLOB type in the respective position. | ||
376 | * | ||
377 | * @param x the query parameter to pass | ||
378 | * @return array entry for the query parameters to use | ||
379 | */ | ||
380 | struct GNUNET_PQ_QueryParam | 391 | struct GNUNET_PQ_QueryParam |
381 | GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) | 392 | GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x) |
382 | { | 393 | { |
@@ -432,13 +443,6 @@ qconv_rel_time (void *cls, | |||
432 | } | 443 | } |
433 | 444 | ||
434 | 445 | ||
435 | /** | ||
436 | * Generate query parameter for a relative time value. | ||
437 | * The database must store a 64-bit integer. | ||
438 | * | ||
439 | * @param x pointer to the query parameter to pass | ||
440 | * @return array entry for the query parameters to use | ||
441 | */ | ||
442 | struct GNUNET_PQ_QueryParam | 446 | struct GNUNET_PQ_QueryParam |
443 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) | 447 | GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x) |
444 | { | 448 | { |
@@ -494,29 +498,17 @@ qconv_abs_time (void *cls, | |||
494 | } | 498 | } |
495 | 499 | ||
496 | 500 | ||
497 | /** | ||
498 | * Generate query parameter for an absolute time value. | ||
499 | * The database must store a 64-bit integer. | ||
500 | * | ||
501 | * @param x pointer to the query parameter to pass | ||
502 | * @return array entry for the query parameters to use | ||
503 | */ | ||
504 | struct GNUNET_PQ_QueryParam | 501 | struct GNUNET_PQ_QueryParam |
505 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) | 502 | GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x) |
506 | { | 503 | { |
507 | struct GNUNET_PQ_QueryParam res = | 504 | struct GNUNET_PQ_QueryParam res = { |
508 | { &qconv_abs_time, NULL, x, sizeof(*x), 1 }; | 505 | &qconv_abs_time, NULL, x, sizeof(*x), 1 |
506 | }; | ||
509 | 507 | ||
510 | return res; | 508 | return res; |
511 | } | 509 | } |
512 | 510 | ||
513 | 511 | ||
514 | /** | ||
515 | * Generate query parameter for an absolute time value. | ||
516 | * The database must store a 64-bit integer. | ||
517 | * | ||
518 | * @param x pointer to the query parameter to pass | ||
519 | */ | ||
520 | struct GNUNET_PQ_QueryParam | 512 | struct GNUNET_PQ_QueryParam |
521 | GNUNET_PQ_query_param_absolute_time_nbo (const struct | 513 | GNUNET_PQ_query_param_absolute_time_nbo (const struct |
522 | GNUNET_TIME_AbsoluteNBO *x) | 514 | GNUNET_TIME_AbsoluteNBO *x) |
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index f764593b0..546822e45 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016, 2020 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 |
@@ -27,6 +27,19 @@ | |||
27 | #include "gnunet_pq_lib.h" | 27 | #include "gnunet_pq_lib.h" |
28 | 28 | ||
29 | 29 | ||
30 | struct GNUNET_PQ_ResultSpec | ||
31 | GNUNET_PQ_result_spec_allow_null (struct GNUNET_PQ_ResultSpec rs, | ||
32 | bool *is_null) | ||
33 | { | ||
34 | struct GNUNET_PQ_ResultSpec rsr; | ||
35 | |||
36 | rsr = rs; | ||
37 | rsr.is_nullable = true; | ||
38 | rsr.is_null = is_null; | ||
39 | return rsr; | ||
40 | } | ||
41 | |||
42 | |||
30 | /** | 43 | /** |
31 | * Function called to clean up memory allocated | 44 | * Function called to clean up memory allocated |
32 | * by a #GNUNET_PQ_ResultConverter. | 45 | * by a #GNUNET_PQ_ResultConverter. |
@@ -112,14 +125,6 @@ extract_varsize_blob (void *cls, | |||
112 | } | 125 | } |
113 | 126 | ||
114 | 127 | ||
115 | /** | ||
116 | * Variable-size result expected. | ||
117 | * | ||
118 | * @param name name of the field in the table | ||
119 | * @param[out] dst where to store the result, allocated | ||
120 | * @param[out] sptr where to store the size of @a dst | ||
121 | * @return array entry for the result specification to use | ||
122 | */ | ||
123 | struct GNUNET_PQ_ResultSpec | 128 | struct GNUNET_PQ_ResultSpec |
124 | GNUNET_PQ_result_spec_variable_size (const char *name, | 129 | GNUNET_PQ_result_spec_variable_size (const char *name, |
125 | void **dst, | 130 | void **dst, |
@@ -196,14 +201,6 @@ extract_fixed_blob (void *cls, | |||
196 | } | 201 | } |
197 | 202 | ||
198 | 203 | ||
199 | /** | ||
200 | * Fixed-size result expected. | ||
201 | * | ||
202 | * @param name name of the field in the table | ||
203 | * @param[out] dst where to store the result | ||
204 | * @param dst_size number of bytes in @a dst | ||
205 | * @return array entry for the result specification to use | ||
206 | */ | ||
207 | struct GNUNET_PQ_ResultSpec | 204 | struct GNUNET_PQ_ResultSpec |
208 | GNUNET_PQ_result_spec_fixed_size (const char *name, | 205 | GNUNET_PQ_result_spec_fixed_size (const char *name, |
209 | void *dst, | 206 | void *dst, |
@@ -301,13 +298,6 @@ clean_rsa_public_key (void *cls, | |||
301 | } | 298 | } |
302 | 299 | ||
303 | 300 | ||
304 | /** | ||
305 | * RSA public key expected. | ||
306 | * | ||
307 | * @param name name of the field in the table | ||
308 | * @param[out] rsa where to store the result | ||
309 | * @return array entry for the result specification to use | ||
310 | */ | ||
311 | struct GNUNET_PQ_ResultSpec | 301 | struct GNUNET_PQ_ResultSpec |
312 | GNUNET_PQ_result_spec_rsa_public_key (const char *name, | 302 | GNUNET_PQ_result_spec_rsa_public_key (const char *name, |
313 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) | 303 | struct GNUNET_CRYPTO_RsaPublicKey **rsa) |
@@ -405,13 +395,6 @@ clean_rsa_signature (void *cls, | |||
405 | } | 395 | } |
406 | 396 | ||
407 | 397 | ||
408 | /** | ||
409 | * RSA signature expected. | ||
410 | * | ||
411 | * @param name name of the field in the table | ||
412 | * @param[out] sig where to store the result; | ||
413 | * @return array entry for the result specification to use | ||
414 | */ | ||
415 | struct GNUNET_PQ_ResultSpec | 398 | struct GNUNET_PQ_ResultSpec |
416 | GNUNET_PQ_result_spec_rsa_signature (const char *name, | 399 | GNUNET_PQ_result_spec_rsa_signature (const char *name, |
417 | struct GNUNET_CRYPTO_RsaSignature **sig) | 400 | struct GNUNET_CRYPTO_RsaSignature **sig) |
@@ -509,13 +492,6 @@ clean_string (void *cls, | |||
509 | } | 492 | } |
510 | 493 | ||
511 | 494 | ||
512 | /** | ||
513 | * 0-terminated string expected. | ||
514 | * | ||
515 | * @param name name of the field in the table | ||
516 | * @param[out] dst where to store the result, allocated | ||
517 | * @return array entry for the result specification to use | ||
518 | */ | ||
519 | struct GNUNET_PQ_ResultSpec | 495 | struct GNUNET_PQ_ResultSpec |
520 | GNUNET_PQ_result_spec_string (const char *name, | 496 | GNUNET_PQ_result_spec_string (const char *name, |
521 | char **dst) | 497 | char **dst) |
@@ -595,13 +571,6 @@ extract_rel_time (void *cls, | |||
595 | } | 571 | } |
596 | 572 | ||
597 | 573 | ||
598 | /** | ||
599 | * Relative time expected. | ||
600 | * | ||
601 | * @param name name of the field in the table | ||
602 | * @param[out] at where to store the result | ||
603 | * @return array entry for the result specification to use | ||
604 | */ | ||
605 | struct GNUNET_PQ_ResultSpec | 574 | struct GNUNET_PQ_ResultSpec |
606 | GNUNET_PQ_result_spec_relative_time (const char *name, | 575 | GNUNET_PQ_result_spec_relative_time (const char *name, |
607 | struct GNUNET_TIME_Relative *rt) | 576 | struct GNUNET_TIME_Relative *rt) |
@@ -685,13 +654,6 @@ extract_abs_time (void *cls, | |||
685 | } | 654 | } |
686 | 655 | ||
687 | 656 | ||
688 | /** | ||
689 | * Absolute time expected. | ||
690 | * | ||
691 | * @param name name of the field in the table | ||
692 | * @param[out] at where to store the result | ||
693 | * @return array entry for the result specification to use | ||
694 | */ | ||
695 | struct GNUNET_PQ_ResultSpec | 657 | struct GNUNET_PQ_ResultSpec |
696 | GNUNET_PQ_result_spec_absolute_time (const char *name, | 658 | GNUNET_PQ_result_spec_absolute_time (const char *name, |
697 | struct GNUNET_TIME_Absolute *at) | 659 | struct GNUNET_TIME_Absolute *at) |
@@ -706,13 +668,6 @@ GNUNET_PQ_result_spec_absolute_time (const char *name, | |||
706 | } | 668 | } |
707 | 669 | ||
708 | 670 | ||
709 | /** | ||
710 | * Absolute time in network byte order expected. | ||
711 | * | ||
712 | * @param name name of the field in the table | ||
713 | * @param[out] at where to store the result | ||
714 | * @return array entry for the result specification to use | ||
715 | */ | ||
716 | struct GNUNET_PQ_ResultSpec | 671 | struct GNUNET_PQ_ResultSpec |
717 | GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, | 672 | GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, |
718 | struct GNUNET_TIME_AbsoluteNBO *at) | 673 | struct GNUNET_TIME_AbsoluteNBO *at) |
@@ -786,13 +741,6 @@ extract_uint16 (void *cls, | |||
786 | } | 741 | } |
787 | 742 | ||
788 | 743 | ||
789 | /** | ||
790 | * uint16_t expected. | ||
791 | * | ||
792 | * @param name name of the field in the table | ||
793 | * @param[out] u16 where to store the result | ||
794 | * @return array entry for the result specification to use | ||
795 | */ | ||
796 | struct GNUNET_PQ_ResultSpec | 744 | struct GNUNET_PQ_ResultSpec |
797 | GNUNET_PQ_result_spec_uint16 (const char *name, | 745 | GNUNET_PQ_result_spec_uint16 (const char *name, |
798 | uint16_t *u16) | 746 | uint16_t *u16) |
@@ -869,13 +817,6 @@ extract_uint32 (void *cls, | |||
869 | } | 817 | } |
870 | 818 | ||
871 | 819 | ||
872 | /** | ||
873 | * uint32_t expected. | ||
874 | * | ||
875 | * @param name name of the field in the table | ||
876 | * @param[out] u32 where to store the result | ||
877 | * @return array entry for the result specification to use | ||
878 | */ | ||
879 | struct GNUNET_PQ_ResultSpec | 820 | struct GNUNET_PQ_ResultSpec |
880 | GNUNET_PQ_result_spec_uint32 (const char *name, | 821 | GNUNET_PQ_result_spec_uint32 (const char *name, |
881 | uint32_t *u32) | 822 | uint32_t *u32) |
@@ -952,22 +893,16 @@ extract_uint64 (void *cls, | |||
952 | } | 893 | } |
953 | 894 | ||
954 | 895 | ||
955 | /** | ||
956 | * uint64_t expected. | ||
957 | * | ||
958 | * @param name name of the field in the table | ||
959 | * @param[out] u64 where to store the result | ||
960 | * @return array entry for the result specification to use | ||
961 | */ | ||
962 | struct GNUNET_PQ_ResultSpec | 896 | struct GNUNET_PQ_ResultSpec |
963 | GNUNET_PQ_result_spec_uint64 (const char *name, | 897 | GNUNET_PQ_result_spec_uint64 (const char *name, |
964 | uint64_t *u64) | 898 | uint64_t *u64) |
965 | { | 899 | { |
966 | struct GNUNET_PQ_ResultSpec res = | 900 | struct GNUNET_PQ_ResultSpec res = { |
967 | { &extract_uint64, | 901 | &extract_uint64, |
968 | NULL, | 902 | NULL, |
969 | NULL, | 903 | NULL, |
970 | (void *) u64, sizeof(*u64), (name), NULL }; | 904 | (void *) u64, sizeof(*u64), (name), NULL |
905 | }; | ||
971 | 906 | ||
972 | return res; | 907 | return res; |
973 | } | 908 | } |
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c index b09354af8..e588da45d 100644 --- a/src/pq/test_pq.c +++ b/src/pq/test_pq.c | |||
@@ -47,10 +47,11 @@ postgres_prepare (struct GNUNET_PQ_Context *db) | |||
47 | ",u16" | 47 | ",u16" |
48 | ",u32" | 48 | ",u32" |
49 | ",u64" | 49 | ",u64" |
50 | ",unn" | ||
50 | ") VALUES " | 51 | ") VALUES " |
51 | "($1, $2, $3, $4, $5, $6," | 52 | "($1, $2, $3, $4, $5, $6," |
52 | "$7, $8, $9);", | 53 | "$7, $8, $9, $10);", |
53 | 9), | 54 | 10), |
54 | GNUNET_PQ_make_prepare ("test_select", | 55 | GNUNET_PQ_make_prepare ("test_select", |
55 | "SELECT" | 56 | "SELECT" |
56 | " pub" | 57 | " pub" |
@@ -62,6 +63,7 @@ postgres_prepare (struct GNUNET_PQ_Context *db) | |||
62 | ",u16" | 63 | ",u16" |
63 | ",u32" | 64 | ",u32" |
64 | ",u64" | 65 | ",u64" |
66 | ",unn" | ||
65 | " FROM test_pq" | 67 | " FROM test_pq" |
66 | " ORDER BY abs_time DESC " | 68 | " ORDER BY abs_time DESC " |
67 | " LIMIT 1;", | 69 | " LIMIT 1;", |
@@ -106,7 +108,8 @@ run_queries (struct GNUNET_PQ_Context *db) | |||
106 | uint32_t u322; | 108 | uint32_t u322; |
107 | uint64_t u64; | 109 | uint64_t u64; |
108 | uint64_t u642; | 110 | uint64_t u642; |
109 | 111 | uint64_t uzzz = 42; | |
112 | |||
110 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); | 113 | priv = GNUNET_CRYPTO_rsa_private_key_create (1024); |
111 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); | 114 | pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); |
112 | memset (&hmsg, 42, sizeof(hmsg)); | 115 | memset (&hmsg, 42, sizeof(hmsg)); |
@@ -127,11 +130,13 @@ run_queries (struct GNUNET_PQ_Context *db) | |||
127 | GNUNET_PQ_query_param_uint16 (&u16), | 130 | GNUNET_PQ_query_param_uint16 (&u16), |
128 | GNUNET_PQ_query_param_uint32 (&u32), | 131 | GNUNET_PQ_query_param_uint32 (&u32), |
129 | GNUNET_PQ_query_param_uint64 (&u64), | 132 | GNUNET_PQ_query_param_uint64 (&u64), |
133 | GNUNET_PQ_query_param_null (), | ||
130 | GNUNET_PQ_query_param_end | 134 | GNUNET_PQ_query_param_end |
131 | }; | 135 | }; |
132 | struct GNUNET_PQ_QueryParam params_select[] = { | 136 | struct GNUNET_PQ_QueryParam params_select[] = { |
133 | GNUNET_PQ_query_param_end | 137 | GNUNET_PQ_query_param_end |
134 | }; | 138 | }; |
139 | bool got_null = false; | ||
135 | struct GNUNET_PQ_ResultSpec results_select[] = { | 140 | struct GNUNET_PQ_ResultSpec results_select[] = { |
136 | GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2), | 141 | GNUNET_PQ_result_spec_rsa_public_key ("pub", &pub2), |
137 | GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2), | 142 | GNUNET_PQ_result_spec_rsa_signature ("sig", &sig2), |
@@ -142,6 +147,9 @@ run_queries (struct GNUNET_PQ_Context *db) | |||
142 | GNUNET_PQ_result_spec_uint16 ("u16", &u162), | 147 | GNUNET_PQ_result_spec_uint16 ("u16", &u162), |
143 | GNUNET_PQ_result_spec_uint32 ("u32", &u322), | 148 | GNUNET_PQ_result_spec_uint32 ("u32", &u322), |
144 | GNUNET_PQ_result_spec_uint64 ("u64", &u642), | 149 | GNUNET_PQ_result_spec_uint64 ("u64", &u642), |
150 | GNUNET_PQ_result_spec_allow_null ( | ||
151 | GNUNET_PQ_result_spec_uint64 ("unn", &uzzz), | ||
152 | &got_null), | ||
145 | GNUNET_PQ_result_spec_end | 153 | GNUNET_PQ_result_spec_end |
146 | }; | 154 | }; |
147 | 155 | ||
@@ -197,6 +205,8 @@ run_queries (struct GNUNET_PQ_Context *db) | |||
197 | GNUNET_break (16 == u162); | 205 | GNUNET_break (16 == u162); |
198 | GNUNET_break (32 == u322); | 206 | GNUNET_break (32 == u322); |
199 | GNUNET_break (64 == u642); | 207 | GNUNET_break (64 == u642); |
208 | GNUNET_break (42 == uzzz); | ||
209 | GNUNET_break (got_null); | ||
200 | GNUNET_PQ_cleanup_result (results_select); | 210 | GNUNET_PQ_cleanup_result (results_select); |
201 | PQclear (result); | 211 | PQclear (result); |
202 | } | 212 | } |
@@ -225,6 +235,7 @@ main (int argc, | |||
225 | ",u16 INT2 NOT NULL" | 235 | ",u16 INT2 NOT NULL" |
226 | ",u32 INT4 NOT NULL" | 236 | ",u32 INT4 NOT NULL" |
227 | ",u64 INT8 NOT NULL" | 237 | ",u64 INT8 NOT NULL" |
238 | ",unn INT8" | ||
228 | ")"), | 239 | ")"), |
229 | GNUNET_PQ_EXECUTE_STATEMENT_END | 240 | GNUNET_PQ_EXECUTE_STATEMENT_END |
230 | }; | 241 | }; |
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c index cf0455477..7b4abaec2 100644 --- a/src/pt/test_gns_vpn.c +++ b/src/pt/test_gns_vpn.c | |||
@@ -560,7 +560,7 @@ identity_cb (void *cls, | |||
560 | void **ctx, | 560 | void **ctx, |
561 | const char *name) | 561 | const char *name) |
562 | { | 562 | { |
563 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; | 563 | const struct GNUNET_IDENTITY_PrivateKey *zone_key; |
564 | struct GNUNET_GNSRECORD_Data rd; | 564 | struct GNUNET_GNSRECORD_Data rd; |
565 | char *rd_string; | 565 | char *rd_string; |
566 | char *peername; | 566 | char *peername; |
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am index a58127abf..9463f19d9 100644 --- a/src/reclaim/Makefile.am +++ b/src/reclaim/Makefile.am | |||
@@ -103,6 +103,7 @@ gnunet_service_reclaim_SOURCES = \ | |||
103 | gnunet-service-reclaim_tickets.h | 103 | gnunet-service-reclaim_tickets.h |
104 | gnunet_service_reclaim_LDADD = \ | 104 | gnunet_service_reclaim_LDADD = \ |
105 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 105 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
106 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
106 | $(top_builddir)/src/util/libgnunetutil.la \ | 107 | $(top_builddir)/src/util/libgnunetutil.la \ |
107 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 108 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
108 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 109 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index b9306b802..cefb66b8f 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -152,12 +152,12 @@ static struct GNUNET_RECLAIM_TicketIterator *ticket_iterator; | |||
152 | /** | 152 | /** |
153 | * ego private key | 153 | * ego private key |
154 | */ | 154 | */ |
155 | static const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey; | 155 | static const struct GNUNET_IDENTITY_PrivateKey *pkey; |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * rp public key | 158 | * rp public key |
159 | */ | 159 | */ |
160 | static struct GNUNET_CRYPTO_EcdsaPublicKey rp_key; | 160 | static struct GNUNET_IDENTITY_PublicKey rp_key; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Ticket to consume | 163 | * Ticket to consume |
@@ -261,7 +261,7 @@ store_cont (void *cls, int32_t success, const char *emsg) | |||
261 | 261 | ||
262 | static void | 262 | static void |
263 | process_attrs (void *cls, | 263 | process_attrs (void *cls, |
264 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 264 | const struct GNUNET_IDENTITY_PublicKey *identity, |
265 | const struct GNUNET_RECLAIM_Attribute *attr, | 265 | const struct GNUNET_RECLAIM_Attribute *attr, |
266 | const struct GNUNET_RECLAIM_Presentation *presentation) | 266 | const struct GNUNET_RECLAIM_Presentation *presentation) |
267 | { | 267 | { |
@@ -346,7 +346,7 @@ ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
346 | aud = | 346 | aud = |
347 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 347 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, |
348 | sizeof(struct | 348 | sizeof(struct |
349 | GNUNET_CRYPTO_EcdsaPublicKey)); | 349 | GNUNET_IDENTITY_PublicKey)); |
350 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(ticket->rnd)); | 350 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof(ticket->rnd)); |
351 | tkt = | 351 | tkt = |
352 | GNUNET_STRINGS_data_to_string_alloc (ticket, | 352 | GNUNET_STRINGS_data_to_string_alloc (ticket, |
@@ -511,7 +511,7 @@ iter_finished (void *cls) | |||
511 | 511 | ||
512 | static void | 512 | static void |
513 | iter_cb (void *cls, | 513 | iter_cb (void *cls, |
514 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 514 | const struct GNUNET_IDENTITY_PublicKey *identity, |
515 | const struct GNUNET_RECLAIM_Attribute *attr) | 515 | const struct GNUNET_RECLAIM_Attribute *attr) |
516 | { | 516 | { |
517 | struct GNUNET_RECLAIM_AttributeListEntry *le; | 517 | struct GNUNET_RECLAIM_AttributeListEntry *le; |
@@ -653,7 +653,7 @@ cred_iter_finished (void *cls) | |||
653 | 653 | ||
654 | static void | 654 | static void |
655 | cred_iter_cb (void *cls, | 655 | cred_iter_cb (void *cls, |
656 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 656 | const struct GNUNET_IDENTITY_PublicKey *identity, |
657 | const struct GNUNET_RECLAIM_Credential *cred) | 657 | const struct GNUNET_RECLAIM_Credential *cred) |
658 | { | 658 | { |
659 | char *cred_str; | 659 | char *cred_str; |
@@ -734,7 +734,7 @@ start_process () | |||
734 | 734 | ||
735 | if ((NULL != rp) && | 735 | if ((NULL != rp) && |
736 | (GNUNET_OK != | 736 | (GNUNET_OK != |
737 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key)) ) | 737 | GNUNET_IDENTITY_public_key_from_string (rp, &rp_key)) ) |
738 | { | 738 | { |
739 | fprintf (stderr, "%s is not a public key!\n", rp); | 739 | fprintf (stderr, "%s is not a public key!\n", rp); |
740 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | 740 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); |
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index d2cdc62a2..0774fecea 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -110,7 +110,7 @@ struct Iterator | |||
110 | /** | 110 | /** |
111 | * Key of the zone we are iterating over. | 111 | * Key of the zone we are iterating over. |
112 | */ | 112 | */ |
113 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 113 | struct GNUNET_IDENTITY_PrivateKey identity; |
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Namestore iterator | 116 | * Namestore iterator |
@@ -266,7 +266,7 @@ struct AttributeDeleteHandle | |||
266 | /** | 266 | /** |
267 | * Identity | 267 | * Identity |
268 | */ | 268 | */ |
269 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 269 | struct GNUNET_IDENTITY_PrivateKey identity; |
270 | 270 | ||
271 | 271 | ||
272 | /** | 272 | /** |
@@ -334,12 +334,12 @@ struct AttributeStoreHandle | |||
334 | /** | 334 | /** |
335 | * Identity | 335 | * Identity |
336 | */ | 336 | */ |
337 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 337 | struct GNUNET_IDENTITY_PrivateKey identity; |
338 | 338 | ||
339 | /** | 339 | /** |
340 | * Identity pubkey | 340 | * Identity pubkey |
341 | */ | 341 | */ |
342 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pkey; | 342 | struct GNUNET_IDENTITY_PublicKey identity_pkey; |
343 | 343 | ||
344 | /** | 344 | /** |
345 | * QueueEntry | 345 | * QueueEntry |
@@ -862,7 +862,7 @@ handle_revoke_ticket_message (void *cls, const struct RevokeTicketMessage *rm) | |||
862 | */ | 862 | */ |
863 | static void | 863 | static void |
864 | consume_result_cb (void *cls, | 864 | consume_result_cb (void *cls, |
865 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 865 | const struct GNUNET_IDENTITY_PublicKey *identity, |
866 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 866 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
867 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 867 | const struct GNUNET_RECLAIM_PresentationList *presentations, |
868 | int32_t success, | 868 | int32_t success, |
@@ -1082,7 +1082,7 @@ handle_attribute_store_message (void *cls, | |||
1082 | ash->r_id = ntohl (sam->id); | 1082 | ash->r_id = ntohl (sam->id); |
1083 | ash->identity = sam->identity; | 1083 | ash->identity = sam->identity; |
1084 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); | 1084 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); |
1085 | GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); | 1085 | GNUNET_IDENTITY_key_get_public (&sam->identity, &ash->identity_pkey); |
1086 | 1086 | ||
1087 | GNUNET_SERVICE_client_continue (idp->client); | 1087 | GNUNET_SERVICE_client_continue (idp->client); |
1088 | ash->client = idp; | 1088 | ash->client = idp; |
@@ -1157,7 +1157,7 @@ cred_error (void *cls) | |||
1157 | */ | 1157 | */ |
1158 | static void | 1158 | static void |
1159 | cred_add_cb (void *cls, | 1159 | cred_add_cb (void *cls, |
1160 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1160 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1161 | const char *label, | 1161 | const char *label, |
1162 | unsigned int rd_count, | 1162 | unsigned int rd_count, |
1163 | const struct GNUNET_GNSRECORD_Data *rd) | 1163 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1266,7 +1266,7 @@ handle_credential_store_message (void *cls, | |||
1266 | ash->r_id = ntohl (sam->id); | 1266 | ash->r_id = ntohl (sam->id); |
1267 | ash->identity = sam->identity; | 1267 | ash->identity = sam->identity; |
1268 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); | 1268 | ash->exp.rel_value_us = GNUNET_ntohll (sam->exp); |
1269 | GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey); | 1269 | GNUNET_IDENTITY_key_get_public (&sam->identity, &ash->identity_pkey); |
1270 | 1270 | ||
1271 | GNUNET_SERVICE_client_continue (idp->client); | 1271 | GNUNET_SERVICE_client_continue (idp->client); |
1272 | ash->client = idp; | 1272 | ash->client = idp; |
@@ -1311,7 +1311,7 @@ send_delete_response (struct AttributeDeleteHandle *adh, int32_t success) | |||
1311 | */ | 1311 | */ |
1312 | static void | 1312 | static void |
1313 | ticket_iter (void *cls, | 1313 | ticket_iter (void *cls, |
1314 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1314 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1315 | const char *label, | 1315 | const char *label, |
1316 | unsigned int rd_count, | 1316 | unsigned int rd_count, |
1317 | const struct GNUNET_GNSRECORD_Data *rd) | 1317 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1739,7 +1739,7 @@ attr_iter_error (void *cls) | |||
1739 | */ | 1739 | */ |
1740 | static void | 1740 | static void |
1741 | attr_iter_cb (void *cls, | 1741 | attr_iter_cb (void *cls, |
1742 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1742 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1743 | const char *label, | 1743 | const char *label, |
1744 | unsigned int rd_count, | 1744 | unsigned int rd_count, |
1745 | const struct GNUNET_GNSRECORD_Data *rd) | 1745 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1764,7 +1764,7 @@ attr_iter_cb (void *cls, | |||
1764 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); | 1764 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_RESULT); |
1765 | arm->id = htonl (ai->request_id); | 1765 | arm->id = htonl (ai->request_id); |
1766 | arm->attr_len = htons (rd->data_size); | 1766 | arm->attr_len = htons (rd->data_size); |
1767 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); | 1767 | GNUNET_IDENTITY_key_get_public (zone, &arm->identity); |
1768 | data_tmp = (char *) &arm[1]; | 1768 | data_tmp = (char *) &arm[1]; |
1769 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); | 1769 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); |
1770 | GNUNET_MQ_send (ai->client->mq, env); | 1770 | GNUNET_MQ_send (ai->client->mq, env); |
@@ -1923,7 +1923,7 @@ cred_iter_error (void *cls) | |||
1923 | */ | 1923 | */ |
1924 | static void | 1924 | static void |
1925 | cred_iter_cb (void *cls, | 1925 | cred_iter_cb (void *cls, |
1926 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1926 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1927 | const char *label, | 1927 | const char *label, |
1928 | unsigned int rd_count, | 1928 | unsigned int rd_count, |
1929 | const struct GNUNET_GNSRECORD_Data *rd) | 1929 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1948,7 +1948,7 @@ cred_iter_cb (void *cls, | |||
1948 | GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT); | 1948 | GNUNET_MESSAGE_TYPE_RECLAIM_CREDENTIAL_RESULT); |
1949 | arm->id = htonl (ai->request_id); | 1949 | arm->id = htonl (ai->request_id); |
1950 | arm->credential_len = htons (rd->data_size); | 1950 | arm->credential_len = htons (rd->data_size); |
1951 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity); | 1951 | GNUNET_IDENTITY_key_get_public (zone, &arm->identity); |
1952 | data_tmp = (char *) &arm[1]; | 1952 | data_tmp = (char *) &arm[1]; |
1953 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); | 1953 | GNUNET_memcpy (data_tmp, rd->data, rd->data_size); |
1954 | 1954 | ||
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index 4dd8100f9..0b1730bec 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -86,12 +86,12 @@ struct RECLAIM_TICKETS_ConsumeHandle | |||
86 | /** | 86 | /** |
87 | * Audience Key | 87 | * Audience Key |
88 | */ | 88 | */ |
89 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 89 | struct GNUNET_IDENTITY_PrivateKey identity; |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Audience Key | 92 | * Audience Key |
93 | */ | 93 | */ |
94 | struct GNUNET_CRYPTO_EcdsaPublicKey identity_pub; | 94 | struct GNUNET_IDENTITY_PublicKey identity_pub; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * Lookup DLL | 97 | * Lookup DLL |
@@ -180,7 +180,7 @@ struct TicketIssueHandle | |||
180 | /** | 180 | /** |
181 | * Issuer Key | 181 | * Issuer Key |
182 | */ | 182 | */ |
183 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 183 | struct GNUNET_IDENTITY_PrivateKey identity; |
184 | 184 | ||
185 | /** | 185 | /** |
186 | * Ticket to issue | 186 | * Ticket to issue |
@@ -263,7 +263,7 @@ struct RECLAIM_TICKETS_RevokeHandle | |||
263 | /** | 263 | /** |
264 | * Issuer Key | 264 | * Issuer Key |
265 | */ | 265 | */ |
266 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 266 | struct GNUNET_IDENTITY_PrivateKey identity; |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * Callback | 269 | * Callback |
@@ -490,7 +490,7 @@ rvk_ticket_update_finished (void *cls) | |||
490 | */ | 490 | */ |
491 | static void | 491 | static void |
492 | rvk_ticket_update (void *cls, | 492 | rvk_ticket_update (void *cls, |
493 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 493 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
494 | const char *label, | 494 | const char *label, |
495 | unsigned int rd_count, | 495 | unsigned int rd_count, |
496 | const struct GNUNET_GNSRECORD_Data *rd) | 496 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -665,7 +665,7 @@ move_attr_finished (void *cls, int32_t success, const char *emsg) | |||
665 | */ | 665 | */ |
666 | static void | 666 | static void |
667 | rvk_move_attr_cb (void *cls, | 667 | rvk_move_attr_cb (void *cls, |
668 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 668 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
669 | const char *label, | 669 | const char *label, |
670 | unsigned int rd_count, | 670 | unsigned int rd_count, |
671 | const struct GNUNET_GNSRECORD_Data *rd) | 671 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -850,7 +850,7 @@ remove_ticket_cont (void *cls, int32_t success, const char *emsg) | |||
850 | */ | 850 | */ |
851 | static void | 851 | static void |
852 | revoke_attrs_cb (void *cls, | 852 | revoke_attrs_cb (void *cls, |
853 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 853 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
854 | const char *label, | 854 | const char *label, |
855 | unsigned int rd_count, | 855 | unsigned int rd_count, |
856 | const struct GNUNET_GNSRECORD_Data *rd) | 856 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -913,7 +913,7 @@ rvk_attrs_err_cb (void *cls) | |||
913 | */ | 913 | */ |
914 | struct RECLAIM_TICKETS_RevokeHandle * | 914 | struct RECLAIM_TICKETS_RevokeHandle * |
915 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 915 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, |
916 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 916 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
917 | RECLAIM_TICKETS_RevokeCallback cb, | 917 | RECLAIM_TICKETS_RevokeCallback cb, |
918 | void *cb_cls) | 918 | void *cb_cls) |
919 | { | 919 | { |
@@ -925,7 +925,7 @@ RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
925 | rvk->cb_cls = cb_cls; | 925 | rvk->cb_cls = cb_cls; |
926 | rvk->identity = *identity; | 926 | rvk->identity = *identity; |
927 | rvk->ticket = *ticket; | 927 | rvk->ticket = *ticket; |
928 | GNUNET_CRYPTO_ecdsa_key_get_public (&rvk->identity, &rvk->ticket.identity); | 928 | GNUNET_IDENTITY_key_get_public (&rvk->identity, &rvk->ticket.identity); |
929 | /** Get shared attributes **/ | 929 | /** Get shared attributes **/ |
930 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, | 930 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, |
931 | sizeof(ticket->rnd)); | 931 | sizeof(ticket->rnd)); |
@@ -1184,7 +1184,7 @@ lookup_authz_cb (void *cls, | |||
1184 | * @return handle to the operation | 1184 | * @return handle to the operation |
1185 | */ | 1185 | */ |
1186 | struct RECLAIM_TICKETS_ConsumeHandle * | 1186 | struct RECLAIM_TICKETS_ConsumeHandle * |
1187 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 1187 | RECLAIM_TICKETS_consume (const struct GNUNET_IDENTITY_PrivateKey *id, |
1188 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1188 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1189 | RECLAIM_TICKETS_ConsumeCallback cb, | 1189 | RECLAIM_TICKETS_ConsumeCallback cb, |
1190 | void *cb_cls) | 1190 | void *cb_cls) |
@@ -1195,7 +1195,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
1195 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); | 1195 | cth = GNUNET_new (struct RECLAIM_TICKETS_ConsumeHandle); |
1196 | 1196 | ||
1197 | cth->identity = *id; | 1197 | cth->identity = *id; |
1198 | GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); | 1198 | GNUNET_IDENTITY_key_get_public (&cth->identity, &cth->identity_pub); |
1199 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); | 1199 | cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
1200 | cth->presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList); | 1200 | cth->presentations = GNUNET_new (struct GNUNET_RECLAIM_PresentationList); |
1201 | cth->ticket = *ticket; | 1201 | cth->ticket = *ticket; |
@@ -1453,7 +1453,7 @@ filter_tickets_error_cb (void *cls) | |||
1453 | */ | 1453 | */ |
1454 | static void | 1454 | static void |
1455 | filter_tickets_cb (void *cls, | 1455 | filter_tickets_cb (void *cls, |
1456 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1456 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1457 | const char *label, | 1457 | const char *label, |
1458 | unsigned int rd_count, | 1458 | unsigned int rd_count, |
1459 | const struct GNUNET_GNSRECORD_Data *rd) | 1459 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1489,7 +1489,7 @@ filter_tickets_cb (void *cls, | |||
1489 | // cmp audience | 1489 | // cmp audience |
1490 | if (0 == memcmp (&tih->ticket.audience, | 1490 | if (0 == memcmp (&tih->ticket.audience, |
1491 | &ticket->audience, | 1491 | &ticket->audience, |
1492 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 1492 | sizeof(struct GNUNET_IDENTITY_PublicKey))) |
1493 | { | 1493 | { |
1494 | tih->ticket = *ticket; | 1494 | tih->ticket = *ticket; |
1495 | continue; | 1495 | continue; |
@@ -1602,7 +1602,7 @@ filter_tickets_finished_cb (void *cls) | |||
1602 | { | 1602 | { |
1603 | struct TicketIssueHandle *tih = cls; | 1603 | struct TicketIssueHandle *tih = cls; |
1604 | 1604 | ||
1605 | GNUNET_CRYPTO_ecdsa_key_get_public (&tih->identity, &tih->ticket.identity); | 1605 | GNUNET_IDENTITY_key_get_public (&tih->identity, &tih->ticket.identity); |
1606 | GNUNET_RECLAIM_id_generate (&tih->ticket.rnd); | 1606 | GNUNET_RECLAIM_id_generate (&tih->ticket.rnd); |
1607 | issue_ticket (tih); | 1607 | issue_ticket (tih); |
1608 | } | 1608 | } |
@@ -1620,9 +1620,9 @@ filter_tickets_finished_cb (void *cls) | |||
1620 | * FIXME: Return handle?? | 1620 | * FIXME: Return handle?? |
1621 | */ | 1621 | */ |
1622 | void | 1622 | void |
1623 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1623 | RECLAIM_TICKETS_issue (const struct GNUNET_IDENTITY_PrivateKey *identity, |
1624 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 1624 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
1625 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 1625 | const struct GNUNET_IDENTITY_PublicKey *audience, |
1626 | RECLAIM_TICKETS_TicketResult cb, | 1626 | RECLAIM_TICKETS_TicketResult cb, |
1627 | void *cb_cls) | 1627 | void *cb_cls) |
1628 | { | 1628 | { |
@@ -1680,7 +1680,7 @@ cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | |||
1680 | */ | 1680 | */ |
1681 | static void | 1681 | static void |
1682 | collect_tickets_cb (void *cls, | 1682 | collect_tickets_cb (void *cls, |
1683 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1683 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
1684 | const char *label, | 1684 | const char *label, |
1685 | unsigned int rd_count, | 1685 | unsigned int rd_count, |
1686 | const struct GNUNET_GNSRECORD_Data *rd) | 1686 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -1765,7 +1765,7 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | |||
1765 | */ | 1765 | */ |
1766 | struct RECLAIM_TICKETS_Iterator * | 1766 | struct RECLAIM_TICKETS_Iterator * |
1767 | RECLAIM_TICKETS_iteration_start ( | 1767 | RECLAIM_TICKETS_iteration_start ( |
1768 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1768 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1769 | RECLAIM_TICKETS_TicketIter cb, | 1769 | RECLAIM_TICKETS_TicketIter cb, |
1770 | void *cb_cls) | 1770 | void *cb_cls) |
1771 | { | 1771 | { |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.h b/src/reclaim/gnunet-service-reclaim_tickets.h index 0dd790fc7..9c31a6143 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.h +++ b/src/reclaim/gnunet-service-reclaim_tickets.h | |||
@@ -138,7 +138,7 @@ typedef void (*RECLAIM_TICKETS_TicketResult) ( | |||
138 | */ | 138 | */ |
139 | typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( | 139 | typedef void (*RECLAIM_TICKETS_ConsumeCallback) ( |
140 | void *cls, | 140 | void *cls, |
141 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 141 | const struct GNUNET_IDENTITY_PublicKey *identity, |
142 | const struct GNUNET_RECLAIM_AttributeList *attributes, | 142 | const struct GNUNET_RECLAIM_AttributeList *attributes, |
143 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 143 | const struct GNUNET_RECLAIM_PresentationList *presentations, |
144 | int32_t success, | 144 | int32_t success, |
@@ -167,7 +167,7 @@ typedef void (*RECLAIM_TICKETS_RevokeCallback) (void *cls, int32_t success); | |||
167 | */ | 167 | */ |
168 | struct RECLAIM_TICKETS_RevokeHandle * | 168 | struct RECLAIM_TICKETS_RevokeHandle * |
169 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 169 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, |
170 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 170 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
171 | RECLAIM_TICKETS_RevokeCallback cb, | 171 | RECLAIM_TICKETS_RevokeCallback cb, |
172 | void *cb_cls); | 172 | void *cb_cls); |
173 | 173 | ||
@@ -193,7 +193,7 @@ RECLAIM_TICKETS_revoke_cancel (struct RECLAIM_TICKETS_RevokeHandle *rh); | |||
193 | * @return handle to the operation | 193 | * @return handle to the operation |
194 | */ | 194 | */ |
195 | struct RECLAIM_TICKETS_ConsumeHandle * | 195 | struct RECLAIM_TICKETS_ConsumeHandle * |
196 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 196 | RECLAIM_TICKETS_consume (const struct GNUNET_IDENTITY_PrivateKey *id, |
197 | const struct GNUNET_RECLAIM_Ticket *ticket, | 197 | const struct GNUNET_RECLAIM_Ticket *ticket, |
198 | RECLAIM_TICKETS_ConsumeCallback cb, | 198 | RECLAIM_TICKETS_ConsumeCallback cb, |
199 | void *cb_cls); | 199 | void *cb_cls); |
@@ -220,9 +220,9 @@ RECLAIM_TICKETS_consume_cancel (struct RECLAIM_TICKETS_ConsumeHandle *cth); | |||
220 | * FIXME: Return handle?? | 220 | * FIXME: Return handle?? |
221 | */ | 221 | */ |
222 | void | 222 | void |
223 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 223 | RECLAIM_TICKETS_issue (const struct GNUNET_IDENTITY_PrivateKey *identity, |
224 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 224 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
225 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 225 | const struct GNUNET_IDENTITY_PublicKey *audience, |
226 | RECLAIM_TICKETS_TicketResult cb, | 226 | RECLAIM_TICKETS_TicketResult cb, |
227 | void *cb_cls); | 227 | void *cb_cls); |
228 | 228 | ||
@@ -255,7 +255,7 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter); | |||
255 | */ | 255 | */ |
256 | struct RECLAIM_TICKETS_Iterator * | 256 | struct RECLAIM_TICKETS_Iterator * |
257 | RECLAIM_TICKETS_iteration_start ( | 257 | RECLAIM_TICKETS_iteration_start ( |
258 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 258 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
259 | RECLAIM_TICKETS_TicketIter cb, | 259 | RECLAIM_TICKETS_TicketIter cb, |
260 | void *cb_cls); | 260 | void *cb_cls); |
261 | 261 | ||
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c index b307a358c..c6d56e02d 100644 --- a/src/reclaim/oidc_helper.c +++ b/src/reclaim/oidc_helper.c | |||
@@ -154,10 +154,12 @@ fix_base64 (char *str) | |||
154 | replace_char (str, '/', '_'); | 154 | replace_char (str, '/', '_'); |
155 | } | 155 | } |
156 | 156 | ||
157 | |||
157 | static json_t* | 158 | static json_t* |
158 | generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 159 | generate_userinfo_json (const struct GNUNET_IDENTITY_PublicKey *sub_key, |
159 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 160 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
160 | const struct GNUNET_RECLAIM_PresentationList *presentations) | 161 | const struct |
162 | GNUNET_RECLAIM_PresentationList *presentations) | ||
161 | { | 163 | { |
162 | struct GNUNET_RECLAIM_AttributeListEntry *le; | 164 | struct GNUNET_RECLAIM_AttributeListEntry *le; |
163 | struct GNUNET_RECLAIM_PresentationListEntry *ple; | 165 | struct GNUNET_RECLAIM_PresentationListEntry *ple; |
@@ -180,7 +182,7 @@ generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | |||
180 | subject = | 182 | subject = |
181 | GNUNET_STRINGS_data_to_string_alloc (sub_key, | 183 | GNUNET_STRINGS_data_to_string_alloc (sub_key, |
182 | sizeof(struct | 184 | sizeof(struct |
183 | GNUNET_CRYPTO_EcdsaPublicKey)); | 185 | GNUNET_IDENTITY_PublicKey)); |
184 | body = json_object (); | 186 | body = json_object (); |
185 | aggr_names = json_object (); | 187 | aggr_names = json_object (); |
186 | aggr_sources = json_object (); | 188 | aggr_sources = json_object (); |
@@ -206,7 +208,8 @@ generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | |||
206 | ple->presentation->data, | 208 | ple->presentation->data, |
207 | ple->presentation->data_size); | 209 | ple->presentation->data_size); |
208 | json_object_set_new (aggr_sources_jwt, | 210 | json_object_set_new (aggr_sources_jwt, |
209 | GNUNET_RECLAIM_presentation_number_to_typename (ple->presentation->type), | 211 | GNUNET_RECLAIM_presentation_number_to_typename ( |
212 | ple->presentation->type), | ||
210 | json_string (pres_val_str) ); | 213 | json_string (pres_val_str) ); |
211 | json_object_set_new (aggr_sources, source_name, aggr_sources_jwt); | 214 | json_object_set_new (aggr_sources, source_name, aggr_sources_jwt); |
212 | GNUNET_free (pres_val_str); | 215 | GNUNET_free (pres_val_str); |
@@ -286,6 +289,7 @@ generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | |||
286 | return body; | 289 | return body; |
287 | } | 290 | } |
288 | 291 | ||
292 | |||
289 | /** | 293 | /** |
290 | * Generate userinfo JSON as string | 294 | * Generate userinfo JSON as string |
291 | * | 295 | * |
@@ -295,14 +299,15 @@ generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | |||
295 | * @return Userinfo JSON | 299 | * @return Userinfo JSON |
296 | */ | 300 | */ |
297 | char * | 301 | char * |
298 | OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 302 | OIDC_generate_userinfo (const struct GNUNET_IDENTITY_PublicKey *sub_key, |
299 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 303 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
300 | const struct GNUNET_RECLAIM_PresentationList *presentations) | 304 | const struct |
305 | GNUNET_RECLAIM_PresentationList *presentations) | ||
301 | { | 306 | { |
302 | char *body_str; | 307 | char *body_str; |
303 | json_t* body = generate_userinfo_json (sub_key, | 308 | json_t*body = generate_userinfo_json (sub_key, |
304 | attrs, | 309 | attrs, |
305 | presentations); | 310 | presentations); |
306 | body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT); | 311 | body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT); |
307 | json_decref (body); | 312 | json_decref (body); |
308 | return body_str; | 313 | return body_str; |
@@ -321,10 +326,11 @@ OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | |||
321 | * @return a new base64-encoded JWT string. | 326 | * @return a new base64-encoded JWT string. |
322 | */ | 327 | */ |
323 | char * | 328 | char * |
324 | OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | 329 | OIDC_generate_id_token (const struct GNUNET_IDENTITY_PublicKey *aud_key, |
325 | const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 330 | const struct GNUNET_IDENTITY_PublicKey *sub_key, |
326 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 331 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
327 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 332 | const struct |
333 | GNUNET_RECLAIM_PresentationList *presentations, | ||
328 | const struct GNUNET_TIME_Relative *expiration_time, | 334 | const struct GNUNET_TIME_Relative *expiration_time, |
329 | const char *nonce, | 335 | const char *nonce, |
330 | const char *secret_key) | 336 | const char *secret_key) |
@@ -356,11 +362,11 @@ OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | |||
356 | subject = | 362 | subject = |
357 | GNUNET_STRINGS_data_to_string_alloc (sub_key, | 363 | GNUNET_STRINGS_data_to_string_alloc (sub_key, |
358 | sizeof(struct | 364 | sizeof(struct |
359 | GNUNET_CRYPTO_EcdsaPublicKey)); | 365 | GNUNET_IDENTITY_PublicKey)); |
360 | audience = | 366 | audience = |
361 | GNUNET_STRINGS_data_to_string_alloc (aud_key, | 367 | GNUNET_STRINGS_data_to_string_alloc (aud_key, |
362 | sizeof(struct | 368 | sizeof(struct |
363 | GNUNET_CRYPTO_EcdsaPublicKey)); | 369 | GNUNET_IDENTITY_PublicKey)); |
364 | header = create_jwt_header (); | 370 | header = create_jwt_header (); |
365 | 371 | ||
366 | // aud REQUIRED public key client_id must be there | 372 | // aud REQUIRED public key client_id must be there |
@@ -438,10 +444,11 @@ OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | |||
438 | * @return a new authorization code (caller must free) | 444 | * @return a new authorization code (caller must free) |
439 | */ | 445 | */ |
440 | char * | 446 | char * |
441 | OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 447 | OIDC_build_authz_code (const struct GNUNET_IDENTITY_PrivateKey *issuer, |
442 | const struct GNUNET_RECLAIM_Ticket *ticket, | 448 | const struct GNUNET_RECLAIM_Ticket *ticket, |
443 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 449 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
444 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 450 | const struct |
451 | GNUNET_RECLAIM_PresentationList *presentations, | ||
445 | const char *nonce_str, | 452 | const char *nonce_str, |
446 | const char *code_challenge) | 453 | const char *code_challenge) |
447 | { | 454 | { |
@@ -525,7 +532,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
525 | // Get length | 532 | // Get length |
526 | code_payload_len = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 533 | code_payload_len = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
527 | + payload_len + sizeof(struct | 534 | + payload_len + sizeof(struct |
528 | GNUNET_CRYPTO_EcdsaSignature); | 535 | GNUNET_IDENTITY_Signature); |
529 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 536 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
530 | "Length of data to encode: %lu\n", | 537 | "Length of data to encode: %lu\n", |
531 | code_payload_len); | 538 | code_payload_len); |
@@ -544,10 +551,10 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
544 | buf_ptr += payload_len; | 551 | buf_ptr += payload_len; |
545 | // Sign and store signature | 552 | // Sign and store signature |
546 | if (GNUNET_SYSERR == | 553 | if (GNUNET_SYSERR == |
547 | GNUNET_CRYPTO_ecdsa_sign_ (issuer, | 554 | GNUNET_IDENTITY_sign_ (issuer, |
548 | purpose, | 555 | purpose, |
549 | (struct GNUNET_CRYPTO_EcdsaSignature *) | 556 | (struct GNUNET_IDENTITY_Signature *) |
550 | buf_ptr)) | 557 | buf_ptr)) |
551 | { | 558 | { |
552 | GNUNET_break (0); | 559 | GNUNET_break (0); |
553 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to sign code\n"); | 560 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to sign code\n"); |
@@ -576,7 +583,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
576 | * @return GNUNET_OK if successful, else GNUNET_SYSERR | 583 | * @return GNUNET_OK if successful, else GNUNET_SYSERR |
577 | */ | 584 | */ |
578 | int | 585 | int |
579 | OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 586 | OIDC_parse_authz_code (const struct GNUNET_IDENTITY_PublicKey *audience, |
580 | const char *code, | 587 | const char *code, |
581 | const char *code_verifier, | 588 | const char *code_verifier, |
582 | struct GNUNET_RECLAIM_Ticket *ticket, | 589 | struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -593,7 +600,7 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | |||
593 | char *code_challenge; | 600 | char *code_challenge; |
594 | char *code_verifier_hash; | 601 | char *code_verifier_hash; |
595 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; | 602 | struct GNUNET_CRYPTO_EccSignaturePurpose *purpose; |
596 | struct GNUNET_CRYPTO_EcdsaSignature *signature; | 603 | struct GNUNET_IDENTITY_Signature *signature; |
597 | uint32_t code_challenge_len; | 604 | uint32_t code_challenge_len; |
598 | uint32_t attrs_ser_len; | 605 | uint32_t attrs_ser_len; |
599 | uint32_t pres_ser_len; | 606 | uint32_t pres_ser_len; |
@@ -609,7 +616,7 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | |||
609 | (void **) &code_payload); | 616 | (void **) &code_payload); |
610 | if (code_payload_len < sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 617 | if (code_payload_len < sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
611 | + sizeof(struct OIDC_Parameters) | 618 | + sizeof(struct OIDC_Parameters) |
612 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature)) | 619 | + sizeof(struct GNUNET_IDENTITY_Signature)) |
613 | { | 620 | { |
614 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Authorization code malformed\n"); | 621 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Authorization code malformed\n"); |
615 | GNUNET_free (code_payload); | 622 | GNUNET_free (code_payload); |
@@ -620,10 +627,10 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | |||
620 | plaintext_len = code_payload_len; | 627 | plaintext_len = code_payload_len; |
621 | plaintext_len -= sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose); | 628 | plaintext_len -= sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose); |
622 | ptr = (char *) &purpose[1]; | 629 | ptr = (char *) &purpose[1]; |
623 | plaintext_len -= sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 630 | plaintext_len -= sizeof(struct GNUNET_IDENTITY_Signature); |
624 | plaintext = ptr; | 631 | plaintext = ptr; |
625 | ptr += plaintext_len; | 632 | ptr += plaintext_len; |
626 | signature = (struct GNUNET_CRYPTO_EcdsaSignature *) ptr; | 633 | signature = (struct GNUNET_IDENTITY_Signature *) ptr; |
627 | params = (struct OIDC_Parameters *) plaintext; | 634 | params = (struct OIDC_Parameters *) plaintext; |
628 | 635 | ||
629 | // cmp code_challenge code_verifier | 636 | // cmp code_challenge code_verifier |
@@ -684,10 +691,11 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | |||
684 | return GNUNET_SYSERR; | 691 | return GNUNET_SYSERR; |
685 | } | 692 | } |
686 | if (GNUNET_OK != | 693 | if (GNUNET_OK != |
687 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN, | 694 | GNUNET_IDENTITY_signature_verify_ ( |
688 | purpose, | 695 | GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN, |
689 | signature, | 696 | purpose, |
690 | &ticket->identity)) | 697 | signature, |
698 | &(ticket->identity))) | ||
691 | { | 699 | { |
692 | GNUNET_free (code_payload); | 700 | GNUNET_free (code_payload); |
693 | if (NULL != *nonce_str) | 701 | if (NULL != *nonce_str) |
@@ -840,7 +848,8 @@ OIDC_check_scopes_for_claim_request (const char*scopes, | |||
840 | } | 848 | } |
841 | } | 849 | } |
842 | 850 | ||
843 | } else if (0 == strcmp (attr, scope_variable)) | 851 | } |
852 | else if (0 == strcmp (attr, scope_variable)) | ||
844 | { | 853 | { |
845 | /** attribute matches requested scope **/ | 854 | /** attribute matches requested scope **/ |
846 | GNUNET_free (scope_variables); | 855 | GNUNET_free (scope_variables); |
diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h index 10a6f3d1f..eb1022423 100644 --- a/src/reclaim/oidc_helper.h +++ b/src/reclaim/oidc_helper.h | |||
@@ -50,8 +50,8 @@ | |||
50 | * @return a new base64-encoded JWT string. | 50 | * @return a new base64-encoded JWT string. |
51 | */ | 51 | */ |
52 | char* | 52 | char* |
53 | OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | 53 | OIDC_generate_id_token (const struct GNUNET_IDENTITY_PublicKey *aud_key, |
54 | const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 54 | const struct GNUNET_IDENTITY_PublicKey *sub_key, |
55 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 55 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
56 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 56 | const struct GNUNET_RECLAIM_PresentationList *presentations, |
57 | const struct GNUNET_TIME_Relative *expiration_time, | 57 | const struct GNUNET_TIME_Relative *expiration_time, |
@@ -71,7 +71,7 @@ OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key, | |||
71 | * @return a new authorization code (caller must free) | 71 | * @return a new authorization code (caller must free) |
72 | */ | 72 | */ |
73 | char* | 73 | char* |
74 | OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | 74 | OIDC_build_authz_code (const struct GNUNET_IDENTITY_PrivateKey *issuer, |
75 | const struct GNUNET_RECLAIM_Ticket *ticket, | 75 | const struct GNUNET_RECLAIM_Ticket *ticket, |
76 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 76 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
77 | const struct GNUNET_RECLAIM_PresentationList *presentations, | 77 | const struct GNUNET_RECLAIM_PresentationList *presentations, |
@@ -93,7 +93,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer, | |||
93 | * @return GNUNET_OK if successful, else GNUNET_SYSERR | 93 | * @return GNUNET_OK if successful, else GNUNET_SYSERR |
94 | */ | 94 | */ |
95 | int | 95 | int |
96 | OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub, | 96 | OIDC_parse_authz_code (const struct GNUNET_IDENTITY_PublicKey *ecdsa_pub, |
97 | const char *code, | 97 | const char *code, |
98 | const char *code_verifier, | 98 | const char *code_verifier, |
99 | struct GNUNET_RECLAIM_Ticket *ticket, | 99 | struct GNUNET_RECLAIM_Ticket *ticket, |
@@ -152,7 +152,7 @@ OIDC_check_scopes_for_claim_request (const char *scopes, | |||
152 | * @return Userinfo JSON | 152 | * @return Userinfo JSON |
153 | */ | 153 | */ |
154 | char * | 154 | char * |
155 | OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key, | 155 | OIDC_generate_userinfo (const struct GNUNET_IDENTITY_PublicKey *sub_key, |
156 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 156 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
157 | const struct GNUNET_RECLAIM_PresentationList *presentations); | 157 | const struct GNUNET_RECLAIM_PresentationList *presentations); |
158 | 158 | ||
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index 5b0bb2b6f..7a8a886bd 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c | |||
@@ -300,7 +300,7 @@ struct OIDC_Variables | |||
300 | /** | 300 | /** |
301 | * The RP client public key | 301 | * The RP client public key |
302 | */ | 302 | */ |
303 | struct GNUNET_CRYPTO_EcdsaPublicKey client_pkey; | 303 | struct GNUNET_IDENTITY_PublicKey client_pkey; |
304 | 304 | ||
305 | /** | 305 | /** |
306 | * The OIDC client id of the RP | 306 | * The OIDC client id of the RP |
@@ -411,7 +411,7 @@ struct RequestHandle | |||
411 | /** | 411 | /** |
412 | * Pointer to ego private key | 412 | * Pointer to ego private key |
413 | */ | 413 | */ |
414 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key; | 414 | struct GNUNET_IDENTITY_PrivateKey priv_key; |
415 | 415 | ||
416 | /** | 416 | /** |
417 | * OIDC variables | 417 | * OIDC variables |
@@ -972,7 +972,7 @@ oidc_ticket_issue_cb (void *cls, | |||
972 | (NULL != handle->tld)) | 972 | (NULL != handle->tld)) |
973 | { | 973 | { |
974 | GNUNET_asprintf (&redirect_uri, | 974 | GNUNET_asprintf (&redirect_uri, |
975 | "%s.%s/%s?%s=%s&state=%s", | 975 | "%s.%s/%s%s%s=%s&state=%s", |
976 | handle->redirect_prefix, | 976 | handle->redirect_prefix, |
977 | handle->tld, | 977 | handle->tld, |
978 | handle->redirect_suffix, | 978 | handle->redirect_suffix, |
@@ -1087,7 +1087,7 @@ oidc_cred_collect_finished_cb (void *cls) | |||
1087 | */ | 1087 | */ |
1088 | static void | 1088 | static void |
1089 | oidc_cred_collect (void *cls, | 1089 | oidc_cred_collect (void *cls, |
1090 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1090 | const struct GNUNET_IDENTITY_PublicKey *identity, |
1091 | const struct GNUNET_RECLAIM_Credential *cred) | 1091 | const struct GNUNET_RECLAIM_Credential *cred) |
1092 | { | 1092 | { |
1093 | struct RequestHandle *handle = cls; | 1093 | struct RequestHandle *handle = cls; |
@@ -1211,7 +1211,7 @@ attr_in_userinfo_request (struct RequestHandle *handle, | |||
1211 | */ | 1211 | */ |
1212 | static void | 1212 | static void |
1213 | oidc_attr_collect (void *cls, | 1213 | oidc_attr_collect (void *cls, |
1214 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1214 | const struct GNUNET_IDENTITY_PublicKey *identity, |
1215 | const struct GNUNET_RECLAIM_Attribute *attr) | 1215 | const struct GNUNET_RECLAIM_Attribute *attr) |
1216 | { | 1216 | { |
1217 | struct RequestHandle *handle = cls; | 1217 | struct RequestHandle *handle = cls; |
@@ -1260,8 +1260,8 @@ code_redirect (void *cls) | |||
1260 | struct RequestHandle *handle = cls; | 1260 | struct RequestHandle *handle = cls; |
1261 | struct GNUNET_TIME_Absolute current_time; | 1261 | struct GNUNET_TIME_Absolute current_time; |
1262 | struct GNUNET_TIME_Absolute *relog_time; | 1262 | struct GNUNET_TIME_Absolute *relog_time; |
1263 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 1263 | struct GNUNET_IDENTITY_PublicKey pubkey; |
1264 | struct GNUNET_CRYPTO_EcdsaPublicKey ego_pkey; | 1264 | struct GNUNET_IDENTITY_PublicKey ego_pkey; |
1265 | struct GNUNET_HashCode cache_key; | 1265 | struct GNUNET_HashCode cache_key; |
1266 | char *identity_cookie; | 1266 | char *identity_cookie; |
1267 | 1267 | ||
@@ -1281,11 +1281,8 @@ code_redirect (void *cls) | |||
1281 | if (current_time.abs_value_us <= relog_time->abs_value_us) | 1281 | if (current_time.abs_value_us <= relog_time->abs_value_us) |
1282 | { | 1282 | { |
1283 | if (GNUNET_OK != | 1283 | if (GNUNET_OK != |
1284 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc | 1284 | GNUNET_IDENTITY_public_key_from_string (handle->oidc |
1285 | ->login_identity, | 1285 | ->login_identity, |
1286 | strlen ( | ||
1287 | handle->oidc | ||
1288 | ->login_identity), | ||
1289 | &pubkey)) | 1286 | &pubkey)) |
1290 | { | 1287 | { |
1291 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); | 1288 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); |
@@ -1376,7 +1373,7 @@ lookup_redirect_uri_result (void *cls, | |||
1376 | char *tmp; | 1373 | char *tmp; |
1377 | char *tmp_key_str; | 1374 | char *tmp_key_str; |
1378 | char *pos; | 1375 | char *pos; |
1379 | struct GNUNET_CRYPTO_EcdsaPublicKey redirect_zone; | 1376 | struct GNUNET_IDENTITY_PublicKey redirect_zone; |
1380 | 1377 | ||
1381 | handle->gns_op = NULL; | 1378 | handle->gns_op = NULL; |
1382 | if (0 == rd_count) | 1379 | if (0 == rd_count) |
@@ -1608,10 +1605,10 @@ static void | |||
1608 | tld_iter (void *cls, const char *section, const char *option, const char *value) | 1605 | tld_iter (void *cls, const char *section, const char *option, const char *value) |
1609 | { | 1606 | { |
1610 | struct RequestHandle *handle = cls; | 1607 | struct RequestHandle *handle = cls; |
1611 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1608 | struct GNUNET_IDENTITY_PublicKey pkey; |
1612 | 1609 | ||
1613 | if (GNUNET_OK != | 1610 | if (GNUNET_OK != |
1614 | GNUNET_CRYPTO_ecdsa_public_key_from_string (value, strlen (value), &pkey)) | 1611 | GNUNET_IDENTITY_public_key_from_string (value, &pkey)) |
1615 | { | 1612 | { |
1616 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value); | 1613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping non key %s\n", value); |
1617 | return; | 1614 | return; |
@@ -1635,8 +1632,8 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1635 | { | 1632 | { |
1636 | struct RequestHandle *handle = cls; | 1633 | struct RequestHandle *handle = cls; |
1637 | struct EgoEntry *tmp_ego; | 1634 | struct EgoEntry *tmp_ego; |
1638 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 1635 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
1639 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 1636 | struct GNUNET_IDENTITY_PublicKey pkey; |
1640 | 1637 | ||
1641 | cookie_identity_interpretation (handle); | 1638 | cookie_identity_interpretation (handle); |
1642 | 1639 | ||
@@ -1664,9 +1661,7 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1664 | } | 1661 | } |
1665 | 1662 | ||
1666 | if (GNUNET_OK != | 1663 | if (GNUNET_OK != |
1667 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id, | 1664 | GNUNET_IDENTITY_public_key_from_string (handle->oidc->client_id, |
1668 | strlen ( | ||
1669 | handle->oidc->client_id), | ||
1670 | &handle->oidc->client_pkey)) | 1665 | &handle->oidc->client_pkey)) |
1671 | { | 1666 | { |
1672 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); | 1667 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); |
@@ -1682,7 +1677,7 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1682 | for (tmp_ego = ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) | 1677 | for (tmp_ego = ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next) |
1683 | { | 1678 | { |
1684 | priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); | 1679 | priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego); |
1685 | GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey); | 1680 | GNUNET_IDENTITY_key_get_public (priv_key, &pkey); |
1686 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) | 1681 | if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey)) |
1687 | { | 1682 | { |
1688 | handle->tld = GNUNET_strdup (tmp_ego->identifier); | 1683 | handle->tld = GNUNET_strdup (tmp_ego->identifier); |
@@ -1865,7 +1860,7 @@ parse_credentials_post_body (struct RequestHandle *handle, | |||
1865 | 1860 | ||
1866 | static int | 1861 | static int |
1867 | check_authorization (struct RequestHandle *handle, | 1862 | check_authorization (struct RequestHandle *handle, |
1868 | struct GNUNET_CRYPTO_EcdsaPublicKey *cid) | 1863 | struct GNUNET_IDENTITY_PublicKey *cid) |
1869 | { | 1864 | { |
1870 | char *expected_pass; | 1865 | char *expected_pass; |
1871 | char *received_cid; | 1866 | char *received_cid; |
@@ -1902,7 +1897,7 @@ check_authorization (struct RequestHandle *handle, | |||
1902 | GNUNET_STRINGS_string_to_data (received_cid, | 1897 | GNUNET_STRINGS_string_to_data (received_cid, |
1903 | strlen (received_cid), | 1898 | strlen (received_cid), |
1904 | cid, | 1899 | cid, |
1905 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1900 | sizeof(struct GNUNET_IDENTITY_PublicKey)); |
1906 | GNUNET_free (received_cid); | 1901 | GNUNET_free (received_cid); |
1907 | return GNUNET_OK; | 1902 | return GNUNET_OK; |
1908 | 1903 | ||
@@ -1948,7 +1943,7 @@ check_authorization (struct RequestHandle *handle, | |||
1948 | GNUNET_STRINGS_string_to_data (received_cid, | 1943 | GNUNET_STRINGS_string_to_data (received_cid, |
1949 | strlen (received_cid), | 1944 | strlen (received_cid), |
1950 | cid, | 1945 | cid, |
1951 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 1946 | sizeof(struct GNUNET_IDENTITY_PublicKey)); |
1952 | 1947 | ||
1953 | GNUNET_free (received_cpw); | 1948 | GNUNET_free (received_cpw); |
1954 | GNUNET_free (received_cid); | 1949 | GNUNET_free (received_cid); |
@@ -1958,10 +1953,10 @@ check_authorization (struct RequestHandle *handle, | |||
1958 | 1953 | ||
1959 | const struct EgoEntry * | 1954 | const struct EgoEntry * |
1960 | find_ego (struct RequestHandle *handle, | 1955 | find_ego (struct RequestHandle *handle, |
1961 | struct GNUNET_CRYPTO_EcdsaPublicKey *test_key) | 1956 | struct GNUNET_IDENTITY_PublicKey *test_key) |
1962 | { | 1957 | { |
1963 | struct EgoEntry *ego_entry; | 1958 | struct EgoEntry *ego_entry; |
1964 | struct GNUNET_CRYPTO_EcdsaPublicKey pub_key; | 1959 | struct GNUNET_IDENTITY_PublicKey pub_key; |
1965 | 1960 | ||
1966 | for (ego_entry = ego_head; NULL != ego_entry; | 1961 | for (ego_entry = ego_head; NULL != ego_entry; |
1967 | ego_entry = ego_entry->next) | 1962 | ego_entry = ego_entry->next) |
@@ -1992,7 +1987,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1992 | struct GNUNET_RECLAIM_AttributeList *cl = NULL; | 1987 | struct GNUNET_RECLAIM_AttributeList *cl = NULL; |
1993 | struct GNUNET_RECLAIM_PresentationList *pl = NULL; | 1988 | struct GNUNET_RECLAIM_PresentationList *pl = NULL; |
1994 | struct GNUNET_RECLAIM_Ticket ticket; | 1989 | struct GNUNET_RECLAIM_Ticket ticket; |
1995 | struct GNUNET_CRYPTO_EcdsaPublicKey cid; | 1990 | struct GNUNET_IDENTITY_PublicKey cid; |
1996 | struct GNUNET_HashCode cache_key; | 1991 | struct GNUNET_HashCode cache_key; |
1997 | struct MHD_Response *resp; | 1992 | struct MHD_Response *resp; |
1998 | char *grant_type; | 1993 | char *grant_type; |
@@ -2145,7 +2140,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
2145 | */ | 2140 | */ |
2146 | static void | 2141 | static void |
2147 | consume_ticket (void *cls, | 2142 | consume_ticket (void *cls, |
2148 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 2143 | const struct GNUNET_IDENTITY_PublicKey *identity, |
2149 | const struct GNUNET_RECLAIM_Attribute *attr, | 2144 | const struct GNUNET_RECLAIM_Attribute *attr, |
2150 | const struct GNUNET_RECLAIM_Presentation *pres) | 2145 | const struct GNUNET_RECLAIM_Presentation *pres) |
2151 | { | 2146 | { |
@@ -2225,7 +2220,7 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
2225 | char *authorization_type; | 2220 | char *authorization_type; |
2226 | char *authorization_access_token; | 2221 | char *authorization_access_token; |
2227 | const struct EgoEntry *aud_ego; | 2222 | const struct EgoEntry *aud_ego; |
2228 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 2223 | const struct GNUNET_IDENTITY_PrivateKey *privkey; |
2229 | 2224 | ||
2230 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Getting userinfo\n"); | 2225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Getting userinfo\n"); |
2231 | GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, | 2226 | GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY, |
@@ -2349,7 +2344,7 @@ list_ego (void *cls, | |||
2349 | const char *identifier) | 2344 | const char *identifier) |
2350 | { | 2345 | { |
2351 | struct EgoEntry *ego_entry; | 2346 | struct EgoEntry *ego_entry; |
2352 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 2347 | struct GNUNET_IDENTITY_PublicKey pk; |
2353 | 2348 | ||
2354 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) | 2349 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
2355 | { | 2350 | { |
@@ -2362,7 +2357,7 @@ list_ego (void *cls, | |||
2362 | { | 2357 | { |
2363 | ego_entry = GNUNET_new (struct EgoEntry); | 2358 | ego_entry = GNUNET_new (struct EgoEntry); |
2364 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 2359 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
2365 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2360 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
2366 | ego_entry->ego = ego; | 2361 | ego_entry->ego = ego; |
2367 | ego_entry->identifier = GNUNET_strdup (identifier); | 2362 | ego_entry->identifier = GNUNET_strdup (identifier); |
2368 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 2363 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
@@ -2389,7 +2384,7 @@ list_ego (void *cls, | |||
2389 | /* Add */ | 2384 | /* Add */ |
2390 | ego_entry = GNUNET_new (struct EgoEntry); | 2385 | ego_entry = GNUNET_new (struct EgoEntry); |
2391 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 2386 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
2392 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 2387 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
2393 | ego_entry->ego = ego; | 2388 | ego_entry->ego = ego; |
2394 | ego_entry->identifier = GNUNET_strdup (identifier); | 2389 | ego_entry->identifier = GNUNET_strdup (identifier); |
2395 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 2390 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index ff11d2a56..022744c82 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -172,7 +172,7 @@ struct RequestHandle | |||
172 | /** | 172 | /** |
173 | * Pointer to ego private key | 173 | * Pointer to ego private key |
174 | */ | 174 | */ |
175 | struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key; | 175 | struct GNUNET_IDENTITY_PrivateKey priv_key; |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * Rest connection | 178 | * Rest connection |
@@ -440,14 +440,14 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
440 | tmp = | 440 | tmp = |
441 | GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, | 441 | GNUNET_STRINGS_data_to_string_alloc (&ticket->identity, |
442 | sizeof(struct | 442 | sizeof(struct |
443 | GNUNET_CRYPTO_EcdsaPublicKey)); | 443 | GNUNET_IDENTITY_PublicKey)); |
444 | value = json_string (tmp); | 444 | value = json_string (tmp); |
445 | json_object_set_new (json_resource, "issuer", value); | 445 | json_object_set_new (json_resource, "issuer", value); |
446 | GNUNET_free (tmp); | 446 | GNUNET_free (tmp); |
447 | tmp = | 447 | tmp = |
448 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, | 448 | GNUNET_STRINGS_data_to_string_alloc (&ticket->audience, |
449 | sizeof(struct | 449 | sizeof(struct |
450 | GNUNET_CRYPTO_EcdsaPublicKey)); | 450 | GNUNET_IDENTITY_PublicKey)); |
451 | value = json_string (tmp); | 451 | value = json_string (tmp); |
452 | json_object_set_new (json_resource, "audience", value); | 452 | json_object_set_new (json_resource, "audience", value); |
453 | GNUNET_free (tmp); | 453 | GNUNET_free (tmp); |
@@ -465,7 +465,7 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
465 | void *cls) | 465 | void *cls) |
466 | { | 466 | { |
467 | struct RequestHandle *handle = cls; | 467 | struct RequestHandle *handle = cls; |
468 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 468 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; |
469 | const char *identity; | 469 | const char *identity; |
470 | struct EgoEntry *ego_entry; | 470 | struct EgoEntry *ego_entry; |
471 | struct GNUNET_RECLAIM_Credential *attribute; | 471 | struct GNUNET_RECLAIM_Credential *attribute; |
@@ -545,7 +545,7 @@ add_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
545 | */ | 545 | */ |
546 | static void | 546 | static void |
547 | cred_collect (void *cls, | 547 | cred_collect (void *cls, |
548 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 548 | const struct GNUNET_IDENTITY_PublicKey *identity, |
549 | const struct GNUNET_RECLAIM_Credential *cred) | 549 | const struct GNUNET_RECLAIM_Credential *cred) |
550 | { | 550 | { |
551 | struct RequestHandle *handle = cls; | 551 | struct RequestHandle *handle = cls; |
@@ -631,7 +631,7 @@ list_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
631 | void *cls) | 631 | void *cls) |
632 | { | 632 | { |
633 | struct RequestHandle *handle = cls; | 633 | struct RequestHandle *handle = cls; |
634 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 634 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
635 | struct EgoEntry *ego_entry; | 635 | struct EgoEntry *ego_entry; |
636 | char *identity; | 636 | char *identity; |
637 | 637 | ||
@@ -688,7 +688,7 @@ delete_credential_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
688 | void *cls) | 688 | void *cls) |
689 | { | 689 | { |
690 | struct RequestHandle *handle = cls; | 690 | struct RequestHandle *handle = cls; |
691 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 691 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
692 | struct GNUNET_RECLAIM_Credential attr; | 692 | struct GNUNET_RECLAIM_Credential attr; |
693 | struct EgoEntry *ego_entry; | 693 | struct EgoEntry *ego_entry; |
694 | char *identity_id_str; | 694 | char *identity_id_str; |
@@ -754,7 +754,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
754 | const char *url, | 754 | const char *url, |
755 | void *cls) | 755 | void *cls) |
756 | { | 756 | { |
757 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 757 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
758 | struct RequestHandle *handle = cls; | 758 | struct RequestHandle *handle = cls; |
759 | struct EgoEntry *ego_entry; | 759 | struct EgoEntry *ego_entry; |
760 | char *identity; | 760 | char *identity; |
@@ -801,7 +801,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
801 | const char *url, | 801 | const char *url, |
802 | void *cls) | 802 | void *cls) |
803 | { | 803 | { |
804 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 804 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; |
805 | const char *identity; | 805 | const char *identity; |
806 | struct RequestHandle *handle = cls; | 806 | struct RequestHandle *handle = cls; |
807 | struct EgoEntry *ego_entry; | 807 | struct EgoEntry *ego_entry; |
@@ -949,7 +949,7 @@ parse_jwt (const struct GNUNET_RECLAIM_Credential *cred, | |||
949 | */ | 949 | */ |
950 | static void | 950 | static void |
951 | attr_collect (void *cls, | 951 | attr_collect (void *cls, |
952 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 952 | const struct GNUNET_IDENTITY_PublicKey *identity, |
953 | const struct GNUNET_RECLAIM_Attribute *attr) | 953 | const struct GNUNET_RECLAIM_Attribute *attr) |
954 | { | 954 | { |
955 | struct RequestHandle *handle = cls; | 955 | struct RequestHandle *handle = cls; |
@@ -996,7 +996,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
996 | const char *url, | 996 | const char *url, |
997 | void *cls) | 997 | void *cls) |
998 | { | 998 | { |
999 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 999 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
1000 | struct RequestHandle *handle = cls; | 1000 | struct RequestHandle *handle = cls; |
1001 | struct EgoEntry *ego_entry; | 1001 | struct EgoEntry *ego_entry; |
1002 | char *identity; | 1002 | char *identity; |
@@ -1050,7 +1050,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1050 | const char *url, | 1050 | const char *url, |
1051 | void *cls) | 1051 | void *cls) |
1052 | { | 1052 | { |
1053 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | 1053 | const struct GNUNET_IDENTITY_PrivateKey *priv_key; |
1054 | struct RequestHandle *handle = cls; | 1054 | struct RequestHandle *handle = cls; |
1055 | struct GNUNET_RECLAIM_Attribute attr; | 1055 | struct GNUNET_RECLAIM_Attribute attr; |
1056 | struct EgoEntry *ego_entry; | 1056 | struct EgoEntry *ego_entry; |
@@ -1108,11 +1108,11 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1108 | const char *url, | 1108 | const char *url, |
1109 | void *cls) | 1109 | void *cls) |
1110 | { | 1110 | { |
1111 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 1111 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; |
1112 | struct RequestHandle *handle = cls; | 1112 | struct RequestHandle *handle = cls; |
1113 | struct EgoEntry *ego_entry; | 1113 | struct EgoEntry *ego_entry; |
1114 | struct GNUNET_RECLAIM_Ticket *ticket = NULL; | 1114 | struct GNUNET_RECLAIM_Ticket *ticket = NULL; |
1115 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; | 1115 | struct GNUNET_IDENTITY_PublicKey tmp_pk; |
1116 | char term_data[handle->rest_handle->data_size + 1]; | 1116 | char term_data[handle->rest_handle->data_size + 1]; |
1117 | json_t *data_json; | 1117 | json_t *data_json; |
1118 | json_error_t err; | 1118 | json_error_t err; |
@@ -1156,7 +1156,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1156 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 1156 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); |
1157 | if (0 == memcmp (&ticket->identity, | 1157 | if (0 == memcmp (&ticket->identity, |
1158 | &tmp_pk, | 1158 | &tmp_pk, |
1159 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 1159 | sizeof(struct GNUNET_IDENTITY_PublicKey))) |
1160 | break; | 1160 | break; |
1161 | } | 1161 | } |
1162 | if (NULL == ego_entry) | 1162 | if (NULL == ego_entry) |
@@ -1178,7 +1178,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1178 | 1178 | ||
1179 | static void | 1179 | static void |
1180 | consume_cont (void *cls, | 1180 | consume_cont (void *cls, |
1181 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1181 | const struct GNUNET_IDENTITY_PublicKey *identity, |
1182 | const struct GNUNET_RECLAIM_Attribute *attr, | 1182 | const struct GNUNET_RECLAIM_Attribute *attr, |
1183 | const struct GNUNET_RECLAIM_Presentation *pres) | 1183 | const struct GNUNET_RECLAIM_Presentation *pres) |
1184 | { | 1184 | { |
@@ -1215,11 +1215,11 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1215 | const char *url, | 1215 | const char *url, |
1216 | void *cls) | 1216 | void *cls) |
1217 | { | 1217 | { |
1218 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 1218 | const struct GNUNET_IDENTITY_PrivateKey *identity_priv; |
1219 | struct RequestHandle *handle = cls; | 1219 | struct RequestHandle *handle = cls; |
1220 | struct EgoEntry *ego_entry; | 1220 | struct EgoEntry *ego_entry; |
1221 | struct GNUNET_RECLAIM_Ticket *ticket; | 1221 | struct GNUNET_RECLAIM_Ticket *ticket; |
1222 | struct GNUNET_CRYPTO_EcdsaPublicKey tmp_pk; | 1222 | struct GNUNET_IDENTITY_PublicKey tmp_pk; |
1223 | char term_data[handle->rest_handle->data_size + 1]; | 1223 | char term_data[handle->rest_handle->data_size + 1]; |
1224 | json_t *data_json; | 1224 | json_t *data_json; |
1225 | json_error_t err; | 1225 | json_error_t err; |
@@ -1259,7 +1259,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1259 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); | 1259 | GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk); |
1260 | if (0 == memcmp (&ticket->audience, | 1260 | if (0 == memcmp (&ticket->audience, |
1261 | &tmp_pk, | 1261 | &tmp_pk, |
1262 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))) | 1262 | sizeof(struct GNUNET_IDENTITY_PublicKey))) |
1263 | break; | 1263 | break; |
1264 | } | 1264 | } |
1265 | if (NULL == ego_entry) | 1265 | if (NULL == ego_entry) |
@@ -1343,7 +1343,7 @@ list_ego (void *cls, | |||
1343 | const char *identifier) | 1343 | const char *identifier) |
1344 | { | 1344 | { |
1345 | struct EgoEntry *ego_entry; | 1345 | struct EgoEntry *ego_entry; |
1346 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1346 | struct GNUNET_IDENTITY_PublicKey pk; |
1347 | 1347 | ||
1348 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) | 1348 | if ((NULL == ego) && (ID_REST_STATE_INIT == state)) |
1349 | { | 1349 | { |
@@ -1354,7 +1354,7 @@ list_ego (void *cls, | |||
1354 | { | 1354 | { |
1355 | ego_entry = GNUNET_new (struct EgoEntry); | 1355 | ego_entry = GNUNET_new (struct EgoEntry); |
1356 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1356 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1357 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1357 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
1358 | ego_entry->ego = ego; | 1358 | ego_entry->ego = ego; |
1359 | ego_entry->identifier = GNUNET_strdup (identifier); | 1359 | ego_entry->identifier = GNUNET_strdup (identifier); |
1360 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 1360 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
@@ -1380,7 +1380,7 @@ list_ego (void *cls, | |||
1380 | /* Add */ | 1380 | /* Add */ |
1381 | ego_entry = GNUNET_new (struct EgoEntry); | 1381 | ego_entry = GNUNET_new (struct EgoEntry); |
1382 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1382 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); |
1383 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1383 | ego_entry->keystring = GNUNET_IDENTITY_public_key_to_string (&pk); |
1384 | ego_entry->ego = ego; | 1384 | ego_entry->ego = ego; |
1385 | ego_entry->identifier = GNUNET_strdup (identifier); | 1385 | ego_entry->identifier = GNUNET_strdup (identifier); |
1386 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, | 1386 | GNUNET_CONTAINER_DLL_insert_tail (ego_head, |
diff --git a/src/reclaim/reclaim.h b/src/reclaim/reclaim.h index bc7f34365..aae8ee89a 100644 --- a/src/reclaim/reclaim.h +++ b/src/reclaim/reclaim.h | |||
@@ -29,7 +29,7 @@ | |||
29 | #define RECLAIM_H | 29 | #define RECLAIM_H |
30 | 30 | ||
31 | #include "gnunet_common.h" | 31 | #include "gnunet_common.h" |
32 | 32 | #include "gnunet_identity_service.h" | |
33 | 33 | ||
34 | GNUNET_NETWORK_STRUCT_BEGIN | 34 | GNUNET_NETWORK_STRUCT_BEGIN |
35 | 35 | ||
@@ -62,7 +62,7 @@ struct AttributeStoreMessage | |||
62 | /** | 62 | /** |
63 | * Identity | 63 | * Identity |
64 | */ | 64 | */ |
65 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 65 | struct GNUNET_IDENTITY_PrivateKey identity; |
66 | 66 | ||
67 | /* followed by the serialized attribute */ | 67 | /* followed by the serialized attribute */ |
68 | }; | 68 | }; |
@@ -91,7 +91,7 @@ struct AttributeDeleteMessage | |||
91 | /** | 91 | /** |
92 | * Identity | 92 | * Identity |
93 | */ | 93 | */ |
94 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 94 | struct GNUNET_IDENTITY_PrivateKey identity; |
95 | 95 | ||
96 | /* followed by the serialized attribute */ | 96 | /* followed by the serialized attribute */ |
97 | }; | 97 | }; |
@@ -151,7 +151,7 @@ struct AttributeResultMessage | |||
151 | /** | 151 | /** |
152 | * The public key of the identity. | 152 | * The public key of the identity. |
153 | */ | 153 | */ |
154 | struct GNUNET_CRYPTO_EcdsaPublicKey identity; | 154 | struct GNUNET_IDENTITY_PublicKey identity; |
155 | 155 | ||
156 | /* followed by: | 156 | /* followed by: |
157 | * serialized attribute data | 157 | * serialized attribute data |
@@ -186,7 +186,7 @@ struct CredentialResultMessage | |||
186 | /** | 186 | /** |
187 | * The public key of the identity. | 187 | * The public key of the identity. |
188 | */ | 188 | */ |
189 | struct GNUNET_CRYPTO_EcdsaPublicKey identity; | 189 | struct GNUNET_IDENTITY_PublicKey identity; |
190 | 190 | ||
191 | /* followed by: | 191 | /* followed by: |
192 | * serialized credential data | 192 | * serialized credential data |
@@ -212,7 +212,7 @@ struct AttributeIterationStartMessage | |||
212 | /** | 212 | /** |
213 | * Identity. | 213 | * Identity. |
214 | */ | 214 | */ |
215 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 215 | struct GNUNET_IDENTITY_PrivateKey identity; |
216 | }; | 216 | }; |
217 | 217 | ||
218 | 218 | ||
@@ -251,7 +251,7 @@ struct CredentialIterationStartMessage | |||
251 | /** | 251 | /** |
252 | * Identity. | 252 | * Identity. |
253 | */ | 253 | */ |
254 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 254 | struct GNUNET_IDENTITY_PrivateKey identity; |
255 | }; | 255 | }; |
256 | 256 | ||
257 | 257 | ||
@@ -323,7 +323,7 @@ struct TicketIterationStartMessage | |||
323 | /** | 323 | /** |
324 | * Identity. | 324 | * Identity. |
325 | */ | 325 | */ |
326 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 326 | struct GNUNET_IDENTITY_PrivateKey identity; |
327 | }; | 327 | }; |
328 | 328 | ||
329 | 329 | ||
@@ -379,12 +379,12 @@ struct IssueTicketMessage | |||
379 | /** | 379 | /** |
380 | * Identity. | 380 | * Identity. |
381 | */ | 381 | */ |
382 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 382 | struct GNUNET_IDENTITY_PrivateKey identity; |
383 | 383 | ||
384 | /** | 384 | /** |
385 | * Requesting party. | 385 | * Requesting party. |
386 | */ | 386 | */ |
387 | struct GNUNET_CRYPTO_EcdsaPublicKey rp; | 387 | struct GNUNET_IDENTITY_PublicKey rp; |
388 | 388 | ||
389 | /** | 389 | /** |
390 | * length of serialized attribute list | 390 | * length of serialized attribute list |
@@ -412,7 +412,7 @@ struct RevokeTicketMessage | |||
412 | /** | 412 | /** |
413 | * Identity. | 413 | * Identity. |
414 | */ | 414 | */ |
415 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 415 | struct GNUNET_IDENTITY_PrivateKey identity; |
416 | 416 | ||
417 | /** | 417 | /** |
418 | * length of serialized attribute list | 418 | * length of serialized attribute list |
@@ -493,7 +493,7 @@ struct ConsumeTicketMessage | |||
493 | /** | 493 | /** |
494 | * Identity. | 494 | * Identity. |
495 | */ | 495 | */ |
496 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 496 | struct GNUNET_IDENTITY_PrivateKey identity; |
497 | 497 | ||
498 | /** | 498 | /** |
499 | * The ticket to consume | 499 | * The ticket to consume |
@@ -539,7 +539,7 @@ struct ConsumeTicketResultMessage | |||
539 | /** | 539 | /** |
540 | * The public key of the identity. | 540 | * The public key of the identity. |
541 | */ | 541 | */ |
542 | struct GNUNET_CRYPTO_EcdsaPublicKey identity; | 542 | struct GNUNET_IDENTITY_PublicKey identity; |
543 | 543 | ||
544 | /* followed by: | 544 | /* followed by: |
545 | * serialized attributes data | 545 | * serialized attributes data |
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 1e0251519..f4f2b946a 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -235,7 +235,7 @@ struct GNUNET_RECLAIM_AttributeIterator | |||
235 | /** | 235 | /** |
236 | * Private key of the zone. | 236 | * Private key of the zone. |
237 | */ | 237 | */ |
238 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 238 | struct GNUNET_IDENTITY_PrivateKey identity; |
239 | 239 | ||
240 | /** | 240 | /** |
241 | * The operation id this zone iteration operation has | 241 | * The operation id this zone iteration operation has |
@@ -302,7 +302,7 @@ struct GNUNET_RECLAIM_CredentialIterator | |||
302 | /** | 302 | /** |
303 | * Private key of the zone. | 303 | * Private key of the zone. |
304 | */ | 304 | */ |
305 | struct GNUNET_CRYPTO_EcdsaPrivateKey identity; | 305 | struct GNUNET_IDENTITY_PrivateKey identity; |
306 | 306 | ||
307 | /** | 307 | /** |
308 | * The operation id this zone iteration operation has | 308 | * The operation id this zone iteration operation has |
@@ -704,7 +704,7 @@ check_attribute_result (void *cls, const struct AttributeResultMessage *msg) | |||
704 | static void | 704 | static void |
705 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) | 705 | handle_attribute_result (void *cls, const struct AttributeResultMessage *msg) |
706 | { | 706 | { |
707 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; | 707 | static struct GNUNET_IDENTITY_PrivateKey identity_dummy; |
708 | struct GNUNET_RECLAIM_Handle *h = cls; | 708 | struct GNUNET_RECLAIM_Handle *h = cls; |
709 | struct GNUNET_RECLAIM_AttributeIterator *it; | 709 | struct GNUNET_RECLAIM_AttributeIterator *it; |
710 | struct GNUNET_RECLAIM_Operation *op; | 710 | struct GNUNET_RECLAIM_Operation *op; |
@@ -806,7 +806,7 @@ static void | |||
806 | handle_credential_result (void *cls, const struct | 806 | handle_credential_result (void *cls, const struct |
807 | CredentialResultMessage *msg) | 807 | CredentialResultMessage *msg) |
808 | { | 808 | { |
809 | static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy; | 809 | static struct GNUNET_IDENTITY_PrivateKey identity_dummy; |
810 | struct GNUNET_RECLAIM_Handle *h = cls; | 810 | struct GNUNET_RECLAIM_Handle *h = cls; |
811 | struct GNUNET_RECLAIM_CredentialIterator *it; | 811 | struct GNUNET_RECLAIM_CredentialIterator *it; |
812 | struct GNUNET_RECLAIM_Operation *op; | 812 | struct GNUNET_RECLAIM_Operation *op; |
@@ -1134,7 +1134,7 @@ GNUNET_RECLAIM_disconnect (struct GNUNET_RECLAIM_Handle *h) | |||
1134 | struct GNUNET_RECLAIM_Operation * | 1134 | struct GNUNET_RECLAIM_Operation * |
1135 | GNUNET_RECLAIM_attribute_store ( | 1135 | GNUNET_RECLAIM_attribute_store ( |
1136 | struct GNUNET_RECLAIM_Handle *h, | 1136 | struct GNUNET_RECLAIM_Handle *h, |
1137 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1137 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1138 | const struct GNUNET_RECLAIM_Attribute *attr, | 1138 | const struct GNUNET_RECLAIM_Attribute *attr, |
1139 | const struct GNUNET_TIME_Relative *exp_interval, | 1139 | const struct GNUNET_TIME_Relative *exp_interval, |
1140 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 1140 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
@@ -1181,7 +1181,7 @@ GNUNET_RECLAIM_attribute_store ( | |||
1181 | struct GNUNET_RECLAIM_Operation * | 1181 | struct GNUNET_RECLAIM_Operation * |
1182 | GNUNET_RECLAIM_attribute_delete ( | 1182 | GNUNET_RECLAIM_attribute_delete ( |
1183 | struct GNUNET_RECLAIM_Handle *h, | 1183 | struct GNUNET_RECLAIM_Handle *h, |
1184 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1184 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1185 | const struct GNUNET_RECLAIM_Attribute *attr, | 1185 | const struct GNUNET_RECLAIM_Attribute *attr, |
1186 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 1186 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
1187 | void *cont_cls) | 1187 | void *cont_cls) |
@@ -1226,7 +1226,7 @@ GNUNET_RECLAIM_attribute_delete ( | |||
1226 | struct GNUNET_RECLAIM_Operation * | 1226 | struct GNUNET_RECLAIM_Operation * |
1227 | GNUNET_RECLAIM_credential_store ( | 1227 | GNUNET_RECLAIM_credential_store ( |
1228 | struct GNUNET_RECLAIM_Handle *h, | 1228 | struct GNUNET_RECLAIM_Handle *h, |
1229 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1229 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1230 | const struct GNUNET_RECLAIM_Credential *attr, | 1230 | const struct GNUNET_RECLAIM_Credential *attr, |
1231 | const struct GNUNET_TIME_Relative *exp_interval, | 1231 | const struct GNUNET_TIME_Relative *exp_interval, |
1232 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 1232 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
@@ -1273,7 +1273,7 @@ GNUNET_RECLAIM_credential_store ( | |||
1273 | struct GNUNET_RECLAIM_Operation * | 1273 | struct GNUNET_RECLAIM_Operation * |
1274 | GNUNET_RECLAIM_credential_delete ( | 1274 | GNUNET_RECLAIM_credential_delete ( |
1275 | struct GNUNET_RECLAIM_Handle *h, | 1275 | struct GNUNET_RECLAIM_Handle *h, |
1276 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1276 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1277 | const struct GNUNET_RECLAIM_Credential *attr, | 1277 | const struct GNUNET_RECLAIM_Credential *attr, |
1278 | GNUNET_RECLAIM_ContinuationWithStatus cont, | 1278 | GNUNET_RECLAIM_ContinuationWithStatus cont, |
1279 | void *cont_cls) | 1279 | void *cont_cls) |
@@ -1330,7 +1330,7 @@ GNUNET_RECLAIM_credential_delete ( | |||
1330 | struct GNUNET_RECLAIM_AttributeIterator * | 1330 | struct GNUNET_RECLAIM_AttributeIterator * |
1331 | GNUNET_RECLAIM_get_attributes_start ( | 1331 | GNUNET_RECLAIM_get_attributes_start ( |
1332 | struct GNUNET_RECLAIM_Handle *h, | 1332 | struct GNUNET_RECLAIM_Handle *h, |
1333 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1333 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1334 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1334 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1335 | void *error_cb_cls, | 1335 | void *error_cb_cls, |
1336 | GNUNET_RECLAIM_AttributeResult proc, | 1336 | GNUNET_RECLAIM_AttributeResult proc, |
@@ -1439,7 +1439,7 @@ GNUNET_RECLAIM_get_attributes_stop (struct GNUNET_RECLAIM_AttributeIterator *it) | |||
1439 | struct GNUNET_RECLAIM_CredentialIterator * | 1439 | struct GNUNET_RECLAIM_CredentialIterator * |
1440 | GNUNET_RECLAIM_get_credentials_start ( | 1440 | GNUNET_RECLAIM_get_credentials_start ( |
1441 | struct GNUNET_RECLAIM_Handle *h, | 1441 | struct GNUNET_RECLAIM_Handle *h, |
1442 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1442 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1443 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1443 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1444 | void *error_cb_cls, | 1444 | void *error_cb_cls, |
1445 | GNUNET_RECLAIM_CredentialResult proc, | 1445 | GNUNET_RECLAIM_CredentialResult proc, |
@@ -1541,8 +1541,8 @@ GNUNET_RECLAIM_get_credentials_stop (struct | |||
1541 | struct GNUNET_RECLAIM_Operation * | 1541 | struct GNUNET_RECLAIM_Operation * |
1542 | GNUNET_RECLAIM_ticket_issue ( | 1542 | GNUNET_RECLAIM_ticket_issue ( |
1543 | struct GNUNET_RECLAIM_Handle *h, | 1543 | struct GNUNET_RECLAIM_Handle *h, |
1544 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *iss, | 1544 | const struct GNUNET_IDENTITY_PrivateKey *iss, |
1545 | const struct GNUNET_CRYPTO_EcdsaPublicKey *rp, | 1545 | const struct GNUNET_IDENTITY_PublicKey *rp, |
1546 | const struct GNUNET_RECLAIM_AttributeList *attrs, | 1546 | const struct GNUNET_RECLAIM_AttributeList *attrs, |
1547 | GNUNET_RECLAIM_IssueTicketCallback cb, | 1547 | GNUNET_RECLAIM_IssueTicketCallback cb, |
1548 | void *cb_cls) | 1548 | void *cb_cls) |
@@ -1590,7 +1590,7 @@ GNUNET_RECLAIM_ticket_issue ( | |||
1590 | struct GNUNET_RECLAIM_Operation * | 1590 | struct GNUNET_RECLAIM_Operation * |
1591 | GNUNET_RECLAIM_ticket_consume ( | 1591 | GNUNET_RECLAIM_ticket_consume ( |
1592 | struct GNUNET_RECLAIM_Handle *h, | 1592 | struct GNUNET_RECLAIM_Handle *h, |
1593 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1593 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1594 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1594 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1595 | GNUNET_RECLAIM_AttributeTicketResult cb, | 1595 | GNUNET_RECLAIM_AttributeTicketResult cb, |
1596 | void *cb_cls) | 1596 | void *cb_cls) |
@@ -1636,7 +1636,7 @@ GNUNET_RECLAIM_ticket_consume ( | |||
1636 | struct GNUNET_RECLAIM_TicketIterator * | 1636 | struct GNUNET_RECLAIM_TicketIterator * |
1637 | GNUNET_RECLAIM_ticket_iteration_start ( | 1637 | GNUNET_RECLAIM_ticket_iteration_start ( |
1638 | struct GNUNET_RECLAIM_Handle *h, | 1638 | struct GNUNET_RECLAIM_Handle *h, |
1639 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1639 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1640 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1640 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1641 | void *error_cb_cls, | 1641 | void *error_cb_cls, |
1642 | GNUNET_RECLAIM_TicketCallback proc, | 1642 | GNUNET_RECLAIM_TicketCallback proc, |
@@ -1731,7 +1731,7 @@ GNUNET_RECLAIM_ticket_iteration_stop (struct GNUNET_RECLAIM_TicketIterator *it) | |||
1731 | struct GNUNET_RECLAIM_Operation * | 1731 | struct GNUNET_RECLAIM_Operation * |
1732 | GNUNET_RECLAIM_ticket_revoke ( | 1732 | GNUNET_RECLAIM_ticket_revoke ( |
1733 | struct GNUNET_RECLAIM_Handle *h, | 1733 | struct GNUNET_RECLAIM_Handle *h, |
1734 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1734 | const struct GNUNET_IDENTITY_PrivateKey *identity, |
1735 | const struct GNUNET_RECLAIM_Ticket *ticket, | 1735 | const struct GNUNET_RECLAIM_Ticket *ticket, |
1736 | GNUNET_RECLAIM_ContinuationWithStatus cb, | 1736 | GNUNET_RECLAIM_ContinuationWithStatus cb, |
1737 | void *cb_cls) | 1737 | void *cb_cls) |
diff --git a/src/reclaim/test_reclaim_attribute.c b/src/reclaim/test_reclaim_attribute.c index f71d86b56..f8faf8021 100644 --- a/src/reclaim/test_reclaim_attribute.c +++ b/src/reclaim/test_reclaim_attribute.c | |||
@@ -9,12 +9,10 @@ main (int argc, char *argv[]) | |||
9 | struct GNUNET_RECLAIM_AttributeList *al; | 9 | struct GNUNET_RECLAIM_AttributeList *al; |
10 | struct GNUNET_RECLAIM_AttributeList *al_two; | 10 | struct GNUNET_RECLAIM_AttributeList *al_two; |
11 | struct GNUNET_RECLAIM_AttributeListEntry *ale; | 11 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
12 | struct GNUNET_RECLAIM_Attribute *attr; | ||
13 | char attrname[100]; | 12 | char attrname[100]; |
14 | char attrdata[100]; | 13 | char attrdata[100]; |
15 | size_t ser_len_claimed; | 14 | size_t ser_len_claimed; |
16 | size_t ser_len_actual; | 15 | size_t ser_len_actual; |
17 | ssize_t deser_len; | ||
18 | char *ser_data; | 16 | char *ser_data; |
19 | int count = 0; | 17 | int count = 0; |
20 | 18 | ||
diff --git a/src/regex/regex_block_lib.c b/src/regex/regex_block_lib.c index a309c2305..159e8bf8a 100644 --- a/src/regex/regex_block_lib.c +++ b/src/regex/regex_block_lib.c | |||
@@ -352,14 +352,14 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block, | |||
352 | } | 352 | } |
353 | off = len; | 353 | off = len; |
354 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 354 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
355 | "Start iterating block of size %u, proof %u, off %u edges %u\n", | 355 | "Start iterating block of size %lu, proof %u, off %lu edges %u\n", |
356 | size, len, off, n); | 356 | (unsigned long) size, len, (unsigned long) off, n); |
357 | /* &aux[off] always points to our token */ | 357 | /* &aux[off] always points to our token */ |
358 | for (n = 0; n < num_edges; n++) | 358 | for (n = 0; n < num_edges; n++) |
359 | { | 359 | { |
360 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 360 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
361 | "Edge %u/%u, off %u tokenlen %u (%.*s)\n", | 361 | "Edge %u/%u, off %lu tokenlen %u (%.*s)\n", |
362 | n + 1, num_edges, off, | 362 | n + 1, num_edges, (unsigned long) off, |
363 | ntohs (edges[n].token_length), ntohs (edges[n].token_length), | 363 | ntohs (edges[n].token_length), ntohs (edges[n].token_length), |
364 | &aux[off]); | 364 | &aux[off]); |
365 | if (NULL != iterator) | 365 | if (NULL != iterator) |
diff --git a/src/regex/regex_internal_dht.c b/src/regex/regex_internal_dht.c index d2c69f131..39d7cd847 100644 --- a/src/regex/regex_internal_dht.c +++ b/src/regex/regex_internal_dht.c | |||
@@ -427,8 +427,7 @@ regex_find_path (const struct GNUNET_HashCode *key, | |||
427 | 427 | ||
428 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 428 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
429 | "Accept state found, now searching for paths to %s\n", | 429 | "Accept state found, now searching for paths to %s\n", |
430 | GNUNET_h2s (key), | 430 | GNUNET_h2s (key)); |
431 | (unsigned int) ctx->position); | ||
432 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ | 431 | get_h = GNUNET_DHT_get_start (ctx->info->dht, /* handle */ |
433 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ | 432 | GNUNET_BLOCK_TYPE_REGEX_ACCEPT, /* type */ |
434 | key, /* key to search */ | 433 | key, /* key to search */ |
@@ -534,8 +533,8 @@ regex_result_iterator (void *cls, | |||
534 | return GNUNET_YES; // We found an accept state! | 533 | return GNUNET_YES; // We found an accept state! |
535 | } | 534 | } |
536 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 535 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
537 | "* %u, %u, [%u]\n", | 536 | "* %lu, %lu, [%u]\n", |
538 | ctx->position, | 537 | (unsigned long) ctx->position, |
539 | strlen (ctx->info->description), | 538 | strlen (ctx->info->description), |
540 | GNUNET_BLOCK_is_accepting (block, result->size)); | 539 | GNUNET_BLOCK_is_accepting (block, result->size)); |
541 | regex_next_edge (block, result->size, ctx); | 540 | regex_next_edge (block, result->size, ctx); |
@@ -729,7 +728,7 @@ REGEX_INTERNAL_search (struct GNUNET_DHT_Handle *dht, | |||
729 | "Initial key for `%s' is %s (based on `%.*s')\n", | 728 | "Initial key for `%s' is %s (based on `%.*s')\n", |
730 | string, | 729 | string, |
731 | GNUNET_h2s (&key), | 730 | GNUNET_h2s (&key), |
732 | size, | 731 | (int) size, |
733 | string); | 732 | string); |
734 | ctx = GNUNET_new (struct RegexSearchContext); | 733 | ctx = GNUNET_new (struct RegexSearchContext); |
735 | ctx->position = size; | 734 | ctx->position = size; |
diff --git a/src/regex/regex_test_graph.c b/src/regex/regex_test_graph.c index 8e1e00fd4..c8efae772 100644 --- a/src/regex/regex_test_graph.c +++ b/src/regex/regex_test_graph.c | |||
@@ -177,8 +177,7 @@ REGEX_TEST_automaton_save_graph_step (void *cls, unsigned int count, | |||
177 | } | 177 | } |
178 | else | 178 | else |
179 | { | 179 | { |
180 | GNUNET_asprintf (&s_acc, "\"%s\" [shape=doublecircle];\n", name, | 180 | GNUNET_asprintf (&s_acc, "\"%s\" [shape=doublecircle];\n", name); |
181 | s->scc_id); | ||
182 | } | 181 | } |
183 | } | 182 | } |
184 | else if (GNUNET_YES == ctx->coloring) | 183 | else if (GNUNET_YES == ctx->coloring) |
@@ -189,7 +188,7 @@ REGEX_TEST_automaton_save_graph_step (void *cls, unsigned int count, | |||
189 | } | 188 | } |
190 | else | 189 | else |
191 | { | 190 | { |
192 | GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle];\n", name, s->scc_id); | 191 | GNUNET_asprintf (&s_acc, "\"%s\" [shape=circle];\n", name); |
193 | } | 192 | } |
194 | 193 | ||
195 | GNUNET_assert (NULL != s_acc); | 194 | GNUNET_assert (NULL != s_acc); |
@@ -228,7 +227,7 @@ REGEX_TEST_automaton_save_graph_step (void *cls, unsigned int count, | |||
228 | else | 227 | else |
229 | { | 228 | { |
230 | GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"ε\"];\n", name, | 229 | GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"ε\"];\n", name, |
231 | to_name, s->scc_id); | 230 | to_name); |
232 | } | 231 | } |
233 | } | 232 | } |
234 | else | 233 | else |
@@ -242,7 +241,7 @@ REGEX_TEST_automaton_save_graph_step (void *cls, unsigned int count, | |||
242 | else | 241 | else |
243 | { | 242 | { |
244 | GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"%s\"];\n", name, | 243 | GNUNET_asprintf (&s_tran, "\"%s\" -> \"%s\" [label = \"%s\"];\n", name, |
245 | to_name, ctran->label, s->scc_id); | 244 | to_name, ctran->label); |
246 | } | 245 | } |
247 | } | 246 | } |
248 | 247 | ||
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am index 9d98502a6..b1a079a0d 100644 --- a/src/revocation/Makefile.am +++ b/src/revocation/Makefile.am | |||
@@ -30,6 +30,7 @@ libgnunet_plugin_block_revocation_la_LIBADD = \ | |||
30 | $(top_builddir)/src/block/libgnunetblockgroup.la \ | 30 | $(top_builddir)/src/block/libgnunetblockgroup.la \ |
31 | $(top_builddir)/src/block/libgnunetblock.la \ | 31 | $(top_builddir)/src/block/libgnunetblock.la \ |
32 | $(top_builddir)/src/util/libgnunetutil.la \ | 32 | $(top_builddir)/src/util/libgnunetutil.la \ |
33 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
33 | $(LTLIBINTL) | 34 | $(LTLIBINTL) |
34 | libgnunet_plugin_block_revocation_la_DEPENDENCIES = \ | 35 | libgnunet_plugin_block_revocation_la_DEPENDENCIES = \ |
35 | libgnunetrevocation.la \ | 36 | libgnunetrevocation.la \ |
@@ -63,6 +64,7 @@ libgnunetrevocation_la_SOURCES = \ | |||
63 | revocation_api.c revocation.h | 64 | revocation_api.c revocation.h |
64 | libgnunetrevocation_la_LIBADD = \ | 65 | libgnunetrevocation_la_LIBADD = \ |
65 | $(top_builddir)/src/util/libgnunetutil.la \ | 66 | $(top_builddir)/src/util/libgnunetutil.la \ |
67 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
66 | $(LIBGCRYPT_LIBS) \ | 68 | $(LIBGCRYPT_LIBS) \ |
67 | $(GN_LIBINTL) $(XLIB) -lgcrypt | 69 | $(GN_LIBINTL) $(XLIB) -lgcrypt |
68 | libgnunetrevocation_la_LDFLAGS = \ | 70 | libgnunetrevocation_la_LDFLAGS = \ |
@@ -80,6 +82,7 @@ gnunet_service_revocation_LDADD = \ | |||
80 | $(top_builddir)/src/core/libgnunetcore.la \ | 82 | $(top_builddir)/src/core/libgnunetcore.la \ |
81 | $(top_builddir)/src/setu/libgnunetsetu.la \ | 83 | $(top_builddir)/src/setu/libgnunetsetu.la \ |
82 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 84 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
85 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
83 | $(top_builddir)/src/util/libgnunetutil.la \ | 86 | $(top_builddir)/src/util/libgnunetutil.la \ |
84 | -lm \ | 87 | -lm \ |
85 | $(GN_LIBINTL) | 88 | $(GN_LIBINTL) |
diff --git a/src/revocation/gnunet-revocation-tvg.c b/src/revocation/gnunet-revocation-tvg.c index 29df1bb4d..cb5e31fcd 100644 --- a/src/revocation/gnunet-revocation-tvg.c +++ b/src/revocation/gnunet-revocation-tvg.c | |||
@@ -65,25 +65,34 @@ run (void *cls, | |||
65 | const char *cfgfile, | 65 | const char *cfgfile, |
66 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 66 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
67 | { | 67 | { |
68 | struct GNUNET_CRYPTO_EcdsaPrivateKey id_priv; | 68 | struct GNUNET_IDENTITY_PrivateKey id_priv; |
69 | struct GNUNET_CRYPTO_EcdsaPublicKey id_pub; | 69 | struct GNUNET_IDENTITY_PublicKey id_pub; |
70 | struct GNUNET_REVOCATION_PowP pow; | 70 | struct GNUNET_REVOCATION_PowP *pow; |
71 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; | 71 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
72 | struct GNUNET_TIME_Relative exp; | 72 | struct GNUNET_TIME_Relative exp; |
73 | 73 | char ztld[128]; | |
74 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv); | 74 | |
75 | GNUNET_CRYPTO_ecdsa_key_get_public (&id_priv, | 75 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
76 | &id_pub); | 76 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
77 | fprintf (stdout, "Zone private key (d, little-endian scalar):\n"); | 77 | GNUNET_IDENTITY_key_get_public (&id_priv, |
78 | print_bytes (&id_priv, sizeof(id_priv), 0); | 78 | &id_pub); |
79 | GNUNET_STRINGS_data_to_string (&id_pub, | ||
80 | GNUNET_IDENTITY_key_get_length (&id_pub), | ||
81 | ztld, | ||
82 | sizeof (ztld)); | ||
83 | fprintf (stdout, "Zone private key (d, little-endian scalar, with ztype prepended):\n"); | ||
84 | print_bytes (&id_priv, sizeof(id_priv), 8); | ||
85 | fprintf (stdout, "\n"); | ||
86 | fprintf (stdout, "Zone identifier (zid):\n"); | ||
87 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | ||
79 | fprintf (stdout, "\n"); | 88 | fprintf (stdout, "\n"); |
80 | fprintf (stdout, "Zone public key (zk):\n"); | 89 | fprintf (stdout, "Encoded zone identifier (zkl = zTLD):\n"); |
81 | print_bytes (&id_pub, sizeof(id_pub), 0); | 90 | fprintf (stdout, "%s\n", ztld); |
82 | fprintf (stdout, "\n"); | 91 | fprintf (stdout, "\n"); |
83 | memset (&pow, 0, sizeof (pow)); | 92 | pow = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
84 | GNUNET_REVOCATION_pow_init (&id_priv, | 93 | GNUNET_REVOCATION_pow_init (&id_priv, |
85 | &pow); | 94 | pow); |
86 | ph = GNUNET_REVOCATION_pow_start (&pow, | 95 | ph = GNUNET_REVOCATION_pow_start (pow, |
87 | TEST_EPOCHS, | 96 | TEST_EPOCHS, |
88 | TEST_DIFFICULTY); | 97 | TEST_DIFFICULTY); |
89 | fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n", | 98 | fprintf (stdout, "Difficulty (%d base difficulty + %d epochs): %d\n\n", |
@@ -97,12 +106,12 @@ run (void *cls, | |||
97 | } | 106 | } |
98 | exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 107 | exp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, |
99 | TEST_EPOCHS); | 108 | TEST_EPOCHS); |
100 | GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (&pow, | 109 | GNUNET_assert (GNUNET_OK == GNUNET_REVOCATION_check_pow (pow, |
101 | TEST_DIFFICULTY, | 110 | TEST_DIFFICULTY, |
102 | exp)); | 111 | exp)); |
103 | fprintf (stdout, "Proof:\n"); | 112 | fprintf (stdout, "Proof:\n"); |
104 | print_bytes (&pow, | 113 | print_bytes (pow, |
105 | sizeof (pow), | 114 | GNUNET_REVOCATION_proof_get_size (pow), |
106 | 8); | 115 | 8); |
107 | } | 116 | } |
108 | 117 | ||
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index 0e1e482ab..d59ea7c81 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c | |||
@@ -101,7 +101,7 @@ static struct GNUNET_SCHEDULER_Task *pow_task; | |||
101 | /** | 101 | /** |
102 | * Proof-of-work object | 102 | * Proof-of-work object |
103 | */ | 103 | */ |
104 | static struct GNUNET_REVOCATION_PowP proof_of_work; | 104 | static struct GNUNET_REVOCATION_PowP *proof_of_work; |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Function run if the user aborts with CTRL-C. | 107 | * Function run if the user aborts with CTRL-C. |
@@ -213,7 +213,7 @@ static void | |||
213 | perform_revocation () | 213 | perform_revocation () |
214 | { | 214 | { |
215 | h = GNUNET_REVOCATION_revoke (cfg, | 215 | h = GNUNET_REVOCATION_revoke (cfg, |
216 | &proof_of_work, | 216 | proof_of_work, |
217 | &print_revocation_result, | 217 | &print_revocation_result, |
218 | NULL); | 218 | NULL); |
219 | } | 219 | } |
@@ -228,11 +228,12 @@ perform_revocation () | |||
228 | static void | 228 | static void |
229 | sync_pow () | 229 | sync_pow () |
230 | { | 230 | { |
231 | size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
231 | if ((NULL != filename) && | 232 | if ((NULL != filename) && |
232 | (sizeof(struct GNUNET_REVOCATION_PowP) != | 233 | (psize != |
233 | GNUNET_DISK_fn_write (filename, | 234 | GNUNET_DISK_fn_write (filename, |
234 | &proof_of_work, | 235 | proof_of_work, |
235 | sizeof(struct GNUNET_REVOCATION_PowP), | 236 | psize, |
236 | GNUNET_DISK_PERM_USER_READ | 237 | GNUNET_DISK_PERM_USER_READ |
237 | | GNUNET_DISK_PERM_USER_WRITE))) | 238 | | GNUNET_DISK_PERM_USER_WRITE))) |
238 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 239 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -269,6 +270,7 @@ static void | |||
269 | calculate_pow (void *cls) | 270 | calculate_pow (void *cls) |
270 | { | 271 | { |
271 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; | 272 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; |
273 | size_t psize; | ||
272 | 274 | ||
273 | /* store temporary results */ | 275 | /* store temporary results */ |
274 | pow_task = NULL; | 276 | pow_task = NULL; |
@@ -277,11 +279,12 @@ calculate_pow (void *cls) | |||
277 | /* actually do POW calculation */ | 279 | /* actually do POW calculation */ |
278 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) | 280 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) |
279 | { | 281 | { |
282 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
280 | if ((NULL != filename) && | 283 | if ((NULL != filename) && |
281 | (sizeof(struct GNUNET_REVOCATION_PowP) != | 284 | (psize != |
282 | GNUNET_DISK_fn_write (filename, | 285 | GNUNET_DISK_fn_write (filename, |
283 | &proof_of_work, | 286 | proof_of_work, |
284 | sizeof(struct GNUNET_REVOCATION_PowP), | 287 | psize, |
285 | GNUNET_DISK_PERM_USER_READ | 288 | GNUNET_DISK_PERM_USER_READ |
286 | | GNUNET_DISK_PERM_USER_WRITE))) | 289 | | GNUNET_DISK_PERM_USER_WRITE))) |
287 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 290 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); |
@@ -325,9 +328,10 @@ calculate_pow (void *cls) | |||
325 | static void | 328 | static void |
326 | ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 329 | ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
327 | { | 330 | { |
328 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 331 | struct GNUNET_IDENTITY_PublicKey key; |
329 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 332 | const struct GNUNET_IDENTITY_PrivateKey *privkey; |
330 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; | 333 | struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; |
334 | size_t psize; | ||
331 | 335 | ||
332 | el = NULL; | 336 | el = NULL; |
333 | if (NULL == ego) | 337 | if (NULL == ego) |
@@ -338,12 +342,15 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
338 | } | 342 | } |
339 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); | 343 | GNUNET_IDENTITY_ego_get_public_key (ego, &key); |
340 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 344 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
341 | memset (&proof_of_work, 0, sizeof (proof_of_work)); | 345 | proof_of_work = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
342 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && | 346 | if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && |
343 | (sizeof(proof_of_work) == | 347 | (0 < (psize = |
344 | GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work)))) | 348 | GNUNET_DISK_fn_read (filename, proof_of_work, |
349 | GNUNET_REVOCATION_MAX_PROOF_SIZE)))) | ||
345 | { | 350 | { |
346 | if (0 != GNUNET_memcmp (&proof_of_work.key, &key)) | 351 | size_t ksize = GNUNET_IDENTITY_key_get_length (&key); |
352 | if (((psize - sizeof (*proof_of_work)) < ksize) || // Key too small | ||
353 | (0 != memcmp (&proof_of_work[1], &key, ksize))) // Keys do not match | ||
347 | { | 354 | { |
348 | fprintf (stderr, | 355 | fprintf (stderr, |
349 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), | 356 | _ ("Error: revocation certificate in `%s' is not for `%s'\n"), |
@@ -352,7 +359,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
352 | return; | 359 | return; |
353 | } | 360 | } |
354 | if (GNUNET_YES == | 361 | if (GNUNET_YES == |
355 | GNUNET_REVOCATION_check_pow (&proof_of_work, | 362 | GNUNET_REVOCATION_check_pow (proof_of_work, |
356 | (unsigned int) matching_bits, | 363 | (unsigned int) matching_bits, |
357 | epoch_duration)) | 364 | epoch_duration)) |
358 | { | 365 | { |
@@ -369,7 +376,7 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
369 | fprintf (stderr, | 376 | fprintf (stderr, |
370 | "%s", | 377 | "%s", |
371 | _ ("Continuing calculation where left off...\n")); | 378 | _ ("Continuing calculation where left off...\n")); |
372 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 379 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
373 | epochs, | 380 | epochs, |
374 | matching_bits); | 381 | matching_bits); |
375 | } | 382 | } |
@@ -379,8 +386,8 @@ ego_callback (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
379 | if (NULL == ph) | 386 | if (NULL == ph) |
380 | { | 387 | { |
381 | GNUNET_REVOCATION_pow_init (privkey, | 388 | GNUNET_REVOCATION_pow_init (privkey, |
382 | &proof_of_work); | 389 | proof_of_work); |
383 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 390 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
384 | epochs, /* Epochs */ | 391 | epochs, /* Epochs */ |
385 | matching_bits); | 392 | matching_bits); |
386 | } | 393 | } |
@@ -403,15 +410,15 @@ run (void *cls, | |||
403 | const char *cfgfile, | 410 | const char *cfgfile, |
404 | const struct GNUNET_CONFIGURATION_Handle *c) | 411 | const struct GNUNET_CONFIGURATION_Handle *c) |
405 | { | 412 | { |
406 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 413 | struct GNUNET_IDENTITY_PublicKey pk; |
414 | size_t psize; | ||
407 | 415 | ||
408 | cfg = c; | 416 | cfg = c; |
409 | if (NULL != test_ego) | 417 | if (NULL != test_ego) |
410 | { | 418 | { |
411 | if (GNUNET_OK != | 419 | if (GNUNET_OK != |
412 | GNUNET_CRYPTO_ecdsa_public_key_from_string (test_ego, | 420 | GNUNET_IDENTITY_public_key_from_string (test_ego, |
413 | strlen (test_ego), | 421 | &pk)) |
414 | &pk)) | ||
415 | { | 422 | { |
416 | fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego); | 423 | fprintf (stderr, _ ("Public key `%s' malformed\n"), test_ego); |
417 | return; | 424 | return; |
@@ -463,23 +470,33 @@ run (void *cls, | |||
463 | } | 470 | } |
464 | if ((NULL != filename) && (perform)) | 471 | if ((NULL != filename) && (perform)) |
465 | { | 472 | { |
466 | if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename, | 473 | size_t bread; |
467 | &proof_of_work, | 474 | proof_of_work = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
468 | sizeof(proof_of_work))) | 475 | if (0 < (bread = GNUNET_DISK_fn_read (filename, |
476 | proof_of_work, | ||
477 | GNUNET_REVOCATION_MAX_PROOF_SIZE))) | ||
469 | { | 478 | { |
470 | fprintf (stderr, | 479 | fprintf (stderr, |
471 | _ ("Failed to read revocation certificate from `%s'\n"), | 480 | _ ("Failed to read revocation certificate from `%s'\n"), |
472 | filename); | 481 | filename); |
473 | return; | 482 | return; |
474 | } | 483 | } |
484 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | ||
485 | if (bread != psize) | ||
486 | { | ||
487 | fprintf (stderr, | ||
488 | _ ("Revocation certificate corrupted in `%s'\n"), | ||
489 | filename); | ||
490 | return; | ||
491 | } | ||
475 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 492 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
476 | if (GNUNET_YES != | 493 | if (GNUNET_YES != |
477 | GNUNET_REVOCATION_check_pow (&proof_of_work, | 494 | GNUNET_REVOCATION_check_pow (proof_of_work, |
478 | (unsigned int) matching_bits, | 495 | (unsigned int) matching_bits, |
479 | epoch_duration)) | 496 | epoch_duration)) |
480 | { | 497 | { |
481 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; | 498 | struct GNUNET_REVOCATION_PowCalculationHandle *ph; |
482 | ph = GNUNET_REVOCATION_pow_start (&proof_of_work, | 499 | ph = GNUNET_REVOCATION_pow_start (proof_of_work, |
483 | epochs, /* Epochs */ | 500 | epochs, /* Epochs */ |
484 | matching_bits); | 501 | matching_bits); |
485 | 502 | ||
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c index ddebb38ad..0fa92f4a6 100644 --- a/src/revocation/gnunet-service-revocation.c +++ b/src/revocation/gnunet-service-revocation.c | |||
@@ -172,7 +172,8 @@ new_peer_entry (const struct GNUNET_PeerIdentity *peer) | |||
172 | static int | 172 | static int |
173 | verify_revoke_message (const struct RevokeMessage *rm) | 173 | verify_revoke_message (const struct RevokeMessage *rm) |
174 | { | 174 | { |
175 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (&rm->proof_of_work, | 175 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; |
176 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, | ||
176 | (unsigned | 177 | (unsigned |
177 | int) revocation_work_required, | 178 | int) revocation_work_required, |
178 | epoch_duration)) | 179 | epoch_duration)) |
@@ -236,7 +237,7 @@ handle_query_message (void *cls, | |||
236 | int res; | 237 | int res; |
237 | 238 | ||
238 | GNUNET_CRYPTO_hash (&qm->key, | 239 | GNUNET_CRYPTO_hash (&qm->key, |
239 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 240 | sizeof(struct GNUNET_IDENTITY_PublicKey), |
240 | &hc); | 241 | &hc); |
241 | res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, | 242 | res = GNUNET_CONTAINER_multihashmap_contains (revocation_map, |
242 | &hc); | 243 | &hc); |
@@ -276,9 +277,11 @@ do_flood (void *cls, | |||
276 | return GNUNET_OK; /* peer connected to us via SET, | 277 | return GNUNET_OK; /* peer connected to us via SET, |
277 | but we have no direct CORE | 278 | but we have no direct CORE |
278 | connection for flooding */ | 279 | connection for flooding */ |
279 | e = GNUNET_MQ_msg (cp, | 280 | e = GNUNET_MQ_msg_extra (cp, |
281 | htonl (rm->pow_size), | ||
280 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 282 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
281 | *cp = *rm; | 283 | *cp = *rm; |
284 | memcpy (&cp[1], &rm[1], htonl (rm->pow_size)); | ||
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
283 | "Flooding revocation to `%s'\n", | 286 | "Flooding revocation to `%s'\n", |
284 | GNUNET_i2s (target)); | 287 | GNUNET_i2s (target)); |
@@ -303,9 +306,12 @@ publicize_rm (const struct RevokeMessage *rm) | |||
303 | struct RevokeMessage *cp; | 306 | struct RevokeMessage *cp; |
304 | struct GNUNET_HashCode hc; | 307 | struct GNUNET_HashCode hc; |
305 | struct GNUNET_SETU_Element e; | 308 | struct GNUNET_SETU_Element e; |
309 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
306 | 310 | ||
307 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, | 311 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; |
308 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 312 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
313 | GNUNET_CRYPTO_hash (pk, | ||
314 | GNUNET_IDENTITY_key_get_length (pk), | ||
309 | &hc); | 315 | &hc); |
310 | if (GNUNET_YES == | 316 | if (GNUNET_YES == |
311 | GNUNET_CONTAINER_multihashmap_contains (revocation_map, | 317 | GNUNET_CONTAINER_multihashmap_contains (revocation_map, |
@@ -371,6 +377,23 @@ publicize_rm (const struct RevokeMessage *rm) | |||
371 | } | 377 | } |
372 | 378 | ||
373 | 379 | ||
380 | static int | ||
381 | check_revoke_message (void *cls, | ||
382 | const struct RevokeMessage *rm) | ||
383 | { | ||
384 | uint16_t size; | ||
385 | |||
386 | size = ntohs (rm->header.size); | ||
387 | if (size <= sizeof(struct RevokeMessage)) | ||
388 | { | ||
389 | GNUNET_break (0); | ||
390 | return GNUNET_SYSERR; | ||
391 | } | ||
392 | return GNUNET_OK; | ||
393 | |||
394 | } | ||
395 | |||
396 | |||
374 | /** | 397 | /** |
375 | * Handle REVOKE message from client. | 398 | * Handle REVOKE message from client. |
376 | * | 399 | * |
@@ -403,6 +426,23 @@ handle_revoke_message (void *cls, | |||
403 | } | 426 | } |
404 | 427 | ||
405 | 428 | ||
429 | static int | ||
430 | check_p2p_revoke (void *cls, | ||
431 | const struct RevokeMessage *rm) | ||
432 | { | ||
433 | uint16_t size; | ||
434 | |||
435 | size = ntohs (rm->header.size); | ||
436 | if (size <= sizeof(struct RevokeMessage)) | ||
437 | { | ||
438 | GNUNET_break (0); | ||
439 | return GNUNET_SYSERR; | ||
440 | } | ||
441 | return GNUNET_OK; | ||
442 | |||
443 | } | ||
444 | |||
445 | |||
406 | /** | 446 | /** |
407 | * Core handler for flooded revocation messages. | 447 | * Core handler for flooded revocation messages. |
408 | * | 448 | * |
@@ -784,16 +824,17 @@ run (void *cls, | |||
784 | struct GNUNET_SERVICE_Handle *service) | 824 | struct GNUNET_SERVICE_Handle *service) |
785 | { | 825 | { |
786 | struct GNUNET_MQ_MessageHandler core_handlers[] = { | 826 | struct GNUNET_MQ_MessageHandler core_handlers[] = { |
787 | GNUNET_MQ_hd_fixed_size (p2p_revoke, | 827 | GNUNET_MQ_hd_var_size (p2p_revoke, |
788 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 828 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
789 | struct RevokeMessage, | 829 | struct RevokeMessage, |
790 | NULL), | 830 | NULL), |
791 | GNUNET_MQ_handler_end () | 831 | GNUNET_MQ_handler_end () |
792 | }; | 832 | }; |
793 | char *fn; | 833 | char *fn; |
794 | uint64_t left; | 834 | uint64_t left; |
795 | struct RevokeMessage *rm; | 835 | struct RevokeMessage *rm; |
796 | struct GNUNET_HashCode hc; | 836 | struct GNUNET_HashCode hc; |
837 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
797 | 838 | ||
798 | GNUNET_CRYPTO_hash ("revocation-set-union-application-id", | 839 | GNUNET_CRYPTO_hash ("revocation-set-union-application-id", |
799 | strlen ("revocation-set-union-application-id"), | 840 | strlen ("revocation-set-union-application-id"), |
@@ -892,9 +933,11 @@ run (void *cls, | |||
892 | GNUNET_free (fn); | 933 | GNUNET_free (fn); |
893 | return; | 934 | return; |
894 | } | 935 | } |
895 | GNUNET_break (0 == ntohl (rm->reserved)); | 936 | struct GNUNET_REVOCATION_PowP *pow = (struct |
896 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, | 937 | GNUNET_REVOCATION_PowP *) &rm[1]; |
897 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 938 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
939 | GNUNET_CRYPTO_hash (pk, | ||
940 | GNUNET_IDENTITY_key_get_length (pk), | ||
898 | &hc); | 941 | &hc); |
899 | GNUNET_break (GNUNET_OK == | 942 | GNUNET_break (GNUNET_OK == |
900 | GNUNET_CONTAINER_multihashmap_put (revocation_map, | 943 | GNUNET_CONTAINER_multihashmap_put (revocation_map, |
@@ -939,10 +982,10 @@ GNUNET_SERVICE_MAIN | |||
939 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, | 982 | GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, |
940 | struct QueryMessage, | 983 | struct QueryMessage, |
941 | NULL), | 984 | NULL), |
942 | GNUNET_MQ_hd_fixed_size (revoke_message, | 985 | GNUNET_MQ_hd_var_size (revoke_message, |
943 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, | 986 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, |
944 | struct RevokeMessage, | 987 | struct RevokeMessage, |
945 | NULL), | 988 | NULL), |
946 | GNUNET_MQ_handler_end ()); | 989 | GNUNET_MQ_handler_end ()); |
947 | 990 | ||
948 | 991 | ||
diff --git a/src/revocation/plugin_block_revocation.c b/src/revocation/plugin_block_revocation.c index 291c56f70..3c9344a49 100644 --- a/src/revocation/plugin_block_revocation.c +++ b/src/revocation/plugin_block_revocation.c | |||
@@ -143,16 +143,18 @@ block_plugin_revocation_evaluate (void *cls, | |||
143 | GNUNET_break_op (0); | 143 | GNUNET_break_op (0); |
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
145 | } | 145 | } |
146 | if (0 >= | 146 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; |
147 | GNUNET_REVOCATION_check_pow (&rm->proof_of_work, | 147 | const struct GNUNET_IDENTITY_PublicKey *pk; |
148 | ic->matching_bits, | 148 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
149 | ic->epoch_duration)) | 149 | if (GNUNET_YES != GNUNET_REVOCATION_check_pow (pow, |
150 | ic->matching_bits, | ||
151 | ic->epoch_duration)) | ||
150 | { | 152 | { |
151 | GNUNET_break_op (0); | 153 | GNUNET_break_op (0); |
152 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 154 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
153 | } | 155 | } |
154 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, | 156 | GNUNET_CRYPTO_hash (pk, |
155 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 157 | GNUNET_IDENTITY_key_get_length (pk), |
156 | &chash); | 158 | &chash); |
157 | if (GNUNET_YES == | 159 | if (GNUNET_YES == |
158 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, | 160 | GNUNET_BLOCK_GROUP_bf_test_and_set (group, |
@@ -182,13 +184,16 @@ block_plugin_revocation_get_key (void *cls, | |||
182 | { | 184 | { |
183 | const struct RevokeMessage *rm = block; | 185 | const struct RevokeMessage *rm = block; |
184 | 186 | ||
185 | if (block_size != sizeof(*rm)) | 187 | if (block_size <= sizeof(*rm)) |
186 | { | 188 | { |
187 | GNUNET_break_op (0); | 189 | GNUNET_break_op (0); |
188 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
189 | } | 191 | } |
190 | GNUNET_CRYPTO_hash (&rm->proof_of_work.key, | 192 | struct GNUNET_REVOCATION_PowP *pow = (struct GNUNET_REVOCATION_PowP *) &rm[1]; |
191 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 193 | const struct GNUNET_IDENTITY_PublicKey *pk; |
194 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
195 | GNUNET_CRYPTO_hash (pk, | ||
196 | GNUNET_IDENTITY_key_get_length (pk), | ||
192 | key); | 197 | key); |
193 | return GNUNET_OK; | 198 | return GNUNET_OK; |
194 | } | 199 | } |
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index 635c56cfc..c3a9c9e6b 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h | |||
@@ -49,7 +49,7 @@ struct QueryMessage | |||
49 | /** | 49 | /** |
50 | * Key to check. | 50 | * Key to check. |
51 | */ | 51 | */ |
52 | struct GNUNET_CRYPTO_EcdsaPublicKey key; | 52 | struct GNUNET_IDENTITY_PublicKey key; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | 55 | ||
@@ -85,14 +85,11 @@ struct RevokeMessage | |||
85 | struct GNUNET_MessageHeader header; | 85 | struct GNUNET_MessageHeader header; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * For alignment. | 88 | * Length of PoW with signature. |
89 | */ | 89 | */ |
90 | uint32_t reserved GNUNET_PACKED; | 90 | uint32_t pow_size GNUNET_PACKED; |
91 | 91 | ||
92 | /** | 92 | /** Followed by the PoW **/ |
93 | * Number that causes a hash collision with the @e public_key. | ||
94 | */ | ||
95 | struct GNUNET_REVOCATION_PowP proof_of_work; | ||
96 | }; | 93 | }; |
97 | 94 | ||
98 | 95 | ||
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 75cfd8761..791c3d008 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -160,7 +160,7 @@ handle_revocation_query_response (void *cls, | |||
160 | */ | 160 | */ |
161 | struct GNUNET_REVOCATION_Query * | 161 | struct GNUNET_REVOCATION_Query * |
162 | GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, | 162 | GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg, |
163 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key, | 163 | const struct GNUNET_IDENTITY_PublicKey *key, |
164 | GNUNET_REVOCATION_Callback func, | 164 | GNUNET_REVOCATION_Callback func, |
165 | void *func_cls) | 165 | void *func_cls) |
166 | { | 166 | { |
@@ -359,10 +359,12 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
359 | } | 359 | } |
360 | h->func = func; | 360 | h->func = func; |
361 | h->func_cls = func_cls; | 361 | h->func_cls = func_cls; |
362 | env = GNUNET_MQ_msg (rm, | 362 | size_t extra_len = GNUNET_REVOCATION_proof_get_size (pow); |
363 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); | 363 | env = GNUNET_MQ_msg_extra (rm, |
364 | rm->reserved = htonl (0); | 364 | extra_len, |
365 | rm->proof_of_work = *pow; | 365 | GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); |
366 | rm->pow_size = htonl (extra_len); | ||
367 | memcpy (&rm[1], pow, extra_len); | ||
366 | GNUNET_MQ_send (h->mq, | 368 | GNUNET_MQ_send (h->mq, |
367 | env); | 369 | env); |
368 | return h; | 370 | return h; |
@@ -420,6 +422,51 @@ calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph) | |||
420 | } | 422 | } |
421 | 423 | ||
422 | 424 | ||
425 | enum GNUNET_GenericReturnValue | ||
426 | check_signature_identity (const struct GNUNET_REVOCATION_PowP *pow, | ||
427 | const struct GNUNET_IDENTITY_PublicKey *key) | ||
428 | { | ||
429 | struct GNUNET_REVOCATION_SignaturePurposePS *spurp; | ||
430 | struct GNUNET_IDENTITY_Signature *sig; | ||
431 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
432 | size_t ksize; | ||
433 | |||
434 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
435 | ksize = GNUNET_IDENTITY_key_get_length (pk); | ||
436 | |||
437 | spurp = GNUNET_malloc (sizeof (*spurp) + ksize); | ||
438 | spurp->timestamp = pow->timestamp; | ||
439 | spurp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
440 | spurp->purpose.size = htonl (sizeof(*spurp) + ksize); | ||
441 | GNUNET_IDENTITY_write_key_to_buffer (pk, | ||
442 | (char*) &spurp[1], | ||
443 | ksize); | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "Expected signature payload len: %u\n", | ||
446 | ntohl (spurp->purpose.size)); | ||
447 | sig = (struct GNUNET_IDENTITY_Signature *) ((char*) &pow[1] + ksize); | ||
448 | if (GNUNET_OK != | ||
449 | GNUNET_IDENTITY_signature_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
450 | &spurp->purpose, | ||
451 | sig, | ||
452 | key)) | ||
453 | { | ||
454 | return GNUNET_SYSERR; | ||
455 | } | ||
456 | return GNUNET_OK; | ||
457 | } | ||
458 | |||
459 | |||
460 | enum GNUNET_GenericReturnValue | ||
461 | check_signature (const struct GNUNET_REVOCATION_PowP *pow) | ||
462 | { | ||
463 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
464 | |||
465 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
466 | return check_signature_identity (pow, pk); | ||
467 | } | ||
468 | |||
469 | |||
423 | /** | 470 | /** |
424 | * Check if the given proof-of-work is valid. | 471 | * Check if the given proof-of-work is valid. |
425 | * | 472 | * |
@@ -433,10 +480,9 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
433 | unsigned int difficulty, | 480 | unsigned int difficulty, |
434 | struct GNUNET_TIME_Relative epoch_duration) | 481 | struct GNUNET_TIME_Relative epoch_duration) |
435 | { | 482 | { |
436 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 483 | char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) |
437 | + sizeof (struct GNUNET_TIME_AbsoluteNBO) | 484 | + sizeof (struct GNUNET_TIME_AbsoluteNBO) |
438 | + sizeof (uint64_t)] GNUNET_ALIGN; | 485 | + sizeof (uint64_t)] GNUNET_ALIGN; |
439 | struct GNUNET_REVOCATION_SignaturePurposePS spurp; | ||
440 | struct GNUNET_HashCode result; | 486 | struct GNUNET_HashCode result; |
441 | struct GNUNET_TIME_Absolute ts; | 487 | struct GNUNET_TIME_Absolute ts; |
442 | struct GNUNET_TIME_Absolute exp; | 488 | struct GNUNET_TIME_Absolute exp; |
@@ -446,25 +492,18 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
446 | unsigned int tmp_score = 0; | 492 | unsigned int tmp_score = 0; |
447 | unsigned int epochs; | 493 | unsigned int epochs; |
448 | uint64_t pow_val; | 494 | uint64_t pow_val; |
495 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
496 | |||
497 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
449 | 498 | ||
450 | /** | 499 | /** |
451 | * Check if signature valid | 500 | * Check if signature valid |
452 | */ | 501 | */ |
453 | spurp.key = pow->key; | 502 | if (GNUNET_OK != check_signature (pow)) |
454 | spurp.timestamp = pow->timestamp; | ||
455 | spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | ||
456 | spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
457 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
458 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
459 | if (GNUNET_OK != | ||
460 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | ||
461 | &spurp.purpose, | ||
462 | &pow->signature, | ||
463 | &pow->key)) | ||
464 | { | 503 | { |
465 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
466 | "Proof of work signature invalid!\n"); | 505 | "Proof of work signature invalid!\n"); |
467 | return GNUNET_NO; | 506 | return GNUNET_SYSERR; |
468 | } | 507 | } |
469 | 508 | ||
470 | /** | 509 | /** |
@@ -479,8 +518,8 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
479 | &pow->timestamp, | 518 | &pow->timestamp, |
480 | sizeof (uint64_t)); | 519 | sizeof (uint64_t)); |
481 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], | 520 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], |
482 | &pow->key, | 521 | pk, |
483 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 522 | GNUNET_IDENTITY_key_get_length (pk)); |
484 | for (unsigned int i = 0; i < POW_COUNT; i++) | 523 | for (unsigned int i = 0; i < POW_COUNT; i++) |
485 | { | 524 | { |
486 | pow_val = GNUNET_ntohll (pow->pow[i]); | 525 | pow_val = GNUNET_ntohll (pow->pow[i]); |
@@ -529,18 +568,15 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
529 | } | 568 | } |
530 | 569 | ||
531 | 570 | ||
532 | /** | 571 | enum GNUNET_GenericReturnValue |
533 | * Initializes a fresh PoW computation. | 572 | sign_pow_identity (const struct GNUNET_IDENTITY_PrivateKey *key, |
534 | * | 573 | struct GNUNET_REVOCATION_PowP *pow) |
535 | * @param key the key to calculate the PoW for. | ||
536 | * @param[out] pow starting point for PoW calculation (not yet valid) | ||
537 | */ | ||
538 | void | ||
539 | GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
540 | struct GNUNET_REVOCATION_PowP *pow) | ||
541 | { | 574 | { |
542 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); | 575 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); |
543 | struct GNUNET_REVOCATION_SignaturePurposePS rp; | 576 | struct GNUNET_REVOCATION_SignaturePurposePS *rp; |
577 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
578 | size_t ksize; | ||
579 | char *sig; | ||
544 | 580 | ||
545 | /** | 581 | /** |
546 | * Predate the validity period to prevent rejections due to | 582 | * Predate the validity period to prevent rejections due to |
@@ -548,19 +584,53 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
548 | */ | 584 | */ |
549 | ts = GNUNET_TIME_absolute_subtract (ts, | 585 | ts = GNUNET_TIME_absolute_subtract (ts, |
550 | GNUNET_TIME_UNIT_WEEKS); | 586 | GNUNET_TIME_UNIT_WEEKS); |
551 | 587 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | |
588 | ksize = GNUNET_IDENTITY_key_get_length (pk); | ||
552 | pow->timestamp = GNUNET_TIME_absolute_hton (ts); | 589 | pow->timestamp = GNUNET_TIME_absolute_hton (ts); |
553 | rp.timestamp = pow->timestamp; | 590 | rp = GNUNET_malloc (sizeof (*rp) + ksize); |
554 | rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | 591 | rp->timestamp = pow->timestamp; |
555 | rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 592 | rp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); |
556 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 593 | rp->purpose.size = htonl (sizeof(*rp) + ksize); |
557 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | 594 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
558 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pow->key); | 595 | "Signature payload len: %u\n", |
559 | rp.key = pow->key; | 596 | ntohl (rp->purpose.size)); |
560 | GNUNET_assert (GNUNET_OK == | 597 | GNUNET_IDENTITY_write_key_to_buffer (pk, |
561 | GNUNET_CRYPTO_ecdsa_sign_ (key, | 598 | ((char*) &rp[1]), |
562 | &rp.purpose, | 599 | ksize); |
563 | &pow->signature)); | 600 | sig = ((char*) &pow[1]) + ksize; |
601 | int result = GNUNET_IDENTITY_sign_ (key, | ||
602 | &rp->purpose, | ||
603 | (void*) sig); | ||
604 | if (result == GNUNET_SYSERR) | ||
605 | return GNUNET_NO; | ||
606 | else | ||
607 | return result; | ||
608 | } | ||
609 | |||
610 | |||
611 | enum GNUNET_GenericReturnValue | ||
612 | sign_pow (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
613 | struct GNUNET_REVOCATION_PowP *pow) | ||
614 | { | ||
615 | struct GNUNET_IDENTITY_PublicKey *pk; | ||
616 | |||
617 | pk = (struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
618 | GNUNET_IDENTITY_key_get_public (key, pk); | ||
619 | return sign_pow_identity (key, pow); | ||
620 | } | ||
621 | |||
622 | |||
623 | /** | ||
624 | * Initializes a fresh PoW computation. | ||
625 | * | ||
626 | * @param key the key to calculate the PoW for. | ||
627 | * @param[out] pow starting point for PoW calculation (not yet valid) | ||
628 | */ | ||
629 | void | ||
630 | GNUNET_REVOCATION_pow_init (const struct GNUNET_IDENTITY_PrivateKey *key, | ||
631 | struct GNUNET_REVOCATION_PowP *pow) | ||
632 | { | ||
633 | GNUNET_assert (GNUNET_OK == sign_pow (key, pow)); | ||
564 | } | 634 | } |
565 | 635 | ||
566 | 636 | ||
@@ -622,15 +692,17 @@ cmp_pow_value (const void *a, const void *b) | |||
622 | enum GNUNET_GenericReturnValue | 692 | enum GNUNET_GenericReturnValue |
623 | GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | 693 | GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) |
624 | { | 694 | { |
625 | char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 695 | char buf[sizeof(struct GNUNET_IDENTITY_PublicKey) |
626 | + sizeof (uint64_t) | 696 | + sizeof (uint64_t) |
627 | + sizeof (uint64_t)] GNUNET_ALIGN; | 697 | + sizeof (uint64_t)] GNUNET_ALIGN; |
628 | struct GNUNET_HashCode result; | 698 | struct GNUNET_HashCode result; |
699 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
629 | unsigned int zeros; | 700 | unsigned int zeros; |
630 | int ret; | 701 | int ret; |
631 | uint64_t pow_nbo; | 702 | uint64_t pow_nbo; |
632 | 703 | ||
633 | pc->current_pow++; | 704 | pc->current_pow++; |
705 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &(pc->pow[1]); | ||
634 | 706 | ||
635 | /** | 707 | /** |
636 | * Do not try duplicates | 708 | * Do not try duplicates |
@@ -644,8 +716,8 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | |||
644 | &pc->pow->timestamp, | 716 | &pc->pow->timestamp, |
645 | sizeof (uint64_t)); | 717 | sizeof (uint64_t)); |
646 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], | 718 | GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], |
647 | &pc->pow->key, | 719 | pk, |
648 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); | 720 | GNUNET_IDENTITY_key_get_length (pk)); |
649 | GNUNET_CRYPTO_pow_hash (&salt, | 721 | GNUNET_CRYPTO_pow_hash (&salt, |
650 | buf, | 722 | buf, |
651 | sizeof(buf), | 723 | sizeof(buf), |
@@ -690,4 +762,22 @@ GNUNET_REVOCATION_pow_stop (struct GNUNET_REVOCATION_PowCalculationHandle *pc) | |||
690 | } | 762 | } |
691 | 763 | ||
692 | 764 | ||
765 | size_t | ||
766 | GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow) | ||
767 | { | ||
768 | size_t size; | ||
769 | size_t ksize; | ||
770 | const struct GNUNET_IDENTITY_PublicKey *pk; | ||
771 | const struct GNUNET_IDENTITY_Signature *sig; | ||
772 | |||
773 | size = sizeof (struct GNUNET_REVOCATION_PowP); | ||
774 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | ||
775 | ksize = GNUNET_IDENTITY_key_get_length (pk); | ||
776 | size += ksize; | ||
777 | sig = (struct GNUNET_IDENTITY_Signature *) ((char*) &pow[1] + ksize); | ||
778 | size += GNUNET_IDENTITY_signature_get_length (sig); | ||
779 | return size; | ||
780 | } | ||
781 | |||
782 | |||
693 | /* end of revocation_api.c */ | 783 | /* end of revocation_api.c */ |
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c index b65567d79..c6457016f 100644 --- a/src/revocation/test_revocation.c +++ b/src/revocation/test_revocation.c | |||
@@ -38,8 +38,8 @@ struct TestPeer | |||
38 | struct GNUNET_TESTBED_Operation *core_op; | 38 | struct GNUNET_TESTBED_Operation *core_op; |
39 | struct GNUNET_IDENTITY_Handle *idh; | 39 | struct GNUNET_IDENTITY_Handle *idh; |
40 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 40 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
41 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 41 | const struct GNUNET_IDENTITY_PrivateKey *privkey; |
42 | struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 42 | struct GNUNET_IDENTITY_PublicKey pubkey; |
43 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 43 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
44 | struct GNUNET_IDENTITY_Operation *create_id_op; | 44 | struct GNUNET_IDENTITY_Operation *create_id_op; |
45 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; | 45 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; |
@@ -142,13 +142,13 @@ revocation_cb (void *cls, enum GNUNET_GenericReturnValue is_valid) | |||
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | static struct GNUNET_REVOCATION_PowP proof_of_work; | 145 | static struct GNUNET_REVOCATION_PowP *proof_of_work; |
146 | 146 | ||
147 | static void | 147 | static void |
148 | ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 148 | ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
149 | { | 149 | { |
150 | static int completed = 0; | 150 | static int completed = 0; |
151 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; | 151 | const struct GNUNET_IDENTITY_PrivateKey *privkey; |
152 | 152 | ||
153 | if ((NULL != ego) && (cls == &testpeers[0])) | 153 | if ((NULL != ego) && (cls == &testpeers[0])) |
154 | { | 154 | { |
@@ -164,10 +164,10 @@ ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
164 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); | 164 | GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); |
165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); | 165 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); |
166 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); | 166 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego); |
167 | memset (&proof_of_work, 0, sizeof (proof_of_work)); | 167 | proof_of_work = GNUNET_malloc (GNUNET_REVOCATION_MAX_PROOF_SIZE); |
168 | GNUNET_REVOCATION_pow_init (privkey, | 168 | GNUNET_REVOCATION_pow_init (privkey, |
169 | &proof_of_work); | 169 | proof_of_work); |
170 | testpeers[1].pow = GNUNET_REVOCATION_pow_start (&proof_of_work, | 170 | testpeers[1].pow = GNUNET_REVOCATION_pow_start (proof_of_work, |
171 | 1, | 171 | 1, |
172 | 5); | 172 | 5); |
173 | int res = | 173 | int res = |
@@ -184,7 +184,7 @@ ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
184 | { | 184 | { |
185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); | 185 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); |
186 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, | 186 | testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, |
187 | &proof_of_work, | 187 | proof_of_work, |
188 | &revocation_cb, | 188 | &revocation_cb, |
189 | NULL); | 189 | NULL); |
190 | GNUNET_REVOCATION_pow_stop (testpeers[1].pow); | 190 | GNUNET_REVOCATION_pow_stop (testpeers[1].pow); |
@@ -194,7 +194,7 @@ ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
194 | 194 | ||
195 | static void | 195 | static void |
196 | identity_create_cb (void *cls, | 196 | identity_create_cb (void *cls, |
197 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 197 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
198 | const char *emsg) | 198 | const char *emsg) |
199 | { | 199 | { |
200 | static int completed = 0; | 200 | static int completed = 0; |
@@ -238,11 +238,13 @@ identity_completion_cb (void *cls, | |||
238 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, | 238 | testpeers[0].create_id_op = GNUNET_IDENTITY_create (testpeers[0].idh, |
239 | "client", | 239 | "client", |
240 | NULL, | 240 | NULL, |
241 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
241 | &identity_create_cb, | 242 | &identity_create_cb, |
242 | &testpeers[0]); | 243 | &testpeers[0]); |
243 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, | 244 | testpeers[1].create_id_op = GNUNET_IDENTITY_create (testpeers[1].idh, |
244 | "toberevoked", | 245 | "toberevoked", |
245 | NULL, | 246 | NULL, |
247 | GNUNET_IDENTITY_TYPE_ECDSA, | ||
246 | &identity_create_cb, | 248 | &identity_create_cb, |
247 | &testpeers[1]); | 249 | &testpeers[1]); |
248 | } | 250 | } |
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 87c6faf98..931d7e753 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -563,8 +563,8 @@ prepare_ibf_iterator (void *cls, | |||
563 | struct IBF_Key salted_key; | 563 | struct IBF_Key salted_key; |
564 | 564 | ||
565 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 565 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
566 | "[OP %x] inserting %lx (hash %s) into ibf\n", | 566 | "[OP %p] inserting %lx (hash %s) into ibf\n", |
567 | (void *) op, | 567 | op, |
568 | (unsigned long) ke->ibf_key.key_val, | 568 | (unsigned long) ke->ibf_key.key_val, |
569 | GNUNET_h2s (&ke->element->element_hash)); | 569 | GNUNET_h2s (&ke->element->element_hash)); |
570 | salt_key (&ke->ibf_key, | 570 | salt_key (&ke->ibf_key, |
@@ -929,7 +929,7 @@ handle_union_p2p_strata_estimator (void *cls, | |||
929 | (0 == other_size)) | 929 | (0 == other_size)) |
930 | { | 930 | { |
931 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 931 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
932 | "Deciding to go for full set transmission (diff=%d, own set=%u)\n", | 932 | "Deciding to go for full set transmission (diff=%d, own set=%llu)\n", |
933 | diff, | 933 | diff, |
934 | op->state->initial_size); | 934 | op->state->initial_size); |
935 | GNUNET_STATISTICS_update (_GSS_statistics, | 935 | GNUNET_STATISTICS_update (_GSS_statistics, |
@@ -1004,8 +1004,8 @@ send_offers_iterator (void *cls, | |||
1004 | GNUNET_assert (NULL != ev); | 1004 | GNUNET_assert (NULL != ev); |
1005 | *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; | 1005 | *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; |
1006 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1006 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1007 | "[OP %x] sending element offer (%s) to peer\n", | 1007 | "[OP %p] sending element offer (%s) to peer\n", |
1008 | (void *) op, | 1008 | op, |
1009 | GNUNET_h2s (&ke->element->element_hash)); | 1009 | GNUNET_h2s (&ke->element->element_hash)); |
1010 | GNUNET_MQ_send (op->mq, ev); | 1010 | GNUNET_MQ_send (op->mq, ev); |
1011 | return GNUNET_YES; | 1011 | return GNUNET_YES; |
@@ -2004,8 +2004,8 @@ handle_union_p2p_demand (void *cls, | |||
2004 | emsg->reserved = htons (0); | 2004 | emsg->reserved = htons (0); |
2005 | emsg->element_type = htons (ee->element.element_type); | 2005 | emsg->element_type = htons (ee->element.element_type); |
2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2007 | "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", | 2007 | "[OP %p] Sending demanded element (size %u, hash %s) to peer\n", |
2008 | (void *) op, | 2008 | op, |
2009 | (unsigned int) ee->element.size, | 2009 | (unsigned int) ee->element.size, |
2010 | GNUNET_h2s (&ee->element_hash)); | 2010 | GNUNET_h2s (&ee->element_hash)); |
2011 | GNUNET_MQ_send (op->mq, ev); | 2011 | GNUNET_MQ_send (op->mq, ev); |
@@ -2120,8 +2120,8 @@ handle_union_p2p_offer (void *cls, | |||
2120 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 2120 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
2121 | 2121 | ||
2122 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2122 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2123 | "[OP %x] Requesting element (hash %s)\n", | 2123 | "[OP %p] Requesting element (hash %s)\n", |
2124 | (void *) op, GNUNET_h2s (hash)); | 2124 | op, GNUNET_h2s (hash)); |
2125 | ev = GNUNET_MQ_msg_header_extra (demands, | 2125 | ev = GNUNET_MQ_msg_header_extra (demands, |
2126 | sizeof(struct GNUNET_HashCode), | 2126 | sizeof(struct GNUNET_HashCode), |
2127 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); | 2127 | GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND); |
diff --git a/src/set/set_api.c b/src/set/set_api.c index ce4b1c965..a082c23c1 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -630,8 +630,7 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
630 | else | 630 | else |
631 | { | 631 | { |
632 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 632 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
633 | "Creating new set (lazy copy)\n", | 633 | "Creating new set (lazy copy)\n"); |
634 | op); | ||
635 | mqm = GNUNET_MQ_msg (copy_msg, | 634 | mqm = GNUNET_MQ_msg (copy_msg, |
636 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); | 635 | GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT); |
637 | copy_msg->cookie = *cookie; | 636 | copy_msg->cookie = *cookie; |
diff --git a/src/setu/gnunet-service-setu.c b/src/setu/gnunet-service-setu.c index 326589186..d00303ca7 100644 --- a/src/setu/gnunet-service-setu.c +++ b/src/setu/gnunet-service-setu.c | |||
@@ -1049,8 +1049,8 @@ prepare_ibf_iterator (void *cls, | |||
1049 | struct IBF_Key salted_key; | 1049 | struct IBF_Key salted_key; |
1050 | 1050 | ||
1051 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1051 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1052 | "[OP %x] inserting %lx (hash %s) into ibf\n", | 1052 | "[OP %p] inserting %lx (hash %s) into ibf\n", |
1053 | (void *) op, | 1053 | op, |
1054 | (unsigned long) ke->ibf_key.key_val, | 1054 | (unsigned long) ke->ibf_key.key_val, |
1055 | GNUNET_h2s (&ke->element->element_hash)); | 1055 | GNUNET_h2s (&ke->element->element_hash)); |
1056 | salt_key (&ke->ibf_key, | 1056 | salt_key (&ke->ibf_key, |
@@ -1429,7 +1429,7 @@ handle_union_p2p_strata_estimator (void *cls, | |||
1429 | (0 == other_size)) | 1429 | (0 == other_size)) |
1430 | { | 1430 | { |
1431 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1431 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1432 | "Deciding to go for full set transmission (diff=%d, own set=%u)\n", | 1432 | "Deciding to go for full set transmission (diff=%d, own set=%llu)\n", |
1433 | diff, | 1433 | diff, |
1434 | op->initial_size); | 1434 | op->initial_size); |
1435 | GNUNET_STATISTICS_update (_GSS_statistics, | 1435 | GNUNET_STATISTICS_update (_GSS_statistics, |
@@ -1504,8 +1504,8 @@ send_offers_iterator (void *cls, | |||
1504 | GNUNET_assert (NULL != ev); | 1504 | GNUNET_assert (NULL != ev); |
1505 | *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; | 1505 | *(struct GNUNET_HashCode *) &mh[1] = ke->element->element_hash; |
1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "[OP %x] sending element offer (%s) to peer\n", | 1507 | "[OP %p] sending element offer (%s) to peer\n", |
1508 | (void *) op, | 1508 | op, |
1509 | GNUNET_h2s (&ke->element->element_hash)); | 1509 | GNUNET_h2s (&ke->element->element_hash)); |
1510 | GNUNET_MQ_send (op->mq, ev); | 1510 | GNUNET_MQ_send (op->mq, ev); |
1511 | return GNUNET_YES; | 1511 | return GNUNET_YES; |
@@ -2403,8 +2403,8 @@ handle_union_p2p_demand (void *cls, | |||
2403 | emsg->reserved = htons (0); | 2403 | emsg->reserved = htons (0); |
2404 | emsg->element_type = htons (ee->element.element_type); | 2404 | emsg->element_type = htons (ee->element.element_type); |
2405 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2405 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2406 | "[OP %x] Sending demanded element (size %u, hash %s) to peer\n", | 2406 | "[OP %p] Sending demanded element (size %u, hash %s) to peer\n", |
2407 | (void *) op, | 2407 | op, |
2408 | (unsigned int) ee->element.size, | 2408 | (unsigned int) ee->element.size, |
2409 | GNUNET_h2s (&ee->element_hash)); | 2409 | GNUNET_h2s (&ee->element_hash)); |
2410 | GNUNET_MQ_send (op->mq, ev); | 2410 | GNUNET_MQ_send (op->mq, ev); |
@@ -2502,8 +2502,8 @@ handle_union_p2p_offer (void *cls, | |||
2502 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 2502 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
2503 | 2503 | ||
2504 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2504 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2505 | "[OP %x] Requesting element (hash %s)\n", | 2505 | "[OP %p] Requesting element (hash %s)\n", |
2506 | (void *) op, GNUNET_h2s (hash)); | 2506 | op, GNUNET_h2s (hash)); |
2507 | ev = GNUNET_MQ_msg_header_extra (demands, | 2507 | ev = GNUNET_MQ_msg_header_extra (demands, |
2508 | sizeof(struct GNUNET_HashCode), | 2508 | sizeof(struct GNUNET_HashCode), |
2509 | GNUNET_MESSAGE_TYPE_SETU_P2P_DEMAND); | 2509 | GNUNET_MESSAGE_TYPE_SETU_P2P_DEMAND); |
@@ -2787,8 +2787,6 @@ check_incoming_msg (void *cls, | |||
2787 | * | 2787 | * |
2788 | * @param cls the operation state | 2788 | * @param cls the operation state |
2789 | * @param msg the received message | 2789 | * @param msg the received message |
2790 | * @return #GNUNET_OK if the channel should be kept alive, | ||
2791 | * #GNUNET_SYSERR to destroy the channel | ||
2792 | */ | 2790 | */ |
2793 | static void | 2791 | static void |
2794 | handle_incoming_msg (void *cls, | 2792 | handle_incoming_msg (void *cls, |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 12c09b7d2..bf0a90b45 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -472,7 +472,7 @@ handle_statistics_value (void *cls, | |||
472 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 472 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
473 | "Received valid statistic on `%s:%s': %llu\n", | 473 | "Received valid statistic on `%s:%s': %llu\n", |
474 | service, name, | 474 | service, name, |
475 | GNUNET_ntohll (smsg->value)); | 475 | (unsigned long long) GNUNET_ntohll (smsg->value)); |
476 | if (GNUNET_OK != | 476 | if (GNUNET_OK != |
477 | h->current->proc (h->current->cls, | 477 | h->current->proc (h->current->cls, |
478 | service, | 478 | service, |
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c index 81652fa4f..bc2f0abe0 100644 --- a/src/testbed-logger/gnunet-service-testbed-logger.c +++ b/src/testbed-logger/gnunet-service-testbed-logger.c | |||
@@ -198,7 +198,7 @@ logger_run (void *cls, | |||
198 | GNUNET_asprintf (&fn, | 198 | GNUNET_asprintf (&fn, |
199 | "%s/%.*s_%jd.dat", | 199 | "%s/%.*s_%jd.dat", |
200 | dir, | 200 | dir, |
201 | hname_len, | 201 | (int) hname_len, |
202 | hname, | 202 | hname, |
203 | (intmax_t) pid); | 203 | (intmax_t) pid); |
204 | GNUNET_free (hname); | 204 | GNUNET_free (hname); |
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index 70b865c73..440f2c24f 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c | |||
@@ -608,7 +608,7 @@ GST_stats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
608 | return; | 608 | return; |
609 | } | 609 | } |
610 | fn = NULL; | 610 | fn = NULL; |
611 | (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, len, | 611 | (void) GNUNET_asprintf (&fn, "%s/%.*s-%jd.dat", stats_dir, (int)len, |
612 | hostname, (intmax_t) getpid ()); | 612 | hostname, (intmax_t) getpid ()); |
613 | GNUNET_free (stats_dir); | 613 | GNUNET_free (stats_dir); |
614 | GNUNET_free (hostname); | 614 | GNUNET_free (hostname); |
diff --git a/src/testbed/test_testbed_api_template.conf b/src/testbed/test_testbed_api_template.conf index 255c1b766..ae0368a8b 100644 --- a/src/testbed/test_testbed_api_template.conf +++ b/src/testbed/test_testbed_api_template.conf | |||
@@ -32,7 +32,7 @@ WAN_QUOTA_IN = 3932160 | |||
32 | USE_EPHEMERAL_KEYS = NO | 32 | USE_EPHEMERAL_KEYS = NO |
33 | IMMEDIATE_START = YES | 33 | IMMEDIATE_START = YES |
34 | 34 | ||
35 | [transport-udp] | 35 | [transport-tcp] |
36 | TIMEOUT = 300 s | 36 | TIMEOUT = 300 s |
37 | 37 | ||
38 | [PATHS] | 38 | [PATHS] |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 697783d96..09752ba28 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -448,7 +448,7 @@ handle_opsuccess ( | |||
448 | uint64_t op_id; | 448 | uint64_t op_id; |
449 | 449 | ||
450 | op_id = GNUNET_ntohll (msg->operation_id); | 450 | op_id = GNUNET_ntohll (msg->operation_id); |
451 | LOG_DEBUG ("Operation %lu successful\n", op_id); | 451 | LOG_DEBUG ("Operation %llu successful\n", op_id); |
452 | if (NULL == (opc = find_opc (c, op_id))) | 452 | if (NULL == (opc = find_opc (c, op_id))) |
453 | { | 453 | { |
454 | LOG_DEBUG ("Operation not found\n"); | 454 | LOG_DEBUG ("Operation not found\n"); |
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 1d765af92..a9a340e99 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -1089,7 +1089,7 @@ gen_topo_from_file (struct TopologyContext *tc, | |||
1089 | if (tc->num_peers <= peer_id) | 1089 | if (tc->num_peers <= peer_id) |
1090 | { | 1090 | { |
1091 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1091 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1092 | _ ("Topology file needs more peers than given ones\n"), filename); | 1092 | _ ("Topology file needs more peers than given ones\n")); |
1093 | goto _exit; | 1093 | goto _exit; |
1094 | } | 1094 | } |
1095 | state = OTHER_PEER_INDEX; | 1095 | state = OTHER_PEER_INDEX; |
@@ -1114,7 +1114,7 @@ gen_topo_from_file (struct TopologyContext *tc, | |||
1114 | if (tc->num_peers <= other_peer_id) | 1114 | if (tc->num_peers <= other_peer_id) |
1115 | { | 1115 | { |
1116 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1116 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1117 | _ ("Topology file needs more peers than given ones\n"), filename); | 1117 | _ ("Topology file needs more peers than given ones\n")); |
1118 | goto _exit; | 1118 | goto _exit; |
1119 | } | 1119 | } |
1120 | if (peer_id != other_peer_id) | 1120 | if (peer_id != other_peer_id) |
@@ -1150,7 +1150,7 @@ gen_topo_from_file (struct TopologyContext *tc, | |||
1150 | } | 1150 | } |
1151 | else | 1151 | else |
1152 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1152 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1153 | _ ("Ignoring to connect peer %u to peer %u\n"), | 1153 | _ ("Ignoring to connect peer %lu to peer %lu\n"), |
1154 | peer_id, | 1154 | peer_id, |
1155 | other_peer_id); | 1155 | other_peer_id); |
1156 | while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) | 1156 | while (('\n' != data[offset]) && ('|' != data[offset]) && (offset < fs)) |
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 5ca5a4e86..e967e8e9a 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -75,6 +75,9 @@ | |||
75 | */ | 75 | */ |
76 | #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS | 76 | #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS |
77 | 77 | ||
78 | #define WORKING_QUEUE_INTERVALL \ | ||
79 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1) | ||
80 | |||
78 | /** | 81 | /** |
79 | * AES key size. | 82 | * AES key size. |
80 | */ | 83 | */ |
@@ -90,6 +93,8 @@ | |||
90 | */ | 93 | */ |
91 | #define GCM_TAG_SIZE (128 / 8) | 94 | #define GCM_TAG_SIZE (128 / 8) |
92 | 95 | ||
96 | #define GENERATE_AT_ONCE 2 | ||
97 | |||
93 | /** | 98 | /** |
94 | * If we fall below this number of available KCNs, | 99 | * If we fall below this number of available KCNs, |
95 | * we generate additional ACKs until we reach | 100 | * we generate additional ACKs until we reach |
@@ -129,7 +134,7 @@ | |||
129 | * sense. Might make sense to adapt to RTT if we had | 134 | * sense. Might make sense to adapt to RTT if we had |
130 | * a good measurement... | 135 | * a good measurement... |
131 | */ | 136 | */ |
132 | #define MAX_SECRETS 128 | 137 | #define MAX_SECRETS 128000 |
133 | 138 | ||
134 | /** | 139 | /** |
135 | * How often do we rekey based on number of bytes transmitted? | 140 | * How often do we rekey based on number of bytes transmitted? |
@@ -251,6 +256,12 @@ struct UDPAck | |||
251 | uint32_t sequence_max GNUNET_PACKED; | 256 | uint32_t sequence_max GNUNET_PACKED; |
252 | 257 | ||
253 | /** | 258 | /** |
259 | * Sequence acknowledgement limit. Specifies current maximum sequence | ||
260 | * number supported by receiver. | ||
261 | */ | ||
262 | uint32_t acks_available GNUNET_PACKED; | ||
263 | |||
264 | /** | ||
254 | * CMAC of the base key being acknowledged. | 265 | * CMAC of the base key being acknowledged. |
255 | */ | 266 | */ |
256 | struct GNUNET_HashCode cmac; | 267 | struct GNUNET_HashCode cmac; |
@@ -500,6 +511,12 @@ struct SenderAddress | |||
500 | unsigned int num_secrets; | 511 | unsigned int num_secrets; |
501 | 512 | ||
502 | /** | 513 | /** |
514 | * Number of BOX keys from ACKs we have currently | ||
515 | * available for this sender. | ||
516 | */ | ||
517 | unsigned int acks_available; | ||
518 | |||
519 | /** | ||
503 | * Which network type does this queue use? | 520 | * Which network type does this queue use? |
504 | */ | 521 | */ |
505 | enum GNUNET_NetworkType nt; | 522 | enum GNUNET_NetworkType nt; |
@@ -653,6 +670,15 @@ struct BroadcastInterface | |||
653 | int found; | 670 | int found; |
654 | }; | 671 | }; |
655 | 672 | ||
673 | /** | ||
674 | * Timeout for this receiver address. | ||
675 | */ | ||
676 | struct GNUNET_TIME_Absolute *rekey_timeout; | ||
677 | |||
678 | /** | ||
679 | * Shared secret we finished the last kce working queue for. | ||
680 | */ | ||
681 | struct SharedSecret *ss_finished; | ||
656 | 682 | ||
657 | /** | 683 | /** |
658 | * Cache of pre-generated key IDs. | 684 | * Cache of pre-generated key IDs. |
@@ -670,6 +696,16 @@ static struct GNUNET_SCHEDULER_Task *read_task; | |||
670 | static struct GNUNET_SCHEDULER_Task *timeout_task; | 696 | static struct GNUNET_SCHEDULER_Task *timeout_task; |
671 | 697 | ||
672 | /** | 698 | /** |
699 | * ID of kce working queue task | ||
700 | */ | ||
701 | static struct GNUNET_SCHEDULER_Task *kce_task; | ||
702 | |||
703 | /** | ||
704 | * Is the kce_task finished? | ||
705 | */ | ||
706 | static int kce_task_finished = GNUNET_NO; | ||
707 | |||
708 | /** | ||
673 | * ID of master broadcast task | 709 | * ID of master broadcast task |
674 | */ | 710 | */ |
675 | static struct GNUNET_SCHEDULER_Task *broadcast_task; | 711 | static struct GNUNET_SCHEDULER_Task *broadcast_task; |
@@ -847,6 +883,7 @@ kce_destroy (struct KeyCacheEntry *kce) | |||
847 | struct SharedSecret *ss = kce->ss; | 883 | struct SharedSecret *ss = kce->ss; |
848 | 884 | ||
849 | ss->active_kce_count--; | 885 | ss->active_kce_count--; |
886 | ss->sender->acks_available--; | ||
850 | GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce); | 887 | GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce); |
851 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache, | 888 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache, |
852 | &kce->kid, | 889 | &kce->kid, |
@@ -902,6 +939,7 @@ kce_generate (struct SharedSecret *ss, uint32_t seq) | |||
902 | get_kid (&ss->master, seq, &kce->kid); | 939 | get_kid (&ss->master, seq, &kce->kid); |
903 | GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce); | 940 | GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce); |
904 | ss->active_kce_count++; | 941 | ss->active_kce_count++; |
942 | ss->sender->acks_available++; | ||
905 | (void) GNUNET_CONTAINER_multishortmap_put ( | 943 | (void) GNUNET_CONTAINER_multishortmap_put ( |
906 | key_cache, | 944 | key_cache, |
907 | &kce->kid, | 945 | &kce->kid, |
@@ -920,12 +958,20 @@ kce_generate (struct SharedSecret *ss, uint32_t seq) | |||
920 | * @param ss shared secret to destroy | 958 | * @param ss shared secret to destroy |
921 | */ | 959 | */ |
922 | static void | 960 | static void |
923 | secret_destroy (struct SharedSecret *ss) | 961 | secret_destroy (struct SharedSecret *ss, int withoutKce) |
924 | { | 962 | { |
925 | struct SenderAddress *sender; | 963 | struct SenderAddress *sender; |
926 | struct ReceiverAddress *receiver; | 964 | struct ReceiverAddress *receiver; |
927 | struct KeyCacheEntry *kce; | 965 | struct KeyCacheEntry *kce; |
928 | 966 | ||
967 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
968 | "secret destroy %u %u\n", | ||
969 | withoutKce, | ||
970 | ss->sequence_allowed); | ||
971 | |||
972 | if (withoutKce && (ss->sequence_allowed > 0)) | ||
973 | return; | ||
974 | |||
929 | if (NULL != (sender = ss->sender)) | 975 | if (NULL != (sender = ss->sender)) |
930 | { | 976 | { |
931 | GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); | 977 | GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); |
@@ -935,7 +981,9 @@ secret_destroy (struct SharedSecret *ss) | |||
935 | { | 981 | { |
936 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); | 982 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); |
937 | receiver->num_secrets--; | 983 | receiver->num_secrets--; |
984 | // Uncomment this for alternativ 1 of backchannel functionality | ||
938 | receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); | 985 | receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); |
986 | // Until here for alternativ 1 | ||
939 | } | 987 | } |
940 | while (NULL != (kce = ss->kce_head)) | 988 | while (NULL != (kce = ss->kce_head)) |
941 | kce_destroy (kce); | 989 | kce_destroy (kce); |
@@ -1284,8 +1332,11 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1284 | { | 1332 | { |
1285 | const struct UDPAck *ack = cls; | 1333 | const struct UDPAck *ack = cls; |
1286 | struct ReceiverAddress *receiver = value; | 1334 | struct ReceiverAddress *receiver = value; |
1335 | struct SharedSecret *pos; | ||
1336 | |||
1287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1288 | "in handle ack\n"); | 1338 | "in handle ack\n"); |
1339 | struct SharedSecret *ss_to_destroy; | ||
1289 | 1340 | ||
1290 | (void) pid; | 1341 | (void) pid; |
1291 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) | 1342 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) |
@@ -1301,9 +1352,12 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1301 | if (allowed > ss->sequence_allowed) | 1352 | if (allowed > ss->sequence_allowed) |
1302 | { | 1353 | { |
1303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1354 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1304 | "%u > %u (%u)\n", allowed, ss->sequence_allowed, | 1355 | "%u > %u (%u %u) for secrect %s\n", allowed, |
1305 | receiver->acks_available); | 1356 | ss->sequence_allowed, |
1306 | 1357 | receiver->acks_available, | |
1358 | ack->acks_available, | ||
1359 | GNUNET_h2s (&ss->master)); | ||
1360 | // Uncomment this for alternativ 1 of backchannel functionality | ||
1307 | receiver->acks_available += (allowed - ss->sequence_allowed); | 1361 | receiver->acks_available += (allowed - ss->sequence_allowed); |
1308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1309 | "Tell transport we have more acks!\n"); | 1363 | "Tell transport we have more acks!\n"); |
@@ -1312,11 +1366,33 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1312 | (allowed | 1366 | (allowed |
1313 | - ss->sequence_allowed), | 1367 | - ss->sequence_allowed), |
1314 | 1); | 1368 | 1); |
1369 | // Until here for alternativ 1 | ||
1315 | ss->sequence_allowed = allowed; | 1370 | ss->sequence_allowed = allowed; |
1316 | /* move ss to head to avoid discarding it anytime soon! */ | 1371 | /* move ss to head to avoid discarding it anytime soon! */ |
1317 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); | 1372 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); |
1318 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); | 1373 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); |
1374 | pos = receiver->ss_head; | ||
1375 | while ( NULL != pos) | ||
1376 | { | ||
1377 | ss_to_destroy = pos; | ||
1378 | pos = pos->next; | ||
1379 | |||
1380 | secret_destroy (ss_to_destroy, GNUNET_YES); | ||
1381 | } | ||
1319 | } | 1382 | } |
1383 | |||
1384 | // Uncomment this for alternativ 2 of backchannel functionality | ||
1385 | /*if (receiver->acks_available != ack->acks_available) | ||
1386 | { | ||
1387 | receiver->acks_available = ack->acks_available; | ||
1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1389 | "Tell transport we have different number of acks!\n"); | ||
1390 | GNUNET_TRANSPORT_communicator_mq_update (ch, | ||
1391 | receiver->d_qh, | ||
1392 | receiver->acks_available, | ||
1393 | 1); | ||
1394 | }*/ | ||
1395 | // Until here for alternativ 2 | ||
1320 | return GNUNET_NO; | 1396 | return GNUNET_NO; |
1321 | } | 1397 | } |
1322 | } | 1398 | } |
@@ -1370,6 +1446,36 @@ try_handle_plaintext (struct SenderAddress *sender, | |||
1370 | } | 1446 | } |
1371 | } | 1447 | } |
1372 | 1448 | ||
1449 | static void | ||
1450 | kce_generate_cb (void *cls) | ||
1451 | { | ||
1452 | struct SharedSecret *ss = cls; | ||
1453 | |||
1454 | |||
1455 | |||
1456 | if (ss->sender->acks_available < KCN_TARGET) | ||
1457 | { | ||
1458 | |||
1459 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1460 | "Precomputing keys\n"); | ||
1461 | |||
1462 | for (int i = 0; i < GENERATE_AT_ONCE; i++) | ||
1463 | kce_generate (ss, ++ss->sequence_allowed); | ||
1464 | |||
1465 | kce_task = GNUNET_SCHEDULER_add_delayed (WORKING_QUEUE_INTERVALL, | ||
1466 | kce_generate_cb, | ||
1467 | ss); | ||
1468 | } | ||
1469 | else | ||
1470 | { | ||
1471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1472 | "We have enough keys.\n"); | ||
1473 | ss_finished = ss; | ||
1474 | kce_task_finished = GNUNET_YES; | ||
1475 | } | ||
1476 | |||
1477 | |||
1478 | } | ||
1373 | 1479 | ||
1374 | /** | 1480 | /** |
1375 | * We established a shared secret with a sender. We should try to send | 1481 | * We established a shared secret with a sender. We should try to send |
@@ -1378,21 +1484,81 @@ try_handle_plaintext (struct SenderAddress *sender, | |||
1378 | * recently). | 1484 | * recently). |
1379 | * | 1485 | * |
1380 | * @param ss shared secret to generate ACKs for | 1486 | * @param ss shared secret to generate ACKs for |
1487 | * @param intial The SharedSecret came with initial KX. | ||
1381 | */ | 1488 | */ |
1382 | static void | 1489 | static void |
1383 | consider_ss_ack (struct SharedSecret *ss) | 1490 | consider_ss_ack (struct SharedSecret *ss, int initial) |
1384 | { | 1491 | { |
1492 | struct SharedSecret *ss_to_destroy; | ||
1493 | struct SharedSecret *pos; | ||
1494 | |||
1385 | GNUNET_assert (NULL != ss->sender); | 1495 | GNUNET_assert (NULL != ss->sender); |
1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1387 | "Considering SS UDPAck %s\n", | 1497 | "Considering SS UDPAck %s\n", |
1388 | GNUNET_i2s_full (&ss->sender->target)); | 1498 | GNUNET_i2s_full (&ss->sender->target)); |
1389 | 1499 | ||
1500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1501 | "We have %u acks available.\n", | ||
1502 | ss->sender->acks_available); | ||
1390 | /* drop ancient KeyCacheEntries */ | 1503 | /* drop ancient KeyCacheEntries */ |
1391 | while ((NULL != ss->kce_head) && | 1504 | while ((NULL != ss->kce_head) && |
1392 | (MAX_SQN_DELTA < | 1505 | (MAX_SQN_DELTA < |
1393 | ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) | 1506 | ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) |
1394 | kce_destroy (ss->kce_tail); | 1507 | kce_destroy (ss->kce_tail); |
1395 | if (ss->active_kce_count < KCN_THRESHOLD) | 1508 | |
1509 | |||
1510 | if (GNUNET_NO == initial) | ||
1511 | kce_generate (ss, ++ss->sequence_allowed); | ||
1512 | |||
1513 | /*if (0 == ss->sender->acks_available) | ||
1514 | { | ||
1515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1516 | "Generating keys\n"); | ||
1517 | while (ss->active_kce_count < KCN_TARGET) | ||
1518 | kce_generate (ss, ++ss->sequence_allowed); | ||
1519 | }*/ | ||
1520 | |||
1521 | if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial)) | ||
1522 | { | ||
1523 | struct UDPAck ack; | ||
1524 | |||
1525 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); | ||
1526 | ack.header.size = htons (sizeof(ack)); | ||
1527 | ack.sequence_max = htonl (ss_finished->sequence_allowed); | ||
1528 | ack.acks_available = ss->sender->acks_available; | ||
1529 | ack.cmac = ss_finished->cmac; | ||
1530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1531 | "Notifying transport of UDPAck %s with intial %u\n", | ||
1532 | GNUNET_i2s_full (&ss_finished->sender->target), | ||
1533 | initial); | ||
1534 | GNUNET_TRANSPORT_communicator_notify (ch, | ||
1535 | &ss_finished->sender->target, | ||
1536 | COMMUNICATOR_ADDRESS_PREFIX, | ||
1537 | &ack.header); | ||
1538 | pos = ss->sender->ss_head; | ||
1539 | while ( NULL != pos) | ||
1540 | { | ||
1541 | ss_to_destroy = pos; | ||
1542 | pos = pos->next; | ||
1543 | secret_destroy (ss_to_destroy, GNUNET_YES); | ||
1544 | } | ||
1545 | kce_task = NULL; | ||
1546 | } | ||
1547 | else if (((NULL == kce_task) && (KCN_THRESHOLD > | ||
1548 | ss->sender->acks_available)) || | ||
1549 | (ss->sender->num_secrets > MAX_SECRETS) ) | ||
1550 | { | ||
1551 | |||
1552 | // kce_generate (ss, ++ss->sequence_allowed); | ||
1553 | // kce_generate (ss, ++ss->sequence_allowed); | ||
1554 | kce_task = GNUNET_SCHEDULER_add_delayed (WORKING_QUEUE_INTERVALL, | ||
1555 | kce_generate_cb, | ||
1556 | ss); | ||
1557 | |||
1558 | } | ||
1559 | |||
1560 | |||
1561 | /*if (ss->active_kce_count < KCN_THRESHOLD) | ||
1396 | { | 1562 | { |
1397 | struct UDPAck ack; | 1563 | struct UDPAck ack; |
1398 | 1564 | ||
@@ -1402,11 +1568,13 @@ consider_ss_ack (struct SharedSecret *ss) | |||
1402 | * For the initial KX (active_kce_count==0), | 1568 | * For the initial KX (active_kce_count==0), |
1403 | * we only generate a single KCE to prevent | 1569 | * we only generate a single KCE to prevent |
1404 | * unnecessary overhead. | 1570 | * unnecessary overhead. |
1405 | */ | 1571 | |
1406 | if (0 < ss->active_kce_count) { | 1572 | if (0 < ss->active_kce_count) |
1573 | { | ||
1407 | while (ss->active_kce_count < KCN_TARGET) | 1574 | while (ss->active_kce_count < KCN_TARGET) |
1408 | kce_generate (ss, ++ss->sequence_allowed); | 1575 | kce_generate (ss, ++ss->sequence_allowed); |
1409 | } else { | 1576 | } |
1577 | else { | ||
1410 | kce_generate (ss, ++ss->sequence_allowed); | 1578 | kce_generate (ss, ++ss->sequence_allowed); |
1411 | } | 1579 | } |
1412 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); | 1580 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); |
@@ -1420,7 +1588,7 @@ consider_ss_ack (struct SharedSecret *ss) | |||
1420 | &ss->sender->target, | 1588 | &ss->sender->target, |
1421 | COMMUNICATOR_ADDRESS_PREFIX, | 1589 | COMMUNICATOR_ADDRESS_PREFIX, |
1422 | &ack.header); | 1590 | &ack.header); |
1423 | } | 1591 | }*/ |
1424 | } | 1592 | } |
1425 | 1593 | ||
1426 | 1594 | ||
@@ -1459,8 +1627,11 @@ decrypt_box (const struct UDPBox *box, | |||
1459 | "# bytes decrypted with BOX", | 1627 | "# bytes decrypted with BOX", |
1460 | sizeof(out_buf), | 1628 | sizeof(out_buf), |
1461 | GNUNET_NO); | 1629 | GNUNET_NO); |
1630 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1631 | "decrypted UDPBox with kid %s\n", | ||
1632 | GNUNET_sh2s (&box->kid)); | ||
1462 | try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf)); | 1633 | try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf)); |
1463 | consider_ss_ack (ss); | 1634 | consider_ss_ack (ss, GNUNET_NO); |
1464 | } | 1635 | } |
1465 | 1636 | ||
1466 | 1637 | ||
@@ -1530,8 +1701,8 @@ setup_sender (const struct GNUNET_PeerIdentity *target, | |||
1530 | { | 1701 | { |
1531 | struct SenderAddress *sender; | 1702 | struct SenderAddress *sender; |
1532 | struct SearchContext sc = { .address = address, | 1703 | struct SearchContext sc = { .address = address, |
1533 | .address_len = address_len, | 1704 | .address_len = address_len, |
1534 | .sender = NULL }; | 1705 | .sender = NULL }; |
1535 | 1706 | ||
1536 | GNUNET_CONTAINER_multipeermap_get_multiple (senders, | 1707 | GNUNET_CONTAINER_multipeermap_get_multiple (senders, |
1537 | target, | 1708 | target, |
@@ -1547,10 +1718,10 @@ setup_sender (const struct GNUNET_PeerIdentity *target, | |||
1547 | sender->address = GNUNET_memdup (address, address_len); | 1718 | sender->address = GNUNET_memdup (address, address_len); |
1548 | sender->address_len = address_len; | 1719 | sender->address_len = address_len; |
1549 | (void) GNUNET_CONTAINER_multipeermap_put ( | 1720 | (void) GNUNET_CONTAINER_multipeermap_put ( |
1550 | senders, | 1721 | senders, |
1551 | &sender->target, | 1722 | &sender->target, |
1552 | sender, | 1723 | sender, |
1553 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1724 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1554 | GNUNET_STATISTICS_set (stats, | 1725 | GNUNET_STATISTICS_set (stats, |
1555 | "# senders active", | 1726 | "# senders active", |
1556 | GNUNET_CONTAINER_multipeermap_size (receivers), | 1727 | GNUNET_CONTAINER_multipeermap_size (receivers), |
@@ -1587,10 +1758,10 @@ verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | |||
1587 | uhs.ephemeral = *ephemeral; | 1758 | uhs.ephemeral = *ephemeral; |
1588 | uhs.monotonic_time = uc->monotonic_time; | 1759 | uhs.monotonic_time = uc->monotonic_time; |
1589 | return GNUNET_CRYPTO_eddsa_verify ( | 1760 | return GNUNET_CRYPTO_eddsa_verify ( |
1590 | GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, | 1761 | GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, |
1591 | &uhs, | 1762 | &uhs, |
1592 | &uc->sender_sig, | 1763 | &uc->sender_sig, |
1593 | &uc->sender.public_key); | 1764 | &uc->sender.public_key); |
1594 | } | 1765 | } |
1595 | 1766 | ||
1596 | 1767 | ||
@@ -1610,22 +1781,22 @@ sockaddr_to_udpaddr_string (const struct sockaddr *address, | |||
1610 | 1781 | ||
1611 | switch (address->sa_family) | 1782 | switch (address->sa_family) |
1612 | { | 1783 | { |
1613 | case AF_INET: | 1784 | case AF_INET: |
1614 | GNUNET_asprintf (&ret, | 1785 | GNUNET_asprintf (&ret, |
1615 | "%s-%s", | 1786 | "%s-%s", |
1616 | COMMUNICATOR_ADDRESS_PREFIX, | 1787 | COMMUNICATOR_ADDRESS_PREFIX, |
1617 | GNUNET_a2s (address, address_len)); | 1788 | GNUNET_a2s (address, address_len)); |
1618 | break; | 1789 | break; |
1619 | 1790 | ||
1620 | case AF_INET6: | 1791 | case AF_INET6: |
1621 | GNUNET_asprintf (&ret, | 1792 | GNUNET_asprintf (&ret, |
1622 | "%s-%s", | 1793 | "%s-%s", |
1623 | COMMUNICATOR_ADDRESS_PREFIX, | 1794 | COMMUNICATOR_ADDRESS_PREFIX, |
1624 | GNUNET_a2s (address, address_len)); | 1795 | GNUNET_a2s (address, address_len)); |
1625 | break; | 1796 | break; |
1626 | 1797 | ||
1627 | default: | 1798 | default: |
1628 | GNUNET_assert (0); | 1799 | GNUNET_assert (0); |
1629 | } | 1800 | } |
1630 | return ret; | 1801 | return ret; |
1631 | } | 1802 | } |
@@ -1744,10 +1915,10 @@ sock_read (void *cls) | |||
1744 | "Unable to decrypt tag, dropping...\n"); | 1915 | "Unable to decrypt tag, dropping...\n"); |
1745 | GNUNET_free (ss); | 1916 | GNUNET_free (ss); |
1746 | GNUNET_STATISTICS_update ( | 1917 | GNUNET_STATISTICS_update ( |
1747 | stats, | 1918 | stats, |
1748 | "# messages dropped (no kid, AEAD decryption failed)", | 1919 | "# messages dropped (no kid, AEAD decryption failed)", |
1749 | 1, | 1920 | 1, |
1750 | GNUNET_NO); | 1921 | GNUNET_NO); |
1751 | return; | 1922 | return; |
1752 | } | 1923 | } |
1753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1924 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1778,9 +1949,9 @@ sock_read (void *cls) | |||
1778 | 1, | 1949 | 1, |
1779 | GNUNET_NO); | 1950 | GNUNET_NO); |
1780 | try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); | 1951 | try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); |
1781 | consider_ss_ack (ss); | 1952 | consider_ss_ack (ss, GNUNET_YES); |
1782 | if (sender->num_secrets > MAX_SECRETS) | 1953 | /*if (sender->num_secrets > MAX_SECRETS) |
1783 | secret_destroy (sender->ss_tail); | 1954 | secret_destroy (sender->ss_tail);*/ |
1784 | } | 1955 | } |
1785 | } | 1956 | } |
1786 | 1957 | ||
@@ -1859,9 +2030,9 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
1859 | else | 2030 | else |
1860 | { | 2031 | { |
1861 | GNUNET_log ( | 2032 | GNUNET_log ( |
1862 | GNUNET_ERROR_TYPE_ERROR, | 2033 | GNUNET_ERROR_TYPE_ERROR, |
1863 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | 2034 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", |
1864 | bindto); | 2035 | bindto); |
1865 | GNUNET_free (cp); | 2036 | GNUNET_free (cp); |
1866 | return NULL; | 2037 | return NULL; |
1867 | } | 2038 | } |
@@ -1939,8 +2110,8 @@ do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) | |||
1939 | memcpy (pad, &hdr, sizeof(hdr)); | 2110 | memcpy (pad, &hdr, sizeof(hdr)); |
1940 | } | 2111 | } |
1941 | GNUNET_assert ( | 2112 | GNUNET_assert ( |
1942 | 0 == | 2113 | 0 == |
1943 | gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); | 2114 | gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); |
1944 | } | 2115 | } |
1945 | 2116 | ||
1946 | 2117 | ||
@@ -1967,6 +2138,19 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq, | |||
1967 | size_t dpos; | 2138 | size_t dpos; |
1968 | gcry_cipher_hd_t out_cipher; | 2139 | gcry_cipher_hd_t out_cipher; |
1969 | struct SharedSecret *ss; | 2140 | struct SharedSecret *ss; |
2141 | struct SharedSecret *ss_to_destroy; | ||
2142 | struct SharedSecret *pos; | ||
2143 | |||
2144 | if (receiver->num_secrets > MAX_SECRETS) | ||
2145 | { | ||
2146 | pos = receiver->ss_head; | ||
2147 | while ( NULL != pos) | ||
2148 | { | ||
2149 | ss_to_destroy = pos; | ||
2150 | pos = pos->next; | ||
2151 | secret_destroy (ss_to_destroy, GNUNET_YES); | ||
2152 | } | ||
2153 | } | ||
1970 | 2154 | ||
1971 | 2155 | ||
1972 | GNUNET_assert (mq == receiver->kx_mq); | 2156 | GNUNET_assert (mq == receiver->kx_mq); |
@@ -2007,13 +2191,13 @@ mq_send_kx (struct GNUNET_MQ_Handle *mq, | |||
2007 | dpos += sizeof(uc); | 2191 | dpos += sizeof(uc); |
2008 | /* Append encrypted payload to dgram */ | 2192 | /* Append encrypted payload to dgram */ |
2009 | GNUNET_assert ( | 2193 | GNUNET_assert ( |
2010 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); | 2194 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); |
2011 | dpos += msize; | 2195 | dpos += msize; |
2012 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | 2196 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); |
2013 | /* Datagram starts with kx */ | 2197 | /* Datagram starts with kx */ |
2014 | kx.ephemeral = uhs.ephemeral; | 2198 | kx.ephemeral = uhs.ephemeral; |
2015 | GNUNET_assert ( | 2199 | GNUNET_assert ( |
2016 | 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); | 2200 | 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); |
2017 | gcry_cipher_close (out_cipher); | 2201 | gcry_cipher_close (out_cipher); |
2018 | memcpy (dgram, &kx, sizeof(kx)); | 2202 | memcpy (dgram, &kx, sizeof(kx)); |
2019 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, | 2203 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, |
@@ -2044,6 +2228,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq, | |||
2044 | { | 2228 | { |
2045 | struct ReceiverAddress *receiver = impl_state; | 2229 | struct ReceiverAddress *receiver = impl_state; |
2046 | uint16_t msize = ntohs (msg->size); | 2230 | uint16_t msize = ntohs (msg->size); |
2231 | struct GNUNET_TIME_Relative rt; | ||
2232 | struct SharedSecret *pos; | ||
2047 | 2233 | ||
2048 | GNUNET_assert (mq == receiver->d_mq); | 2234 | GNUNET_assert (mq == receiver->d_mq); |
2049 | if ((msize > receiver->d_mtu) || | 2235 | if ((msize > receiver->d_mtu) || |
@@ -2058,7 +2244,18 @@ mq_send_d (struct GNUNET_MQ_Handle *mq, | |||
2058 | /* begin "BOX" encryption method, scan for ACKs from tail! */ | 2244 | /* begin "BOX" encryption method, scan for ACKs from tail! */ |
2059 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) | 2245 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) |
2060 | { | 2246 | { |
2247 | if (0 < ss->sequence_used) | ||
2248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2249 | "Trying to send UDPBox with shared secrect %s sequence_used %u and ss->sequence_allowed %u\n", | ||
2250 | GNUNET_h2s (&ss->master), | ||
2251 | ss->sequence_used, | ||
2252 | ss->sequence_allowed); | ||
2253 | // Uncomment this for alternativ 1 of backchannel functionality | ||
2061 | if (ss->sequence_used >= ss->sequence_allowed) | 2254 | if (ss->sequence_used >= ss->sequence_allowed) |
2255 | // Until here for alternativ 1 | ||
2256 | // Uncomment this for alternativ 2 of backchannel functionality | ||
2257 | // if (0 == ss->sequence_allowed) | ||
2258 | // Until here for alternativ 2 | ||
2062 | { | 2259 | { |
2063 | continue; | 2260 | continue; |
2064 | } | 2261 | } |
@@ -2074,7 +2271,7 @@ mq_send_d (struct GNUNET_MQ_Handle *mq, | |||
2074 | /* Append encrypted payload to dgram */ | 2271 | /* Append encrypted payload to dgram */ |
2075 | dpos = sizeof(struct UDPBox); | 2272 | dpos = sizeof(struct UDPBox); |
2076 | GNUNET_assert ( | 2273 | GNUNET_assert ( |
2077 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); | 2274 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); |
2078 | dpos += msize; | 2275 | dpos += msize; |
2079 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | 2276 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); |
2080 | GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, | 2277 | GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, |
@@ -2087,14 +2284,43 @@ mq_send_d (struct GNUNET_MQ_Handle *mq, | |||
2087 | receiver->address, | 2284 | receiver->address, |
2088 | receiver->address_len)) | 2285 | receiver->address_len)) |
2089 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); | 2286 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); |
2287 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2288 | "Sending UDPBox to %s\n", GNUNET_a2s (receiver->address, | ||
2289 | receiver->address_len)); | ||
2090 | GNUNET_MQ_impl_send_continue (mq); | 2290 | GNUNET_MQ_impl_send_continue (mq); |
2091 | receiver->acks_available--; | 2291 | // receiver->acks_available--; |
2092 | if (0 == receiver->acks_available) | 2292 | if (0 == receiver->acks_available) |
2093 | { | 2293 | { |
2094 | /* We have no more ACKs */ | 2294 | /* We have no more ACKs */ |
2095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2096 | "No more acks\n"); | 2296 | "No more acks\n"); |
2097 | } | 2297 | } |
2298 | |||
2299 | /* (NULL == rekey_timeout) | ||
2300 | rekey_timeout = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); | ||
2301 | else | ||
2302 | { | ||
2303 | rt = GNUNET_TIME_absolute_get_remaining (rekey_timeout); | ||
2304 | if (0 == rt.rel_value_us) | ||
2305 | { | ||
2306 | rekey_timeout = NULL; | ||
2307 | pos = receiver->ss_head; | ||
2308 | while ( NULL != pos) | ||
2309 | { | ||
2310 | ss_to_destroy = pos; | ||
2311 | pos = pos->next; | ||
2312 | secret_destroy (ss_to_destroy, GNUNET_NO); | ||
2313 | } | ||
2314 | if (0 != receiver->acks_available) | ||
2315 | GNUNET_TRANSPORT_communicator_mq_update (ch, | ||
2316 | receiver->d_qh, | ||
2317 | // TODO We can not do this. But how can we signal this queue is not able to handle a message. Test code interprets q-len as additional length. | ||
2318 | -receiver->acks_available, | ||
2319 | 1); | ||
2320 | } | ||
2321 | }*/ | ||
2322 | |||
2323 | |||
2098 | return; | 2324 | return; |
2099 | } | 2325 | } |
2100 | } | 2326 | } |
@@ -2205,25 +2431,25 @@ setup_receiver_mq (struct ReceiverAddress *receiver) | |||
2205 | // GNUNET_assert (NULL == receiver->mq); | 2431 | // GNUNET_assert (NULL == receiver->mq); |
2206 | switch (receiver->address->sa_family) | 2432 | switch (receiver->address->sa_family) |
2207 | { | 2433 | { |
2208 | case AF_INET: | 2434 | case AF_INET: |
2209 | base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ | 2435 | base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ |
2210 | - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ | 2436 | - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ |
2211 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; | 2437 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; |
2212 | break; | 2438 | break; |
2213 | 2439 | ||
2214 | case AF_INET6: | 2440 | case AF_INET6: |
2215 | base_mtu = 1280 /* Minimum MTU required by IPv6 */ | 2441 | base_mtu = 1280 /* Minimum MTU required by IPv6 */ |
2216 | - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ | 2442 | - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ |
2217 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; | 2443 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; |
2218 | break; | 2444 | break; |
2219 | 2445 | ||
2220 | default: | 2446 | default: |
2221 | GNUNET_assert (0); | 2447 | GNUNET_assert (0); |
2222 | break; | 2448 | break; |
2223 | } | 2449 | } |
2224 | /* MTU based on full KX messages */ | 2450 | /* MTU based on full KX messages */ |
2225 | receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ | 2451 | receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ |
2226 | - sizeof(struct UDPConfirmation); /* 104 */ | 2452 | - sizeof(struct UDPConfirmation); /* 104 */ |
2227 | /* MTU based on BOXed messages */ | 2453 | /* MTU based on BOXed messages */ |
2228 | receiver->d_mtu = base_mtu - sizeof(struct UDPBox); | 2454 | receiver->d_mtu = base_mtu - sizeof(struct UDPBox); |
2229 | 2455 | ||
@@ -2314,10 +2540,10 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
2314 | receiver->target = *peer; | 2540 | receiver->target = *peer; |
2315 | receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len); | 2541 | receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len); |
2316 | (void) GNUNET_CONTAINER_multipeermap_put ( | 2542 | (void) GNUNET_CONTAINER_multipeermap_put ( |
2317 | receivers, | 2543 | receivers, |
2318 | &receiver->target, | 2544 | &receiver->target, |
2319 | receiver, | 2545 | receiver, |
2320 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2546 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2321 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2547 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2322 | "Added %s to receivers\n", | 2548 | "Added %s to receivers\n", |
2323 | GNUNET_i2s_full (&receiver->target)); | 2549 | GNUNET_i2s_full (&receiver->target)); |
@@ -2553,55 +2779,55 @@ ifc_broadcast (void *cls) | |||
2553 | 2779 | ||
2554 | switch (bi->sa->sa_family) | 2780 | switch (bi->sa->sa_family) |
2555 | { | 2781 | { |
2556 | case AF_INET: { | 2782 | case AF_INET: { |
2557 | static int yes = 1; | 2783 | static int yes = 1; |
2558 | static int no = 0; | 2784 | static int no = 0; |
2559 | ssize_t sent; | 2785 | ssize_t sent; |
2560 | 2786 | ||
2561 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | 2787 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2562 | SOL_SOCKET, | 2788 | SOL_SOCKET, |
2563 | SO_BROADCAST, | 2789 | SO_BROADCAST, |
2564 | &yes, | 2790 | &yes, |
2565 | sizeof(int))) | 2791 | sizeof(int))) |
2566 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 2792 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
2567 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, | 2793 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2568 | &bi->bcm, | 2794 | &bi->bcm, |
2569 | sizeof(bi->bcm), | 2795 | sizeof(bi->bcm), |
2570 | bi->ba, | 2796 | bi->ba, |
2571 | bi->salen); | 2797 | bi->salen); |
2572 | if (-1 == sent) | 2798 | if (-1 == sent) |
2573 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); | 2799 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); |
2574 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | 2800 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2575 | SOL_SOCKET, | 2801 | SOL_SOCKET, |
2576 | SO_BROADCAST, | 2802 | SO_BROADCAST, |
2577 | &no, | 2803 | &no, |
2578 | sizeof(int))) | 2804 | sizeof(int))) |
2579 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 2805 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
2580 | break; | 2806 | break; |
2581 | } | 2807 | } |
2582 | 2808 | ||
2583 | case AF_INET6: { | 2809 | case AF_INET6: { |
2584 | ssize_t sent; | 2810 | ssize_t sent; |
2585 | struct sockaddr_in6 dst; | 2811 | struct sockaddr_in6 dst; |
2586 | 2812 | ||
2587 | dst.sin6_family = AF_INET6; | 2813 | dst.sin6_family = AF_INET6; |
2588 | dst.sin6_port = htons (my_port); | 2814 | dst.sin6_port = htons (my_port); |
2589 | dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; | 2815 | dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; |
2590 | dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; | 2816 | dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; |
2591 | 2817 | ||
2592 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, | 2818 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2593 | &bi->bcm, | 2819 | &bi->bcm, |
2594 | sizeof(bi->bcm), | 2820 | sizeof(bi->bcm), |
2595 | (const struct sockaddr *) &dst, | 2821 | (const struct sockaddr *) &dst, |
2596 | sizeof(dst)); | 2822 | sizeof(dst)); |
2597 | if (-1 == sent) | 2823 | if (-1 == sent) |
2598 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); | 2824 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); |
2599 | break; | 2825 | break; |
2600 | } | 2826 | } |
2601 | 2827 | ||
2602 | default: | 2828 | default: |
2603 | GNUNET_break (0); | 2829 | GNUNET_break (0); |
2604 | break; | 2830 | break; |
2605 | } | 2831 | } |
2606 | } | 2832 | } |
2607 | 2833 | ||
@@ -2683,7 +2909,7 @@ iface_proc (void *cls, | |||
2683 | (const struct sockaddr_in6 *) broadcast_addr; | 2909 | (const struct sockaddr_in6 *) broadcast_addr; |
2684 | 2910 | ||
2685 | GNUNET_assert ( | 2911 | GNUNET_assert ( |
2686 | 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); | 2912 | 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); |
2687 | 2913 | ||
2688 | /* http://tools.ietf.org/html/rfc2553#section-5.2: | 2914 | /* http://tools.ietf.org/html/rfc2553#section-5.2: |
2689 | * | 2915 | * |
@@ -2820,17 +3046,17 @@ run (void *cls, | |||
2820 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); | 3046 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); |
2821 | switch (in->sa_family) | 3047 | switch (in->sa_family) |
2822 | { | 3048 | { |
2823 | case AF_INET: | 3049 | case AF_INET: |
2824 | my_port = ntohs (((struct sockaddr_in *) in)->sin_port); | 3050 | my_port = ntohs (((struct sockaddr_in *) in)->sin_port); |
2825 | break; | 3051 | break; |
2826 | 3052 | ||
2827 | case AF_INET6: | 3053 | case AF_INET6: |
2828 | my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port); | 3054 | my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port); |
2829 | break; | 3055 | break; |
2830 | 3056 | ||
2831 | default: | 3057 | default: |
2832 | GNUNET_break (0); | 3058 | GNUNET_break (0); |
2833 | my_port = 0; | 3059 | my_port = 0; |
2834 | } | 3060 | } |
2835 | stats = GNUNET_STATISTICS_create ("C-UDP", cfg); | 3061 | stats = GNUNET_STATISTICS_create ("C-UDP", cfg); |
2836 | senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); | 3062 | senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
@@ -2845,9 +3071,9 @@ run (void *cls, | |||
2845 | if (NULL == my_private_key) | 3071 | if (NULL == my_private_key) |
2846 | { | 3072 | { |
2847 | GNUNET_log ( | 3073 | GNUNET_log ( |
2848 | GNUNET_ERROR_TYPE_ERROR, | 3074 | GNUNET_ERROR_TYPE_ERROR, |
2849 | _ ( | 3075 | _ ( |
2850 | "Transport service is lacking key configuration settings. Exiting.\n")); | 3076 | "Transport service is lacking key configuration settings. Exiting.\n")); |
2851 | GNUNET_SCHEDULER_shutdown (); | 3077 | GNUNET_SCHEDULER_shutdown (); |
2852 | return; | 3078 | return; |
2853 | } | 3079 | } |
@@ -2923,8 +3149,8 @@ main (int argc, char *const *argv) | |||
2923 | options, | 3149 | options, |
2924 | &run, | 3150 | &run, |
2925 | NULL)) | 3151 | NULL)) |
2926 | ? 0 | 3152 | ? 0 |
2927 | : 1; | 3153 | : 1; |
2928 | GNUNET_free_nz ((void *) argv); | 3154 | GNUNET_free_nz ((void *) argv); |
2929 | return ret; | 3155 | return ret; |
2930 | } | 3156 | } |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 207c17f2f..92e37a91c 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -700,6 +700,7 @@ handle_send_transmit_continuation (void *cls, | |||
700 | 700 | ||
701 | delay = GNUNET_TIME_absolute_get_duration (stcc->send_time); | 701 | delay = GNUNET_TIME_absolute_get_duration (stcc->send_time); |
702 | addr = GST_neighbour_get_current_address (&stcc->target); | 702 | addr = GST_neighbour_get_current_address (&stcc->target); |
703 | #ifdef ENABLE_TTD | ||
703 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 704 | if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
704 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 705 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
705 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", | 706 | "It took us %s to send %u/%u bytes to %s (%d, %s)\n", |
@@ -718,6 +719,7 @@ handle_send_transmit_continuation (void *cls, | |||
718 | GNUNET_i2s (&stcc->target), | 719 | GNUNET_i2s (&stcc->target), |
719 | success, | 720 | success, |
720 | (NULL != addr) ? addr->transport_name : "%"); | 721 | (NULL != addr) ? addr->transport_name : "%"); |
722 | #endif | ||
721 | 723 | ||
722 | if (GNUNET_NO == stcc->down) | 724 | if (GNUNET_NO == stcc->down) |
723 | { | 725 | { |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 92ed2fe52..219fae57b 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -769,10 +769,10 @@ http_client_plugin_send (void *cls, | |||
769 | char *stat_txt; | 769 | char *stat_txt; |
770 | 770 | ||
771 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 771 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
772 | "Session %p/request %p: Sending message with %u to peer `%s' \n", | 772 | "Session %p/request %p: Sending message with %lu to peer `%s' \n", |
773 | s, | 773 | s, |
774 | s->put.easyhandle, | 774 | s->put.easyhandle, |
775 | msgbuf_size, | 775 | (unsigned long) msgbuf_size, |
776 | GNUNET_i2s (&s->address->peer)); | 776 | GNUNET_i2s (&s->address->peer)); |
777 | 777 | ||
778 | /* create new message and schedule */ | 778 | /* create new message and schedule */ |
@@ -1087,11 +1087,10 @@ client_send_cb (void *stream, | |||
1087 | if (msg->pos == msg->size) | 1087 | if (msg->pos == msg->size) |
1088 | { | 1088 | { |
1089 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1089 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1090 | "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", | 1090 | "Session %p/request %p: sent message with %lu bytes sent, removing message from queue\n", |
1091 | s, | 1091 | s, |
1092 | s->put.easyhandle, | 1092 | s->put.easyhandle, |
1093 | msg->size, | 1093 | (unsigned long) msg->size); |
1094 | msg->pos); | ||
1095 | /* Calling transmit continuation */ | 1094 | /* Calling transmit continuation */ |
1096 | GNUNET_CONTAINER_DLL_remove (s->msg_head, | 1095 | GNUNET_CONTAINER_DLL_remove (s->msg_head, |
1097 | s->msg_tail, | 1096 | s->msg_tail, |
@@ -1249,10 +1248,10 @@ client_receive (void *stream, | |||
1249 | size_t len = size * nmemb; | 1248 | size_t len = size * nmemb; |
1250 | 1249 | ||
1251 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1250 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1252 | "Session %p / request %p: Received %u bytes from peer `%s'\n", | 1251 | "Session %p / request %p: Received %lu bytes from peer `%s'\n", |
1253 | s, | 1252 | s, |
1254 | s->get.easyhandle, | 1253 | s->get.easyhandle, |
1255 | len, | 1254 | (unsigned long) len, |
1256 | GNUNET_i2s (&s->address->peer)); | 1255 | GNUNET_i2s (&s->address->peer)); |
1257 | now = GNUNET_TIME_absolute_get (); | 1256 | now = GNUNET_TIME_absolute_get (); |
1258 | if (now.abs_value_us < s->next_receive.abs_value_us) | 1257 | if (now.abs_value_us < s->next_receive.abs_value_us) |
@@ -1346,7 +1345,7 @@ client_run (void *cls) | |||
1346 | /* Log status of terminated request */ | 1345 | /* Log status of terminated request */ |
1347 | if ((0 != msg->data.result) || (http_statuscode != 200)) | 1346 | if ((0 != msg->data.result) || (http_statuscode != 200)) |
1348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1347 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1349 | "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n", | 1348 | "Session %p/request %p: %s request to `%s' ended with status %li reason %i: `%s'\n", |
1350 | s, msg->easy_handle, | 1349 | s, msg->easy_handle, |
1351 | (GNUNET_YES == put_request) ? "PUT" : "GET", | 1350 | (GNUNET_YES == put_request) ? "PUT" : "GET", |
1352 | GNUNET_i2s (&s->address->peer), | 1351 | GNUNET_i2s (&s->address->peer), |
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c index d81d6db9c..0e3778837 100644 --- a/src/transport/plugin_transport_http_common.c +++ b/src/transport/plugin_transport_http_common.c | |||
@@ -629,7 +629,7 @@ http_common_plugin_address_to_string (const char *plugin, | |||
629 | if (addr_str[ntohl (address->urlen) - 1] != '\0') | 629 | if (addr_str[ntohl (address->urlen) - 1] != '\0') |
630 | return NULL; | 630 | return NULL; |
631 | GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options), | 631 | GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options), |
632 | &address[1]); | 632 | (char*)&address[1]); |
633 | if (strlen (res) + 1 < 500) | 633 | if (strlen (res) + 1 < 500) |
634 | { | 634 | { |
635 | GNUNET_memcpy (rbuf, res, strlen (res) + 1); | 635 | GNUNET_memcpy (rbuf, res, strlen (res) + 1); |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index d1b21ba9c..6e95ca00c 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -745,10 +745,10 @@ http_server_plugin_send (void *cls, | |||
745 | char *stat_txt; | 745 | char *stat_txt; |
746 | 746 | ||
747 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 747 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
748 | "Session %p/request %p: Sending message with %u to peer `%s'\n", | 748 | "Session %p/request %p: Sending message with %lu to peer `%s'\n", |
749 | session, | 749 | session, |
750 | session->server_send, | 750 | session->server_send, |
751 | msgbuf_size, | 751 | (unsigned long) msgbuf_size, |
752 | GNUNET_i2s (&session->target)); | 752 | GNUNET_i2s (&session->target)); |
753 | 753 | ||
754 | /* create new message and schedule */ | 754 | /* create new message and schedule */ |
@@ -1270,8 +1270,8 @@ server_parse_url (struct HTTP_Server_Plugin *plugin, | |||
1270 | if (hash_length != plugin->peer_id_length) | 1270 | if (hash_length != plugin->peer_id_length) |
1271 | { | 1271 | { |
1272 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1272 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1273 | "URL target is %u bytes, expecting %u\n", | 1273 | "URL target is %lu bytes, expecting %u\n", |
1274 | hash_length, plugin->peer_id_length); | 1274 | (unsigned long) hash_length, plugin->peer_id_length); |
1275 | return GNUNET_SYSERR; | 1275 | return GNUNET_SYSERR; |
1276 | } | 1276 | } |
1277 | if (GNUNET_OK != | 1277 | if (GNUNET_OK != |
@@ -1616,8 +1616,8 @@ server_send_callback (void *cls, | |||
1616 | { | 1616 | { |
1617 | sc->connected = GNUNET_YES; | 1617 | sc->connected = GNUNET_YES; |
1618 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1618 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1619 | "Sent %u bytes to peer `%s' with session %p \n", | 1619 | "Sent %lu bytes to peer `%s' with session %p \n", |
1620 | bytes_read, | 1620 | (unsigned long) bytes_read, |
1621 | GNUNET_i2s (&s->target), | 1621 | GNUNET_i2s (&s->target), |
1622 | s); | 1622 | s); |
1623 | GNUNET_asprintf (&stat_txt, | 1623 | GNUNET_asprintf (&stat_txt, |
@@ -1761,14 +1761,14 @@ server_access_cb (void *cls, | |||
1761 | 1761 | ||
1762 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1762 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1763 | _ ( | 1763 | _ ( |
1764 | "Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), | 1764 | "Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %lu\n"), |
1765 | sc, | 1765 | sc, |
1766 | plugin->cur_request, | 1766 | plugin->cur_request, |
1767 | plugin->max_request, | 1767 | plugin->max_request, |
1768 | method, | 1768 | method, |
1769 | version, | 1769 | version, |
1770 | url, | 1770 | url, |
1771 | (*upload_data_size)); | 1771 | (unsigned long) (*upload_data_size)); |
1772 | if (NULL == sc) | 1772 | if (NULL == sc) |
1773 | { | 1773 | { |
1774 | /* CORS pre-flight request */ | 1774 | /* CORS pre-flight request */ |
@@ -1868,19 +1868,19 @@ server_access_cb (void *cls, | |||
1868 | 1868 | ||
1869 | /* (*upload_data_size > 0) for every segment received */ | 1869 | /* (*upload_data_size > 0) for every segment received */ |
1870 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1870 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1871 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", | 1871 | "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %lu bytes\n", |
1872 | s, sc, | 1872 | s, sc, |
1873 | GNUNET_i2s (&s->target), | 1873 | GNUNET_i2s (&s->target), |
1874 | http_common_plugin_address_to_string (plugin->protocol, | 1874 | http_common_plugin_address_to_string (plugin->protocol, |
1875 | s->address->address, | 1875 | s->address->address, |
1876 | s->address->address_length), | 1876 | s->address->address_length), |
1877 | *upload_data_size); | 1877 | (unsigned long) *upload_data_size); |
1878 | delay = GNUNET_TIME_absolute_get_remaining (s->next_receive); | 1878 | delay = GNUNET_TIME_absolute_get_remaining (s->next_receive); |
1879 | if (0 == delay.rel_value_us) | 1879 | if (0 == delay.rel_value_us) |
1880 | { | 1880 | { |
1881 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1881 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1882 | "PUT with %u bytes forwarded to MST\n", | 1882 | "PUT with %lu bytes forwarded to MST\n", |
1883 | *upload_data_size); | 1883 | (unsigned long) *upload_data_size); |
1884 | if (s->msg_tk == NULL) | 1884 | if (s->msg_tk == NULL) |
1885 | { | 1885 | { |
1886 | s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, | 1886 | s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index e3bc21543..8378a64dd 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -2010,8 +2010,8 @@ do_transmit (void *cls, size_t size, void *buf) | |||
2010 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); | 2010 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
2011 | session->bytes_in_queue -= pos->message_size; | 2011 | session->bytes_in_queue -= pos->message_size; |
2012 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2012 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2013 | "Failed to transmit %u byte message to `%s'.\n", | 2013 | "Failed to transmit %lu byte message to `%s'.\n", |
2014 | pos->message_size, | 2014 | (unsigned long) pos->message_size, |
2015 | GNUNET_i2s (&session->target)); | 2015 | GNUNET_i2s (&session->target)); |
2016 | ret += pos->message_size; | 2016 | ret += pos->message_size; |
2017 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); | 2017 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); |
@@ -2067,9 +2067,9 @@ do_transmit (void *cls, size_t size, void *buf) | |||
2067 | session->bytes_in_queue -= pos->message_size; | 2067 | session->bytes_in_queue -= pos->message_size; |
2068 | GNUNET_assert (size >= pos->message_size); | 2068 | GNUNET_assert (size >= pos->message_size); |
2069 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2069 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2070 | "Transmitting message of type %u size %u to peer %s at %s\n", | 2070 | "Transmitting message of type %u size %lu to peer %s at %s\n", |
2071 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), | 2071 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), |
2072 | pos->message_size, | 2072 | (unsigned long) pos->message_size, |
2073 | GNUNET_i2s (&session->target), | 2073 | GNUNET_i2s (&session->target), |
2074 | tcp_plugin_address_to_string (session->plugin, | 2074 | tcp_plugin_address_to_string (session->plugin, |
2075 | session->address->address, | 2075 | session->address->address, |
@@ -2192,8 +2192,8 @@ tcp_plugin_send (void *cls, | |||
2192 | pm->transmit_cont_cls = cont_cls; | 2192 | pm->transmit_cont_cls = cont_cls; |
2193 | 2193 | ||
2194 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2194 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2195 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 2195 | "Asked to transmit %lu bytes to `%s', added message to list.\n", |
2196 | msgbuf_size, | 2196 | (unsigned long) msgbuf_size, |
2197 | GNUNET_i2s (&session->target)); | 2197 | GNUNET_i2s (&session->target)); |
2198 | 2198 | ||
2199 | if (GNUNET_YES == | 2199 | if (GNUNET_YES == |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index ec3a0edd8..49e84dfe7 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1821,7 +1821,8 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1821 | struct GNUNET_ATS_Session *session = frag_ctx->session; | 1821 | struct GNUNET_ATS_Session *session = frag_ctx->session; |
1822 | size_t msg_len = ntohs (msg->size); | 1822 | size_t msg_len = ntohs (msg->size); |
1823 | 1823 | ||
1824 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); | 1824 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %lu bytes\n", |
1825 | (unsigned long) msg_len); | ||
1825 | udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msg_len); | 1826 | udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msg_len); |
1826 | udpw->session = session; | 1827 | udpw->session = session; |
1827 | udpw->msg_buf = (char *) &udpw[1]; | 1828 | udpw->msg_buf = (char *) &udpw[1]; |
@@ -1996,8 +1997,8 @@ udp_plugin_send (void *cls, | |||
1996 | return GNUNET_SYSERR; | 1997 | return GNUNET_SYSERR; |
1997 | } | 1998 | } |
1998 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1999 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1999 | "UDP transmits %u-byte message to `%s' using address `%s'\n", | 2000 | "UDP transmits %lu-byte message to `%s' using address `%s'\n", |
2000 | udpmlen, | 2001 | (unsigned long) udpmlen, |
2001 | GNUNET_i2s (&s->target), | 2002 | GNUNET_i2s (&s->target), |
2002 | udp_address_to_string (plugin, | 2003 | udp_address_to_string (plugin, |
2003 | s->address->address, | 2004 | s->address->address, |
@@ -3113,18 +3114,18 @@ remove_timeout_messages_and_select (struct Plugin *plugin, | |||
3113 | { | 3114 | { |
3114 | /* this message is not delayed */ | 3115 | /* this message is not delayed */ |
3115 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3116 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3116 | "Message for peer `%s' (%u bytes) is not delayed \n", | 3117 | "Message for peer `%s' (%lu bytes) is not delayed \n", |
3117 | GNUNET_i2s (&udpw->session->target), | 3118 | GNUNET_i2s (&udpw->session->target), |
3118 | udpw->payload_size); | 3119 | (unsigned long) udpw->payload_size); |
3119 | break; /* Found message to send, break */ | 3120 | break; /* Found message to send, break */ |
3120 | } | 3121 | } |
3121 | else | 3122 | else |
3122 | { | 3123 | { |
3123 | /* Message is delayed, try next */ | 3124 | /* Message is delayed, try next */ |
3124 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3125 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3125 | "Message for peer `%s' (%u bytes) is delayed for %s\n", | 3126 | "Message for peer `%s' (%lu bytes) is delayed for %s\n", |
3126 | GNUNET_i2s (&udpw->session->target), | 3127 | GNUNET_i2s (&udpw->session->target), |
3127 | udpw->payload_size, | 3128 | (unsigned long) udpw->payload_size, |
3128 | GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); | 3129 | GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); |
3129 | udpw = udpw->next; | 3130 | udpw = udpw->next; |
3130 | } | 3131 | } |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 9d3e7d354..2324914c9 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -1304,8 +1304,8 @@ unix_plugin_send (void *cls, | |||
1304 | return GNUNET_SYSERR; | 1304 | return GNUNET_SYSERR; |
1305 | } | 1305 | } |
1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1307 | "Sending %u bytes with session for peer `%s' `%s'\n", | 1307 | "Sending %lu bytes with session for peer `%s' `%s'\n", |
1308 | msgbuf_size, | 1308 | (unsigned long) msgbuf_size, |
1309 | GNUNET_i2s (&session->target), | 1309 | GNUNET_i2s (&session->target), |
1310 | unix_plugin_address_to_string (NULL, | 1310 | unix_plugin_address_to_string (NULL, |
1311 | session->address->address, | 1311 | session->address->address, |
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c index 3e173b8a4..924362ef2 100644 --- a/src/transport/tcp_connection_legacy.c +++ b/src/transport/tcp_connection_legacy.c | |||
@@ -1142,9 +1142,9 @@ RETRY: | |||
1142 | return; | 1142 | return; |
1143 | } | 1143 | } |
1144 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1144 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1145 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", | 1145 | "receive_ready read %lu/%lu bytes from `%s' (%p)!\n", |
1146 | (unsigned int) ret, | 1146 | (unsigned long) ret, |
1147 | connection->max, | 1147 | (unsigned long) connection->max, |
1148 | GNUNET_a2s (connection->addr, connection->addrlen), | 1148 | GNUNET_a2s (connection->addr, connection->addrlen), |
1149 | connection); | 1149 | connection); |
1150 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 1150 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
@@ -1327,8 +1327,8 @@ connect_error (void *cls) | |||
1327 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1327 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1328 | 1328 | ||
1329 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1329 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1330 | "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", | 1330 | "Transmission request of size %lu fails (%s/%u), connection failed (%p).\n", |
1331 | connection->nth.notify_size, | 1331 | (unsigned long) connection->nth.notify_size, |
1332 | connection->hostname, | 1332 | connection->hostname, |
1333 | connection->port, | 1333 | connection->port, |
1334 | connection); | 1334 | connection); |
@@ -1423,9 +1423,9 @@ RETRY: | |||
1423 | return; | 1423 | return; |
1424 | } | 1424 | } |
1425 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1425 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1426 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", | 1426 | "Connection transmitted %lu/%lu bytes to `%s' (%p)\n", |
1427 | (unsigned int) ret, | 1427 | (unsigned long) ret, |
1428 | have, | 1428 | (unsigned long) have, |
1429 | GNUNET_a2s (connection->addr, connection->addrlen), | 1429 | GNUNET_a2s (connection->addr, connection->addrlen), |
1430 | connection); | 1430 | connection); |
1431 | connection->write_buffer_pos += ret; | 1431 | connection->write_buffer_pos += ret; |
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index 12dce3993..8606b353b 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -1433,7 +1433,7 @@ LEGACY_SERVICE_run (int argc, | |||
1433 | { | 1433 | { |
1434 | clock_offset = skew_offset - skew_variance; | 1434 | clock_offset = skew_offset - skew_variance; |
1435 | GNUNET_TIME_set_offset (clock_offset); | 1435 | GNUNET_TIME_set_offset (clock_offset); |
1436 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); | 1436 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %lld ms\n", clock_offset); |
1437 | } | 1437 | } |
1438 | /* actually run service */ | 1438 | /* actually run service */ |
1439 | err = 0; | 1439 | err = 0; |
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c index e3573ac2c..8251a5169 100644 --- a/src/transport/test_communicator_basic.c +++ b/src/transport/test_communicator_basic.c | |||
@@ -82,6 +82,11 @@ static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; | |||
82 | 82 | ||
83 | static unsigned int iterations_left = TOTAL_ITERATIONS; | 83 | static unsigned int iterations_left = TOTAL_ITERATIONS; |
84 | 84 | ||
85 | #define TIMEOUT_MULTIPLIER 1 | ||
86 | |||
87 | #define DELAY \ | ||
88 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,50) | ||
89 | |||
85 | #define SHORT_BURST_WINDOW \ | 90 | #define SHORT_BURST_WINDOW \ |
86 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) | 91 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) |
87 | 92 | ||
@@ -97,13 +102,21 @@ enum TestPhase | |||
97 | }; | 102 | }; |
98 | 103 | ||
99 | 104 | ||
100 | static size_t num_sent = 0; | 105 | static size_t num_sent_short = 0; |
106 | |||
107 | static size_t num_sent_long = 0; | ||
108 | |||
109 | static size_t num_sent_size = 0; | ||
101 | 110 | ||
102 | static uint32_t ack = 0; | 111 | static uint32_t ack = 0; |
103 | 112 | ||
104 | static enum TestPhase phase; | 113 | static enum TestPhase phase; |
105 | 114 | ||
106 | static size_t num_received = 0; | 115 | static size_t num_received_short = 0; |
116 | |||
117 | static size_t num_received_long = 0; | ||
118 | |||
119 | static size_t num_received_size = 0; | ||
107 | 120 | ||
108 | static uint64_t avg_latency = 0; | 121 | static uint64_t avg_latency = 0; |
109 | 122 | ||
@@ -230,6 +243,10 @@ make_payload (size_t payload_size) | |||
230 | static void | 243 | static void |
231 | latency_timeout (void *cls) | 244 | latency_timeout (void *cls) |
232 | { | 245 | { |
246 | |||
247 | size_t num_sent = 0; | ||
248 | size_t num_received = 0; | ||
249 | |||
233 | to_task = NULL; | 250 | to_task = NULL; |
234 | if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0) | 251 | if (GNUNET_TIME_absolute_get_remaining (timeout).rel_value_us > 0) |
235 | { | 252 | { |
@@ -239,6 +256,21 @@ latency_timeout (void *cls) | |||
239 | return; | 256 | return; |
240 | } | 257 | } |
241 | 258 | ||
259 | switch (phase) | ||
260 | { | ||
261 | case TP_BURST_SHORT: | ||
262 | num_sent = num_sent_short; | ||
263 | num_received = num_received_short; | ||
264 | break; | ||
265 | case TP_BURST_LONG: | ||
266 | num_sent = num_sent_long; | ||
267 | num_received = num_received_long; | ||
268 | break; | ||
269 | case TP_SIZE_CHECK: | ||
270 | num_sent = num_sent_size; | ||
271 | num_received = num_received_size; | ||
272 | break; | ||
273 | } | ||
242 | LOG (GNUNET_ERROR_TYPE_ERROR, | 274 | LOG (GNUNET_ERROR_TYPE_ERROR, |
243 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", | 275 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", |
244 | phase, num_sent, num_received); | 276 | phase, num_sent, num_received); |
@@ -246,6 +278,8 @@ latency_timeout (void *cls) | |||
246 | GNUNET_SCHEDULER_shutdown (); | 278 | GNUNET_SCHEDULER_shutdown (); |
247 | } | 279 | } |
248 | 280 | ||
281 | /*static void | ||
282 | size_test (void *cls);*/ | ||
249 | 283 | ||
250 | static void | 284 | static void |
251 | size_test (void *cls) | 285 | size_test (void *cls) |
@@ -253,6 +287,9 @@ size_test (void *cls) | |||
253 | char *payload; | 287 | char *payload; |
254 | size_t max_size = 64000; | 288 | size_t max_size = 64000; |
255 | 289 | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "size_test_cb %u\n", | ||
292 | num_sent_size); | ||
256 | GNUNET_assert (TP_SIZE_CHECK == phase); | 293 | GNUNET_assert (TP_SIZE_CHECK == phase); |
257 | if (LONG_MESSAGE_SIZE != long_message_size) | 294 | if (LONG_MESSAGE_SIZE != long_message_size) |
258 | max_size = long_message_size; | 295 | max_size = long_message_size; |
@@ -260,7 +297,7 @@ size_test (void *cls) | |||
260 | return; /* Leave some room for our protocol, so not 2^16 exactly */ | 297 | return; /* Leave some room for our protocol, so not 2^16 exactly */ |
261 | ack += 10; | 298 | ack += 10; |
262 | payload = make_payload (ack); | 299 | payload = make_payload (ack); |
263 | num_sent++; | 300 | num_sent_size++; |
264 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 301 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
265 | (ack < max_size) | 302 | (ack < max_size) |
266 | ? &size_test | 303 | ? &size_test |
@@ -269,47 +306,98 @@ size_test (void *cls) | |||
269 | payload, | 306 | payload, |
270 | ack); | 307 | ack); |
271 | GNUNET_free (payload); | 308 | GNUNET_free (payload); |
272 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 309 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( |
310 | GNUNET_TIME_UNIT_SECONDS, | ||
311 | TIMEOUT_MULTIPLIER)); | ||
273 | } | 312 | } |
274 | 313 | ||
314 | /*static void | ||
315 | size_test (void *cls) | ||
316 | { | ||
317 | GNUNET_SCHEDULER_add_delayed (DELAY, | ||
318 | &size_test_cb, | ||
319 | NULL); | ||
320 | }*/ | ||
321 | |||
322 | static void | ||
323 | long_test (void *cls); | ||
275 | 324 | ||
276 | static void | 325 | static void |
277 | long_test (void *cls) | 326 | long_test_cb (void *cls) |
278 | { | 327 | { |
279 | char *payload; | 328 | char *payload; |
280 | 329 | ||
330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "long_test_cb %u/%u\n", | ||
332 | num_sent_long, | ||
333 | num_received_long); | ||
281 | payload = make_payload (long_message_size); | 334 | payload = make_payload (long_message_size); |
282 | num_sent++; | 335 | num_sent_long++; |
283 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 336 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
284 | (BURST_PACKETS == | 337 | ((BURST_PACKETS |
285 | num_sent) | 338 | * 0.91 == |
339 | num_received_long) || | ||
340 | (BURST_PACKETS == | ||
341 | num_sent_long)) | ||
286 | ? NULL | 342 | ? NULL |
287 | : &long_test, | 343 | : &long_test, |
288 | NULL, | 344 | NULL, |
289 | payload, | 345 | payload, |
290 | long_message_size); | 346 | long_message_size); |
291 | GNUNET_free (payload); | 347 | GNUNET_free (payload); |
292 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 348 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( |
349 | GNUNET_TIME_UNIT_SECONDS, | ||
350 | TIMEOUT_MULTIPLIER)); | ||
293 | } | 351 | } |
294 | 352 | ||
353 | static void | ||
354 | long_test (void *cls) | ||
355 | { | ||
356 | /*LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
357 | "long_test %u\n", | ||
358 | num_sent_long);*/ | ||
359 | GNUNET_SCHEDULER_add_delayed (DELAY, | ||
360 | &long_test_cb, | ||
361 | NULL); | ||
362 | } | ||
295 | 363 | ||
296 | static void | 364 | static void |
297 | short_test (void *cls) | 365 | short_test (void *cls); |
366 | |||
367 | static void | ||
368 | short_test_cb (void *cls) | ||
298 | { | 369 | { |
299 | char *payload; | 370 | char *payload; |
300 | 371 | ||
372 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
373 | "short_test_cb %u/%u\n", | ||
374 | num_sent_short, | ||
375 | num_received_short); | ||
301 | payload = make_payload (SHORT_MESSAGE_SIZE); | 376 | payload = make_payload (SHORT_MESSAGE_SIZE); |
302 | num_sent++; | 377 | num_sent_short++; |
303 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, | 378 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (my_tc, |
304 | (BURST_PACKETS == | 379 | ((BURST_PACKETS |
305 | num_sent) | 380 | * 0.91 == |
381 | num_received_short) || | ||
382 | (BURST_PACKETS == | ||
383 | num_sent_short)) | ||
306 | ? NULL | 384 | ? NULL |
307 | : &short_test, | 385 | : &short_test, |
308 | NULL, | 386 | NULL, |
309 | payload, | 387 | payload, |
310 | SHORT_MESSAGE_SIZE); | 388 | SHORT_MESSAGE_SIZE); |
311 | GNUNET_free (payload); | 389 | GNUNET_free (payload); |
312 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 390 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( |
391 | GNUNET_TIME_UNIT_SECONDS, | ||
392 | TIMEOUT_MULTIPLIER)); | ||
393 | } | ||
394 | |||
395 | static void | ||
396 | short_test (void *cls) | ||
397 | { | ||
398 | GNUNET_SCHEDULER_add_delayed (DELAY, | ||
399 | &short_test_cb, | ||
400 | NULL); | ||
313 | } | 401 | } |
314 | 402 | ||
315 | 403 | ||
@@ -373,12 +461,17 @@ add_queue_cb (void *cls, | |||
373 | else | 461 | else |
374 | long_message_size = LONG_MESSAGE_SIZE; | 462 | long_message_size = LONG_MESSAGE_SIZE; |
375 | phase = TP_BURST_SHORT; | 463 | phase = TP_BURST_SHORT; |
376 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 464 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( |
465 | GNUNET_TIME_UNIT_SECONDS, | ||
466 | TIMEOUT_MULTIPLIER)); | ||
377 | GNUNET_assert (NULL == to_task); | 467 | GNUNET_assert (NULL == to_task); |
378 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 468 | to_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( |
469 | GNUNET_TIME_UNIT_SECONDS, | ||
470 | TIMEOUT_MULTIPLIER), | ||
379 | &latency_timeout, | 471 | &latency_timeout, |
380 | NULL); | 472 | NULL); |
381 | prepare_test (NULL); | 473 | // prepare_test (NULL); |
474 | short_test (NULL); | ||
382 | } | 475 | } |
383 | 476 | ||
384 | 477 | ||
@@ -388,10 +481,26 @@ update_avg_latency (const char*payload) | |||
388 | struct GNUNET_TIME_AbsoluteNBO *ts_n; | 481 | struct GNUNET_TIME_AbsoluteNBO *ts_n; |
389 | struct GNUNET_TIME_Absolute ts; | 482 | struct GNUNET_TIME_Absolute ts; |
390 | struct GNUNET_TIME_Relative latency; | 483 | struct GNUNET_TIME_Relative latency; |
484 | size_t num_received = 0; | ||
391 | 485 | ||
392 | ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload; | 486 | ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload; |
393 | ts = GNUNET_TIME_absolute_ntoh (*ts_n); | 487 | ts = GNUNET_TIME_absolute_ntoh (*ts_n); |
394 | latency = GNUNET_TIME_absolute_get_duration (ts); | 488 | latency = GNUNET_TIME_absolute_get_duration (ts); |
489 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
490 | "Latency of received packet: %u\n", | ||
491 | latency); | ||
492 | switch (phase) | ||
493 | { | ||
494 | case TP_BURST_SHORT: | ||
495 | num_received = num_received_short; | ||
496 | break; | ||
497 | case TP_BURST_LONG: | ||
498 | num_received = num_received_long; | ||
499 | break; | ||
500 | case TP_SIZE_CHECK: | ||
501 | num_received = num_received_size; | ||
502 | break; | ||
503 | } | ||
395 | if (1 >= num_received) | 504 | if (1 >= num_received) |
396 | avg_latency = latency.rel_value_us; | 505 | avg_latency = latency.rel_value_us; |
397 | else | 506 | else |
@@ -400,7 +509,6 @@ update_avg_latency (const char*payload) | |||
400 | 509 | ||
401 | } | 510 | } |
402 | 511 | ||
403 | |||
404 | /** | 512 | /** |
405 | * @brief Handle an incoming message | 513 | * @brief Handle an incoming message |
406 | * | 514 | * |
@@ -412,7 +520,8 @@ update_avg_latency (const char*payload) | |||
412 | */ | 520 | */ |
413 | static void | 521 | static void |
414 | incoming_message_cb (void *cls, | 522 | incoming_message_cb (void *cls, |
415 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | 523 | struct |
524 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle | ||
416 | *tc_h, | 525 | *tc_h, |
417 | const char*payload, | 526 | const char*payload, |
418 | size_t payload_len) | 527 | size_t payload_len) |
@@ -424,7 +533,9 @@ incoming_message_cb (void *cls, | |||
424 | return; | 533 | return; |
425 | } | 534 | } |
426 | /* Reset timeout */ | 535 | /* Reset timeout */ |
427 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS); | 536 | timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply ( |
537 | GNUNET_TIME_UNIT_SECONDS, | ||
538 | TIMEOUT_MULTIPLIER)); | ||
428 | switch (phase) | 539 | switch (phase) |
429 | { | 540 | { |
430 | case TP_INIT: | 541 | case TP_INIT: |
@@ -433,30 +544,31 @@ incoming_message_cb (void *cls, | |||
433 | case TP_BURST_SHORT: | 544 | case TP_BURST_SHORT: |
434 | { | 545 | { |
435 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | 546 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); |
436 | num_received++; | 547 | num_received_short++; |
437 | duration = GNUNET_TIME_absolute_get_duration (start_short); | 548 | duration = GNUNET_TIME_absolute_get_duration (start_short); |
438 | update_avg_latency (payload); | 549 | update_avg_latency (payload); |
439 | if (num_received == BURST_PACKETS) | 550 | if (num_received_short == BURST_PACKETS * 0.91) |
440 | { | 551 | { |
441 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 552 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
442 | "Short size packet test done.\n"); | 553 | "Short size packet test done.\n"); |
443 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE | 554 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((SHORT_MESSAGE_SIZE |
444 | * num_received * 1000 | 555 | * num_received_short |
556 | * 1000 | ||
445 | * 1000) | 557 | * 1000) |
446 | / duration.rel_value_us); | 558 | / duration.rel_value_us); |
447 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 559 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
448 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 560 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
449 | (unsigned long) num_received, | 561 | (unsigned long) num_received_short, |
450 | (unsigned long) num_sent, | 562 | (unsigned long) num_sent_short, |
451 | (unsigned long long) duration.rel_value_us, | 563 | (unsigned long long) duration.rel_value_us, |
452 | goodput, | 564 | goodput, |
453 | (unsigned long long) avg_latency); | 565 | (unsigned long long) avg_latency); |
454 | GNUNET_free (goodput); | 566 | GNUNET_free (goodput); |
455 | start_long = GNUNET_TIME_absolute_get (); | 567 | start_long = GNUNET_TIME_absolute_get (); |
456 | phase = TP_BURST_LONG; | 568 | phase = TP_BURST_LONG; |
457 | num_sent = 0; | 569 | // num_sent_short = 0; |
458 | avg_latency = 0; | 570 | avg_latency = 0; |
459 | num_received = 0; | 571 | // num_received = 0; |
460 | long_test (NULL); | 572 | long_test (NULL); |
461 | } | 573 | } |
462 | break; | 574 | break; |
@@ -467,32 +579,34 @@ incoming_message_cb (void *cls, | |||
467 | { | 579 | { |
468 | LOG (GNUNET_ERROR_TYPE_WARNING, | 580 | LOG (GNUNET_ERROR_TYPE_WARNING, |
469 | "Ignoring packet with wrong length\n"); | 581 | "Ignoring packet with wrong length\n"); |
470 | return; // Ignore | 582 | return; // Ignore |
471 | } | 583 | } |
472 | num_received++; | 584 | num_received_long++; |
473 | duration = GNUNET_TIME_absolute_get_duration (start_long); | 585 | duration = GNUNET_TIME_absolute_get_duration (start_long); |
474 | update_avg_latency (payload); | 586 | update_avg_latency (payload); |
475 | if (num_received == BURST_PACKETS) | 587 | if (num_received_long == BURST_PACKETS * 0.91) |
476 | { | 588 | { |
477 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 589 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
478 | "Long size packet test done.\n"); | 590 | "Long size packet test done.\n"); |
479 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size | 591 | char *goodput = GNUNET_STRINGS_byte_size_fancy ((long_message_size |
480 | * num_received * 1000 | 592 | * num_received_long |
593 | * 1000 | ||
481 | * 1000) | 594 | * 1000) |
482 | / duration.rel_value_us); | 595 | / duration. |
596 | rel_value_us); | ||
483 | 597 | ||
484 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 598 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
485 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | 599 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", |
486 | (unsigned long) num_received, | 600 | (unsigned long) num_received_long, |
487 | (unsigned long) num_sent, | 601 | (unsigned long) num_sent_long, |
488 | (unsigned long long) duration.rel_value_us, | 602 | (unsigned long long) duration.rel_value_us, |
489 | goodput, | 603 | goodput, |
490 | (unsigned long long) avg_latency); | 604 | (unsigned long long) avg_latency); |
491 | GNUNET_free (goodput); | 605 | GNUNET_free (goodput); |
492 | ack = 0; | 606 | ack = 0; |
493 | phase = TP_SIZE_CHECK; | 607 | phase = TP_SIZE_CHECK; |
494 | num_received = 0; | 608 | // num_received = 0; |
495 | num_sent = 0; | 609 | // num_sent_long = 0; |
496 | avg_latency = 0; | 610 | avg_latency = 0; |
497 | size_test (NULL); | 611 | size_test (NULL); |
498 | } | 612 | } |
@@ -505,25 +619,29 @@ incoming_message_cb (void *cls, | |||
505 | GNUNET_assert (TP_SIZE_CHECK == phase); | 619 | GNUNET_assert (TP_SIZE_CHECK == phase); |
506 | if (LONG_MESSAGE_SIZE != long_message_size) | 620 | if (LONG_MESSAGE_SIZE != long_message_size) |
507 | max_size = long_message_size; | 621 | max_size = long_message_size; |
508 | num_received++; | 622 | num_received_size++; |
509 | update_avg_latency (payload); | 623 | update_avg_latency (payload); |
510 | if (num_received >= (max_size) / 10) | 624 | if (num_received_size >= (max_size) / 10) |
511 | { | 625 | { |
512 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 626 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
513 | "Size packet test done.\n"); | 627 | "Size packet test done.\n"); |
514 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | 628 | LOG (GNUNET_ERROR_TYPE_MESSAGE, |
515 | "%lu/%lu packets -- avg latency: %llu us\n", | 629 | "%lu/%lu packets -- avg latency: %llu us\n", |
516 | (unsigned long) num_received, | 630 | (unsigned long) num_received_size, |
517 | (unsigned long) num_sent, | 631 | (unsigned long) num_sent_size, |
518 | (unsigned long long) avg_latency); | 632 | (unsigned long long) avg_latency); |
519 | num_received = 0; | 633 | num_received_size = 0; |
520 | num_sent = 0; | 634 | num_sent_size = 0; |
521 | avg_latency = 0; | 635 | avg_latency = 0; |
522 | iterations_left--; | 636 | iterations_left--; |
523 | if (0 != iterations_left) | 637 | if (0 != iterations_left) |
524 | { | 638 | { |
525 | start_short = GNUNET_TIME_absolute_get (); | 639 | start_short = GNUNET_TIME_absolute_get (); |
526 | phase = TP_BURST_SHORT; | 640 | phase = TP_BURST_SHORT; |
641 | num_sent_short = 0; | ||
642 | num_sent_long = 0; | ||
643 | num_received_short = 0; | ||
644 | num_received_long = 0; | ||
527 | short_test (NULL); | 645 | short_test (NULL); |
528 | break; | 646 | break; |
529 | } | 647 | } |
@@ -561,8 +679,8 @@ static void | |||
561 | run (void *cls) | 679 | run (void *cls) |
562 | { | 680 | { |
563 | ret = 0; | 681 | ret = 0; |
564 | num_received = 0; | 682 | // num_received = 0; |
565 | num_sent = 0; | 683 | // num_sent = 0; |
566 | for (unsigned int i = 0; i < NUM_PEERS; i++) | 684 | for (unsigned int i = 0; i < NUM_PEERS; i++) |
567 | { | 685 | { |
568 | tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | 686 | tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 98cfd5e29..076fbf331 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -553,7 +553,12 @@ handle_update_queue_message (void *cls, | |||
553 | tc_queue->mtu = ntohl (msg->mtu); | 553 | tc_queue->mtu = ntohl (msg->mtu); |
554 | tc_queue->cs = msg->cs; | 554 | tc_queue->cs = msg->cs; |
555 | tc_queue->priority = ntohl (msg->priority); | 555 | tc_queue->priority = ntohl (msg->priority); |
556 | // Uncomment this for alternativ 1 of backchannel functionality | ||
556 | tc_queue->q_len += GNUNET_ntohll (msg->q_len); | 557 | tc_queue->q_len += GNUNET_ntohll (msg->q_len); |
558 | // Until here for alternativ 1 | ||
559 | // Uncomment this for alternativ 2 of backchannel functionality | ||
560 | // tc_queue->q_len = GNUNET_ntohll (msg->q_len); | ||
561 | // Until here for alternativ 2 | ||
557 | GNUNET_SERVICE_client_continue (client->client); | 562 | GNUNET_SERVICE_client_continue (client->client); |
558 | } | 563 | } |
559 | 564 | ||
@@ -1130,8 +1135,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send | |||
1130 | } | 1135 | } |
1131 | } | 1136 | } |
1132 | GNUNET_assert (NULL != tc_queue); | 1137 | GNUNET_assert (NULL != tc_queue); |
1138 | // Uncomment this for alternativ 1 of backchannel functionality | ||
1133 | if (tc_queue->q_len != GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED) | 1139 | if (tc_queue->q_len != GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED) |
1134 | tc_queue->q_len--; | 1140 | tc_queue->q_len--; |
1141 | // Until here for alternativ 1 | ||
1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1136 | "Sending message\n"); | 1143 | "Sending message\n"); |
1137 | inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size; | 1144 | inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size; |
diff --git a/src/util/bio.c b/src/util/bio.c index 39050bb87..43a2abc89 100644 --- a/src/util/bio.c +++ b/src/util/bio.c | |||
@@ -356,10 +356,10 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | |||
356 | if (big > max_length) | 356 | if (big > max_length) |
357 | { | 357 | { |
358 | GNUNET_asprintf (&h->emsg, | 358 | GNUNET_asprintf (&h->emsg, |
359 | _ ("String `%s' longer than allowed (%u > %u)"), | 359 | _ ("String `%s' longer than allowed (%u > %lu)"), |
360 | what, | 360 | what, |
361 | big, | 361 | big, |
362 | max_length); | 362 | (unsigned long) max_length); |
363 | return GNUNET_SYSERR; | 363 | return GNUNET_SYSERR; |
364 | } | 364 | } |
365 | buf = GNUNET_malloc (big); | 365 | buf = GNUNET_malloc (big); |
diff --git a/src/util/client.c b/src/util/client.c index 86dabe664..2df439175 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -654,7 +654,7 @@ try_connect_using_address (void *cls, | |||
654 | "Trying to connect using address `%s:%u'\n", | 654 | "Trying to connect using address `%s:%u'\n", |
655 | GNUNET_a2s (addr, | 655 | GNUNET_a2s (addr, |
656 | addrlen), | 656 | addrlen), |
657 | cstate->port); | 657 | (unsigned int) cstate->port); |
658 | ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen); | 658 | ap = GNUNET_malloc (sizeof(struct AddressProbe) + addrlen); |
659 | ap->addr = (const struct sockaddr *) &ap[1]; | 659 | ap->addr = (const struct sockaddr *) &ap[1]; |
660 | GNUNET_memcpy (&ap[1], | 660 | GNUNET_memcpy (&ap[1], |
diff --git a/src/util/configuration_loader.c b/src/util/configuration_loader.c index b9e5cb67f..a59477b25 100644 --- a/src/util/configuration_loader.c +++ b/src/util/configuration_loader.c | |||
@@ -47,7 +47,8 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
47 | 47 | ||
48 | base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname; | 48 | base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname; |
49 | 49 | ||
50 | if (NULL != (baseconfig = getenv (base_config_varname))) | 50 | if (NULL != base_config_varname |
51 | && NULL != (baseconfig = getenv (base_config_varname))) | ||
51 | { | 52 | { |
52 | baseconfig = GNUNET_strdup (baseconfig); | 53 | baseconfig = GNUNET_strdup (baseconfig); |
53 | } | 54 | } |
@@ -62,14 +63,16 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
62 | GNUNET_free (ipath); | 63 | GNUNET_free (ipath); |
63 | } | 64 | } |
64 | 65 | ||
65 | if (GNUNET_SYSERR == | 66 | char *dname = GNUNET_STRINGS_filename_expand (baseconfig); |
66 | GNUNET_CONFIGURATION_load_from (cfg, | 67 | GNUNET_free (baseconfig); |
67 | baseconfig)) | 68 | |
69 | if (GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES) && | ||
70 | GNUNET_SYSERR == GNUNET_CONFIGURATION_load_from (cfg, dname)) | ||
68 | { | 71 | { |
69 | GNUNET_free (baseconfig); | 72 | GNUNET_free (dname); |
70 | return GNUNET_SYSERR; /* no configuration at all found */ | 73 | return GNUNET_SYSERR; /* no configuration at all found */ |
71 | } | 74 | } |
72 | GNUNET_free (baseconfig); | 75 | GNUNET_free (dname); |
73 | if ((NULL != filename) && | 76 | if ((NULL != filename) && |
74 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) | 77 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) |
75 | { | 78 | { |
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 34b88d761..1f2dd2e5b 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -150,6 +150,8 @@ get_path_from_proc_maps () | |||
150 | FILE *f; | 150 | FILE *f; |
151 | char *lgu; | 151 | char *lgu; |
152 | 152 | ||
153 | if (NULL == current_pd->libname) | ||
154 | return NULL; | ||
153 | GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ()); | 155 | GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ()); |
154 | if (NULL == (f = fopen (fn, "r"))) | 156 | if (NULL == (f = fopen (fn, "r"))) |
155 | return NULL; | 157 | return NULL; |
diff --git a/src/util/program.c b/src/util/program.c index 8bda34b4f..b5484855c 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -232,15 +232,20 @@ GNUNET_PROGRAM_run2 (int argc, | |||
232 | sizeof(struct GNUNET_GETOPT_CommandLineOption), | 232 | sizeof(struct GNUNET_GETOPT_CommandLineOption), |
233 | &cmd_sorter); | 233 | &cmd_sorter); |
234 | loglev = NULL; | 234 | loglev = NULL; |
235 | xdg = getenv ("XDG_CONFIG_HOME"); | 235 | if (NULL != pd->config_file && NULL != pd->user_config_file) |
236 | if (NULL != xdg) | 236 | { |
237 | GNUNET_asprintf (&cfg_fn, | 237 | xdg = getenv ("XDG_CONFIG_HOME"); |
238 | "%s%s%s", | 238 | if (NULL != xdg) |
239 | xdg, | 239 | GNUNET_asprintf (&cfg_fn, |
240 | DIR_SEPARATOR_STR, | 240 | "%s%s%s", |
241 | pd->config_file); | 241 | xdg, |
242 | DIR_SEPARATOR_STR, | ||
243 | pd->config_file); | ||
244 | else | ||
245 | cfg_fn = GNUNET_strdup (pd->user_config_file); | ||
246 | } | ||
242 | else | 247 | else |
243 | cfg_fn = GNUNET_strdup (pd->user_config_file); | 248 | cfg_fn = NULL; |
244 | lpfx = GNUNET_strdup (binaryName); | 249 | lpfx = GNUNET_strdup (binaryName); |
245 | if (NULL != (spc = strstr (lpfx, " "))) | 250 | if (NULL != (spc = strstr (lpfx, " "))) |
246 | *spc = '\0'; | 251 | *spc = '\0'; |
@@ -269,7 +274,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
269 | } | 274 | } |
270 | else | 275 | else |
271 | { | 276 | { |
272 | if (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)) | 277 | if (NULL != cfg_fn && GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)) |
273 | { | 278 | { |
274 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) | 279 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) |
275 | { | 280 | { |
@@ -284,7 +289,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
284 | goto cleanup; | 289 | goto cleanup; |
285 | } | 290 | } |
286 | } | 291 | } |
287 | else | 292 | else if (NULL != cfg_fn) |
288 | { | 293 | { |
289 | GNUNET_free (cfg_fn); | 294 | GNUNET_free (cfg_fn); |
290 | cfg_fn = NULL; | 295 | cfg_fn = NULL; |
diff --git a/src/util/service.c b/src/util/service.c index ddd31181d..4c647430d 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -2120,7 +2120,9 @@ GNUNET_SERVICE_run_ (int argc, | |||
2120 | { | 2120 | { |
2121 | clock_offset = skew_offset - skew_variance; | 2121 | clock_offset = skew_offset - skew_variance; |
2122 | GNUNET_TIME_set_offset (clock_offset); | 2122 | GNUNET_TIME_set_offset (clock_offset); |
2123 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); | 2123 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2124 | "Skewing clock by %lld ms\n", | ||
2125 | (long long) clock_offset); | ||
2124 | } | 2126 | } |
2125 | GNUNET_RESOLVER_connect (sh.cfg); | 2127 | GNUNET_RESOLVER_connect (sh.cfg); |
2126 | 2128 | ||
diff --git a/src/util/strings.c b/src/util/strings.c index 9d6f4039e..0fb6eaf0c 100644 --- a/src/util/strings.c +++ b/src/util/strings.c | |||
@@ -176,7 +176,7 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, | |||
176 | char * | 176 | char * |
177 | GNUNET_STRINGS_byte_size_fancy (unsigned long long size) | 177 | GNUNET_STRINGS_byte_size_fancy (unsigned long long size) |
178 | { | 178 | { |
179 | const char *unit = _ (/* size unit */ "b"); | 179 | const char *unit = /* size unit */ "b"; |
180 | char *ret; | 180 | char *ret; |
181 | 181 | ||
182 | if (size > 5 * 1024) | 182 | if (size > 5 * 1024) |
@@ -703,43 +703,44 @@ GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, | |||
703 | int do_round) | 703 | int do_round) |
704 | { | 704 | { |
705 | static GNUNET_THREAD_LOCAL char buf[128]; | 705 | static GNUNET_THREAD_LOCAL char buf[128]; |
706 | const char *unit = _ (/* time unit */ "µs"); | 706 | const char *unit = /* time unit */ "µs"; |
707 | uint64_t dval = delta.rel_value_us; | 707 | uint64_t dval = delta.rel_value_us; |
708 | 708 | ||
709 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us) | 709 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us) |
710 | return _ ("forever"); | 710 | return "forever"; |
711 | if (0 == delta.rel_value_us) | 711 | if (0 == delta.rel_value_us) |
712 | return _ ("0 ms"); | 712 | return "0 ms"; |
713 | if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000))) | 713 | if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000))) |
714 | { | 714 | { |
715 | dval = dval / 1000; | 715 | dval = dval / 1000; |
716 | unit = _ (/* time unit */ "ms"); | 716 | unit = /* time unit */ "ms"; |
717 | if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000))) | 717 | if (((GNUNET_YES == do_round) && (dval > 5 * 1000)) || (0 == (dval % 1000))) |
718 | { | 718 | { |
719 | dval = dval / 1000; | 719 | dval = dval / 1000; |
720 | unit = _ (/* time unit */ "s"); | 720 | unit = /* time unit */ "s"; |
721 | if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60))) | 721 | if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60))) |
722 | { | 722 | { |
723 | dval = dval / 60; | 723 | dval = dval / 60; |
724 | unit = _ (/* time unit */ "m"); | 724 | unit = /* time unit */ "m"; |
725 | if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60))) | 725 | if (((GNUNET_YES == do_round) && (dval > 5 * 60)) || (0 == (dval % 60))) |
726 | { | 726 | { |
727 | dval = dval / 60; | 727 | dval = dval / 60; |
728 | unit = _ (/* time unit */ "h"); | 728 | unit = /* time unit */ "h"; |
729 | if (((GNUNET_YES == do_round) && (dval > 5 * 24)) || | 729 | if (((GNUNET_YES == do_round) && (dval > 5 * 24)) || |
730 | (0 == (dval % 24))) | 730 | (0 == (dval % 24))) |
731 | { | 731 | { |
732 | dval = dval / 24; | 732 | dval = dval / 24; |
733 | if (1 == dval) | 733 | if (1 == dval) |
734 | unit = _ (/* time unit */ "day"); | 734 | unit = /* time unit */ "day"; |
735 | else | 735 | else |
736 | unit = _ (/* time unit */ "days"); | 736 | unit = /* time unit */ "days"; |
737 | } | 737 | } |
738 | } | 738 | } |
739 | } | 739 | } |
740 | } | 740 | } |
741 | } | 741 | } |
742 | GNUNET_snprintf (buf, sizeof(buf), "%llu %s", dval, unit); | 742 | GNUNET_snprintf (buf, sizeof(buf), "%llu %s", |
743 | (unsigned long long) dval, unit); | ||
743 | return buf; | 744 | return buf; |
744 | } | 745 | } |
745 | 746 | ||
@@ -761,7 +762,7 @@ GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t) | |||
761 | struct tm *tp; | 762 | struct tm *tp; |
762 | 763 | ||
763 | if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 764 | if (t.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
764 | return _ ("end of time"); | 765 | return "end of time"; |
765 | tt = t.abs_value_us / 1000LL / 1000LL; | 766 | tt = t.abs_value_us / 1000LL / 1000LL; |
766 | tp = localtime (&tt); | 767 | tp = localtime (&tt); |
767 | /* This is hacky, but i don't know a way to detect libc character encoding. | 768 | /* This is hacky, but i don't know a way to detect libc character encoding. |
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am index 3d248efd8..f2d569c75 100644 --- a/src/zonemaster/Makefile.am +++ b/src/zonemaster/Makefile.am | |||
@@ -24,6 +24,7 @@ gnunet_service_zonemaster_SOURCES = \ | |||
24 | gnunet_service_zonemaster_LDADD = \ | 24 | gnunet_service_zonemaster_LDADD = \ |
25 | $(top_builddir)/src/dht/libgnunetdht.la \ | 25 | $(top_builddir)/src/dht/libgnunetdht.la \ |
26 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 26 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
27 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
27 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 28 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
28 | $(top_builddir)/src/util/libgnunetutil.la \ | 29 | $(top_builddir)/src/util/libgnunetutil.la \ |
29 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 30 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
@@ -32,10 +33,10 @@ gnunet_service_zonemaster_LDADD = \ | |||
32 | 33 | ||
33 | gnunet_service_zonemaster_monitor_SOURCES = \ | 34 | gnunet_service_zonemaster_monitor_SOURCES = \ |
34 | gnunet-service-zonemaster-monitor.c | 35 | gnunet-service-zonemaster-monitor.c |
35 | |||
36 | gnunet_service_zonemaster_monitor_LDADD = \ | 36 | gnunet_service_zonemaster_monitor_LDADD = \ |
37 | $(top_builddir)/src/dht/libgnunetdht.la \ | 37 | $(top_builddir)/src/dht/libgnunetdht.la \ |
38 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 38 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
39 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
39 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 40 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
40 | $(top_builddir)/src/util/libgnunetutil.la \ | 41 | $(top_builddir)/src/util/libgnunetutil.la \ |
41 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 42 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
diff --git a/src/zonemaster/gnunet-service-zonemaster-monitor.c b/src/zonemaster/gnunet-service-zonemaster-monitor.c index 4a368048e..c6dd2b6ca 100644 --- a/src/zonemaster/gnunet-service-zonemaster-monitor.c +++ b/src/zonemaster/gnunet-service-zonemaster-monitor.c | |||
@@ -240,7 +240,7 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | |||
240 | * @return DHT PUT handle, NULL on error | 240 | * @return DHT PUT handle, NULL on error |
241 | */ | 241 | */ |
242 | static struct GNUNET_DHT_PutHandle * | 242 | static struct GNUNET_DHT_PutHandle * |
243 | perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 243 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, |
244 | const char *label, | 244 | const char *label, |
245 | const struct GNUNET_GNSRECORD_Data *rd_public, | 245 | const struct GNUNET_GNSRECORD_Data *rd_public, |
246 | unsigned int rd_public_count, | 246 | unsigned int rd_public_count, |
@@ -271,9 +271,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
271 | GNUNET_break (0); | 271 | GNUNET_break (0); |
272 | return NULL; /* whoops */ | 272 | return NULL; /* whoops */ |
273 | } | 273 | } |
274 | block_size = ntohl (block->purpose.size) | 274 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
275 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) | ||
276 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
277 | GNUNET_GNSRECORD_query_from_private_key (key, | 275 | GNUNET_GNSRECORD_query_from_private_key (key, |
278 | label, | 276 | label, |
279 | &query); | 277 | &query); |
@@ -314,7 +312,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
314 | */ | 312 | */ |
315 | static void | 313 | static void |
316 | handle_monitor_event (void *cls, | 314 | handle_monitor_event (void *cls, |
317 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 315 | const struct GNUNET_IDENTITY_PrivateKey *zone, |
318 | const char *label, | 316 | const char *label, |
319 | unsigned int rd_count, | 317 | unsigned int rd_count, |
320 | const struct GNUNET_GNSRECORD_Data *rd) | 318 | const struct GNUNET_GNSRECORD_Data *rd) |
diff --git a/src/zonemaster/gnunet-service-zonemaster.c b/src/zonemaster/gnunet-service-zonemaster.c index c5aab8d92..11fa9921d 100644 --- a/src/zonemaster/gnunet-service-zonemaster.c +++ b/src/zonemaster/gnunet-service-zonemaster.c | |||
@@ -579,7 +579,7 @@ convert_records_for_export (const struct GNUNET_GNSRECORD_Data *rd, | |||
579 | * @return DHT PUT handle, NULL on error | 579 | * @return DHT PUT handle, NULL on error |
580 | */ | 580 | */ |
581 | static struct GNUNET_DHT_PutHandle * | 581 | static struct GNUNET_DHT_PutHandle * |
582 | perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 582 | perform_dht_put (const struct GNUNET_IDENTITY_PrivateKey *key, |
583 | const char *label, | 583 | const char *label, |
584 | const struct GNUNET_GNSRECORD_Data *rd_public, | 584 | const struct GNUNET_GNSRECORD_Data *rd_public, |
585 | unsigned int rd_public_count, | 585 | unsigned int rd_public_count, |
@@ -610,9 +610,7 @@ perform_dht_put (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
610 | GNUNET_break (0); | 610 | GNUNET_break (0); |
611 | return NULL; /* whoops */ | 611 | return NULL; /* whoops */ |
612 | } | 612 | } |
613 | block_size = ntohl (block->purpose.size) | 613 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
614 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) | ||
615 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
616 | GNUNET_GNSRECORD_query_from_private_key (key, | 614 | GNUNET_GNSRECORD_query_from_private_key (key, |
617 | label, | 615 | label, |
618 | &query); | 616 | &query); |
@@ -725,7 +723,7 @@ zone_iteration_finished (void *cls) | |||
725 | */ | 723 | */ |
726 | static void | 724 | static void |
727 | put_gns_record (void *cls, | 725 | put_gns_record (void *cls, |
728 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 726 | const struct GNUNET_IDENTITY_PrivateKey *key, |
729 | const char *label, | 727 | const char *label, |
730 | unsigned int rd_count, | 728 | unsigned int rd_count, |
731 | const struct GNUNET_GNSRECORD_Data *rd) | 729 | const struct GNUNET_GNSRECORD_Data *rd) |