summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Message.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/Message.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Message.hs15
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"
55data Query a = Query 55data Query a = Query
56 { thisNodeId :: NodeId 56 { thisNodeId :: NodeId
57 , queryParams :: a 57 , queryParams :: a
58 } 58 } deriving (Show, Eq)
59 59
60instance BEncode a => BEncode (Query a) where 60instance 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
75data Response a = Response 75data Response a = Response
76 { remoteNodeId :: NodeId 76 { remoteNodeId :: NodeId
77 , responseVals :: a 77 , responseVals :: a
78 } 78 } deriving (Show, Eq)
79 79
80instance BEncode a => BEncode (Response a) where 80instance 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.
95data Ping = Ping 96data Ping = Ping
96 deriving Typeable 97 deriving (Show, Eq, Typeable)
97 98
98instance BEncode Ping where 99instance 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.
112newtype FindNode = FindNode NodeId 113newtype FindNode = FindNode NodeId
113 deriving Typeable 114 deriving (Show, Eq, Typeable)
114 115
115target_key :: BKey 116target_key :: BKey
116target_key = "target" 117target_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--
126newtype NodeFound ip = NodeFound [NodeInfo ip] 127newtype NodeFound ip = NodeFound [NodeInfo ip]
127 deriving Typeable 128 deriving (Show, Eq, Typeable)
128 129
129nodes_key :: BKey 130nodes_key :: BKey
130nodes_key = "nodes" 131nodes_key = "nodes"