diff options
author | Joe Crayne <joe@jerkface.net> | 2018-10-03 14:37:17 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-03 10:23:45 -0400 |
commit | 0c7768ba8eb62a6a74176f737a1c9c42308d5a8c (patch) | |
tree | 4c41e5cc4f6d0486466f2d74084b682c027aaf01 /examples | |
parent | 7ca3adad36ace11b523f7029fee4d43054f941ef (diff) |
Use seqence number context when serializing CryptoMessage.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/atox.hs | 6 | ||||
-rw-r--r-- | examples/dhtd.hs | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/examples/atox.hs b/examples/atox.hs index 7845d911..3bae5203 100644 --- a/examples/atox.hs +++ b/examples/atox.hs | |||
@@ -92,7 +92,7 @@ data SetCmd = SetME | |||
92 | deriving (Eq,Bounded,Ord,Enum,Show) | 92 | deriving (Eq,Bounded,Ord,Enum,Show) |
93 | 93 | ||
94 | forkToxInputThread myRead = forkIO $ do | 94 | forkToxInputThread myRead = forkIO $ do |
95 | let myconduit = Conduit.sourceHandle myRead .| conduitGet2 (S.get :: Get CryptoMessage) -- :: ConduitT i CryptoMessage IO () | 95 | let myconduit = Conduit.sourceHandle myRead .| conduitGet2 (getCryptoMessage 0 :: Get CryptoMessage) -- :: ConduitT i CryptoMessage IO () |
96 | Conduit.runConduit (myconduit .| Conduit.awaitForever handle) | 96 | Conduit.runConduit (myconduit .| Conduit.awaitForever handle) |
97 | where | 97 | where |
98 | handle (UpToN IPC (B.uncons -> Just (ord -> toEnum -> i,arg))) = updateState i arg | 98 | handle (UpToN IPC (B.uncons -> Just (ord -> toEnum -> i,arg))) = updateState i arg |
@@ -113,7 +113,7 @@ forkToxInputThread myRead = forkIO $ do | |||
113 | modifyTVar' sMap (Map.insert key view) | 113 | modifyTVar' sMap (Map.insert key view) |
114 | 114 | ||
115 | updateState AppendMsg arg | 115 | updateState AppendMsg arg |
116 | = case S.decode arg of | 116 | = case getCryptoMessage 0 `S.runGet` arg of |
117 | Left str -> puts (packUtf8 str) | 117 | Left str -> puts (packUtf8 str) |
118 | Right msg -> liftIO . atomically $ do | 118 | Right msg -> liftIO . atomically $ do |
119 | me <- readTVar sMe | 119 | me <- readTVar sMe |
@@ -133,7 +133,7 @@ doit myReadFd myWriteFd = do | |||
133 | terminalInputLoop myWrite | 133 | terminalInputLoop myWrite |
134 | 134 | ||
135 | hSend :: MonadIO m => Handle -> CryptoMessage -> m () | 135 | hSend :: MonadIO m => Handle -> CryptoMessage -> m () |
136 | hSend h msg = liftIO $ B.hPutStrLn h (S.encode msg) | 136 | hSend h msg = liftIO $ B.hPutStrLn h (S.runPut $ putCryptoMessage 0 msg) |
137 | 137 | ||
138 | terminalInputLoop myWriteH = fix $ \loop -> do | 138 | terminalInputLoop myWriteH = fix $ \loop -> do |
139 | line <- B.getLine | 139 | line <- B.getLine |
diff --git a/examples/dhtd.hs b/examples/dhtd.hs index 6161fbb4..5bc2b87a 100644 --- a/examples/dhtd.hs +++ b/examples/dhtd.hs | |||
@@ -99,7 +99,7 @@ import qualified Network.Tox.DHT.Transport as Tox | |||
99 | import qualified Network.Tox.DHT.Handlers as Tox | 99 | import qualified Network.Tox.DHT.Handlers as Tox |
100 | import qualified Network.Tox.Onion.Transport as Tox | 100 | import qualified Network.Tox.Onion.Transport as Tox |
101 | import qualified Network.Tox.Onion.Handlers as Tox | 101 | import qualified Network.Tox.Onion.Handlers as Tox |
102 | import qualified Network.Tox.Crypto.Transport as Tox (CryptoMessage(..)) | 102 | import qualified Network.Tox.Crypto.Transport as Tox (CryptoMessage(..),putCryptoMessage,getCryptoMessage) |
103 | import qualified Network.Tox.Crypto.Handlers as Tox | 103 | import qualified Network.Tox.Crypto.Handlers as Tox |
104 | import Data.Typeable | 104 | import Data.Typeable |
105 | import Network.Tox.ContactInfo as Tox | 105 | import Network.Tox.ContactInfo as Tox |
@@ -1407,7 +1407,7 @@ netcrypto (Just (DHT {..})) (Just mypubkey) h roster (Just tox) exes paramStr = | |||
1407 | when (them /= their_pub) $ do | 1407 | when (them /= their_pub) $ do |
1408 | atomically $ writeTVar whoAreThey their_pub | 1408 | atomically $ writeTVar whoAreThey their_pub |
1409 | B.hPutStr myWrite ("\NUL\SOH" `B.append` S.encode (Tox.key2id their_pub)) | 1409 | B.hPutStr myWrite ("\NUL\SOH" `B.append` S.encode (Tox.key2id their_pub)) |
1410 | B.hPutStr myWrite (S.encode msg) | 1410 | B.hPutStr myWrite (S.runPut $ Tox.putCryptoMessage 0 msg) |
1411 | return (Just id) | 1411 | return (Just id) |
1412 | addHooks currentHooks typs = forM_ typs $ \typ -> modifyTVar (Tox.ncHooks session) (Map.insert typ (currentHooks typ ++ [makeHook session typ])) | 1412 | addHooks currentHooks typs = forM_ typs $ \typ -> modifyTVar (Tox.ncHooks session) (Map.insert typ (currentHooks typ ++ [makeHook session typ])) |
1413 | case ranges of | 1413 | case ranges of |
@@ -1426,7 +1426,7 @@ netcrypto (Just (DHT {..})) (Just mypubkey) h roster (Just tox) exes paramStr = | |||
1426 | tid <- myThreadId | 1426 | tid <- myThreadId |
1427 | let sidStr = printf "(%x)" (Tox.ncSessionId session) | 1427 | let sidStr = printf "(%x)" (Tox.ncSessionId session) |
1428 | labelThread tid (exekey ++ ".forward" ++ sidStr) | 1428 | labelThread tid (exekey ++ ".forward" ++ sidStr) |
1429 | let myconduit = Conduit.sourceHandle myRead .| conduitGet2 S.get -- :: ConduitT i CryptoMessage IO () | 1429 | let myconduit = Conduit.sourceHandle myRead .| conduitGet2 (Tox.getCryptoMessage 0) -- :: ConduitT i CryptoMessage IO () |
1430 | Conduit.runConduit (myconduit .| awaitForever (\msg -> do | 1430 | Conduit.runConduit (myconduit .| awaitForever (\msg -> do |
1431 | let typ = toWord64 (getMessageType msg) | 1431 | let typ = toWord64 (getMessageType msg) |
1432 | mbSendIt <- liftIO $ atomically (lookupInRangeMap typ (Tox.ncOutHooks session)) | 1432 | mbSendIt <- liftIO $ atomically (lookupInRangeMap typ (Tox.ncOutHooks session)) |