diff options
-rw-r--r-- | src/Network/BitTorrent/Tracker/RPC/UDP.hs | 32 | ||||
-rw-r--r-- | tests/Network/BitTorrent/DHT/MessageSpec.hs | 6 |
2 files changed, 31 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs index db9c32b3..b0f44ec6 100644 --- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs +++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs | |||
@@ -60,34 +60,56 @@ import Network.BitTorrent.Tracker.Message | |||
60 | -- Options | 60 | -- Options |
61 | -----------------------------------------------------------------------} | 61 | -----------------------------------------------------------------------} |
62 | 62 | ||
63 | -- | 'System.Timeout.timeout' specific. | ||
63 | sec :: Int | 64 | sec :: Int |
64 | sec = 1000000 | 65 | sec = 1000000 |
65 | 66 | ||
67 | -- | See <http://www.bittorrent.org/beps/bep_0015.html#time-outs> | ||
66 | defMinTimeout :: Int | 68 | defMinTimeout :: Int |
67 | defMinTimeout = 15 * sec | 69 | defMinTimeout = 15 * sec |
68 | 70 | ||
71 | -- | See <http://www.bittorrent.org/beps/bep_0015.html#time-outs> | ||
69 | defMaxTimeout :: Int | 72 | defMaxTimeout :: Int |
70 | defMaxTimeout = 15 * 2 ^ (8 :: Int) * sec | 73 | defMaxTimeout = 15 * 2 ^ (8 :: Int) * sec |
71 | 74 | ||
75 | -- | See: <http://www.bittorrent.org/beps/bep_0015.html#time-outs> | ||
72 | defMultiplier :: Int | 76 | defMultiplier :: Int |
73 | defMultiplier = 2 | 77 | defMultiplier = 2 |
74 | 78 | ||
75 | -- announce request packet | 79 | -- TODO why 98? |
76 | defMaxPacketSize :: Int | 80 | defMaxPacketSize :: Int |
77 | defMaxPacketSize = 98 | 81 | defMaxPacketSize = 98 |
78 | 82 | ||
83 | -- | Manager configuration. | ||
79 | data Options = Options | 84 | data Options = Options |
80 | { optMaxPacketSize :: {-# UNPACK #-} !Int | 85 | { -- | Max size of a /response/ packet. |
81 | 86 | -- | |
82 | -- | in seconds. | 87 | -- 'optMaxPacketSize' /must/ be a positive value. |
88 | -- | ||
89 | optMaxPacketSize :: {-# UNPACK #-} !Int | ||
90 | |||
91 | -- | Starting timeout interval. If a response is not received | ||
92 | -- after 'optMinTimeout' then 'Manager' repeat RPC with timeout | ||
93 | -- interval multiplied by 'optMultiplier' and so on until | ||
94 | -- timeout interval reach 'optMaxTimeout'. | ||
95 | -- | ||
96 | -- 'optMinTimeout' /must/ be a positive value. | ||
97 | -- | ||
83 | , optMinTimeout :: {-# UNPACK #-} !Int | 98 | , optMinTimeout :: {-# UNPACK #-} !Int |
84 | 99 | ||
85 | -- | in seconds. | 100 | -- | After 'optMaxTimeout' reached and tracker still not |
101 | -- responding both 'announce' and 'scrape' functions will throw | ||
102 | -- 'TimeoutExpired' exception. | ||
103 | -- | ||
104 | -- 'optMaxTimeout' /must/ be greater than 'optMinTimeout'. | ||
105 | -- | ||
86 | , optMaxTimeout :: {-# UNPACK #-} !Int | 106 | , optMaxTimeout :: {-# UNPACK #-} !Int |
87 | 107 | ||
108 | -- | 'optMultiplier' must a positive value. | ||
88 | , optMultiplier :: {-# UNPACK #-} !Int | 109 | , optMultiplier :: {-# UNPACK #-} !Int |
89 | } deriving (Show, Eq) | 110 | } deriving (Show, Eq) |
90 | 111 | ||
112 | -- | Options suitable for bittorrent client. | ||
91 | instance Default Options where | 113 | instance Default Options where |
92 | def = Options | 114 | def = Options |
93 | { optMaxPacketSize = defMaxPacketSize | 115 | { optMaxPacketSize = defMaxPacketSize |
diff --git a/tests/Network/BitTorrent/DHT/MessageSpec.hs b/tests/Network/BitTorrent/DHT/MessageSpec.hs index 0d84c919..4ec875dd 100644 --- a/tests/Network/BitTorrent/DHT/MessageSpec.hs +++ b/tests/Network/BitTorrent/DHT/MessageSpec.hs | |||
@@ -7,6 +7,7 @@ import Data.BEncode as BE | |||
7 | import Data.ByteString.Lazy as BL | 7 | import Data.ByteString.Lazy as BL |
8 | import Data.Default | 8 | import Data.Default |
9 | import Data.List as L | 9 | import Data.List as L |
10 | import Data.Maybe | ||
10 | import Network.BitTorrent.Core | 11 | import Network.BitTorrent.Core |
11 | import Network.BitTorrent.DHT.Message | 12 | import Network.BitTorrent.DHT.Message |
12 | import qualified Network.KRPC as KRPC (def) | 13 | import qualified Network.KRPC as KRPC (def) |
@@ -57,12 +58,13 @@ spec :: Spec | |||
57 | spec = do | 58 | spec = do |
58 | context ("you need running DHT node at " ++ show remoteAddr) $ do | 59 | context ("you need running DHT node at " ++ show remoteAddr) $ do |
59 | it "is running" $ do | 60 | it "is running" $ do |
60 | _ <- retry 5 $ timeout (100 * 1000) $ do | 61 | running <- retry 5 $ timeout (100 * 1000) $ do |
61 | nid <- genNodeId | 62 | nid <- genNodeId |
62 | Response _remoteAddr Ping <- | 63 | Response _remoteAddr Ping <- |
63 | rpc (query remoteAddr (Query nid Ping)) | 64 | rpc (query remoteAddr (Query nid Ping)) |
64 | return () | 65 | return () |
65 | return () | 66 | running `shouldSatisfy` isJust |
67 | |||
66 | describe "ping" $ do | 68 | describe "ping" $ do |
67 | it "properly bencoded" $ do | 69 | it "properly bencoded" $ do |
68 | BE.decode "d2:id20:abcdefghij0123456789e" | 70 | BE.decode "d2:id20:abcdefghij0123456789e" |