summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2014-02-26 16:10:18 +0100
committerDaniel Gröber <dxld@darkboxed.org>2014-02-26 16:10:18 +0100
commit6146b69ecc0f47b1b09e0a3edfa92cb2eda61963 (patch)
tree686e6308f45146b5547228e3f4def851462feadd
parentb041624dca8b66d89180158e28bc5d0808046023 (diff)
parent80d9b5f02c5b245717651132482f11ac66a7ef4a (diff)
Merge branch 'master' of https://github.com/cobit/bittorrent
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/UDP.hs32
-rw-r--r--tests/Network/BitTorrent/DHT/MessageSpec.hs6
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.
63sec :: Int 64sec :: Int
64sec = 1000000 65sec = 1000000
65 66
67-- | See <http://www.bittorrent.org/beps/bep_0015.html#time-outs>
66defMinTimeout :: Int 68defMinTimeout :: Int
67defMinTimeout = 15 * sec 69defMinTimeout = 15 * sec
68 70
71-- | See <http://www.bittorrent.org/beps/bep_0015.html#time-outs>
69defMaxTimeout :: Int 72defMaxTimeout :: Int
70defMaxTimeout = 15 * 2 ^ (8 :: Int) * sec 73defMaxTimeout = 15 * 2 ^ (8 :: Int) * sec
71 74
75-- | See: <http://www.bittorrent.org/beps/bep_0015.html#time-outs>
72defMultiplier :: Int 76defMultiplier :: Int
73defMultiplier = 2 77defMultiplier = 2
74 78
75-- announce request packet 79-- TODO why 98?
76defMaxPacketSize :: Int 80defMaxPacketSize :: Int
77defMaxPacketSize = 98 81defMaxPacketSize = 98
78 82
83-- | Manager configuration.
79data Options = Options 84data 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.
91instance Default Options where 113instance 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
7import Data.ByteString.Lazy as BL 7import Data.ByteString.Lazy as BL
8import Data.Default 8import Data.Default
9import Data.List as L 9import Data.List as L
10import Data.Maybe
10import Network.BitTorrent.Core 11import Network.BitTorrent.Core
11import Network.BitTorrent.DHT.Message 12import Network.BitTorrent.DHT.Message
12import qualified Network.KRPC as KRPC (def) 13import qualified Network.KRPC as KRPC (def)
@@ -57,12 +58,13 @@ spec :: Spec
57spec = do 58spec = 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"