From c1d01920220bcab32b5a77c0b25e65518e8d90d4 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 17 Nov 2018 03:09:48 -0500 Subject: dependent-sum based CryptoMessage. --- src/Network/Tox/AggregateSession.hs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/Network/Tox/AggregateSession.hs') diff --git a/src/Network/Tox/AggregateSession.hs b/src/Network/Tox/AggregateSession.hs index df16dc4e..8c728660 100644 --- a/src/Network/Tox/AggregateSession.hs +++ b/src/Network/Tox/AggregateSession.hs @@ -2,6 +2,7 @@ -- single online/offline presence. This allows multiple lossless links to the -- same identity at different addresses, or even to the same address. {-# LANGUAGE CPP #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE PatternSynonyms #-} module Network.Tox.AggregateSession @@ -23,6 +24,7 @@ module Network.Tox.AggregateSession import Control.Concurrent.STM import Control.Concurrent.STM.TMChan import Control.Monad +import Data.Dependent.Sum import Data.Function import qualified Data.IntMap.Strict as IntMap ;import Data.IntMap.Strict (IntMap) @@ -39,13 +41,12 @@ import GHC.Conc (labelThread) import Connection (Status (..)) import Crypto.Tox (PublicKey, toPublic) +import Data.Tox.Msg import Data.Wrapper.PSQInt as PSQ import DPut import DebugTag import Network.QueryResponse -import Network.Tox.Crypto.Transport (CryptoMessage (..), pattern KillPacket, - pattern ONLINE, pattern PING, - pattern PacketRequest) +import Network.Tox.Crypto.Transport import Network.Tox.DHT.Transport (key2id) import Network.Tox.NodeId (ToxProgress (..)) import Network.Tox.Session @@ -122,17 +123,17 @@ keepAlive s q = do , take 8 $ show $ key2id $ sTheirUserKey s , show $ sSessionID s]) - let outPrint e = dput XNetCrypto $ shows (sSessionID s,sTheirAddr s) $ " <-- " ++ e + let -- outPrint e = dput XNetCrypto $ shows (sSessionID s,sTheirAddr s) $ " <-- " ++ e unexpected e = dput XUnexpected $ shows (sSessionID s,sTheirAddr s) $ " <-- " ++ e doAlive = do -- outPrint $ "Beacon" - sendMessage (sTransport s) () (OneByte PING) + sendMessage (sTransport s) () (Pkt ALIVE ==> ()) doRequestMissing = do (ns,nmin) <- sMissingInbound s -- outPrint $ "PacketRequest " ++ show (nmin,ns) - sendMessage (sTransport s) () (RequestResend PacketRequest ns) + sendMessage (sTransport s) () (Pkt PacketRequest ==> MissingPackets ns) `catchIOError` \e -> do unexpected $ "PacketRequest " ++ take 200 (show (nmin,length ns,ns)) unexpected $ "PacketRequest: " ++ show e @@ -195,7 +196,7 @@ forkSession c s setStatus = forkIO $ do atomically $ setStatus $ InProgress AwaitingSessionPacket awaitPacket $ \_ (online,()) -> do - when (msgID online /= ONLINE) $ do + when (msgID online /= M ONLINE) $ do inPrint $ "Unexpected initial packet: " ++ show (msgID online) atomically $ do setStatus Established sendPacket online @@ -204,9 +205,9 @@ forkSession c s setStatus = forkIO $ do awaitPacket $ \awaitNext (x,()) -> do bump case msgID x of - PING -> return () - KillPacket -> sClose s - _ -> atomically $ sendPacket x + M ALIVE -> return () + M KillPacket -> sClose s + _ -> atomically $ sendPacket x awaitNext atomically $ setStatus Dormant killThread beacon -- cgit v1.2.3