diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/BitTorrent.hs | 8 | ||||
-rw-r--r-- | src/Network/BitTorrent/Extension.hs | 14 | ||||
-rw-r--r-- | src/Network/BitTorrent/Internal.hs | 18 |
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 | ||
32 | import Control.Concurrent | 34 | import Control.Concurrent |
@@ -41,7 +43,11 @@ import Network.BitTorrent.Internal | |||
41 | import Network.BitTorrent.Exchange | 43 | import Network.BitTorrent.Exchange |
42 | import Network.BitTorrent.Exchange.Protocol | 44 | import Network.BitTorrent.Exchange.Protocol |
43 | import Network.BitTorrent.Tracker | 45 | import Network.BitTorrent.Tracker |
46 | import Network.BitTorrent.Extension | ||
47 | |||
44 | 48 | ||
49 | defaultClient :: IO ClientSession | ||
50 | defaultClient = 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 #-} |
14 | module Network.BitTorrent.Extension | 14 | module 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 | ||
19 | import Data.Bits | 26 | import Data.Bits |
@@ -35,7 +42,6 @@ enabledCaps :: Capabilities -- ^ of the client. | |||
35 | enabledCaps = (.&.) | 42 | enabledCaps = (.&.) |
36 | 43 | ||
37 | 44 | ||
38 | |||
39 | data Extension = ExtDHT -- ^ BEP 5 | 45 | data 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 | |||
48 | extensionMask ExtDHT = 0x01 | 54 | extensionMask ExtDHT = 0x01 |
49 | extensionMask ExtFast = 0x04 | 55 | extensionMask ExtFast = 0x04 |
50 | 56 | ||
57 | defaultExtensions :: [Extension] | ||
58 | defaultExtensions = [] | ||
51 | 59 | ||
52 | encodeExts :: [Extension] -> Capabilities | 60 | encodeExts :: [Extension] -> Capabilities |
53 | encodeExts = foldr (.&.) 0 . map extensionMask | 61 | encodeExts = 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 | ||
110 | type ThreadCount = Int | 112 | type ThreadCount = Int |
111 | 113 | ||
114 | defaultThreadCount :: ThreadCount | ||
115 | defaultThreadCount = 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. |
114 | data ClientSession = ClientSession { | 119 | data ClientSession = ClientSession { |
@@ -166,6 +171,13 @@ newClient n exts = do | |||
166 | 171 | ||
167 | type SessionCount = Int | 172 | type SessionCount = Int |
168 | 173 | ||
174 | defSeederConns :: SessionCount | ||
175 | defSeederConns = defaultUnchokeSlots | ||
176 | |||
177 | defLeacherConns :: SessionCount | ||
178 | defLeacherConns = 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 |
171 | data SwarmSession = SwarmSession { | 183 | data SwarmSession = SwarmSession { |
@@ -204,12 +216,6 @@ newLeacher :: ClientSession -> Torrent -> IO SwarmSession | |||
204 | newLeacher cs t @ Torrent {..} | 216 | newLeacher cs t @ Torrent {..} |
205 | = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t | 217 | = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t |
206 | 218 | ||
207 | defSeederConns :: SessionCount | ||
208 | defSeederConns = defaultUnchokeSlots | ||
209 | |||
210 | defLeacherConns :: SessionCount | ||
211 | defLeacherConns = defaultNumWant | ||
212 | |||
213 | --isLeacher :: SwarmSession -> IO Bool | 219 | --isLeacher :: SwarmSession -> IO Bool |
214 | --isLeacher = undefined | 220 | --isLeacher = undefined |
215 | 221 | ||