summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Message.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-22 18:11:58 -0500
committerjoe <joe@jerkface.net>2017-01-22 18:11:58 -0500
commite7c2f98454a4e52b7e7b62b49f91b59cfc77a91b (patch)
tree40ae4586e590f88c56a4d4d4e8a8d669f9b23944 /src/Network/BitTorrent/DHT/Message.hs
parent8cf4de73d77197032fd8ebfc4e4f3a00b287e0e7 (diff)
PSQ instead of list for peer set. Also: dhtd "swarms" command.
Diffstat (limited to 'src/Network/BitTorrent/DHT/Message.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Message.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/Message.hs b/src/Network/BitTorrent/DHT/Message.hs
index 9d66741f..d31cce82 100644
--- a/src/Network/BitTorrent/DHT/Message.hs
+++ b/src/Network/BitTorrent/DHT/Message.hs
@@ -86,6 +86,7 @@ module Network.BitTorrent.DHT.Message
86import Control.Applicative 86import Control.Applicative
87import Data.BEncode as BE 87import Data.BEncode as BE
88import Data.BEncode.BDict 88import Data.BEncode.BDict
89import Data.ByteString (ByteString)
89import Data.List as L 90import Data.List as L
90import Data.Monoid 91import Data.Monoid
91import Data.Serialize as S 92import Data.Serialize as S
@@ -251,6 +252,9 @@ peers_key = "values"
251token_key :: BKey 252token_key :: BKey
252token_key = "token" 253token_key = "token"
253 254
255name_key :: BKey
256name_key = "name"
257
254instance (Typeable ip, Serialize ip) => BEncode (GotPeers ip) where 258instance (Typeable ip, Serialize ip) => BEncode (GotPeers ip) where
255 toBEncode GotPeers {..} = toDict $ 259 toBEncode GotPeers {..} = toDict $
256 case peers of 260 case peers of
@@ -295,11 +299,17 @@ data Announce = Announce
295 -- | infohash of the torrent; 299 -- | infohash of the torrent;
296 , topic :: InfoHash 300 , topic :: InfoHash
297 301
302 -- | some clients announce the friendly name of the torrent here.
303 , announcedName :: Maybe ByteString
304
298 -- | the port /this/ peer is listening; 305 -- | the port /this/ peer is listening;
299 , port :: PortNumber 306 , port :: PortNumber
300 307
308 -- TODO: optional boolean "seed" key
309
301 -- | received in response to a previous get_peers query. 310 -- | received in response to a previous get_peers query.
302 , sessionToken :: Token 311 , sessionToken :: Token
312
303 } deriving (Show, Eq, Typeable) 313 } deriving (Show, Eq, Typeable)
304 314
305port_key :: BKey 315port_key :: BKey
@@ -312,6 +322,7 @@ instance BEncode Announce where
312 toBEncode Announce {..} = toDict $ 322 toBEncode Announce {..} = toDict $
313 implied_port_key .=? flagField impliedPort 323 implied_port_key .=? flagField impliedPort
314 .: info_hash_key .=! topic 324 .: info_hash_key .=! topic
325 .: name_key .=? announcedName
315 .: port_key .=! port 326 .: port_key .=! port
316 .: token_key .=! sessionToken 327 .: token_key .=! sessionToken
317 .: endDict 328 .: endDict
@@ -321,6 +332,7 @@ instance BEncode Announce where
321 fromBEncode = fromDict $ do 332 fromBEncode = fromDict $ do
322 Announce <$> (boolField <$> optional (field (req implied_port_key))) 333 Announce <$> (boolField <$> optional (field (req implied_port_key)))
323 <*>! info_hash_key 334 <*>! info_hash_key
335 <*>? name_key
324 <*>! port_key 336 <*>! port_key
325 <*>! token_key 337 <*>! token_key
326 where 338 where