Skip to content

Commit bc19e70

Browse files
committed
Finish description of sequence diagram
1 parent 9fa72f9 commit bc19e70

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

discv5/discv5-theory.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,13 @@ registration algorithm if the same topic is being registered and searched for.
527527

528528
## Hole punch asymmetric NATs
529529

530+
### Message flow
531+
530532
The protocol introduces the notification packet kind. There are 4 total message
531533
containers, these are abbreviated in the sequence diagram below as follows:
532534
- m - message packet
533-
- whoareyou - WHOEAREYOU packet
534-
- hm - handshake message packet
535+
- whoareyou - [WHOEAREYOU] packet
536+
- hm - [handshake message packet]
535537
- n - notification packet
536538

537539
```mermaid
@@ -543,29 +545,61 @@ containers, these are abbreviated in the sequence diagram below as follows:
543545
Relay-->>Alice: m(NODES[Bob's ENR])
544546
Alice->>Bob: m(nonce,FINDNODE)
545547
Note left of Alice:Hole punched in Alice's NAT for Bob
548+
Note left of Alice:FINDNODE timed out
546549
Alice->>Relay: n(RELAYINIT[nonce])
547550
Relay->>Bob:n(RELAYMSG[nonce])
548551
Bob-->>Alice: whoareyou(nonce)
549552
Note right of Bob: Hole punched in Bob's NAT for Alice
550553
```
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].
552556

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]
554558
request to Bob, who's ENR it received from Relay. By making an outgoing request to
555559
Bob, if Alice is behind a NAT, Alice's NAT adds the filtering rule
556560
`(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`.
558581

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
559585

560586
[EIP-778]: ../enr.md
561587
[identity scheme]: ../enr.md#record-structure
588+
[message packet]: ./discv5-wire.md#ordinary-message-packet-flag--0
562589
[handshake message packet]: ./discv5-wire.md#handshake-message-packet-flag--2
563590
[WHOAREYOU packet]: ./discv5-wire.md#whoareyou-packet-flag--1
591+
[notification packet]: ./discv5-wire.md#notification-packet-flag--3
564592
[PING]: ./discv5-wire.md#ping-request-0x01
565593
[PONG]: ./discv5-wire.md#pong-response-0x02
566594
[FINDNODE]: ./discv5-wire.md#findnode-request-0x03
567595
[REGTOPIC]: ./discv5-wire.md#regtopic-request-0x07
568596
[REGCONFIRMATION]: ./discv5-wire.md#regconfirmation-response-0x09
569597
[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

Comments
 (0)