diff options
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC.hs | 5 | ||||
-rw-r--r-- | tests/Network/BitTorrent/Tracker/RPCSpec.hs | 7 |
3 files changed, 10 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index cab30331..c860d9d4 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs | |||
@@ -73,6 +73,10 @@ newtype PeerId = PeerId { getPeerId :: ByteString } | |||
73 | peerIdLen :: Int | 73 | peerIdLen :: Int |
74 | peerIdLen = 20 | 74 | peerIdLen = 20 |
75 | 75 | ||
76 | -- | For testing purposes only. | ||
77 | instance Default PeerId where | ||
78 | def = azureusStyle defaultClientId defaultVersionNumber "" | ||
79 | |||
76 | instance Hashable PeerId where | 80 | instance Hashable PeerId where |
77 | hashWithSalt = hashUsing getPeerId | 81 | hashWithSalt = hashUsing getPeerId |
78 | {-# INLINE hashWithSalt #-} | 82 | {-# INLINE hashWithSalt #-} |
diff --git a/src/Network/BitTorrent/Tracker/RPC.hs b/src/Network/BitTorrent/Tracker/RPC.hs index 0ffb2017..022751b4 100644 --- a/src/Network/BitTorrent/Tracker/RPC.hs +++ b/src/Network/BitTorrent/Tracker/RPC.hs | |||
@@ -47,10 +47,13 @@ import qualified Network.BitTorrent.Tracker.RPC.UDP as UDP | |||
47 | -- | Info to advertise to trackers. | 47 | -- | Info to advertise to trackers. |
48 | data PeerInfo = PeerInfo | 48 | data PeerInfo = PeerInfo |
49 | { peerId :: !PeerId | 49 | { peerId :: !PeerId |
50 | , peerPort :: !PortNumber | ||
51 | , peerIP :: !(Maybe HostAddress) | 50 | , peerIP :: !(Maybe HostAddress) |
51 | , peerPort :: !PortNumber | ||
52 | } deriving (Show, Eq) | 52 | } deriving (Show, Eq) |
53 | 53 | ||
54 | instance Default PeerInfo where | ||
55 | def = PeerInfo def Nothing 6881 | ||
56 | |||
54 | -- | Simplified announce query. | 57 | -- | Simplified announce query. |
55 | data SAnnounceQuery = SAnnounceQuery | 58 | data SAnnounceQuery = SAnnounceQuery |
56 | { sInfoHash :: InfoHash | 59 | { sInfoHash :: InfoHash |
diff --git a/tests/Network/BitTorrent/Tracker/RPCSpec.hs b/tests/Network/BitTorrent/Tracker/RPCSpec.hs index da4a0878..c3c7f9e2 100644 --- a/tests/Network/BitTorrent/Tracker/RPCSpec.hs +++ b/tests/Network/BitTorrent/Tracker/RPCSpec.hs | |||
@@ -15,9 +15,6 @@ import Network.BitTorrent.Tracker.RPC as RPC | |||
15 | uris :: [URI] | 15 | uris :: [URI] |
16 | uris = UDP.trackerURIs ++ HTTP.trackerURIs | 16 | uris = UDP.trackerURIs ++ HTTP.trackerURIs |
17 | 17 | ||
18 | pinfo :: PeerInfo | ||
19 | pinfo = PeerInfo "-HS0003-203534.37422" 6000 Nothing | ||
20 | |||
21 | instance Arbitrary SAnnounceQuery where | 18 | instance Arbitrary SAnnounceQuery where |
22 | arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary | 19 | arbitrary = SAnnounceQuery <$> arbitrary <*> arbitrary |
23 | <*> arbitrary <*> arbitrary | 20 | <*> arbitrary <*> arbitrary |
@@ -28,13 +25,13 @@ spec = do | |||
28 | context (show uri) $ do | 25 | context (show uri) $ do |
29 | describe "announce" $ do | 26 | describe "announce" $ do |
30 | it "have valid response" $ do | 27 | it "have valid response" $ do |
31 | withManager def pinfo $ \ mgr -> do | 28 | withManager def def $ \ mgr -> do |
32 | q <- arbitrarySample | 29 | q <- arbitrarySample |
33 | _ <- announce mgr uri q | 30 | _ <- announce mgr uri q |
34 | return () | 31 | return () |
35 | 32 | ||
36 | describe "scrape" $ do | 33 | describe "scrape" $ do |
37 | it "have valid response" $ do | 34 | it "have valid response" $ do |
38 | withManager def pinfo $ \ mgr -> do | 35 | withManager def def $ \ mgr -> do |
39 | xs <- scrape mgr uri [def] | 36 | xs <- scrape mgr uri [def] |
40 | L.length xs `shouldSatisfy` (>= 1) | 37 | L.length xs `shouldSatisfy` (>= 1) |