diff options
Diffstat (limited to 'dht/src/Network/Tox/Crypto/Transport.hs')
-rw-r--r-- | dht/src/Network/Tox/Crypto/Transport.hs | 8 |
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 | |||
91 | showCryptoMsg :: Word32 -> CryptoMessage -> [Char] | 91 | showCryptoMsg :: Word32 -> CryptoMessage -> [Char] |
92 | showCryptoMsg _ msg = show msg | 92 | showCryptoMsg _ msg = show msg |
93 | 93 | ||
94 | parseCrypto :: (ByteString, SockAddr) -> Either (CryptoPacket Encrypted, SockAddr) (ByteString, SockAddr) | 94 | parseCrypto :: (ByteString, addr ) -> Either (CryptoPacket Encrypted, addr) (ByteString, addr) |
95 | parseCrypto (bbs,saddr) = case B.uncons bbs of | 95 | parseCrypto (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 | ||
101 | encodeCrypto :: (CryptoPacket Encrypted, SockAddr) -> Maybe (ByteString, SockAddr) | 101 | encodeCrypto :: (CryptoPacket Encrypted, addr) -> Maybe (ByteString, addr) |
102 | encodeCrypto (x,saddr) = Just (B.cons 0x1b (runPut $ put x),saddr) | 102 | encodeCrypto (x,saddr) = Just (B.cons 0x1b (runPut $ put x),saddr) |
103 | 103 | ||
104 | parseHandshakes :: ByteString -> SockAddr -> Either String (Handshake Encrypted, SockAddr) | 104 | parseHandshakes :: ByteString -> addr -> Either String (Handshake Encrypted, addr) |
105 | parseHandshakes (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseHandshakes: "++) $ (,saddr) <$> runGet get pkt | 105 | parseHandshakes (B.uncons -> Just (0x1a,pkt)) saddr = left ("parseHandshakes: "++) $ (,saddr) <$> runGet get pkt |
106 | parseHandshakes bs _ = Left $ "parseHandshakes_: " ++ show (B.unpack $ B.take 1 bs) | 106 | parseHandshakes bs _ = Left $ "parseHandshakes_: " ++ show (B.unpack $ B.take 1 bs) |
107 | 107 | ||
108 | encodeHandshakes :: Handshake Encrypted -> SockAddr -> (ByteString, SockAddr) | 108 | encodeHandshakes :: Handshake Encrypted -> addr -> (ByteString, addr) |
109 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) | 109 | encodeHandshakes x saddr = (B.cons 0x1a (runPut $ put x),saddr) |
110 | 110 | ||
111 | {- | 111 | {- |