summaryrefslogtreecommitdiff
path: root/dht/conn-notes.txt
blob: 257987d1c645b77633a48738a33568ad7b1c4b7e (plain)
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
Status of a tox friend netcrypto session.
-----------------------------------------
data ToxProgress
    = AwaitingDHTKey        -- ^ Waiting to receive their DHT key.
    | AcquiringIPAddress    -- ^ Searching DHT to obtain their node's IP & port.
    | AcquiringCookie       -- ^ Attempting to obtain a cookie.
    | AwaitingHandshake     -- ^ Waiting to receive a handshake.
    | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed".
    deriving (Eq,Ord,Enum,Show)


Information about contact toxid and events that provide it.
----------------------------------------------------------
	SockAddr
		receive packet with dhtkey associated with toxid
		receive query result with dhtkey associated with toxid
		receive netcrypto session packet from toxid
	DHTKey
		receive dhtpk over DataToRoute transport.
		receive dht message from SockAddr
		receive dhtpk via dht-request



Recurring tasks associated with obtaining a connection.
-------------------------------------------------------
while (account is active):
	tox4id:announce{toxid}
	tox6id:

	while (policy=TryingToConnect and friend session is not established)
		search{toxid} contact, send my dhtkey to results
			(AwaitingDHTKey .. AwaitingSessionPacket)

		while (dhtkey is fresh but sockaddr is stale)
			search{node} dhtkey
				(AcquiringIPAddress..)

		while (dhtkey and sockaddr are fresh)
				(AcquiringCookie)
			getCookie { on timeout, consider sockaddr stale, set sockaddr to Nothing)
				(AwaitingHandshake)
			send handshake

Plan: Suppose our user key is OrjBG.GyWuQhGc1pb0KssgmYAocohFh35Vx8mREC9Nu and we have
a contact with user key DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN.  The following AnnounceKeys
will be scheduled:

	toxid:OrjBG.GyWuQhGc1pb0KssgmYAocohFh35Vx8mREC9Nu

		This task searches for our own user key, and publishes itself
		at rendezvous nodes.

	dhtkey:OrjBG.Gy:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN

		This task searches for our contact's user key and uses the
		rendezvous nodes that it finds in order to share our dhtkey
		with our contact.


	connect:OrjBG.Gy:DdhbLjiwaV0GAiGKgesNPbvj2TbhrBHEWEEc5icfvQN

		Depending on whether or not the ip/port is "fresh", this task
		has two modes only one of which is active at a time:

		(1) (stale) Search for our contact's dhtkey (nodeid) in order
		to discover his ip address and port.

		(2) (fresh) Send handshakes to our friend every 5 seconds.

The toxid:* task will be scheduled as long as you are online.  The dhtkey:* and
connect:* will only be scheduled when there is no active "netcrypto" session
link with your contact.

On inbound
----------
	Handshake recieved!
		(AwaitingSessionPacket)


Interesting tox repositories
--------------------------------------------
	https://github.com/TokTok/spec

	https://github.com/TokTok/hs-toxcore
	https://github.com/iphydf/hstox

	https://github.com/TokTok/c-toxcore