summaryrefslogtreecommitdiff
path: root/src/Data/Tox.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/Tox.hs')
-rw-r--r--src/Data/Tox.hs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/Data/Tox.hs b/src/Data/Tox.hs
index 4449ce65..888ca3b6 100644
--- a/src/Data/Tox.hs
+++ b/src/Data/Tox.hs
@@ -1,11 +1,13 @@
1{-# LANGUAGE DeriveDataTypeable #-} 1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-} 2{-# LANGUAGE DeriveFunctor #-}
3{-# LANGUAGE DeriveTraversable #-} 3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE DeriveFunctor #-} 4{-# LANGUAGE DeriveTraversable #-}
5{-# LANGUAGE PatternSynonyms #-} 5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE RecordWildCards #-} 6{-# LANGUAGE PatternSynonyms #-}
7{-# LANGUAGE TupleSections #-} 7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE UnboxedTuples #-} 8{-# LANGUAGE TupleSections #-}
9{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE UnboxedTuples #-}
9module Data.Tox where 11module Data.Tox where
10 12
11import Data.ByteString (ByteString) 13import Data.ByteString (ByteString)
@@ -14,7 +16,7 @@ import Data.Word
14import Data.LargeWord 16import Data.LargeWord
15import Data.IP 17import Data.IP
16import Data.Serialize 18import Data.Serialize
17import Network.BitTorrent.Address () -- Serialize IP 19import Network.BitTorrent.Address (NodeInfo(..)) -- Serialize IP
18import GHC.Generics (Generic) 20import GHC.Generics (Generic)
19import Network.Socket 21import Network.Socket
20import Network.RPC hiding (NodeId) 22import Network.RPC hiding (NodeId)
@@ -27,7 +29,7 @@ type Nonce24 = Word192 -- 24 bytes
27type NodeId = Word256 -- 32 bytes (mainline uses only 20-byte node IDs) 29type NodeId = Word256 -- 32 bytes (mainline uses only 20-byte node IDs)
28 30
29 31
30data NodeFormat = NodeFormat 32data NodeFormat = NodeFormat
31 { nodePublicKey :: Key32 -- 32 byte public key 33 { nodePublicKey :: Key32 -- 32 byte public key
32 , nodeIsTCP :: Bool -- This has no analog in mainline NodeInfo structure 34 , nodeIsTCP :: Bool -- This has no analog in mainline NodeInfo structure
33 , nodeIP :: IP -- IPv4 or IPv6 address 35 , nodeIP :: IP -- IPv4 or IPv6 address
@@ -133,11 +135,11 @@ instance Serialize NodeFormat where
133 typ <- get :: Get Word8 135 typ <- get :: Get Word8
134 (ip,istcp) <- 136 (ip,istcp) <-
135 case typ :: Word8 of 137 case typ :: Word8 of
136 2 -> (,False) . IPv4 <$> get 138 2 -> (,False) . IPv4 <$> get
137 130 -> (,True) . IPv4 <$> get 139 130 -> (,True) . IPv4 <$> get
138 10 -> (,False) . IPv6 <$> get 140 10 -> (,False) . IPv6 <$> get
139 138 -> (,True) . IPv6 <$> get 141 138 -> (,True) . IPv6 <$> get
140 _ -> fail "Unsupported type of Tox node_format structure" 142 _ -> fail "Unsupported type of Tox node_format structure"
141 port <- get 143 port <- get
142 pubkey <- get 144 pubkey <- get
143 return $ NodeFormat { nodeIsTCP = istcp 145 return $ NodeFormat { nodeIsTCP = istcp