@@ -527,11 +527,13 @@ registration algorithm if the same topic is being registered and searched for.
527
527
528
528
## Hole punch asymmetric NATs
529
529
530
+ ### Message flow
531
+
530
532
The protocol introduces the notification packet kind. There are 4 total message
531
533
containers, these are abbreviated in the sequence diagram below as follows:
532
534
- m - message packet
533
- - whoareyou - WHOEAREYOU packet
534
- - hm - handshake message packet
535
+ - whoareyou - [ WHOEAREYOU] packet
536
+ - hm - [ handshake message packet]
535
537
- n - notification packet
536
538
537
539
``` mermaid
@@ -543,29 +545,61 @@ containers, these are abbreviated in the sequence diagram below as follows:
543
545
Relay-->>Alice: m(NODES[Bob's ENR])
544
546
Alice->>Bob: m(nonce,FINDNODE)
545
547
Note left of Alice:Hole punched in Alice's NAT for Bob
548
+ Note left of Alice:FINDNODE timed out
546
549
Alice->>Relay: n(RELAYINIT[nonce])
547
550
Relay->>Bob:n(RELAYMSG[nonce])
548
551
Bob-->>Alice: whoareyou(nonce)
549
552
Note right of Bob: Hole punched in Bob's NAT for Alice
550
553
```
551
- Bob is behind a NAT. Bob is in Relay's kbuckets, they have a session together.
554
+ Bob is behind a NAT. Bob is in Relay's kbuckets, they have a session together and Bob
555
+ has sent a packet to Relay in the last ~ 20 seconds[ ^ 1 ] .
552
556
553
- As part of a periodic recursive query to fill its kbuckets, Alice sends a FINDNODE
557
+ As part of a periodic recursive query to fill its kbuckets, Alice sends a [ FINDNODE]
554
558
request to Bob, who's ENR it received from Relay. By making an outgoing request to
555
559
Bob, if Alice is behind a NAT, Alice's NAT adds the filtering rule
556
560
` (Alice's-LAN-ip, Alice's-LAN-port, Bob's-WAN-ip, Bob's-WAN-port, entry-lifetime) ` to
557
- it's UDP session table [ ^ 1 ] [ ^ 2 ] . The request to Bob times out as Bob is behind a NAT.
561
+ it's UDP session table[ ^ 2 ] [ ^ 3 ] . This means a hole now is punched for Bob in Alice's NAT
562
+ for the duration of ` entry-lifetime ` . The request to Bob times out as Bob is behind a NAT.
563
+
564
+ Alice initiates an attempt to punch a hole in Bob's NAT via Relay. Alice reset the request
565
+ time out on the timed out [ FINDNODE] message and wraps the message's nonce in a [ RELAYINIT]
566
+ notification and sends it to Relay. The notification also contains its ENR and Bob's node
567
+ id.
568
+
569
+ Relay disassembles the [ RELAYINIT] notification and uses the ` tgt-id ` to look up Bob's
570
+ ENR in its kbuckets. With high probability, Relay will find Bob's ENR in its kbuckets
571
+ as ~ 1 second ago, Relay assembled a [ NODES] response for Alice containing Bob's ENR (see
572
+ [ UDP Communication] for recommended time out times). Relay assembles a [ RELAYMSG]
573
+ notification with Alice's message nonce and ENR, then sends it to the address in Bob's
574
+ ENR.
575
+
576
+ Bob disassembles the [ RELAYMSG] and uses the ` nonce ` to assemble a [ WHOAREYOU packet] ,
577
+ then sends it to Alice using the address in the ` inr-enr ` . Bob's NAT adds the filtering
578
+ rule ` (Bob's-LAN-ip, Bob's-LAN-port, Alice's-WAN-ip, Alice's-WAN-port, entry-lifetime) ` to
579
+ it's UDP session table[ ^ 2 ] [ ^ 3 ] . A hole is punched in Bob's NAT for Alice for the duration
580
+ of ` entry-lifetime ` .
558
581
582
+ From here on it's business as usual. See [ Sessions] .
583
+
584
+ ### Redundancy of enrs in NODES responses and connectivity status assumptions about Relay and Bob
559
585
560
586
[ EIP-778 ] : ../enr.md
561
587
[ identity scheme ] : ../enr.md#record-structure
588
+ [ message packet ] : ./discv5-wire.md#ordinary-message-packet-flag--0
562
589
[ handshake message packet ] : ./discv5-wire.md#handshake-message-packet-flag--2
563
590
[ WHOAREYOU packet ] : ./discv5-wire.md#whoareyou-packet-flag--1
591
+ [ notification packet ] : ./discv5-wire.md#notification-packet-flag--3
564
592
[ PING ] : ./discv5-wire.md#ping-request-0x01
565
593
[ PONG ] : ./discv5-wire.md#pong-response-0x02
566
594
[ FINDNODE ] : ./discv5-wire.md#findnode-request-0x03
567
595
[ REGTOPIC ] : ./discv5-wire.md#regtopic-request-0x07
568
596
[ REGCONFIRMATION ] : ./discv5-wire.md#regconfirmation-response-0x09
569
597
[ TOPICQUERY ] : ./discv5-wire.md#topicquery-request-0x0a
570
- [ ^ 1 ] : https://datatracker.ietf.org/doc/html/rfc4787
571
- [ ^ 2 ] : https://www.ietf.org/rfc/rfc6146.txt
598
+ [ RELAYINIT ] : ./discv5-wire.md#relayinit-0x01
599
+ [ RELAYMSG ] : ./discv5-wire.md#relaymsg-0x02
600
+
601
+ [ UDP communication ] : ./discv5-wire.md#udp-communication
602
+
603
+ [ ^ 1 ] : https://pdos.csail.mit.edu/papers/p2pnat.pdf
604
+ [ ^ 2 ] : https://datatracker.ietf.org/doc/html/rfc4787
605
+ [ ^ 3 ] : https://www.ietf.org/rfc/rfc6146.txt
0 commit comments