diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Peer/Addr.hs | 2 | ||||
-rw-r--r-- | src/Network/DHT/Kademlia.hs | 21 |
2 files changed, 10 insertions, 13 deletions
diff --git a/src/Network/BitTorrent/Peer/Addr.hs b/src/Network/BitTorrent/Peer/Addr.hs index 0e6fcfb9..1c2ac2eb 100644 --- a/src/Network/BitTorrent/Peer/Addr.hs +++ b/src/Network/BitTorrent/Peer/Addr.hs | |||
@@ -28,7 +28,7 @@ data PeerAddr = PeerAddr { | |||
28 | peerID :: Maybe PeerID | 28 | peerID :: Maybe PeerID |
29 | , peerIP :: HostAddress | 29 | , peerIP :: HostAddress |
30 | , peerPort :: PortNumber | 30 | , peerPort :: PortNumber |
31 | } deriving Show | 31 | } deriving (Show, Eq) |
32 | 32 | ||
33 | instance BEncodable PortNumber where | 33 | instance BEncodable PortNumber where |
34 | toBEncode = toBEncode . fromEnum | 34 | toBEncode = toBEncode . fromEnum |
diff --git a/src/Network/DHT/Kademlia.hs b/src/Network/DHT/Kademlia.hs index d5418beb..bc03ac16 100644 --- a/src/Network/DHT/Kademlia.hs +++ b/src/Network/DHT/Kademlia.hs | |||
@@ -1,4 +1,3 @@ | |||
1 | -- TODO move to Network.DHT.Kademlia | ||
2 | {-# LANGUAGE OverloadedStrings #-} | 1 | {-# LANGUAGE OverloadedStrings #-} |
3 | module Network.DHT.Kademlia | 2 | module Network.DHT.Kademlia |
4 | ( | 3 | ( |
@@ -8,7 +7,8 @@ import Data.ByteString | |||
8 | import Network | 7 | import Network |
9 | import Remote.KRPC | 8 | import Remote.KRPC |
10 | 9 | ||
11 | 10 | import Data.Kademlia.Routing.Table | |
11 | {- | ||
12 | 12 | ||
13 | -- | Global unique identifier of the node. Size of the identifier | 13 | -- | Global unique identifier of the node. Size of the identifier |
14 | -- should(!) be equal to the size of DHT keys. This limitation arises | 14 | -- should(!) be equal to the size of DHT keys. This limitation arises |
@@ -32,11 +32,7 @@ type Token = ByteString | |||
32 | ping :: Method NodeID NodeID | 32 | ping :: Method NodeID NodeID |
33 | ping = method "ping" ["id"] ["id"] | 33 | ping = method "ping" ["id"] ["id"] |
34 | 34 | ||
35 | type PeerContact = () | 35 | |
36 | data NodeContact = NodeContact { | ||
37 | peerContact :: PeerContact | ||
38 | , nodeID :: NodeID | ||
39 | } | ||
40 | 36 | ||
41 | -- | Used to lookup peer ID from node ID. | 37 | -- | Used to lookup peer ID from node ID. |
42 | -- | 38 | -- |
@@ -47,16 +43,16 @@ find_node = method "find_node" ["id", "target"] ["id", "nodes"] | |||
47 | announce_peer :: Method (NodeID, InfoHash, PortNumber, Token) NodeID | 43 | announce_peer :: Method (NodeID, InfoHash, PortNumber, Token) NodeID |
48 | announce_peer = undefined | 44 | announce_peer = undefined |
49 | 45 | ||
46 | -- WARN is the 'system' random suitable for this? | ||
47 | -- | Generate random NodeID used for the entire session. | ||
48 | -- Distribution of ID's should be as uniform as possible. | ||
49 | -- | ||
50 | genNodeID :: IO NodeID | 50 | genNodeID :: IO NodeID |
51 | genNodeID = undefined | 51 | genNodeID = randomIO |
52 | 52 | ||
53 | {- | 53 | {- |
54 | type InfoHash = Int | ||
55 | type Token = Int | 54 | type Token = Int |
56 | 55 | ||
57 | ping :: Method NodeId NodeId | ||
58 | ping = method "ping" ["id"] ["id"] | ||
59 | |||
60 | get_peers :: Method (NodeId :*: InfoHash) (NodeId, Token, NodeAddr :|: NodeAddr) | 56 | get_peers :: Method (NodeId :*: InfoHash) (NodeId, Token, NodeAddr :|: NodeAddr) |
61 | get_peers = method "get_peers" | 57 | get_peers = method "get_peers" |
62 | ("id", "target") | 58 | ("id", "target") |
@@ -65,4 +61,5 @@ get_peers = method "get_peers" | |||
65 | 61 | ||
66 | 62 | ||
67 | 63 | ||
64 | -} | ||
68 | -} \ No newline at end of file | 65 | -} \ No newline at end of file |