diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-26 01:26:27 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-26 01:26:27 +0400 |
commit | 62253eb04e3ad1225d2a87a3c9647c6c092114df (patch) | |
tree | 56216a539b49f1b2fc8ad09c72d2b769460ccc07 /src/Network/BitTorrent/DHT | |
parent | b4d3b295f75538234d82025617bc7cad6b4e9d19 (diff) |
Test ping and find_node bencoding
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r-- | src/Network/BitTorrent/DHT/Message.hs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/DHT/Message.hs b/src/Network/BitTorrent/DHT/Message.hs index 85abf019..9000a9be 100644 --- a/src/Network/BitTorrent/DHT/Message.hs +++ b/src/Network/BitTorrent/DHT/Message.hs | |||
@@ -55,7 +55,7 @@ node_id_key = "id" | |||
55 | data Query a = Query | 55 | data Query a = Query |
56 | { thisNodeId :: NodeId | 56 | { thisNodeId :: NodeId |
57 | , queryParams :: a | 57 | , queryParams :: a |
58 | } | 58 | } deriving (Show, Eq) |
59 | 59 | ||
60 | instance BEncode a => BEncode (Query a) where | 60 | instance BEncode a => BEncode (Query a) where |
61 | toBEncode Query {..} = toDict $ | 61 | toBEncode Query {..} = toDict $ |
@@ -75,7 +75,7 @@ instance BEncode a => BEncode (Query a) where | |||
75 | data Response a = Response | 75 | data Response a = Response |
76 | { remoteNodeId :: NodeId | 76 | { remoteNodeId :: NodeId |
77 | , responseVals :: a | 77 | , responseVals :: a |
78 | } | 78 | } deriving (Show, Eq) |
79 | 79 | ||
80 | instance BEncode a => BEncode (Response a) where | 80 | instance BEncode a => BEncode (Response a) where |
81 | toBEncode = toBEncode . toQuery | 81 | toBEncode = toBEncode . toQuery |
@@ -91,9 +91,10 @@ instance BEncode a => BEncode (Response a) where | |||
91 | -- ping method | 91 | -- ping method |
92 | -----------------------------------------------------------------------} | 92 | -----------------------------------------------------------------------} |
93 | 93 | ||
94 | -- | The most basic query is a ping. | 94 | -- | The most basic query is a ping. Ping query is used to check if a |
95 | -- quered node is still alive. | ||
95 | data Ping = Ping | 96 | data Ping = Ping |
96 | deriving Typeable | 97 | deriving (Show, Eq, Typeable) |
97 | 98 | ||
98 | instance BEncode Ping where | 99 | instance BEncode Ping where |
99 | toBEncode Ping = toDict endDict | 100 | toBEncode Ping = toDict endDict |
@@ -110,7 +111,7 @@ instance KRPC (Query Ping) [Ping] where | |||
110 | -- | Find node is used to find the contact information for a node | 111 | -- | Find node is used to find the contact information for a node |
111 | -- given its ID. | 112 | -- given its ID. |
112 | newtype FindNode = FindNode NodeId | 113 | newtype FindNode = FindNode NodeId |
113 | deriving Typeable | 114 | deriving (Show, Eq, Typeable) |
114 | 115 | ||
115 | target_key :: BKey | 116 | target_key :: BKey |
116 | target_key = "target" | 117 | target_key = "target" |
@@ -119,12 +120,12 @@ instance BEncode FindNode where | |||
119 | toBEncode (FindNode nid) = toDict $ target_key .=! nid .: endDict | 120 | toBEncode (FindNode nid) = toDict $ target_key .=! nid .: endDict |
120 | fromBEncode = fromDict $ FindNode <$>! target_key | 121 | fromBEncode = fromDict $ FindNode <$>! target_key |
121 | 122 | ||
122 | -- | When a node receives a find_node query, it should respond with a | 123 | -- | When a node receives a 'FindNode' query, it should respond with a |
123 | -- the compact node info for the target node or the K (8) closest good | 124 | -- the compact node info for the target node or the K (8) closest good |
124 | -- nodes in its own routing table. | 125 | -- nodes in its own routing table. |
125 | -- | 126 | -- |
126 | newtype NodeFound ip = NodeFound [NodeInfo ip] | 127 | newtype NodeFound ip = NodeFound [NodeInfo ip] |
127 | deriving Typeable | 128 | deriving (Show, Eq, Typeable) |
128 | 129 | ||
129 | nodes_key :: BKey | 130 | nodes_key :: BKey |
130 | nodes_key = "nodes" | 131 | nodes_key = "nodes" |