summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Kademlia/Common.hs48
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 #-}
3module Data.Kademlia.Common
4 (NodeID, NodeInfo
5 ) where
6
7import Control.Applicative
8import Data.ByteString
9import Network
10import Network.Socket
11import Data.Serialize
12
13
14type NodeID = ByteString
15type 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--
21genNodeID :: IO NodeID
22genNodeID = undefined -- randomIO
23
24instance Serialize PortNumber where
25 get = fromIntegral <$> getWord16be
26 put = putWord16be . fromIntegral
27
28
29data NodeAddr = NodeAddr {
30 nodeIP :: HostAddress
31 , nodePort :: PortNumber
32 } deriving (Show, Eq)
33
34instance Serialize NodeAddr where
35 get = NodeAddr <$> getWord32be <*> get
36 put NodeAddr {..} = do
37 putWord32be nodeIP
38 put nodePort
39
40
41data NodeInfo = NodeInfo {
42 nodeID :: NodeID
43 , nodeAddr :: NodeAddr
44 } deriving (Show, Eq)
45
46instance Serialize NodeInfo where
47 get = NodeInfo <$> getByteString 20 <*> get
48 put NodeInfo {..} = put nodeID >> put nodeAddr