diff options
author | Joe Crayne <joe@jerkface.net> | 2018-08-22 20:50:23 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-09-07 13:18:43 -0400 |
commit | fb3d30fd7fb1e68623b3bffc9f42ecb2adabce66 (patch) | |
tree | 1de81c6bc6319e3889951d354adc71b104c5437b /src/Network/Tox/Crypto/Handlers.hs | |
parent | 9dded0e540876c9e928cfcb3c69666ce00b5852c (diff) |
Removed obsolete Connection.Tox.
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 75 |
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 | |||
52 | import DPut | 52 | import DPut |
53 | import Text.Printf | 53 | import Text.Printf |
54 | import Data.Bool | 54 | import Data.Bool |
55 | import Connection (Status(..), Policy(..)) | ||
56 | import Network.Tox.Handshake | 55 | import Network.Tox.Handshake |
57 | 56 | ||
58 | -- | This type indicates the progress of a tox encrypted friend link | 57 | type 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 | ||
112 | data 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 | |||
120 | type LookupPolicyFunction = Key -> STM Policy | ||
121 | |||
122 | data Key = Key NodeId{-me-} NodeId{-them-} | ||
123 | deriving (Eq,Ord) | ||
124 | |||
125 | instance Show Key where show = show . showKey_ | ||
126 | |||
127 | showKey_ :: Key -> String | ||
128 | showKey_ (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] -> |