summaryrefslogtreecommitdiff
path: root/src/Network/DHT/Mainline.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-03 22:59:31 -0400
committerjoe <joe@jerkface.net>2017-07-03 22:59:31 -0400
commitf75d515bc0100e5ca372d592aa2f5f4ff2fc858c (patch)
tree71bc354c8f6b8fed2275eb8c215d99b654c7f473 /src/Network/DHT/Mainline.hs
parent78b05bf38b83b5d46468e1f938bb8c2d9dd0804f (diff)
Fleshed out KRPC instances for Mainline DHT.
Diffstat (limited to 'src/Network/DHT/Mainline.hs')
-rw-r--r--src/Network/DHT/Mainline.hs44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/Network/DHT/Mainline.hs b/src/Network/DHT/Mainline.hs
index d68755a7..9af42a6d 100644
--- a/src/Network/DHT/Mainline.hs
+++ b/src/Network/DHT/Mainline.hs
@@ -218,11 +218,13 @@ instance Serialize (Response Ping) where
218 218
219-- | \"q\" = \"ping\" 219-- | \"q\" = \"ping\"
220instance KRPC KMessageOf (Query KMessageOf (Ping KMessageOf)) (Response KMessageOf (Ping KMessageOf)) where 220instance KRPC KMessageOf (Query KMessageOf (Ping KMessageOf)) (Response KMessageOf (Ping KMessageOf)) where
221#ifdef VERSION_bencoding 221 method = "ping"
222 method = "ping" 222 makeQueryExtra _ nid _ _ = return $ MainlineQuery nid False -- TODO: check for NAT issues. (BEP 43)
223#else 223 makeResponseExtra _ nid _ _ = return $ MainlineResponse nid
224 method = Method Tox.Ping -- response: Tox.Pong 224
225#endif 225 -- TODO KError Sender/Responder
226 messageSender (Q q) _ = queringNodeId $ queryExtra $ queryArgs q
227 messageResponder _ (R r) = queredNodeId $ responseExtra $ respVals r
226 228
227{----------------------------------------------------------------------- 229{-----------------------------------------------------------------------
228-- find_node method 230-- find_node method
@@ -302,13 +304,14 @@ instance Serialize (Response KMessageOf (NodeFound KMessageOf ip)) where
302-- | \"q\" == \"find_node\" 304-- | \"q\" == \"find_node\"
303instance (Address ip, Typeable ip) 305instance (Address ip, Typeable ip)
304 => KRPC KMessageOf (Query KMessageOf (FindNode KMessageOf ip)) (Response KMessageOf (NodeFound KMessageOf ip)) where 306 => KRPC KMessageOf (Query KMessageOf (FindNode KMessageOf ip)) (Response KMessageOf (NodeFound KMessageOf ip)) where
305#ifdef VERSION_bencoding 307 method = "find_node"
306 method = "find_node" 308 makeQueryExtra _ nid _ _ = return $ MainlineQuery nid False -- TODO: check for NAT issues. (BEP 43)
307#else 309 makeResponseExtra _ nid _ _ = return $ MainlineResponse nid
308 method = Method Tox.GetNodes -- response: Tox.SendNodes 310
309#endif 311 -- TODO KError Sender/Responder
312 messageSender (Q q) _ = queringNodeId $ queryExtra $ queryArgs q
313 messageResponder _ (R r) = queredNodeId $ responseExtra $ respVals r
310 314
311#ifdef VERSION_bencoding
312{----------------------------------------------------------------------- 315{-----------------------------------------------------------------------
313-- get_peers method 316-- get_peers method
314-----------------------------------------------------------------------} 317-----------------------------------------------------------------------}
@@ -371,7 +374,14 @@ instance (Typeable ip, Serialize ip) => BEncode (GotPeers ip) where
371-- | \"q" = \"get_peers\" 374-- | \"q" = \"get_peers\"
372instance (Typeable ip, Serialize ip) => 375instance (Typeable ip, Serialize ip) =>
373 KRPC KMessageOf (Query KMessageOf (GetPeers ip)) (Response KMessageOf (GotPeers ip)) where 376 KRPC KMessageOf (Query KMessageOf (GetPeers ip)) (Response KMessageOf (GotPeers ip)) where
374 method = "get_peers" 377 method = "get_peers"
378 makeQueryExtra _ nid _ _ = return $ MainlineQuery nid False -- TODO: check for NAT issues. (BEP 43)
379 makeResponseExtra _ nid _ _ = return $ MainlineResponse nid
380
381 -- TODO KError Sender/Responder
382 messageSender (Q q) _ = queringNodeId $ queryExtra $ queryArgs q
383 messageResponder _ (R r) = queredNodeId $ responseExtra $ respVals r
384
375 385
376{----------------------------------------------------------------------- 386{-----------------------------------------------------------------------
377-- announce method 387-- announce method
@@ -443,10 +453,14 @@ instance BEncode Announced where
443 453
444-- | \"q" = \"announce\" 454-- | \"q" = \"announce\"
445instance KRPC KMessageOf (Query KMessageOf Announce) (Response KMessageOf Announced) where 455instance KRPC KMessageOf (Query KMessageOf Announce) (Response KMessageOf Announced) where
446 method = "announce_peer" 456 method = "announce_peer"
457 makeQueryExtra _ nid _ _ = return $ MainlineQuery nid False -- TODO: check for NAT issues. (BEP 43)
458 makeResponseExtra _ nid _ _ = return $ MainlineResponse nid
459
460 -- TODO KError Sender/Responder
461 messageSender (Q q) _ = queringNodeId $ queryExtra $ queryArgs q
462 messageResponder _ (R r) = queredNodeId $ responseExtra $ respVals r
447 463
448-- endif VERSION_bencoding
449#endif
450 464
451-- | Yields all 8 DHT neighborhoods available to you given a particular ip 465-- | Yields all 8 DHT neighborhoods available to you given a particular ip
452-- address. 466-- address.