1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent" [
<!ENTITY RFC2119 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY RFC2782 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2782.xml">
<!ENTITY RFC3629 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml">
<!ENTITY RFC3686 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3686.xml">
<!ENTITY RFC3826 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3826.xml">
<!ENTITY RFC3912 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3912.xml">
<!ENTITY RFC3986 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3986.xml">
<!ENTITY RFC4648 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.4648.xml">
<!ENTITY RFC5869 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5869.xml">
<!ENTITY RFC5890 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5890.xml">
<!ENTITY RFC5891 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5891.xml">
<!ENTITY RFC6781 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6781.xml">
<!ENTITY RFC6895 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6895.xml">
<!ENTITY RFC6940 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6940.xml">
<!ENTITY RFC6979 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.6979.xml">
<!ENTITY RFC7748 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.7748.xml">
<!ENTITY RFC8032 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8032.xml">
<!ENTITY RFC8126 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8126.xml">
<!ENTITY RFC8174 PUBLIC '' "http://xml.resource.org/public/rfc/bibxml/reference.RFC.8174.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?rfc strict="yes" ?>
<?rfc toc="yes" ?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="info" docName="draft-schanzen-r5n-00" ipr="trust200902" obsoletes="" updates="" submissionType="IETF" xml:lang="en" version="3">
<!-- xml2rfc v2v3 conversion 2.26.0 -->
<front>
<title abbrev="The R5N Distributed Hash Table">
The R5N Distributed Hash Table
</title>
<seriesInfo name="Internet-Draft" value="draft-schanzen-r5n-00"/>
<author fullname="Martin Schanzenbach" initials="M." surname="Schanzenbach">
<organization>GNUnet e.V.</organization>
<address>
<postal>
<street>Boltzmannstrasse 3</street>
<city>Garching</city>
<code>85748</code>
<country>DE</country>
</postal>
<email>schanzen@gnunet.org</email>
</address>
</author>
<author fullname="Christian Grothoff" initials="C." surname="Grothoff">
<organization>Berner Fachhochschule</organization>
<address>
<postal>
<street>Hoeheweg 80</street>
<city>Biel/Bienne</city>
<code>2501</code>
<country>CH</country>
</postal>
<email>grothoff@gnunet.org</email>
</address>
</author>
<author fullname="Bernd Fix" initials="B." surname="Fix">
<organization>GNUnet e.V.</organization>
<address>
<postal>
<street>Boltzmannstrasse 3</street>
<city>Garching</city>
<code>85748</code>
<country>DE</country>
</postal>
<email>fix@gnunet.org</email>
</address>
</author>
<!-- Meta-data Declarations -->
<area>General</area>
<workgroup>Independent Stream</workgroup>
<keyword>distributed hash tables</keyword>
<abstract>
<t>This document contains the R5N DHT technical specification.</t>
<t>
This document defines the normative wire format of resource records,
resolution processes, cryptographic routines and security considerations for
use by implementers.
</t>
<t>
This specification was developed outside the IETF and does not have IETF
consensus. It is published here to guide implementation of R5N and to
ensure interoperability among implementations.
</t>
</abstract>
</front>
<middle>
<section anchor="introduction" numbered="true" toc="default">
<name>Introduction</name>
<!-- FIXME: Here we should also cite and discuss RELOAD (https://datatracker.ietf.org/doc/html/rfc6940)
and establish why we need this spec and are not a "Topology plugin"
in RELOAD. The argumentation revolves around the trust model (openness) and
security aspects (path signatures).
-->
<t>
Distributed Hash Tables (DHTs) are a key data structure for the
construction of completely decentralized applications.
DHTs are important because they generally provide a robust and
efficient means to distribute the storage and retrieval of
key-value pairs.
</t>
<t>
While <xref target="RFC6940" /> already provides a peer-to-peer (P2P)
signaling protocol with extensible routing and topology mechanisms,
it also relies on strict admission control through the use of either
centralized enrollment servers or pre-shared keys.
Modern decentralized applications require a more open system that
enables ad-hoc participation and other means to prevent common attacks
on P2P overlays.
</t>
<t>
This document contains the technical specification
of the R5N DHT <xref target="R5N" />, a secure DHT routing algorithm
and data structure for decentralized applications.
R5N is an open P2P overlay routing mechanism which supports ad-hoc
participation and security properties including support for
topologies in restricted-route environments and path signatures.
</t>
<t>
This document defines the normative wire format of peer-to-peer
messages, routing algorithms, cryptographic routines and security
considerations for use by implementors.
</t>
<section numbered="true" toc="default">
<name>Requirements Notation</name>
<t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only
when, they appear in all capitals, as shown here.
</t>
</section>
</section>
<section anchor="architecture" numbered="true" toc="default">
<name>Architecture</name>
<t>
R5N is an overlay network with a pluggable transport layer.
The following figure shows the R5N architecture.
</t>
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
| +-----------------+ +-------+
Applications | | GNU Name System | | CADET | ...
| +-----------------+ +-------+
-------------+------------------------------------ Overlay Interface
| ^
| | +---------------+
| | | Block Storage |
| | +---------------+
| | ^
R5N | v v
| +--------------------+ +---------+
| | Message Processing |<-->| Routing |
| +--------------------+ +---------+
| ^ ^
| v v
-------------+------------------------------------ Underlay Interface
| +--------+ +--------+
| |GNUnet | |IP | ...
Connectivity | |Underlay| |Underlay|
| |Link | |Link |
| +--------+ +--------+
]]></artwork>
</figure>
<dl>
<dt>Applications</dt>
<dd>
Applications are components which directly use the DHT overlay
interfaces. Possible applications include the GNU Name System
<xref target="I-D.draft-schanzen-gns" /> or the CADET transport system
<xref target="cadet" />.
</dd>
<dt>Overlay Interface</dt>
<dd>
The Overlay Interface exposes the core operations of the DHT overlay
to applications.
This includes querying and retrieving data from the DHT.
</dd>
<dt>Block Storage</dt>
<dd>
The Block Storage component is used to persist and manage data
by peers. It includes logic for quotas, caching stragegies and
data validation.
</dd>
<dt>Message Processing</dt>
<dd>
The Message Processing component processes requests from and responses
to applications as well as messages from the underlay network.
</dd>
<dt>Routing</dt>
<dd>
The Routing component includes the routing table as well as
routing and peer selection logic. It facilitates the R5N routing
algorithm with required data structures and algorithms.
</dd>
<dt>Underlay Interface</dt>
<dd>
The DHT Underlay Interface is an abstraction layer on top of the
supported links of a peer. Peers may be linked by a variety of
different transports, including "classical" protocols such as
TCP, UDP and TLS or advanced protocols such as GNUnet, L2P or Tor.
</dd>
</dl>
</section>
<section anchor="overlay" numbered="true" toc="default">
<name>Overlay</name>
<t>
In the DHT overlay, a peer is addressable by its Peer ID.
The Peer ID is the 256-bit hash of the peer public key.
The peer public key is the public key of the corresponding
Ed25519<xref target="ed25519" /> peer private key.
</t>
<t>
Any implementation of this specification MUST expose the two API
procedures "GET" and "PUT".
</t>
<section>
<name>The GET procedure</name>
<t>
The GET procedure is defined as follows:
</t>
<artwork name="" type="" align="left" alt=""><![CDATA[
GET(key[, options]) -> RESULTS as List
or
GET(key[, options], callbackFunction)
]]></artwork>
<t>
The procedure takes two arguments. The first argument is the query
key and is mandatory. The GET procedure may also allow the caller
to specifiy query options.
</t>
<t>
The procedure either returns a list of results or allows the caller
to provide a callback function which is called for any result
received from the DHT until the procedure is cancelled.
</t>
</section>
<section>
<name>The PUT procedure</name>
<t>
The PUT procedure is defined as follows:
</t>
<artwork name="" type="" align="left" alt=""><![CDATA[
PUT(key[, options], BLOCK)
]]></artwork>
<t>
The procedure takes three arguments. The first argument is the query
key and is mandatory. The PUT procedure may also allow the caller
to specifiy put options. The third argument is the payload data which
is to be stored under the provided put key.
</t>
</section>
</section>
<section anchor="blockstorage" numbered="true" toc="default">
<name>Block Storage</name>
<section>
<name>Block Types</name>
<t>
Applications can and should define their own block types.
The block type determines the format and handling of the block
payload by peers in PUT and RESULT messages.
Block types MUST be registered with GANA <xref target="gana"/>.
</t>
<t>
For bootstrapping and peer discovery, the DHT implementation uses
its own block type called "HELLO". A block with this block type
contains the peer ID of the peer initiating the GET request.
</t>
<section>
<name>HELLO</name>
<t>
The HELLO block type wire format is illustrated in
<xref target="figure_hellobt"/>. A block of type HELLO MUST NOT
include extended query data (xquery). Any implementation
encountering a HELLO block with xquery data MUST consider the
block invalid and ignore it.
</t>
<t>
A HELLO reply block MAY be empty. Otherwise, it contains the
HELLO URI of a peer.
</t>
<figure anchor="figure_hellobt">
<artwork name="" type="" align="left" alt=""><![CDATA[
FIXME: Wire format
]]></artwork>
</figure>
</section>
</section>
</section>
<section anchor="underlay" numbered="true" toc="default">
<name>Underlay</name>
<t>
In the network underlay, a peer is addressable by traditional
means out of scope of this document. For example, the peer may
have a TCP/IP address, or a HTTPS endpoint.
While the specific addressing options and mechanisms are out of scope
for this document, it is necessary to define a universal addressing
format in order to facilitate the distribution of connectivity
information to other peers in the DHT overlay.
This format is the "HELLO" message. A "HELLO" is a human-readable
UTF-8 <xref target="RFC3629" /> string consisting of the peer
public key and the HELLO URI <xref target="RFC3986" />.
</t>
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
hello-format := <peer-public-key> <hello-uri>
peer-public-key := [A-HJ-NP-Z1-9]+
]]></artwork>
</figure>
<t>
For the string representation of the peer public key,
the base-32 encoding "StringEncode" is used.
However, instead of following <xref target="RFC4648"/> the
character map is based on the optical character recognition friendly
proposal of Crockford <xref target="CrockfordB32"/>.
The only difference to Crockford is that the letter
"U" decodes to the same base-32 value as the letter "V" (27).
</t>
<t>
The "scheme" part of the HELLO URI defined the addressing scheme
which is used. An example of an addressing scheme used throughout
this document is "ip+tcp", which refers to a standard TCP/IP socket
connection. The "hier"-part of the URI must provide a suitable
address for the given addressing scheme.
The following is a non-normative example of a HELLO containing three
HELLO URIs:
</t>
<!-- FIXME peer id type | length | id payload | 0-terminated strings for addresses -->
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
Y924NSHMMZ1N1SQCE5TXF93ED6S6JY311K0QT86G9WJC68F6XVZ0 \
ip+tcp://1.2.3.4:6789 \
gnunet+tcp://12.3.4.5/ \
i2p+udp://1.2.4.5:424/ \
tor+onionv3://rasdflkjasdfliasduf.onion/
]]></artwork>
</figure>
<!--
1) The current API is always fire+forget, it doesn't allow for flow
control. I think we need to add that, possibly for sending and receiving.
IDK.
2) I'm not sure what to do with the crypto: mandate EdDSA or allow the
underlay to do whatever public keys it likes.
We need keys in the overlay. (Path signatures). Do they need to
be the same keys???
3) I think we may want to mandate that the lower layer at least
authenticate the other peer (i.e. every UDP message could be in
cleartext, but would need to come with an EdDSA signature, alas 92 byte
overhead and a signature verification _required_). Otherwise, I don't
see how we can offer even the most minimal protections against peer
impersonation attacks. WDYT?
Security considerations? Prerequisites?
-->
<t>
It is expected that there are basic mechanisms available to
manage peer connectivity and addressing.
The required functionality are abstracted through the following
procedures and events:
</t>
<dl>
<dt>PEER_CONNECTED(phash,address)</dt>
<dd>
is a signal that allows the DHT to react to peers which connect.
Such an event triggers, for example, updates in the
routing table.
</dd>
<dt>PEER_DISCONNECTED(phash,address)</dt>
<dd>
is a signal that allows the DHT to react to peers which disconnect.
Such an event triggers, for example, updates in the
routing table.
</dd>
<dt>TRY_CONNECT(pid, address)</dt>
<dd>
A function which allows a peer to attempt the establishment of
a connection to another peer using an address.
</dd>
<dt>HOLD(pash)</dt>
<dd>
A function which tells the underlay to keep a hold on the connection
to another peer.
</dd>
<dt>DROP(pash)</dt>
<dd>
A function which tells the underlay to drop the connection to another
peer.
</dd>
<dt>RECEIVE(source, message)</dt>
<dd>
A function or event that allows the peer to receive protocol
messages as defined in this document from a connected peer.
</dd>
<dt>SEND(target, message)</dt>
<dd>
A function that allows a peer to send protocol messages as defined
in this document to a connected peer. If call to SEND fails,
the message has not been sent.
</dd>
<dt>NETWORK_SIZE_ESTIMATE(N)</dt>
<dd>
A function or event that provides estimates on the network size
for use in the DHT routing algorithms.
</dd>
<dt>ADDRESS_ADD(pk, address)</dt>
<dd>
The underlay signals us that an address was added.
This information is used, for example, to publish
connectivity as part of the bootstrapping and overlay creation.
</dd>
<dt>ADDRESS_DELETE(pk, address)</dt>
<dd>
The underlay signals us that an address was removed.
This information is used, for example, to publish
connectivity as part of the bootstrapping and overlay creation.
</dd>
<dt>VERIFY(blob)</dt>
<dd>
Signature verification by underlay.
</dd>
</dl>
</section>
<section anchor="routing" numbered="true" toc="default">
<name>Routing</name>
<section anchor="peer_selection" numbered="true" toc="default">
<name>Peer selection</name>
<t>
In order to select peers from the routing table which are suitable
destinations for sending messages, R5N uses a hybrid approach:
Given an estimated network size N, the peer selection for the
first N hops is random. After the initial N hops, peer selection
follows an XOR-based peer distance calculation.
</t>
<t>
As the message traverses a random path through the network for the
first N hops, it is essential that routing loops are avoided.
In R5N, a bloomfilter is used as part of the routing metadata in
messages. The bloomfilter is updates at each hop with the hops
peer identity.
For the next hop selection in both the random and the deterministic
case, any peer which is in the bloomfilter for the respective message
is not included in the peer selection process.
</t>
<!-- Fixme: We may want to propose our modified, optimized XOR metric here or reference Kademlia -->
<t>
The procedure to select a peer for a given message key and bloomfilter
is defined as follows:
</t>
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
PEER-SELECT(key, bloomfilter)
peers := <Select all known peers NOT in message bloomfilter>
IF hops >= N
dist := MAX_VALUE
FOR EACH p IN peers
IF XOR(p, key) < dist
dist := XOR(p, key)
target := p
END
END
ELSE
r := rand()
target := peers[r]
END
END
]]></artwork>
</figure>
<t>
The procedure to determine if we are the closest know peer for a given
message key and bloomfilter is defined as follows:
</t>
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
FIND-BUCKET(peerID, key, buckets)
N := MATCHING-BITS (peerID, key)
return Nth bucket FROM buckets
END
AM-CLOSEST-PEER(key, myPeerID, bloomfilter, buckets)
closestPeersBucket := FIND-BUCKET (myPeerID, key, buckets)
IF key == myPeerID
return TRUE
END
myDistance := XOR(myPeerID, key)
FOR EACH p IN closestPeersBucket
IF XOR(p, key) < myDistance
return FALSE
END
XOR(p, key) == myDistance
return TRUE
END
END
return TRUE
END
]]></artwork>
</figure>
</section>
</section>
<section anchor="p2p_messages" numbered="true" toc="default">
<name>Message Processing</name>
<section anchor="p2p_bf" numbered="true" toc="default">
<name>Bloomfilter</name>
<t>
In order to prevent circular routes, GET and PUT messages contain
a 128-bit Bloom filter (m=128). The Bloom filter is used to detect duplicate
peer IDs along the route.
A Bloom filter "bf" is initially empty, consisting only of zeroes.
There are two functions which can be invoked on the Bloom filter:
BF-SET(bf, e) and BF-TEST(bf, e) where "e" is an element which is to added
to the Bloom filter or queried against the set.
Any bloom filter uses k=16 different hash functions each of which is
defined as follows:
</t>
<figure>
<artwork name="" type="" align="left" alt=""><![CDATA[
BF-TEST(key, bloomfilter)
H_key := SHA512 (key) as UINT32[]
FOR i IN 0..15
bit := H_key[i] % 1024
IF bloomfilter[bit] IS SET
RETURN TRUE
END
END
RETURN FALSE
END
BF-SET(key, bloomfilter)
H_key := SHA512 (key) as UINT32[]
FOR i IN 0..15
bit := H_key[i] % 1024
bloomfilter[bit] := 1
END
END
]]></artwork>
</figure>
</section>
<section anchor="p2p_opts" numbered="true" toc="default">
<name>Processing options</name>
<t>
In order to indicate certain processing requirements for messages
a number of processing options may be specificied in the respective
field of the signalling messages.
The options field is 8 octets in length and each options is encoded
in a single bit.
</t>
<dl>
<dt>Demultiplex everywhere (0)</dt>
<dd>
Each peer along the way should process the request. Otherwise
only peers that are locally closest to the key and no longer in the
random path mode should process it.
</dd>
<dt>Record route (1)</dt>
<dd>
Indicates to keep track of the route that the message
took in the P2P network.
</dd>
<dt>Find peer (2)</dt>
<dd>
Indicates a 'FIND-PEER' request. Implies that approximate results are
acceptable.
</dd>
</dl>
</section>
<section anchor="p2p_xq" numbered="true" toc="default">
<name>Extended query</name>
<t>TODO: What is this for? Not documented anywhere</t>
</section>
<section anchor="p2p_put" numbered="true" toc="default">
<name>PUT message</name>
<section anchor="p2p_put_wire">
<name>Wire Format</name>
<figure anchor="figure_putmsg">
<artwork name="" type="" align="left" alt=""><![CDATA[
0 8 16 24 32 40 48 56
+-----+-----+-----+-----+-----+-----+-----+-----+
| MSIZE | MTYPE | BTYPE |
+-----+-----+-----+-----+-----+-----+-----+-----+
| OPTIONS | HOPCOUNT | REPL_LVL | PATH_LEN |
+-----+-----+-----+-----+-----+-----+-----+-----+
| EXPIRATION |
+-----+-----+-----+-----+-----+-----+-----+-----+
| BLOOMFILTER /
/ (128 byte) |
+-----+-----+-----+-----+-----+-----+-----+-----+
| KEY /
/ (64 byte) |
+-----+-----+-----+-----+-----+-----+-----+-----+
/ PUTPATH (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
/ BLOCK (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
]]></artwork>
</figure>
<t>where:</t>
<dl>
<dt>MSIZE</dt>
<dd>
denotes the size of this message in network byte order.
</dd>
<dt>MTYPE</dt>
<dd>
is the 16-bit message type. This type can be one of the DHT message
types but for put messages it must be set to
the value 146 in network byte order.
</dd>
<dt>BTYPE</dt>
<dd>
is a 32-bit block type field. The block type indicates the content
type of the payload. In network byte order.
</dd>
<dt>OPTIONS</dt>
<dd>
is a 16-bit options field (see below).
</dd>
<dt>HOPCOUNT</dt>
<dd>
is a 16-bit number indicating how many hops this message has
traversed to far. In network byte order.
</dd>
<dt>REPL_LVL</dt>
<dd>
is a 16-bit number indicating the desired replication level of
the data. In network byte order.
</dd>
<dt>PATH_LEN</dt>
<dd>
is a 16-bit number indicating the length of the PUT path recorded
in PUTPATH. As PUTPATH is optiona, this value may be zero.
In network byte order.
</dd>
<dt>EXPIRATION</dt>
<dd>
denotes the absolute 64-bit expiration date of the content.
In microseconds since midnight (0 hour), January 1, 1970 in network
byte order.
</dd>
<dt>BLOOMFILTER</dt>
<dd>
A bloomfilter (for peer identities) to stop circular routes.
</dd>
<dt>KEY</dt>
<dd>
The key under which the PUT request wants to store content
under.
</dd>
<dt>PUTPATH</dt>
<dd>
the variable-length PUT path.
The path consists of a list of PATH_LEN peer IDs.
</dd>
<dt>BLOCK</dt>
<dd>
the variable-length block payload. The contents are determined
by the BTYPE field.
</dd>
</dl>
</section>
<section anchor="p2p_put_processing">
<name>Processing</name>
<t>
Upon receiving a PUT message from a connected peer. An implementation
MUST process it step by step as follows:
</t>
<ol>
<li>
The EXPIRATION field is evaluated. If the message is expired,
it MUST be discarded.
</li>
<li>
If the BTYPE is not supported by the implementation, no validation
of the block payload is performed and processing continues at (4).
Else, the block MUST be validated as defined in (3).
</li>
<li>
The block key is extracted from BLOCK. If the block key
does not match KEY or cannot be extracted because the BLOCK
is malformed, the message MUST be discarded.
The block is evaluated. TODO FIXME: In the code, we do not really
do this. We should review.
</li>
<li>
The sender peer ID SHOULD be in the BLOOMFILTER. If not, the
implementation MAY log an error, but MUST continue.
</li>
<li>
If the "Record Route" flag is set in OPTIONS, add the local peer ID
to PUTPATH. FIXME: Should should come way later (?)
</li>
<li>
If the KEY of this PUT message is in the list of pending queries,
return the message through the API. FIXME: Is this a conversion to
a RESULT??
</li>
<li>
If the local peer is the closest peer (AM-CLOSEST-PEER) or the
"Demultiplex Everywhere" options flag ist set, the message MUST
be stored locally in the block storage.
</li>
<li>
Given the value in REPL_LVL, the number of peers to forward to
MUST be calculated (NUM-FORWARD-PEERS). If there is at least one
peer to forward to, the implementation SHOULD select up to this
number of peers to forward the message to. The implementation MAY
forward to fewer or no peers in order to handle resource constraints
such as bandwidth.
The message BLOOMFILTER MUST be updated with the local peer ID.
</li>
</ol>
</section>
</section>
<section anchor="p2p_get" numbered="true" toc="default">
<name>GET Message</name>
<section anchor="p2p_get_wire">
<name>Wire Format</name>
<figure anchor="figure_getmsg">
<artwork name="" type="" align="left" alt=""><![CDATA[
0 8 16 24 32 40 48 56
+-----+-----+-----+-----+-----+-----+-----+-----+
| MSIZE | MTYPE | BTYPE |
+-----+-----+-----+-----+-----+-----+-----+-----+
| OPTIONS | HOPCOUNT | REPL_LVL | XQ_SIZE |
+-----+-----+-----+-----+-----+-----+-----+-----+
| BLOOMFILTER /
/ (128 byte) |
+-----+-----+-----+-----+-----+-----+-----+-----+
| KEY /
/ (64 byte) |
+-----+-----+-----+-----+-----+-----+-----+-----+
/ BF_MUTATOR | XQUERY /
+-----+-----+-----+-----+ /
/ (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
/ BF_RESULT (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
]]></artwork>
</figure>
<t>where:</t>
<dl>
<dt>MSIZE</dt>
<dd>
denotes the size of this message in network byte order.
</dd>
<dt>MTYPE</dt>
<dd>
is the 16-bit message type. This type can be one of the DHT message
types but for put messages it must be set to
the value 147 in network byte order.
</dd>
<dt>BTYPE</dt>
<dd>
is a 32-bit block type field. The block type indicates the content
type of the payload. In network byte order.
</dd>
<dt>OPTIONS</dt>
<dd>
is a 16-bit options field (see below).
</dd>
<dt>HOPCOUNT</dt>
<dd>
is a 16-bit number indicating how many hops this message has
traversed to far. In network byte order.
</dd>
<dt>REPL_LVL</dt>
<dd>
is a 16-bit number indicating the desired replication level of
the data. In network byte order.
</dd>
<dt>XQ_SIZE</dt>
<dd>
is a 32-bit number indicating the length of the optional
extended query XQUERY. In network byte order.
</dd>
<dt>BLOOMFILTER</dt>
<dd>
A bloomfilter (for peer identities) to stop circular routes.
</dd>
<dt>KEY</dt>
<dd>
The key under which the PUT request wants to store content
under.
</dd>
<dt>XQUERY</dt>
<dd>
the variable-length extended query. Optional.
</dd>
<dt>BF_MUTATOR</dt>
<dd>
The 32-bit bloomfilter mutator for the result bloomfilter.
</dd>
<dt>RESULT_BF</dt>
<dd>
the variable-length result bloomfilter.
</dd>
</dl>
</section>
<section anchor="p2p_get_processing">
<name>Processing</name>
<t>
Upon receiving a GET message from a connected peer. An implementation
MUST process it step by step as follows:
</t>
<ol>
<li>
The KEY and XQUERY is validated against the requested BTYPE.
If the BTYPE is not supported, or if the block key
does not match the BTYPE or if the XQUERY is malformed,
the message MUST be discarded.
</li>
<li>
The sender peer ID SHOULD be in the BLOOMFILTER. If not, the
implementation MAY log an error, but MUST continue.
</li>
<li>
<t>
If the local peer is the closest peer (AM-CLOSEST-PEER) or the
"Demultiplex Everywhere" options flag is set, a reply MUST be
produced:
</t>
<ol>
<li>
If OPTIONS indicate a "Find Peer" request, FIXME the peer selection
foo from buckets that probably needs fixing. Take into account
REPLY_BF
</li>
<li>
Else, if there is a BLOCK in the local Block Storage which is
not already in the RESULT_BF, a RESULT message MUST be sent.
FIXME link to how the result is sent?
</li>
</ol>
</li>
<li>
FIXME: We only handle if not GNUNET_BLOCK_EVALUATION_OK_LAST??
</li>
<li>
Given the value in REPL_LVL, the number of peers to forward to
MUST be calculated (NUM-FORWARD-PEERS). If there is at least one
peer to forward to, the implementation SHOULD select up to this
number of peers to forward the message to. The implementation MAY
forward to fewer or no peers in order to handle resource constraints
such as bandwidth.
The message BLOOMFILTER MUST be updated with the local peer ID.
</li>
</ol>
</section>
</section>
<section anchor="p2p_result" numbered="true" toc="default">
<name>RESULT message</name>
<section anchor="p2p_result_wire">
<name>Wire Format</name>
<figure anchor="figure_resmsg">
<artwork name="" type="" align="left" alt=""><![CDATA[
0 8 16 24 32 40 48 56
+-----+-----+-----+-----+-----+-----+-----+-----+
| MSIZE | MTYPE | BTYPE |
+-----+-----+-----+-----+-----+-----+-----+-----+
| // | OPTIONS | PUTPATH_L | GETPATH_L |
+-----+-----+-----+-----+-----+-----+-----+-----+
| EXPIRATION |
+-----+-----+-----+-----+-----+-----+-----+-----+
| KEY /
/ (64 byte) |
+-----+-----+-----+-----+-----+-----+-----+-----+
/ PUTPATH /
/ (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
/ GETPATH /
/ (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
/ BLOCK /
/ (variable length) /
+-----+-----+-----+-----+-----+-----+-----+-----+
]]></artwork>
</figure>
<t>where:</t>
<dl>
<dt>MSIZE</dt>
<dd>
denotes the size of this message in network byte order.
</dd>
<dt>MTYPE</dt>
<dd>
is the 16-bit message type. This type can be one of the DHT message
types but for put messages it must be set to
the value 148 in network byte order.
</dd>
<dt>OPTIONS</dt>
<dd>
is a 16-bit options field (see below).
</dd>
<dt>BTYPE</dt>
<dd>
is a 32-bit block type field. The block type indicates the content
type of the payload. In network byte order.
</dd>
<dt>PUTPATH_L</dt>
<dd>
is a 16-bit number indicating the length of the PUT path recorded
in PUTPATH. As PUTPATH is optiona, this value may be zero.
In network byte order.
</dd>
<dt>GET_PATH_LEN</dt>
<dd>
is a 16-bit number indicating the length of the GET path recorded
in GETPATH. As PUTPATH is optiona, this value may be zero.
In network byte order.
</dd>
<dt>EXPIRATION</dt>
<dd>
denotes the absolute 64-bit expiration date of the content.
In microseconds since midnight (0 hour), January 1, 1970 in network
byte order.
</dd>
<dt>KEY</dt>
<dd>
The key under which the PUT request wants to store content
under.
</dd>
<dt>PUTPATH</dt>
<dd>
the variable-length PUT path.
The path consists of a list of PATH_LEN peer IDs.
</dd>
<dt>GETPATH</dt>
<dd>
the variable-length PUT path.
The path consists of a list of PATH_LEN peer IDs.
</dd>
<dt>BLOCK</dt>
<dd>
the variable-length resource record data payload.
The contents are defined by the respective type of the resource record.
</dd>
</dl>
</section>
<section anchor="p2p_result_processing">
<name>Processing</name>
<t>
Upon receiving a RESULT message from a connected peer. An implementation
MUST process it step by step as follows:
</t>
<ol>
<li>
The EXPIRATION field is evaluated. If the message is expired,
it MUST be discarded.
</li>
<li>
If the MTYPE of the message indicates a HELLO block, the
payload MUST be considered for the local routing table.
FIXME: Considered how?
</li>
<li>
If the sender peer (FIXME which peer?) is already found in the
GETPATH, the path MUST be truncated.
</li>
<li>
FIXME: No validation??
</li>
<li>
If the KEY of this PUT message is in the list of pending queries,
return the message through the API.
</li>
<li>
The implementation MAY cache RESULT messages.
</li>
<li>
If no requests for this KEY or BTYPE are known, result processing
is completed.
</li>
<li>
If the request is of type "Find Peer" and the message BTYPE is
of type HELLO the block key is extracted from BLOCK, and if the
block key does not match KEY or cannot be extracted because
the BLOCK is malformed, the message MUST be discarded.
Otherwise, the block is evaluated against the message KEY.
FIXME: If OK_MORE or OK_LAST the RESULT is routed. One (!) peer is
selected from the connected peers (!). If none is found the message
is discarded.
</li>
</ol>
</section>
</section>
</section>
<section>
<name>Bootstrapping</name>
<t>
It is assumed that the peer is already connected to at least
one other peer.
First, those initial peers are sorted into their respective buckets.
</t>
<t>
In order to find the closest peers in the network to itself, an
implementation MUST now periodically send HELLO GET queries for its own
peer ID.
Both the "record route" and "find peer" message options are set in the
GET queries in order to learn peers and network topology from the
message route and in order to receive approximate replies to the
query key (the peer ID).
</t>
<t>FIXME: Periodically -> more specific? No. Frequency may be adapted depending on network conditions, known peers, busy/idle etc.</t>
<t>
Any implementation encountering a HELLO GET request initially
sends its own peer ID if it.
</t>
</section>
<section anchor="security" numbered="true" toc="default">
<name>Security Considerations</name>
<!-- FIXME: Here we should (again) discuss how the system is open and
does not have/require a trust anchor a priori. This is (again) in contrast
to RELOAD -->
</section>
<section anchor="gana" numbered="true" toc="default">
<name>GANA Considerations</name>
<t>
GANA <xref target="GANA" />
is requested to create a "DHT Block Types" registry.
The registry shall record for each entry:
</t>
<ul>
<li>Name: The name of the block type (case-insensitive ASCII
string, restricted to alphanumeric characters</li>
<li>Number: 32-bit</li>
<li>Comment: Optionally, a brief English text describing the purpose of
the block type (in UTF-8)</li>
<li>Contact: Optionally, the contact information of a person to contact for
further information</li>
<li>References: Optionally, references describing the record type
(such as an RFC)</li>
</ul>
<t>
The registration policy for this sub-registry is "First Come First
Served", as described in <xref target="RFC8126"/>.
GANA is requested to populate this registry as follows:
</t>
<figure anchor="figure_btypenums">
<artwork name="" type="" align="left" alt=""><![CDATA[
Number | Name | Contact | References | Description
-------+--------+---------+------------+-------------------------
0 ANY N/A [This.I-D] Reserved
7 HELLO N/A [This.I-D] Type of a block that contains
a HELLO for a peer
11 GNS N/A GNS Block for storing record data
]]></artwork>
</figure>
<t>
GANA is requested to amend the "GNUnet Signature Purpose" registry
as follows:
</t>
<figure anchor="figure_purposenums">
<artwork name="" type="" align="left" alt=""><![CDATA[
Purpose | Name | References | Description
--------+-----------------+------------+--------------------------
]]></artwork>
</figure>
</section>
<!-- gana -->
<section>
<name>Test Vectors</name>
</section>
</middle>
<back>
<references>
<name>Normative References</name>
&RFC2119;
&RFC3629;
&RFC3986;
&RFC4648;
&RFC6940;
&RFC8126;
&RFC8174;
<reference anchor="ed25519" target="http://link.springer.com/chapter/10.1007/978-3-642-23951-9_9">
<front>
<title>High-Speed High-Security Signatures</title>
<author initials="D." surname="Bernstein" fullname="Daniel Bernstein">
<organization>University of Illinois at Chicago</organization>
</author>
<author initials="N." surname="Duif"
fullname="Niels Duif">
<organization>Technische Universiteit Eindhoven</organization>
</author>
<author initials="T." surname="Lange"
fullname="Tanja Lange">
<organization>Technische Universiteit Eindhoven</organization>
</author>
<author initials="P." surname="Schwabe"
fullname="Peter Schwabe">
<organization>National Taiwan University</organization>
</author>
<author initials="B." surname="Yang"
fullname="Bo-Yin Yang">
<organization>Academia Sinica</organization>
</author>
<date year="2011"/>
</front>
</reference>
<reference anchor="CrockfordB32" target="https://www.crockford.com/base32.html">
<front>
<title>Base32</title>
<author initials="D." surname="Douglas" fullname="Crockford">
</author>
<date year="2019" month="March"/>
</front>
</reference>
<reference anchor="GANA" target="https://gana.gnunet.org/">
<front>
<title>GNUnet Assigned Numbers Authority (GANA)</title>
<author><organization>GNUnet e.V.</organization>
</author>
<date month="April" year="2020" />
</front>
</reference>
</references>
<references>
<name>Informative References</name>
<reference anchor="R5N" target="https://doi.org/10.1109/ICNSS.2011.6060022">
<front>
<title>R5N: Randomized recursive routing for restricted-route networks</title>
<author initials="N. S." surname="Evans" fullname="Nathan S. Evans">
<organization>Technische Universität München</organization>
</author>
<author initials="C." surname="Grothoff"
fullname="Christian Grothoff">
<organization>Technische Universität München</organization>
</author>
<date year="2011"/>
</front>
</reference>
<reference anchor="cadet" target="https://doi.org/10.1109/MedHocNet.2014.6849107">
<front>
<title>CADET: Confidential ad-hoc decentralized end-to-end transport</title>
<author initials="B." surname="Polot" fullname="Bartlomiej Polot">
<organization>Technische Universität München</organization>
</author>
<author initials="C." surname="Grothoff"
fullname="Christian Grothoff">
<organization>Technische Universität München</organization>
</author>
<date year="2014"/>
</front>
</reference>
<reference anchor="I-D.draft-schanzen-gns" target="https://datatracker.ietf.org/doc/draft-schanzen-gns/">
<front>
<title>The GNU Name System</title>
<author initials="M." surname="Schanzenbach" fullname="Martin Schanzenbach">
<organization>GNUnet e.V.</organization>
</author>
<author initials="C." surname="Grothoff"
fullname="Christian Grothoff">
<organization>GNUnet e.V.</organization>
</author>
<author initials="B." surname="Fix"
fullname="Bernd Fix">
<organization>GNUnet e.V.</organization>
</author>
<date year="2021"/>
</front>
</reference>
</references>
<!-- Change Log
v00 2017-07-23 MS Initial version
-->
</back>
</rfc>
|