diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT/Message.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/Message.hs | 20 |
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 |
94 | import Data.BEncode as BE | 94 | import Data.BEncode as BE |
95 | import Data.BEncode.BDict as BDict | 95 | import Data.BEncode.BDict as BDict |
96 | import Network.BitTorrent.Address | ||
97 | #else | 96 | #else |
98 | import qualified Data.Tox as Tox | 97 | import qualified Data.Tox as Tox |
99 | import Data.Tox (NodeId) | 98 | import Data.Tox (NodeId) |
100 | import Data.Word | 99 | import Data.Word |
101 | import Control.Monad | 100 | import Control.Monad |
102 | import Network.KRPC.Method | 101 | import Network.KRPC.Method |
103 | import Network.BitTorrent.Address hiding (NodeId) | ||
104 | #endif | 102 | #endif |
103 | import Network.BitTorrent.Address hiding (NodeId) | ||
105 | import Data.ByteString (ByteString) | 104 | import Data.ByteString (ByteString) |
106 | import Data.List as L | 105 | import Data.List as L |
107 | import Data.Monoid | 106 | import Data.Monoid |
@@ -109,11 +108,14 @@ import Data.Serialize as S | |||
109 | import Data.Typeable | 108 | import Data.Typeable |
110 | import Network | 109 | import Network |
111 | import Network.KRPC | 110 | import Network.KRPC |
111 | import Network.KRPC.Message (KMessageOf) | ||
112 | import Data.Maybe | 112 | import Data.Maybe |
113 | 113 | ||
114 | import Data.Torrent (InfoHash) | 114 | import Data.Torrent (InfoHash) |
115 | import Network.BitTorrent.DHT.Token | 115 | import Network.BitTorrent.DHT.Token |
116 | import Network.KRPC () | 116 | import Network.KRPC () |
117 | import Network.DHT.Mainline () | ||
118 | import 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. |
136 | data Query a = Query | 138 | data 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. |
163 | data Response a = Response | 165 | data 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 |
236 | newtype FindNode ip = FindNode NodeId | 238 | newtype FindNode ip = FindNode (NodeId KMessageOf) |
237 | #else | 239 | #else |
238 | data FindNode ip = FindNode NodeId Tox.Nonce8 -- Tox: Get Nodes | 240 | data 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 |
265 | newtype NodeFound ip = NodeFound [NodeInfo ip] | 267 | newtype NodeFound ip = NodeFound [NodeInfo KMessageOf ip ()] |
266 | #else | 268 | #else |
267 | data NodeFound ip = NodeFound [Tox.NodeFormat] Tox.Nonce8 | 269 | data NodeFound ip = NodeFound [Tox.NodeFormat] Tox.Nonce8 |
268 | #endif | 270 | #endif |
@@ -273,9 +275,9 @@ nodes_key :: BKey | |||
273 | nodes_key = "nodes" | 275 | nodes_key = "nodes" |
274 | 276 | ||
275 | -- Convert IPv4 address. Useful for using variadic IP type. | 277 | -- Convert IPv4 address. Useful for using variadic IP type. |
276 | from4 :: forall s. Address s => NodeInfo IPv4 -> Either String (NodeInfo s) | 278 | from4 :: forall dht u s. Address s => NodeInfo dht IPv4 u -> Either String (NodeInfo dht s u) |
277 | from4 n = maybe (Left "Error converting IPv4") Right | 279 | from4 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 |
281 | binary :: Serialize a => BKey -> BE.Get [a] | 283 | binary :: 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 | ||
337 | type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] | 339 | type PeerList ip = Either [NodeInfo KMessageOf ip ()] [PeerAddr ip] |
338 | 340 | ||
339 | data GotPeers ip = GotPeers | 341 | data 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 |