summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Kademlia/RoutingTable.hs28
-rw-r--r--src/Network/DHT/Kademlia.hs68
2 files changed, 96 insertions, 0 deletions
diff --git a/src/Data/Kademlia/RoutingTable.hs b/src/Data/Kademlia/RoutingTable.hs
new file mode 100644
index 00000000..98e15a0b
--- /dev/null
+++ b/src/Data/Kademlia/RoutingTable.hs
@@ -0,0 +1,28 @@
1module Data.Kademlia.RoutingTable
2 (
3 ) where
4
5import Data.ByteString
6
7type NodeID = ByteString
8type InfoHash = ByteString
9
10type Bucket = [NodeID]
11
12data Tree
13 = Tip Bucket
14 | Bin Table Table
15
16data Table = Table {
17 tree :: Tree
18 , bucketSize :: Int
19 }
20
21closest :: InfoHash -> Table -> [NodeID]
22closest = undefined
23
24insert :: NodeID -> Table -> Table
25insert x t = undefined
26
27-- TODO table serialization: usually we need to save table between
28-- target program executions
diff --git a/src/Network/DHT/Kademlia.hs b/src/Network/DHT/Kademlia.hs
new file mode 100644
index 00000000..d5418beb
--- /dev/null
+++ b/src/Network/DHT/Kademlia.hs
@@ -0,0 +1,68 @@
1-- TODO move to Network.DHT.Kademlia
2{-# LANGUAGE OverloadedStrings #-}
3module Network.DHT.Kademlia
4 (
5 ) where
6
7import Data.ByteString
8import Network
9import Remote.KRPC
10
11
12
13-- | Global unique identifier of the node. Size of the identifier
14-- should(!) be equal to the size of DHT keys. This limitation arises
15-- from the design of Kademlia: we should estimate distance between
16-- keys and NodeId in routing algorithms.
17--
18type NodeID = ByteString
19
20type NodeAddr = ByteString
21type InfoHash = ByteString
22type Token = ByteString
23
24-- | Used to check out if a node is alive or not. This has a tow-fold effect:
25--
26-- * If(!) caller get response it should update the bucket
27-- corresponding to the callee.
28--
29-- * Callee of the ping should update the bucket corresponding
30-- to the caller as well.
31--
32ping :: Method NodeID NodeID
33ping = method "ping" ["id"] ["id"]
34
35type PeerContact = ()
36data NodeContact = NodeContact {
37 peerContact :: PeerContact
38 , nodeID :: NodeID
39 }
40
41-- | Used to lookup peer ID from node ID.
42--
43find_node :: Method (NodeID, NodeID) (NodeID, NodeContact)
44find_node = method "find_node" ["id", "target"] ["id", "nodes"]
45
46-- |
47announce_peer :: Method (NodeID, InfoHash, PortNumber, Token) NodeID
48announce_peer = undefined
49
50genNodeID :: IO NodeID
51genNodeID = undefined
52
53{-
54type InfoHash = Int
55type Token = Int
56
57ping :: Method NodeId NodeId
58ping = method "ping" ["id"] ["id"]
59
60get_peers :: Method (NodeId :*: InfoHash) (NodeId, Token, NodeAddr :|: NodeAddr)
61get_peers = method "get_peers"
62 ("id", "target")
63 ("id", "token", view ("values" :|: "nodes"))
64
65
66
67
68-} \ No newline at end of file