summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent.hs8
-rw-r--r--src/Network/BitTorrent/Extension.hs14
-rw-r--r--src/Network/BitTorrent/Internal.hs18
3 files changed, 30 insertions, 10 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index b9dc39eb..546c7644 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -12,7 +12,7 @@ module Network.BitTorrent
12 12
13 -- * Session 13 -- * Session
14 , ClientSession 14 , ClientSession
15 , newClient 15 , newClient, defaultClient
16 16
17 , SwarmSession 17 , SwarmSession
18 , newLeacher, newSeeder 18 , newLeacher, newSeeder
@@ -27,6 +27,8 @@ module Network.BitTorrent
27 , Block(..), BlockIx(..), ppBlock, ppBlockIx 27 , Block(..), BlockIx(..), ppBlock, ppBlockIx
28 28
29 , awaitEvent, yieldEvent 29 , awaitEvent, yieldEvent
30
31 , Extension, defaultExtensions, ppExtension
30 ) where 32 ) where
31 33
32import Control.Concurrent 34import Control.Concurrent
@@ -41,7 +43,11 @@ import Network.BitTorrent.Internal
41import Network.BitTorrent.Exchange 43import Network.BitTorrent.Exchange
42import Network.BitTorrent.Exchange.Protocol 44import Network.BitTorrent.Exchange.Protocol
43import Network.BitTorrent.Tracker 45import Network.BitTorrent.Tracker
46import Network.BitTorrent.Extension
47
44 48
49defaultClient :: IO ClientSession
50defaultClient = newClient defaultThreadCount defaultExtensions
45 51
46-- discover should hide tracker and DHT communication under the hood 52-- discover should hide tracker and DHT communication under the hood
47-- thus we can obtain an unified interface 53-- thus we can obtain an unified interface
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