diff options
Diffstat (limited to 'src/Data/Kademlia/Common.hs')
-rw-r--r-- | src/Data/Kademlia/Common.hs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/Data/Kademlia/Common.hs b/src/Data/Kademlia/Common.hs deleted file mode 100644 index 874120d8..00000000 --- a/src/Data/Kademlia/Common.hs +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | {-# LANGUAGE RecordWildCards #-} | ||
3 | module Data.Kademlia.Common | ||
4 | (NodeID, NodeInfo | ||
5 | ) where | ||
6 | |||
7 | import Control.Applicative | ||
8 | import Data.ByteString | ||
9 | import Network | ||
10 | import Network.Socket | ||
11 | import Data.Serialize | ||
12 | |||
13 | |||
14 | type NodeID = ByteString | ||
15 | type Distance = NodeID | ||
16 | |||
17 | -- WARN is the 'system' random suitable for this? | ||
18 | -- | Generate random NodeID used for the entire session. | ||
19 | -- Distribution of ID's should be as uniform as possible. | ||
20 | -- | ||
21 | genNodeID :: IO NodeID | ||
22 | genNodeID = undefined -- randomIO | ||
23 | |||
24 | instance Serialize PortNumber where | ||
25 | get = fromIntegral <$> getWord16be | ||
26 | put = putWord16be . fromIntegral | ||
27 | |||
28 | |||
29 | data NodeAddr = NodeAddr { | ||
30 | nodeIP :: HostAddress | ||
31 | , nodePort :: PortNumber | ||
32 | } deriving (Show, Eq) | ||
33 | |||
34 | instance Serialize NodeAddr where | ||
35 | get = NodeAddr <$> getWord32be <*> get | ||
36 | put NodeAddr {..} = do | ||
37 | putWord32be nodeIP | ||
38 | put nodePort | ||
39 | |||
40 | |||
41 | data NodeInfo = NodeInfo { | ||
42 | nodeID :: NodeID | ||
43 | , nodeAddr :: NodeAddr | ||
44 | } deriving (Show, Eq) | ||
45 | |||
46 | instance Serialize NodeInfo where | ||
47 | get = NodeInfo <$> getByteString 20 <*> get | ||
48 | put NodeInfo {..} = put nodeID >> put nodeAddr | ||