From fb3d30fd7fb1e68623b3bffc9f42ecb2adabce66 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Wed, 22 Aug 2018 20:50:23 -0400 Subject: Removed obsolete Connection.Tox. --- src/Network/Tox/Crypto/Handlers.hs | 75 +---------------------------------- src/Network/Tox/NodeId.hs | 80 +++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 74 deletions(-) (limited to 'src/Network/Tox') 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 import DPut import Text.Printf import Data.Bool -import Connection (Status(..), Policy(..)) import Network.Tox.Handshake --- | This type indicates the progress of a tox encrypted friend link --- connection. Two scenarios are illustrated below. The parenthesis show the --- current 'G.Status' 'ToxProgress' of the session. --- --- --- Perfect handshake scenario: --- --- Peer 1 Peer 2 --- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) --- Cookie request -> --- <- Cookie response --- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) --- Handshake packet -> --- * accepts connection --- (InProgress AwaitingSessionPacket) --- <- Handshake packet --- *accepts connection --- (InProgress AwaitingSessionPacket) --- Encrypted packet -> <- Encrypted packet --- *confirms connection *confirms connection --- (Established) (Established) --- --- Connection successful. --- --- Encrypted packets -> <- Encrypted packets --- --- --- --- --- More realistic handshake scenario: --- Peer 1 Peer 2 --- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) --- Cookie request -> *packet lost* --- Cookie request -> --- <- Cookie response --- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) --- --- *Peer 2 randomly starts new connection to peer 1 --- (InProgress AcquiringCookie) --- <- Cookie request --- Cookie response -> --- (InProgress AwaitingHandshake) --- --- Handshake packet -> <- Handshake packet --- *accepts connection * accepts connection --- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket) --- --- Encrypted packet -> <- Encrypted packet --- *confirms connection *confirms connection --- (Established) (Established) --- --- Connection successful. --- --- Encrypted packets -> <- Encrypted packets -data ToxProgress - = AwaitingDHTKey -- ^ Waiting to receive their DHT key. - | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port. - | AcquiringCookie -- ^ Attempting to obtain a cookie. - | AwaitingHandshake -- ^ Waiting to receive a handshake. - | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed". - deriving (Eq,Ord,Enum,Show) - -type LookupPolicyFunction = Key -> STM Policy - -data Key = Key NodeId{-me-} NodeId{-them-} - deriving (Eq,Ord) - -instance Show Key where show = show . showKey_ - -showKey_ :: Key -> String -showKey_ (Key me them) = show me ++ ":" ++ show them +type LookupPolicyFunction = ToxContact -> STM Policy -- * These types are isomorphic to Maybe, but have the advantage of documenting -- when an item is expected to become known. @@ -1075,7 +1004,7 @@ handshakeH sessions addrRaw hshake@(Handshake (Cookie n24 ecookie) nonce24 encry case Map.lookup addr sessionsmap of Nothing -> do dmsg $ "sockaddr(" ++ show addr ++ ") not in session map(" ++ show (map (second ncSessionId) (Map.assocs sessionsmap)) ++ "), so freshCryptoSession" - let k = Key (key2id . toPublic $ key) (key2id remotePublicKey) + let k = ToxContact (key2id . toPublic $ key) (key2id remotePublicKey) policy <- netCryptoPolicyByKey sessions k case policy of 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 , parseNoSpamId , nospam64 , nospam16 - , verifyChecksum) where + , verifyChecksum + , ToxContact(..) + , ToxProgress(..) + ) where import Control.Applicative import Control.Arrow @@ -617,3 +620,78 @@ solveBase64NoSpamID b64digits pub = do let nospam' = fromIntegral (n64' `shiftR` 32) cksum' = fromIntegral (n64' `shiftR` 16) return $ NoSpamId (NoSpam nospam' (Just cksum')) pub + +-- | This type indicates a roster-link relationship between a local toxid and a +-- remote toxid. Note that these toxids are represented as the type 'NodeId' +-- even though they are long-term keys rather than the public keys of Tox DHT +-- nodes. +data ToxContact = ToxContact NodeId{-me-} NodeId{-them-} + deriving (Eq,Ord) + +instance Show ToxContact where show = show . showToxContact_ + +showToxContact_ :: ToxContact -> String +showToxContact_ (ToxContact me them) = show me ++ ":" ++ show them + +-- | This type indicates the progress of a tox encrypted friend link +-- connection. Two scenarios are illustrated below. The parenthesis show the +-- current 'G.Status' 'ToxProgress' of the session. +-- +-- +-- Perfect handshake scenario: +-- +-- Peer 1 Peer 2 +-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) +-- Cookie request -> +-- <- Cookie response +-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) +-- Handshake packet -> +-- * accepts connection +-- (InProgress AwaitingSessionPacket) +-- <- Handshake packet +-- *accepts connection +-- (InProgress AwaitingSessionPacket) +-- Encrypted packet -> <- Encrypted packet +-- *confirms connection *confirms connection +-- (Established) (Established) +-- +-- Connection successful. +-- +-- Encrypted packets -> <- Encrypted packets +-- +-- +-- +-- +-- More realistic handshake scenario: +-- Peer 1 Peer 2 +-- (InProgress AcquiringCookie) (Dormant/InProgress AcquiringCookie) +-- Cookie request -> *packet lost* +-- Cookie request -> +-- <- Cookie response +-- (InProgress AwaitingHandshake) (Dormant/InProgress AcquiringCookie) +-- +-- *Peer 2 randomly starts new connection to peer 1 +-- (InProgress AcquiringCookie) +-- <- Cookie request +-- Cookie response -> +-- (InProgress AwaitingHandshake) +-- +-- Handshake packet -> <- Handshake packet +-- *accepts connection * accepts connection +-- (InProgress AwaitingSessionPacket) (InProgress AwaitingSessionPacket) +-- +-- Encrypted packet -> <- Encrypted packet +-- *confirms connection *confirms connection +-- (Established) (Established) +-- +-- Connection successful. +-- +-- Encrypted packets -> <- Encrypted packets +data ToxProgress + = AwaitingDHTKey -- ^ Waiting to receive their DHT key. + | AcquiringIPAddress -- ^ Searching DHT to obtain their node's IP & port. + | AcquiringCookie -- ^ Attempting to obtain a cookie. + | AwaitingHandshake -- ^ Waiting to receive a handshake. + | AwaitingSessionPacket -- ^ Connection is "accepted" but not yet "confirmed". + deriving (Eq,Ord,Enum,Show) + -- cgit v1.2.3