diff options
author | joe <joe@jerkface.net> | 2018-06-16 02:59:42 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-16 02:59:42 -0400 |
commit | 8d6a50dde334a2dc4039c0c718a992e4df36402f (patch) | |
tree | 58558561314a49a29ea6a0ab82a6a4cb9550cf81 /src/Network | |
parent | 939c23d57365a49d366b6534c6f343f0a12a770a (diff) |
more persueContact wip
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 1acc333e..57e1741f 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -56,9 +56,70 @@ import Debug.Trace | |||
56 | import Text.Printf | 56 | import Text.Printf |
57 | import Data.Bool | 57 | import Data.Bool |
58 | import Connection (Status(..), Policy(..)) | 58 | import Connection (Status(..), Policy(..)) |
59 | import Connection.Tox.Threads (ToxProgress(..)) | ||
60 | import Network.Tox.ContactInfo | 59 | import Network.Tox.ContactInfo |
61 | 60 | ||
61 | -- | This type indicates the progress of a tox encrypted friend link | ||
62 | -- connection. Two scenarios are illustrated below. The parenthesis show the | ||
63 | -- current 'G.Status' 'ToxProgress' of the session. | ||
64 | -- | ||
65 | -- | ||
66 | -- Perfect handshake scenario: | ||
67 | -- | ||
68 | -- Peer 1 Peer 2 | ||
69 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
70 | -- Cookie request -> | ||
71 | -- <- Cookie response | ||
72 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
73 | -- Handshake packet -> | ||
74 | -- * accepts connection | ||
75 | -- (InProgress AwaitingSessionPacket) | ||
76 | -- <- Handshake packet | ||
77 | -- *accepts connection | ||
78 | -- (InProgress AwaitingSessionPacket) | ||
79 | -- Encrypted packet -> <- Encrypted packet | ||
80 | -- *confirms connection *confirms connection | ||
81 | -- (Established) (Established) | ||
82 | -- | ||
83 | -- Connection successful. | ||
84 | -- | ||
85 | -- Encrypted packets -> <- Encrypted packets | ||
86 | -- | ||
87 | -- | ||
88 | -- | ||
89 | -- | ||
90 | -- More realistic handshake scenario: | ||
91 | -- Peer 1 Peer 2 | ||
92 | -- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) | ||
93 | -- Cookie request -> *packet lost* | ||
94 | -- Cookie request -> | ||
95 | -- <- Cookie response | ||
96 | -- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) | ||
97 | -- | ||
98 | -- *Peer 2 randomly starts new connection to peer 1 | ||
99 | -- (InProgress AcquiringCookie) | ||
100 | -- <- Cookie request | ||
101 | -- Cookie response -> | ||
102 | -- (InProgress AwaitingHandshake) | ||
103 | -- | ||
104 | -- Handshake packet -> <- Handshake packet | ||
105 | -- *accepts connection * accepts connection | ||
106 | -- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket) | ||
107 | -- | ||
108 | -- Encrypted packet -> <- Encrypted packet | ||
109 | -- *confirms connection *confirms connection | ||
110 | -- (Established) (Established) | ||
111 | -- | ||
112 | -- Connection successful. | ||
113 | -- | ||
114 | -- Encrypted packets -> <- Encrypted packets | ||
115 | data ToxProgress | ||
116 | = AwaitingDHTKey -- ^ Waiting to receive their DHT key. | ||
117 | | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port. | ||
118 | | AcquiringCookie -- ^ Attempting to obtain a cookie. | ||
119 | | AwaitingHandshake -- ^ Waiting to receive a handshake. | ||
120 | | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed". | ||
121 | deriving (Eq,Ord,Enum,Show) | ||
122 | |||
62 | type LookupPolicyFunction = Key -> STM Policy | 123 | type LookupPolicyFunction = Key -> STM Policy |
63 | 124 | ||
64 | data Key = Key NodeId{-me-} NodeId{-them-} | 125 | data Key = Key NodeId{-me-} NodeId{-them-} |