diff options
author | joe <joe@jerkface.net> | 2018-06-13 14:51:04 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-13 15:07:53 -0400 |
commit | fd3f604f8961d7c7db48015c9ed7be40ea872a7c (patch) | |
tree | e53960ea57a8838ae3e3a63df07aaaf3aeef1f65 /Connection/Tox/Threads.hs | |
parent | 7cdb8da4f1c6df5d4b2755498e79c9886fd0750f (diff) |
tox: WIP connection manager for tox sessions.
Diffstat (limited to 'Connection/Tox/Threads.hs')
-rw-r--r-- | Connection/Tox/Threads.hs | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/Connection/Tox/Threads.hs b/Connection/Tox/Threads.hs index 8b19c7cf..dcee37d1 100644 --- a/Connection/Tox/Threads.hs +++ b/Connection/Tox/Threads.hs | |||
@@ -12,7 +12,7 @@ | |||
12 | module Connection.Tox.Threads where | 12 | module Connection.Tox.Threads where |
13 | 13 | ||
14 | import Connection | 14 | import Connection |
15 | import Connection.Tox | 15 | -- import Connection.Tox |
16 | import Data.IP (IP) | 16 | import Data.IP (IP) |
17 | import Network.Tox.Crypto.Transport | 17 | import Network.Tox.Crypto.Transport |
18 | import Network.Tox.NodeId | 18 | import Network.Tox.NodeId |
@@ -27,6 +27,70 @@ import Data.Function | |||
27 | import Data.Functor.Identity | 27 | import Data.Functor.Identity |
28 | import System.Timeout | 28 | import System.Timeout |
29 | 29 | ||
30 | |||
31 | -- | This type indicates the progress of a tox encrypted friend link | ||
32 | -- connection. Two scenarios are illustrated below. The parenthesis show the | ||
33 | -- current 'G.Status' 'ToxProgress' of the session. | ||
34 | -- | ||
35 | -- | ||
36 | -- Perfect handshake scenario: | ||
37 | -- | ||
38 | -- Peer 1 Peer 2 | ||
39 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
40 | -- Cookie request -> | ||
41 | -- <- Cookie response | ||
42 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
43 | -- Handshake packet -> | ||
44 | -- * accepts connection | ||
45 | -- (InProgress AwaitingSessionPacket) | ||
46 | -- <- Handshake packet | ||
47 | -- *accepts connection | ||
48 | -- (InProgress AwaitingSessionPacket) | ||
49 | -- Encrypted packet -> <- Encrypted packet | ||
50 | -- *confirms connection *confirms connection | ||
51 | -- (Established) (Established) | ||
52 | -- | ||
53 | -- Connection successful. | ||
54 | -- | ||
55 | -- Encrypted packets -> <- Encrypted packets | ||
56 | -- | ||
57 | -- | ||
58 | -- | ||
59 | -- | ||
60 | -- More realistic handshake scenario: | ||
61 | -- Peer 1 Peer 2 | ||
62 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
63 | -- Cookie request -> *packet lost* | ||
64 | -- Cookie request -> | ||
65 | -- <- Cookie response | ||
66 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
67 | -- | ||
68 | -- *Peer 2 randomly starts new connection to peer 1 | ||
69 | -- (InProgress AcquiringCookie) | ||
70 | -- <- Cookie request | ||
71 | -- Cookie response -> | ||
72 | -- (InProgress AwaitingHandshake) | ||
73 | -- | ||
74 | -- Handshake packet -> <- Handshake packet | ||
75 | -- *accepts connection * accepts connection | ||
76 | -- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket) | ||
77 | -- | ||
78 | -- Encrypted packet -> <- Encrypted packet | ||
79 | -- *confirms connection *confirms connection | ||
80 | -- (Established) (Established) | ||
81 | -- | ||
82 | -- Connection successful. | ||
83 | -- | ||
84 | -- Encrypted packets -> <- Encrypted packets | ||
85 | data ToxProgress | ||
86 | = AwaitingDHTKey -- ^ Waiting to receive their DHT key. | ||
87 | | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port. | ||
88 | | AcquiringCookie -- ^ Attempting to obtain a cookie. | ||
89 | | AwaitingHandshake -- ^ Waiting to receive a handshake. | ||
90 | | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed". | ||
91 | deriving (Eq,Ord,Enum,Show) | ||
92 | |||
93 | |||
30 | type NodeSearch = Search NodeId (IP,PortNumber) () NodeInfo NodeInfo | 94 | type NodeSearch = Search NodeId (IP,PortNumber) () NodeInfo NodeInfo |
31 | 95 | ||
32 | data AcceptContactMethods = AcceptContactMethods | 96 | data AcceptContactMethods = AcceptContactMethods |