Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DhtPacket Human documentation #120

Open
NamsooCho opened this issue Apr 28, 2018 · 4 comments
Open

DhtPacket Human documentation #120

NamsooCho opened this issue Apr 28, 2018 · 4 comments

Comments

@NamsooCho
Copy link
Member

NamsooCho commented Apr 28, 2018

Description of DHT packets

1. Overview

PingRequest and NodesRequest provide method to interact with Tox Networks.

  • Purpose of packet

    • PingRequest : check if the node is alive
    • NodesRequest : get nodes closest to me and my friends.
    • NatPingRequest : check if my friend is behind NAT, then punch hole
  • Data types used

    • Kbucket : contains nodes closest to me
    • Bucket : contains nodes closest to my friend, nodes to bootstrap

2. PingRequest

  • When DHT node receives PingRequest, it responds with PingResponse and sends PingRequest.

  • When DHT node receives NodesRequest, it responds with NodesResponse and sends PingRequest.

  • Before DHT node sends PingRequest, it checks if the node is addable to close list

    • addable : send PingRequest
    • not addable: don't send PingRequest

3. PingResponse

  • When DHT node receives PingResponse, it checks if the node is addable to close list
    • addable : add node to close list and friend's close list
    • not addable : don't add node to close list

4. NodesRequest

There are two timers interval

  • 60 seconds interval : to ping nodes in close list and friend's close list
  • 20 seconds interval : to get nodes close to me and my friends
    • 20 seconds interval timer expires only 5 times after start-up.

There are two case sending NodesRequest

  • on two timers expire
  • bootstrapping

BootStrapping is checking nodes whether it is alive or not.

The nodes to bootstrap are nodes in NodesResponse and if

  • the node is addable to close list of my Public Key or
  • the node is addable to close list of my friend's Public Key

When DHT node receives NodesRequest, it responds with NodesResponse.

NodesResponse contains maximum 4 nodes in close list and friend's close list.

Maximum 4 nodes are closest to requested Public Key.

5. NodesResponse

When DHT node receives NodesResponse, it unpack nodes in packet's payload.

Unpacked nodes are added to

  • if addable to close list, add
  • if addable to close list of my friend, add
  • if addable to bootstrap list, add
  • if addable to bootstrap list of my friend, add

6. Replacing order of Kbucket and Bucket

Nodes in close list have two status

  • Good : node is alive and 'alive' is meaning that last responding time is within 182 seconds.
  • Bad : node is not alive, which means last responding time exceeds 182 seconds.

The old node in close list is replaced by new node order by

  • Bad and farthest
  • Good and farther than new node
  • if there is no bad or no (good and father than new node), then new node is not addable

7. NatPingRequest

If a friend is not connected with me and friend is online, at every 3 seconds

  • send NatPingRequest to all entry of close_nodes of the friend

Close nodes of a friend have SocketAddrs, if

  • more than half of ip addresses are same and
  • last time of receiving NatPingResponse is within 6 seconds and
  • do_hole_punching variable == 1

are true then starts hole punching.

When DHT node receives NatPingRequest, it checks if Receiver PK is same with my PK

  • if same PK, find Sender's PK in my friend's list
    • if found, responds with NatPingResponse
    • if not found, do nothing
  • if not same, search DHT node's close list to find same PK
    • if found, send NatPingRequest to the node
    • if not found, do nothing

8. NatPingResponse

When DHT node receives NatPingResponse, it checks if Receiver PK is same with my PK

  • if same PK, find Sender's PK in my friend's list
    • if found, check if ping_id is same with ping_id saved
      • if same, set do_hole_punching variable to 1
      • if not same, do nothing
    • if not found, do nothing
  • if not same, search DHT node's close list to find same PK
    • if found, send NatPingResponse to the node
    • if not found, do nothing
@NamsooCho NamsooCho changed the title NodesRequest human docs. NodesRequest and PingRequest Human documentation May 1, 2018
@NamsooCho NamsooCho changed the title NodesRequest and PingRequest Human documentation DhtPacket Human documentation May 1, 2018
@kurnevsky
Copy link
Member

kurnevsky commented May 3, 2018

When we send PingRequest:

  • node made PingRequest to us
  • node made NodesRequest to us

When we send NodesRequest:

  • we got node from NodesResponse
  • we loaded node from saved state
  • it's node from initial bootstrap list

When we just add to kbucket:

  • we got PingResponse from node
  • we got NodesResponse from node

@NamsooCho
Copy link
Member Author

The bootstrap_nodes has only 8 nodes from NodesResponses.
These nodes are close to PK of friend.
If the node gotten by NodesResponse is far from PK of friend, then the node is discarded.

@kpp
Copy link
Member

kpp commented May 4, 2018

The bootstrap_nodes has only 8 nodes from NodesResponses.

https://github.com/tox-rs/tox/blob/master/src/toxcore/dht/packet/nodes_response.rs#L133

@NamsooCho
Copy link
Member Author

Yes, one NodesResponse has maximum 4 nodes.
DHT node receives many NodesReponse packet,
a friend can have maximum 8nodes from many NodesResponse packets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants