diff options
author | joe <joe@jerkface.net> | 2017-06-08 00:00:56 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-06-08 00:00:56 -0400 |
commit | d6fac9a8df0ce872ede54d6a71ca6d6c750eadc9 (patch) | |
tree | c4a7cd804714796bc918091ebb29f4ad4009a401 /src/Data | |
parent | 05345c643d0bcebe17f9474d9561da6e90fff34e (diff) |
WIP: Adapting DHT to Tox network (part 5).
Diffstat (limited to 'src/Data')
-rw-r--r-- | src/Data/Tox.hs | 28 |
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 #-} | ||
9 | module Data.Tox where | 11 | module Data.Tox where |
10 | 12 | ||
11 | import Data.ByteString (ByteString) | 13 | import Data.ByteString (ByteString) |
@@ -14,7 +16,7 @@ import Data.Word | |||
14 | import Data.LargeWord | 16 | import Data.LargeWord |
15 | import Data.IP | 17 | import Data.IP |
16 | import Data.Serialize | 18 | import Data.Serialize |
17 | import Network.BitTorrent.Address () -- Serialize IP | 19 | import Network.BitTorrent.Address (NodeInfo(..)) -- Serialize IP |
18 | import GHC.Generics (Generic) | 20 | import GHC.Generics (Generic) |
19 | import Network.Socket | 21 | import Network.Socket |
20 | import Network.RPC hiding (NodeId) | 22 | import Network.RPC hiding (NodeId) |
@@ -27,7 +29,7 @@ type Nonce24 = Word192 -- 24 bytes | |||
27 | type NodeId = Word256 -- 32 bytes (mainline uses only 20-byte node IDs) | 29 | type NodeId = Word256 -- 32 bytes (mainline uses only 20-byte node IDs) |
28 | 30 | ||
29 | 31 | ||
30 | data NodeFormat = NodeFormat | 32 | data 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 |