summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-13 07:36:48 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-13 07:36:48 +0400
commit38d8eb046cefce18a6689488994c05abf1223ffe (patch)
treea222a85d637759befe1f88ba0c775cc6f8a56181 /src/Network/BitTorrent
parent9557004a2c916d475038f99cf26e5c36bbbae0a4 (diff)
+ Add defaultClient function.
This exposes problems with keepalives: exsample: sendWakeup: resource exhausted (Resource temporarily unavailable )
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Extension.hs14
-rw-r--r--src/Network/BitTorrent/Internal.hs18
2 files changed, 23 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/Extension.hs b/src/Network/BitTorrent/Extension.hs
index 13a30581..a498bc19 100644
--- a/src/Network/BitTorrent/Extension.hs
+++ b/src/Network/BitTorrent/Extension.hs
@@ -12,8 +12,15 @@
12-- 12--
13{-# LANGUAGE OverloadedStrings #-} 13{-# LANGUAGE OverloadedStrings #-}
14module Network.BitTorrent.Extension 14module Network.BitTorrent.Extension
15 ( Capabilities, ppCaps, defaultCaps, enabledCaps 15 ( -- * Capabilities
16 , Extension(..), ppExtension, encodeExts, decodeExts 16 Capabilities
17 , ppCaps, defaultCaps
18 , enabledCaps
19
20 -- * Extensions
21 , Extension(..)
22 , defaultExtensions, ppExtension
23 , encodeExts, decodeExts
17 ) where 24 ) where
18 25
19import Data.Bits 26import Data.Bits
@@ -35,7 +42,6 @@ enabledCaps :: Capabilities -- ^ of the client.
35enabledCaps = (.&.) 42enabledCaps = (.&.)
36 43
37 44
38
39data Extension = ExtDHT -- ^ BEP 5 45data Extension = ExtDHT -- ^ BEP 5
40 | ExtFast -- ^ BEP 6 46 | ExtFast -- ^ BEP 6
41 deriving (Show, Eq, Ord, Enum, Bounded) 47 deriving (Show, Eq, Ord, Enum, Bounded)
@@ -48,6 +54,8 @@ extensionMask :: Extension -> Word64
48extensionMask ExtDHT = 0x01 54extensionMask ExtDHT = 0x01
49extensionMask ExtFast = 0x04 55extensionMask ExtFast = 0x04
50 56
57defaultExtensions :: [Extension]
58defaultExtensions = []
51 59
52encodeExts :: [Extension] -> Capabilities 60encodeExts :: [Extension] -> Capabilities
53encodeExts = foldr (.&.) 0 . map extensionMask 61encodeExts = foldr (.&.) 0 . map extensionMask
diff --git a/src/Network/BitTorrent/Internal.hs b/src/Network/BitTorrent/Internal.hs
index 2fadd9ce..afe1fff1 100644
--- a/src/Network/BitTorrent/Internal.hs
+++ b/src/Network/BitTorrent/Internal.hs
@@ -28,6 +28,8 @@ module Network.BitTorrent.Internal
28 , ClientSession (clientPeerID, allowedExtensions) 28 , ClientSession (clientPeerID, allowedExtensions)
29 , newClient, getCurrentProgress 29 , newClient, getCurrentProgress
30 30
31 , ThreadCount, defaultThreadCount
32
31 -- * Swarm 33 -- * Swarm
32 , SwarmSession(SwarmSession, torrentMeta, clientSession) 34 , SwarmSession(SwarmSession, torrentMeta, clientSession)
33 , newLeacher, newSeeder 35 , newLeacher, newSeeder
@@ -109,6 +111,9 @@ startProgress = Progress 0 0
109 111
110type ThreadCount = Int 112type ThreadCount = Int
111 113
114defaultThreadCount :: ThreadCount
115defaultThreadCount = 1000
116
112-- | In one application we could have many clients with difference 117-- | In one application we could have many clients with difference
113-- ID's and different enabled extensions. 118-- ID's and different enabled extensions.
114data ClientSession = ClientSession { 119data ClientSession = ClientSession {
@@ -166,6 +171,13 @@ newClient n exts = do
166 171
167type SessionCount = Int 172type SessionCount = Int
168 173
174defSeederConns :: SessionCount
175defSeederConns = defaultUnchokeSlots
176
177defLeacherConns :: SessionCount
178defLeacherConns = defaultNumWant
179
180
169-- | Extensions are set globally by 181-- | Extensions are set globally by
170-- Swarm session are un 182-- Swarm session are un
171data SwarmSession = SwarmSession { 183data SwarmSession = SwarmSession {
@@ -204,12 +216,6 @@ newLeacher :: ClientSession -> Torrent -> IO SwarmSession
204newLeacher cs t @ Torrent {..} 216newLeacher cs t @ Torrent {..}
205 = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t 217 = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t
206 218
207defSeederConns :: SessionCount
208defSeederConns = defaultUnchokeSlots
209
210defLeacherConns :: SessionCount
211defLeacherConns = defaultNumWant
212
213--isLeacher :: SwarmSession -> IO Bool 219--isLeacher :: SwarmSession -> IO Bool
214--isLeacher = undefined 220--isLeacher = undefined
215 221