diff options
author | joe <joe@jerkface.net> | 2017-10-16 19:22:53 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-10-16 19:22:53 -0400 |
commit | 35aed24bdd67cecbd77e0c64c6c054e736aac787 (patch) | |
tree | 6211ae95a2ba74f181e7fb7f93c736bf44c71960 /src/Network/BitTorrent | |
parent | c75c9c8714b1e2f489ac5fe365ecda618c8da872 (diff) |
Untested announce-peer command for bittorrent dht.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT/Token.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/MainlineDHT.hs | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/Token.hs b/src/Network/BitTorrent/DHT/Token.hs index 756b5a98..3da59c53 100644 --- a/src/Network/BitTorrent/DHT/Token.hs +++ b/src/Network/BitTorrent/DHT/Token.hs | |||
@@ -44,6 +44,7 @@ module Network.BitTorrent.DHT.Token | |||
44 | , Network.BitTorrent.DHT.Token.update | 44 | , Network.BitTorrent.DHT.Token.update |
45 | ) where | 45 | ) where |
46 | 46 | ||
47 | import Control.Arrow | ||
47 | import Control.Monad.State | 48 | import Control.Monad.State |
48 | #ifdef VERSION_bencoding | 49 | #ifdef VERSION_bencoding |
49 | import Data.BEncode (BEncode) | 50 | import Data.BEncode (BEncode) |
@@ -75,6 +76,9 @@ newtype Token = Token BS.ByteString | |||
75 | instance Show Token where | 76 | instance Show Token where |
76 | show (Token bs) = B8.unpack $ Base16.encode bs | 77 | show (Token bs) = B8.unpack $ Base16.encode bs |
77 | 78 | ||
79 | instance Read Token where | ||
80 | readsPrec i s = pure $ (Token *** B8.unpack) $ Base16.decode (B8.pack s) | ||
81 | |||
78 | -- | Meaningless token, for testing purposes only. | 82 | -- | Meaningless token, for testing purposes only. |
79 | instance Default Token where | 83 | instance Default Token where |
80 | def = makeToken (0::Int) 0 | 84 | def = makeToken (0::Int) 0 |
diff --git a/src/Network/BitTorrent/MainlineDHT.hs b/src/Network/BitTorrent/MainlineDHT.hs index f4ce4019..a7359bda 100644 --- a/src/Network/BitTorrent/MainlineDHT.hs +++ b/src/Network/BitTorrent/MainlineDHT.hs | |||
@@ -906,6 +906,15 @@ data Announce = Announce | |||
906 | 906 | ||
907 | } deriving (Show, Eq, Typeable) | 907 | } deriving (Show, Eq, Typeable) |
908 | 908 | ||
909 | mkAnnounce :: PortNumber -> InfoHash -> Token -> Announce | ||
910 | mkAnnounce portnum info token = Announce | ||
911 | { topic = info | ||
912 | , port = portnum | ||
913 | , sessionToken = token | ||
914 | , announcedName = Nothing | ||
915 | , impliedPort = False | ||
916 | } | ||
917 | |||
909 | peer_ip_key = "ip" | 918 | peer_ip_key = "ip" |
910 | peer_id_key = "peer id" | 919 | peer_id_key = "peer id" |
911 | peer_port_key = "port" | 920 | peer_port_key = "port" |
@@ -1078,3 +1087,6 @@ resolve want hostAndPort = do | |||
1078 | return $ addrAddress info | 1087 | return $ addrAddress info |
1079 | 1088 | ||
1080 | 1089 | ||
1090 | announce :: MainlineClient -> Announce -> NodeInfo -> IO (Maybe Announced) | ||
1091 | announce client msg addr = do | ||
1092 | mainlineSend (Method "announce_peer") id (\() -> msg) client () addr | ||