summaryrefslogtreecommitdiff
path: root/src/Network/Tox/Crypto/Handlers.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-08-22 20:50:23 -0400
committerJoe Crayne <joe@jerkface.net>2018-09-07 13:18:43 -0400
commitfb3d30fd7fb1e68623b3bffc9f42ecb2adabce66 (patch)
tree1de81c6bc6319e3889951d354adc71b104c5437b /src/Network/Tox/Crypto/Handlers.hs
parent9dded0e540876c9e928cfcb3c69666ce00b5852c (diff)
Removed obsolete Connection.Tox.
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs75
1 files changed, 2 insertions, 73 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs
index 07c033b6..3269f5dd 100644
--- a/src/Network/Tox/Crypto/Handlers.hs
+++ b/src/Network/Tox/Crypto/Handlers.hs
@@ -52,80 +52,9 @@ import Data.InOrOut
52import DPut 52import DPut
53import Text.Printf 53import Text.Printf
54import Data.Bool 54import Data.Bool
55import Connection (Status(..), Policy(..))
56import Network.Tox.Handshake 55import Network.Tox.Handshake
57 56
58-- | This type indicates the progress of a tox encrypted friend link 57type LookupPolicyFunction = ToxContact -> STM Policy
59-- connection. Two scenarios are illustrated below. The parenthesis show the
60-- current 'G.Status' 'ToxProgress' of the session.
61--
62--
63-- Perfect handshake scenario:
64--
65-- Peer 1 Peer 2
66-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie)
67-- Cookie request ->
68-- <- Cookie response
69-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie)
70-- Handshake packet ->
71-- * accepts connection
72-- (InProgress AwaitingSessionPacket)
73-- <- Handshake packet
74-- *accepts connection
75-- (InProgress AwaitingSessionPacket)
76-- Encrypted packet -> <- Encrypted packet
77-- *confirms connection *confirms connection
78-- (Established) (Established)
79--
80-- Connection successful.
81--
82-- Encrypted packets -> <- Encrypted packets
83--
84--
85--
86--
87-- More realistic handshake scenario:
88-- Peer 1 Peer 2
89-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie)
90-- Cookie request -> *packet lost*
91-- Cookie request ->
92-- <- Cookie response
93-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie)
94--
95-- *Peer 2 randomly starts new connection to peer 1
96-- (InProgress AcquiringCookie)
97-- <- Cookie request
98-- Cookie response ->
99-- (InProgress AwaitingHandshake)
100--
101-- Handshake packet -> <- Handshake packet
102-- *accepts connection * accepts connection
103-- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket)
104--
105-- Encrypted packet -> <- Encrypted packet
106-- *confirms connection *confirms connection
107-- (Established) (Established)
108--
109-- Connection successful.
110--
111-- Encrypted packets -> <- Encrypted packets
112data ToxProgress
113 = AwaitingDHTKey -- ^ Waiting to receive their DHT key.
114 | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port.
115 | AcquiringCookie -- ^ Attempting to obtain a cookie.
116 | AwaitingHandshake -- ^ Waiting to receive a handshake.
117 | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed".
118 deriving (Eq,Ord,Enum,Show)
119
120type LookupPolicyFunction = Key -> STM Policy
121
122data Key = Key NodeId{-me-} NodeId{-them-}
123 deriving (Eq,Ord)
124
125instance Show Key where show = show . showKey_
126
127showKey_ :: Key -> String
128showKey_ (Key me them) = show me ++ ":" ++ show them
129 58
130-- * These types are isomorphic to Maybe, but have the advantage of documenting 59-- * These types are isomorphic to Maybe, but have the advantage of documenting
131-- when an item is expected to become known. 60-- when an item is expected to become known.
@@ -1075,7 +1004,7 @@ handshakeH sessions addrRaw hshake@(Handshake (Cookie n24 ecookie) nonce24 encry
1075 case Map.lookup addr sessionsmap of 1004 case Map.lookup addr sessionsmap of
1076 Nothing -> do 1005 Nothing -> do
1077 dmsg $ "sockaddr(" ++ show addr ++ ") not in session map(" ++ show (map (second ncSessionId) (Map.assocs sessionsmap)) ++ "), so freshCryptoSession" 1006 dmsg $ "sockaddr(" ++ show addr ++ ") not in session map(" ++ show (map (second ncSessionId) (Map.assocs sessionsmap)) ++ "), so freshCryptoSession"
1078 let k = Key (key2id . toPublic $ key) (key2id remotePublicKey) 1007 let k = ToxContact (key2id . toPublic $ key) (key2id remotePublicKey)
1079 policy <- netCryptoPolicyByKey sessions k 1008 policy <- netCryptoPolicyByKey sessions k
1080 case policy of 1009 case policy of
1081 x | x `elem` [OpenToConnect,TryingToConnect] -> 1010 x | x `elem` [OpenToConnect,TryingToConnect] ->