summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/Crypto/Transport.hs
diff options
context:
space:
mode:
Diffstat (limited to 'dht/src/Network/Tox/Crypto/Transport.hs')
-rw-r--r--dht/src/Network/Tox/Crypto/Transport.hs8
1 files changed, 4 insertions, 4 deletions
diff --git a/dht/src/Network/Tox/Crypto/Transport.hs b/dht/src/Network/Tox/Crypto/Transport.hs
index a18b550d..127b2dac 100644
--- a/dht/src/Network/Tox/Crypto/Transport.hs
+++ b/dht/src/Network/Tox/Crypto/Transport.hs
@@ -91,21 +91,21 @@ import GHC.TypeNats
91showCryptoMsg :: Word32 -> CryptoMessage -> [Char] 91showCryptoMsg :: Word32 -> CryptoMessage -> [Char]
92showCryptoMsg _ msg = show msg 92showCryptoMsg _ msg = show msg
93 93
94parseCrypto :: (ByteString, SockAddr) -> Either (CryptoPacket Encrypted, SockAddr) (ByteString, SockAddr) 94parseCrypto :: (ByteString, addr ) -> Either (CryptoPacket Encrypted, addr) (ByteString, addr)
95parseCrypto (bbs,saddr) = case B.uncons bbs of 95parseCrypto (bbs,saddr) = case B.uncons bbs of
96 Just (0x1b,bs) -> case runGet get bs of 96 Just (0x1b,bs) -> case runGet get bs of
97 Right pkt -> Left (pkt, saddr) -- Successful parse, handle this packet. 97 Right pkt -> Left (pkt, saddr) -- Successful parse, handle this packet.
98 Left _ -> Right (bs,saddr) -- Failed parse, strip first byte and pass it on. 98 Left _ -> Right (bs,saddr) -- Failed parse, strip first byte and pass it on.
99 _ -> Right (bbs,saddr) -- Type-code mismatch, pass it on. 99 _ -> Right (bbs,saddr) -- Type-code mismatch, pass it on.
100 100
101encodeCrypto :: (CryptoPacket Encrypted, SockAddr) -> Maybe (ByteString, SockAddr) 101encodeCrypto :: (CryptoPacket Encrypted, addr) -> Maybe (ByteString, addr)
102encodeCrypto (x,saddr) = Just (B.cons 0x1b (runPut $ put x),saddr) 102encodeCrypto (x,saddr) = Just (B.cons 0x1b (runPut $ put x),saddr)
103 103
104parseHandshakes :: ByteString -> SockAddr -> Either String (Handshake Encrypted, SockAddr) 104parseHandshakes :: ByteString -> addr -> Either String (Handshake Encrypted, addr)
105parseHandshakes (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseHandshakes: "++) $ (,saddr) <$> runGet get pkt 105parseHandshakes (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseHandshakes: "++) $ (,saddr) <$> runGet get pkt
106parseHandshakes bs _ = Left $ "parseHandshakes_: " ++ show (B.unpack $ B.take 1 bs) 106parseHandshakes bs _ = Left $ "parseHandshakes_: " ++ show (B.unpack $ B.take 1 bs)
107 107
108encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) 108encodeHandshakes :: Handshake Encrypted -> addr -> (ByteString, addr)
109encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) 109encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr)
110 110
111{- 111{-