diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-15 19:24:33 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-02-19 12:39:55 +0100 |
commit | b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc (patch) | |
tree | 47df762cdbcce501ec5536c8963b5c9ee55da31d /src/hello | |
parent | 3a71153405e8fc26712807b4bdb5987fb3bf2b9e (diff) | |
download | gnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.tar.gz gnunet-b0abdf7127f2403ff583d224e0d9d4e68c1c5bfc.zip |
-more work on DHTU integration
Diffstat (limited to 'src/hello')
-rw-r--r-- | src/hello/hello-uri.c | 149 |
1 files changed, 140 insertions, 9 deletions
diff --git a/src/hello/hello-uri.c b/src/hello/hello-uri.c index 49e4f6ed3..355443455 100644 --- a/src/hello/hello-uri.c +++ b/src/hello/hello-uri.c | |||
@@ -40,12 +40,6 @@ | |||
40 | #include "gnunet_protocols.h" | 40 | #include "gnunet_protocols.h" |
41 | #include "gnunet_util_lib.h" | 41 | #include "gnunet_util_lib.h" |
42 | 42 | ||
43 | /** | ||
44 | * For how long are HELLO signatures valid? | ||
45 | */ | ||
46 | #define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply ( \ | ||
47 | GNUNET_TIME_UNIT_DAYS, 2) | ||
48 | |||
49 | 43 | ||
50 | GNUNET_NETWORK_STRUCT_BEGIN | 44 | GNUNET_NETWORK_STRUCT_BEGIN |
51 | 45 | ||
@@ -72,7 +66,7 @@ struct HelloSignaturePurpose | |||
72 | }; | 66 | }; |
73 | 67 | ||
74 | /** | 68 | /** |
75 | * Binary block we sign when we sign an address. | 69 | * Message used when gossiping HELLOs between peers. |
76 | */ | 70 | */ |
77 | struct HelloUriMessage | 71 | struct HelloUriMessage |
78 | { | 72 | { |
@@ -117,6 +111,42 @@ struct BlockHeader | |||
117 | 111 | ||
118 | }; | 112 | }; |
119 | 113 | ||
114 | |||
115 | /** | ||
116 | * Message used when a DHT provides its HELLO to direct | ||
117 | * neighbours. | ||
118 | */ | ||
119 | struct DhtHelloMessage | ||
120 | { | ||
121 | /** | ||
122 | * Type must be #GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO | ||
123 | */ | ||
124 | struct GNUNET_MessageHeader header; | ||
125 | |||
126 | /** | ||
127 | * Reserved. 0. | ||
128 | */ | ||
129 | uint16_t reserved GNUNET_PACKED; | ||
130 | |||
131 | /** | ||
132 | * Number of URLs encoded after the end of the struct, in NBO. | ||
133 | */ | ||
134 | uint16_t url_counter GNUNET_PACKED; | ||
135 | |||
136 | /** | ||
137 | * Signature over the block, of purpose #GNUNET_SIGNATURE_PURPOSE_HELLO. | ||
138 | */ | ||
139 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
140 | |||
141 | /** | ||
142 | * When does the HELLO expire? | ||
143 | */ | ||
144 | struct GNUNET_TIME_AbsoluteNBO expiration_time; | ||
145 | |||
146 | /* followed by the serialized addresses of the 'block' */ | ||
147 | }; | ||
148 | |||
149 | |||
120 | GNUNET_NETWORK_STRUCT_END | 150 | GNUNET_NETWORK_STRUCT_END |
121 | 151 | ||
122 | 152 | ||
@@ -521,6 +551,11 @@ GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, | |||
521 | struct HelloUriMessage *msg; | 551 | struct HelloUriMessage *msg; |
522 | size_t blen; | 552 | size_t blen; |
523 | 553 | ||
554 | if (builder->a_length > UINT16_MAX) | ||
555 | { | ||
556 | GNUNET_break (0); | ||
557 | return NULL; | ||
558 | } | ||
524 | blen = 0; | 559 | blen = 0; |
525 | GNUNET_assert (GNUNET_NO == | 560 | GNUNET_assert (GNUNET_NO == |
526 | GNUNET_HELLO_builder_to_block (builder, | 561 | GNUNET_HELLO_builder_to_block (builder, |
@@ -530,6 +565,7 @@ GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, | |||
530 | env = GNUNET_MQ_msg_extra (msg, | 565 | env = GNUNET_MQ_msg_extra (msg, |
531 | blen, | 566 | blen, |
532 | GNUNET_MESSAGE_TYPE_HELLO_URI); | 567 | GNUNET_MESSAGE_TYPE_HELLO_URI); |
568 | msg->url_counter = htonl ((uint16_t) builder->a_length); | ||
533 | GNUNET_assert (GNUNET_OK == | 569 | GNUNET_assert (GNUNET_OK == |
534 | GNUNET_HELLO_builder_to_block (builder, | 570 | GNUNET_HELLO_builder_to_block (builder, |
535 | priv, | 571 | priv, |
@@ -539,6 +575,50 @@ GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder, | |||
539 | } | 575 | } |
540 | 576 | ||
541 | 577 | ||
578 | struct GNUNET_MessageHeader * | ||
579 | GNUNET_HELLO_builder_to_dht_hello_msg ( | ||
580 | const struct GNUNET_HELLO_Builder *builder, | ||
581 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) | ||
582 | { | ||
583 | struct DhtHelloMessage *msg; | ||
584 | size_t blen; | ||
585 | |||
586 | if (builder->a_length > UINT16_MAX) | ||
587 | { | ||
588 | GNUNET_break (0); | ||
589 | return NULL; | ||
590 | } | ||
591 | blen = 0; | ||
592 | GNUNET_assert (GNUNET_NO == | ||
593 | GNUNET_HELLO_builder_to_block (builder, | ||
594 | priv, | ||
595 | NULL, | ||
596 | &blen)); | ||
597 | GNUNET_assert (blen < UINT16_MAX); | ||
598 | GNUNET_assert (blen >= sizeof (struct BlockHeader)); | ||
599 | { | ||
600 | char buf[blen] GNUNET_ALIGN; | ||
601 | const struct BlockHeader *block = (const struct BlockHeader *) buf; | ||
602 | |||
603 | GNUNET_assert (GNUNET_OK == | ||
604 | GNUNET_HELLO_builder_to_block (builder, | ||
605 | priv, | ||
606 | buf, | ||
607 | &blen)); | ||
608 | msg = GNUNET_malloc (sizeof (*msg) + blen); | ||
609 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO); | ||
610 | msg->header.size = htons (sizeof (*msg) + blen); | ||
611 | memcpy (&msg[1], | ||
612 | &block[1], | ||
613 | blen - sizeof (*block)); | ||
614 | msg->sig = block->sig; | ||
615 | msg->expiration_time = block->expiration_time; | ||
616 | } | ||
617 | msg->url_counter = htonl ((uint16_t) builder->a_length); | ||
618 | return &msg->header; | ||
619 | } | ||
620 | |||
621 | |||
542 | char * | 622 | char * |
543 | GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, | 623 | GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, |
544 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) | 624 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) |
@@ -550,7 +630,7 @@ GNUNET_HELLO_builder_to_url (const struct GNUNET_HELLO_Builder *builder, | |||
550 | char *sigs; | 630 | char *sigs; |
551 | const char *sep = "?"; | 631 | const char *sep = "?"; |
552 | 632 | ||
553 | et = GNUNET_TIME_relative_to_timestamp (HELLO_ADDRESS_EXPIRATION); | 633 | et = GNUNET_TIME_relative_to_timestamp (GNUNET_HELLO_ADDRESS_EXPIRATION); |
554 | sign_hello (builder, | 634 | sign_hello (builder, |
555 | et, | 635 | et, |
556 | priv, | 636 | priv, |
@@ -629,7 +709,7 @@ GNUNET_HELLO_builder_to_block (const struct GNUNET_HELLO_Builder *builder, | |||
629 | return GNUNET_NO; | 709 | return GNUNET_NO; |
630 | } | 710 | } |
631 | bh.pid = builder->pid; | 711 | bh.pid = builder->pid; |
632 | et = GNUNET_TIME_relative_to_timestamp (HELLO_ADDRESS_EXPIRATION); | 712 | et = GNUNET_TIME_relative_to_timestamp (GNUNET_HELLO_ADDRESS_EXPIRATION); |
633 | bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_time); | 713 | bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_time); |
634 | sign_hello (builder, | 714 | sign_hello (builder, |
635 | et, | 715 | et, |
@@ -742,3 +822,54 @@ GNUNET_HELLO_builder_iterate (const struct GNUNET_HELLO_Builder *builder, | |||
742 | a->uri); | 822 | a->uri); |
743 | } | 823 | } |
744 | } | 824 | } |
825 | |||
826 | |||
827 | enum GNUNET_GenericReturnValue | ||
828 | GNUNET_HELLO_dht_msg_to_block (const struct GNUNET_MessageHeader *hello, | ||
829 | const struct GNUNET_PeerIdentity *pid, | ||
830 | void **block, | ||
831 | size_t *block_size, | ||
832 | struct GNUNET_TIME_Absolute *block_expiration) | ||
833 | { | ||
834 | const struct DhtHelloMessage *msg | ||
835 | = (const struct DhtHelloMessage *) hello; | ||
836 | uint16_t len = ntohs (hello->size); | ||
837 | struct BlockHeader *bh; | ||
838 | struct GNUNET_HELLO_Builder *b; | ||
839 | enum GNUNET_GenericReturnValue ret; | ||
840 | |||
841 | if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO != ntohs (hello->type)) | ||
842 | { | ||
843 | GNUNET_break (0); | ||
844 | return GNUNET_SYSERR; | ||
845 | } | ||
846 | if (len < sizeof (*msg)) | ||
847 | { | ||
848 | GNUNET_break (0); | ||
849 | return GNUNET_SYSERR; | ||
850 | } | ||
851 | len -= sizeof (*msg); | ||
852 | *block_size = len + sizeof (*bh); | ||
853 | *block = GNUNET_malloc (*block_size); | ||
854 | bh = *block; | ||
855 | bh->pid = *pid; | ||
856 | bh->sig = msg->sig; | ||
857 | bh->expiration_time = msg->expiration_time; | ||
858 | *block_expiration = GNUNET_TIME_absolute_ntoh (msg->expiration_time); | ||
859 | memcpy (&bh[1], | ||
860 | &msg[1], | ||
861 | len); | ||
862 | b = GNUNET_HELLO_builder_from_block (*block, | ||
863 | *block_size); | ||
864 | ret = verify_hello (b, | ||
865 | *block_expiration, | ||
866 | &msg->sig); | ||
867 | GNUNET_HELLO_builder_free (b); | ||
868 | if (GNUNET_SYSERR == ret) | ||
869 | { | ||
870 | GNUNET_free (*block); | ||
871 | *block_size = 0; | ||
872 | return GNUNET_SYSERR; | ||
873 | } | ||
874 | return ret; | ||
875 | } | ||