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.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/DHT/Message.hs b/src/Network/BitTorrent/DHT/Message.hs
index 0e2bfdd9..c3df683a 100644
--- a/src/Network/BitTorrent/DHT/Message.hs
+++ b/src/Network/BitTorrent/DHT/Message.hs
@@ -93,15 +93,14 @@ import Data.Bool
93#ifdef VERSION_bencoding 93#ifdef VERSION_bencoding
94import Data.BEncode as BE 94import Data.BEncode as BE
95import Data.BEncode.BDict as BDict 95import Data.BEncode.BDict as BDict
96import Network.BitTorrent.Address
97#else 96#else
98import qualified Data.Tox as Tox 97import qualified Data.Tox as Tox
99import Data.Tox (NodeId) 98import Data.Tox (NodeId)
100import Data.Word 99import Data.Word
101import Control.Monad 100import Control.Monad
102import Network.KRPC.Method 101import Network.KRPC.Method
103import Network.BitTorrent.Address hiding (NodeId)
104#endif 102#endif
103import Network.BitTorrent.Address hiding (NodeId)
105import Data.ByteString (ByteString) 104import Data.ByteString (ByteString)
106import Data.List as L 105import Data.List as L
107import Data.Monoid 106import Data.Monoid
@@ -109,11 +108,14 @@ import Data.Serialize as S
109import Data.Typeable 108import Data.Typeable
110import Network 109import Network
111import Network.KRPC 110import Network.KRPC
111import Network.KRPC.Message (KMessageOf)
112import Data.Maybe 112import Data.Maybe
113 113
114import Data.Torrent (InfoHash) 114import Data.Torrent (InfoHash)
115import Network.BitTorrent.DHT.Token 115import Network.BitTorrent.DHT.Token
116import Network.KRPC () 116import Network.KRPC ()
117import Network.DHT.Mainline ()
118import Network.RPC hiding (Query,Response)
117 119
118{----------------------------------------------------------------------- 120{-----------------------------------------------------------------------
119-- envelopes 121-- envelopes
@@ -134,7 +136,7 @@ read_only_key = "ro"
134-- | All queries have an \"id\" key and value containing the node ID 136-- | All queries have an \"id\" key and value containing the node ID
135-- of the querying node. 137-- of the querying node.
136data Query a = Query 138data Query a = Query
137 { queringNodeId :: NodeId -- ^ node id of /quering/ node; 139 { queringNodeId :: NodeId KMessageOf -- ^ node id of /quering/ node;
138 , queryIsReadOnly :: Bool -- ^ node is read-only as per BEP 43 140 , queryIsReadOnly :: Bool -- ^ node is read-only as per BEP 43
139 , queryParams :: a -- ^ query parameters. 141 , queryParams :: a -- ^ query parameters.
140 } deriving (Show, Eq, Typeable) 142 } deriving (Show, Eq, Typeable)
@@ -161,7 +163,7 @@ data Query a = Query a
161-- | All responses have an \"id\" key and value containing the node ID 163-- | All responses have an \"id\" key and value containing the node ID
162-- of the responding node. 164-- of the responding node.
163data Response a = Response 165data Response a = Response
164 { queredNodeId :: NodeId -- ^ node id of /quered/ node; 166 { queredNodeId :: NodeId KMessageOf -- ^ node id of /quered/ node;
165 , responseVals :: a -- ^ query result. 167 , responseVals :: a -- ^ query result.
166 } deriving (Show, Eq, Typeable) 168 } deriving (Show, Eq, Typeable)
167 169
@@ -233,7 +235,7 @@ instance KRPC (Query Ping) (Response Ping) where
233-- | Find node is used to find the contact information for a node 235-- | Find node is used to find the contact information for a node
234-- given its ID. 236-- given its ID.
235#ifdef VERSION_bencoding 237#ifdef VERSION_bencoding
236newtype FindNode ip = FindNode NodeId 238newtype FindNode ip = FindNode (NodeId KMessageOf)
237#else 239#else
238data FindNode ip = FindNode NodeId Tox.Nonce8 -- Tox: Get Nodes 240data FindNode ip = FindNode NodeId Tox.Nonce8 -- Tox: Get Nodes
239#endif 241#endif
@@ -262,7 +264,7 @@ instance Serialize (Query (FindNode ip)) where
262-- nodes in its own routing table. 264-- nodes in its own routing table.
263-- 265--
264#ifdef VERSION_bencoding 266#ifdef VERSION_bencoding
265newtype NodeFound ip = NodeFound [NodeInfo ip] 267newtype NodeFound ip = NodeFound [NodeInfo KMessageOf ip ()]
266#else 268#else
267data NodeFound ip = NodeFound [Tox.NodeFormat] Tox.Nonce8 269data NodeFound ip = NodeFound [Tox.NodeFormat] Tox.Nonce8
268#endif 270#endif
@@ -273,9 +275,9 @@ nodes_key :: BKey
273nodes_key = "nodes" 275nodes_key = "nodes"
274 276
275-- Convert IPv4 address. Useful for using variadic IP type. 277-- Convert IPv4 address. Useful for using variadic IP type.
276from4 :: forall s. Address s => NodeInfo IPv4 -> Either String (NodeInfo s) 278from4 :: forall dht u s. Address s => NodeInfo dht IPv4 u -> Either String (NodeInfo dht s u)
277from4 n = maybe (Left "Error converting IPv4") Right 279from4 n = maybe (Left "Error converting IPv4") Right
278 $ traverse (fromAddr :: IPv4 -> Maybe s) n 280 $ traverseAddress (fromAddr :: IPv4 -> Maybe s) n
279 281
280#ifdef VERSION_bencoding 282#ifdef VERSION_bencoding
281binary :: Serialize a => BKey -> BE.Get [a] 283binary :: Serialize a => BKey -> BE.Get [a]
@@ -334,7 +336,7 @@ instance Typeable ip => BEncode (GetPeers ip) where
334 toBEncode (GetPeers ih) = toDict $ info_hash_key .=! ih .: endDict 336 toBEncode (GetPeers ih) = toDict $ info_hash_key .=! ih .: endDict
335 fromBEncode = fromDict $ GetPeers <$>! info_hash_key 337 fromBEncode = fromDict $ GetPeers <$>! info_hash_key
336 338
337type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] 339type PeerList ip = Either [NodeInfo KMessageOf ip ()] [PeerAddr ip]
338 340
339data GotPeers ip = GotPeers 341data GotPeers ip = GotPeers
340 { -- | If the queried node has no peers for the infohash, returned 342 { -- | If the queried node has no peers for the infohash, returned