summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-16 19:35:46 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-16 19:35:46 +0400
commit448b86fca5cac5abfef66598391614a8a4f83a46 (patch)
treef17e9d2adc7e23b83e4f198a38a94945188e7477 /src/Network
parentafef54f0fa5c7fee567d960d4183caa5817f46e5 (diff)
~ Some initial DHT skeleton.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/DHT/Kademlia.hs68
1 files changed, 68 insertions, 0 deletions
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