summaryrefslogtreecommitdiff
path: root/src/Network/DHT/Kademlia.hs
blob: bc03ac16d8b63565f47127a4fcd8b3ef77a063c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{-# LANGUAGE OverloadedStrings #-}
module Network.DHT.Kademlia
       (
       ) where

import Data.ByteString
import Network
import Remote.KRPC

import Data.Kademlia.Routing.Table
{-

-- | Global unique identifier of the node. Size of the identifier
-- should(!) be equal to the size of DHT keys. This limitation arises
-- from the design of Kademlia: we should estimate distance between
-- keys and NodeId in routing algorithms.
--
type NodeID = ByteString

type NodeAddr = ByteString
type InfoHash = ByteString
type Token    = ByteString

-- | Used to check out if a node is alive or not. This has a tow-fold effect:
--
--     * If(!) caller get response it should update the bucket
--     corresponding to the callee.
--
--     * Callee of the ping should update the bucket corresponding
--     to the caller as well.
--
ping :: Method NodeID NodeID
ping = method "ping" ["id"] ["id"]



-- | Used to lookup peer ID from node ID.
--
find_node :: Method (NodeID, NodeID) (NodeID, NodeContact)
find_node = method "find_node" ["id", "target"] ["id", "nodes"]

-- |
announce_peer :: Method (NodeID, InfoHash, PortNumber, Token) NodeID
announce_peer = undefined

-- WARN is the 'system' random suitable for this?
-- | Generate random NodeID used for the entire session.
--   Distribution of ID's should be as uniform as possible.
--
genNodeID :: IO NodeID
genNodeID = randomIO

{-
type Token = Int

get_peers :: Method (NodeId :*: InfoHash) (NodeId, Token, NodeAddr :|: NodeAddr)
get_peers = method "get_peers"
  ("id", "target")
  ("id", "token", view ("values" :|: "nodes"))




-}
-}