summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-16 02:59:42 -0400
committerjoe <joe@jerkface.net>2018-06-16 02:59:42 -0400
commit8d6a50dde334a2dc4039c0c718a992e4df36402f (patch)
tree58558561314a49a29ea6a0ab82a6a4cb9550cf81 /src/Network
parent939c23d57365a49d366b6534c6f343f0a12a770a (diff)
more persueContact wip
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs63
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
56import Text.Printf 56import Text.Printf
57import Data.Bool 57import Data.Bool
58import Connection (Status(..), Policy(..)) 58import Connection (Status(..), Policy(..))
59import Connection.Tox.Threads (ToxProgress(..))
60import Network.Tox.ContactInfo 59import 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
115data 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
62type LookupPolicyFunction = Key -> STM Policy 123type LookupPolicyFunction = Key -> STM Policy
63 124
64data Key = Key NodeId{-me-} NodeId{-them-} 125data Key = Key NodeId{-me-} NodeId{-them-}