summaryrefslogtreecommitdiff
path: root/src/Network/Tox
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
parent9dded0e540876c9e928cfcb3c69666ce00b5852c (diff)
Removed obsolete Connection.Tox.
Diffstat (limited to 'src/Network/Tox')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs75
-rw-r--r--src/Network/Tox/NodeId.hs80
2 files changed, 81 insertions, 74 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] ->
diff --git a/src/Network/Tox/NodeId.hs b/src/Network/Tox/NodeId.hs
index 3a732b43..d5da692a 100644
--- a/src/Network/Tox/NodeId.hs
+++ b/src/Network/Tox/NodeId.hs
@@ -33,7 +33,10 @@ module Network.Tox.NodeId
33 , parseNoSpamId 33 , parseNoSpamId
34 , nospam64 34 , nospam64
35 , nospam16 35 , nospam16
36 , verifyChecksum) where 36 , verifyChecksum
37 , ToxContact(..)
38 , ToxProgress(..)
39 ) where
37 40
38import Control.Applicative 41import Control.Applicative
39import Control.Arrow 42import Control.Arrow
@@ -617,3 +620,78 @@ solveBase64NoSpamID b64digits pub = do
617 let nospam' = fromIntegral (n64' `shiftR` 32) 620 let nospam' = fromIntegral (n64' `shiftR` 32)
618 cksum' = fromIntegral (n64' `shiftR` 16) 621 cksum' = fromIntegral (n64' `shiftR` 16)
619 return $ NoSpamId (NoSpam nospam' (Just cksum')) pub 622 return $ NoSpamId (NoSpam nospam' (Just cksum')) pub
623
624-- | This type indicates a roster-link relationship between a local toxid and a
625-- remote toxid. Note that these toxids are represented as the type 'NodeId'
626-- even though they are long-term keys rather than the public keys of Tox DHT
627-- nodes.
628data ToxContact = ToxContact NodeId{-me-} NodeId{-them-}
629 deriving (Eq,Ord)
630
631instance Show ToxContact where show = show . showToxContact_
632
633showToxContact_ :: ToxContact -> String
634showToxContact_ (ToxContact me them) = show me ++ ":" ++ show them
635
636-- | This type indicates the progress of a tox encrypted friend link
637-- connection. Two scenarios are illustrated below. The parenthesis show the
638-- current 'G.Status' 'ToxProgress' of the session.
639--
640--
641-- Perfect handshake scenario:
642--
643-- Peer 1 Peer 2
644-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie)
645-- Cookie request ->
646-- <- Cookie response
647-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie)
648-- Handshake packet ->
649-- * accepts connection
650-- (InProgress AwaitingSessionPacket)
651-- <- Handshake packet
652-- *accepts connection
653-- (InProgress AwaitingSessionPacket)
654-- Encrypted packet -> <- Encrypted packet
655-- *confirms connection *confirms connection
656-- (Established) (Established)
657--
658-- Connection successful.
659--
660-- Encrypted packets -> <- Encrypted packets
661--
662--
663--
664--
665-- More realistic handshake scenario:
666-- Peer 1 Peer 2
667-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie)
668-- Cookie request -> *packet lost*
669-- Cookie request ->
670-- <- Cookie response
671-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie)
672--
673-- *Peer 2 randomly starts new connection to peer 1
674-- (InProgress AcquiringCookie)
675-- <- Cookie request
676-- Cookie response ->
677-- (InProgress AwaitingHandshake)
678--
679-- Handshake packet -> <- Handshake packet
680-- *accepts connection * accepts connection
681-- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket)
682--
683-- Encrypted packet -> <- Encrypted packet
684-- *confirms connection *confirms connection
685-- (Established) (Established)
686--
687-- Connection successful.
688--
689-- Encrypted packets -> <- Encrypted packets
690data ToxProgress
691 = AwaitingDHTKey -- ^ Waiting to receive their DHT key.
692 | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port.
693 | AcquiringCookie -- ^ Attempting to obtain a cookie.
694 | AwaitingHandshake -- ^ Waiting to receive a handshake.
695 | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed".
696 deriving (Eq,Ord,Enum,Show)
697