diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-14 03:36:40 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-14 03:36:40 +0400 |
commit | 5cd492bc9e7ebbaa9557f7a6ae15582febd60a7d (patch) | |
tree | c14ccd9ae6228bd03aec587aa23b5f38459b4abd /src/Network/BitTorrent | |
parent | 3e61effb90416456f98c3db3224db9c7343eed6c (diff) |
~ Remove DHT stuff from Sessions.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Sessions.hs | 28 | ||||
-rw-r--r-- | src/Network/BitTorrent/Sessions/Types.lhs | 1 |
2 files changed, 3 insertions, 26 deletions
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs index 7fcde20b..1f34bd4c 100644 --- a/src/Network/BitTorrent/Sessions.hs +++ b/src/Network/BitTorrent/Sessions.hs | |||
@@ -17,10 +17,8 @@ module Network.BitTorrent.Sessions | |||
17 | -- * Client | 17 | -- * Client |
18 | , ClientSession ( ClientSession | 18 | , ClientSession ( ClientSession |
19 | , clientPeerId, allowedExtensions | 19 | , clientPeerId, allowedExtensions |
20 | , nodeListener, peerListener | ||
21 | ) | 20 | ) |
22 | , withClientSession | 21 | , withClientSession |
23 | , listenerPort, dhtPort | ||
24 | 22 | ||
25 | , ThreadCount | 23 | , ThreadCount |
26 | , defaultThreadCount | 24 | , defaultThreadCount |
@@ -77,7 +75,6 @@ import Network.BitTorrent.Exchange.Protocol as BT | |||
77 | import Network.BitTorrent.Tracker.Protocol as BT | 75 | import Network.BitTorrent.Tracker.Protocol as BT |
78 | import Network.BitTorrent.Tracker as BT | 76 | import Network.BitTorrent.Tracker as BT |
79 | import Network.BitTorrent.Exchange as BT | 77 | import Network.BitTorrent.Exchange as BT |
80 | import Network.BitTorrent.DHT as BT | ||
81 | import System.Torrent.Storage | 78 | import System.Torrent.Storage |
82 | 79 | ||
83 | {----------------------------------------------------------------------- | 80 | {----------------------------------------------------------------------- |
@@ -126,16 +123,6 @@ startListener cs @ ClientSession {..} port = | |||
126 | let storage = error "storage" | 123 | let storage = error "storage" |
127 | runP2P conn (exchange storage) | 124 | runP2P conn (exchange storage) |
128 | 125 | ||
129 | startDHT :: ClientSession -> PortNumber -> IO () | ||
130 | startDHT ClientSession {..} nodePort = withRunning peerListener failure start | ||
131 | where | ||
132 | start ClientService {..} = do | ||
133 | ses <- newNodeSession servPort | ||
134 | startService nodeListener nodePort (dhtServer ses) | ||
135 | |||
136 | failure = throwIO $ userError msg | ||
137 | msg = "unable to start DHT server: peer listener is not running" | ||
138 | |||
139 | -- | Create a new client session. The data passed to this function are | 126 | -- | Create a new client session. The data passed to this function are |
140 | -- usually loaded from configuration file. | 127 | -- usually loaded from configuration file. |
141 | openClientSession :: SessionCount -> [Extension] -> PortNumber -> PortNumber -> IO ClientSession | 128 | openClientSession :: SessionCount -> [Extension] -> PortNumber -> PortNumber -> IO ClientSession |
@@ -144,7 +131,6 @@ openClientSession n exts listenerPort _ = do | |||
144 | <$> genPeerId | 131 | <$> genPeerId |
145 | <*> pure exts | 132 | <*> pure exts |
146 | <*> newEmptyMVar | 133 | <*> newEmptyMVar |
147 | <*> newEmptyMVar | ||
148 | <*> MSem.new n | 134 | <*> MSem.new n |
149 | <*> pure n | 135 | <*> pure n |
150 | <*> newTVarIO M.empty | 136 | <*> newTVarIO M.empty |
@@ -156,7 +142,6 @@ openClientSession n exts listenerPort _ = do | |||
156 | 142 | ||
157 | closeClientSession :: ClientSession -> IO () | 143 | closeClientSession :: ClientSession -> IO () |
158 | closeClientSession ClientSession {..} = do | 144 | closeClientSession ClientSession {..} = do |
159 | stopService nodeListener | ||
160 | stopService peerListener | 145 | stopService peerListener |
161 | 146 | ||
162 | sws <- readTVarIO swarmSessions | 147 | sws <- readTVarIO swarmSessions |
@@ -182,11 +167,8 @@ getPeerCount ClientSession {..} = liftIO $ do | |||
182 | unused <- peekAvail activeThreads | 167 | unused <- peekAvail activeThreads |
183 | return (maxActive - unused) | 168 | return (maxActive - unused) |
184 | 169 | ||
185 | listenerPort :: ClientSession -> IO PortNumber | 170 | getListenerPort :: ClientSession -> IO PortNumber |
186 | listenerPort ClientSession {..} = servPort <$> readMVar peerListener | 171 | getListenerPort ClientSession {..} = servPort <$> readMVar peerListener |
187 | |||
188 | dhtPort :: ClientSession -> IO PortNumber | ||
189 | dhtPort ClientSession {..} = servPort <$> readMVar nodeListener | ||
190 | 172 | ||
191 | {----------------------------------------------------------------------- | 173 | {----------------------------------------------------------------------- |
192 | Swarm session | 174 | Swarm session |
@@ -203,7 +185,7 @@ defLeacherConns = defaultNumWant | |||
203 | 185 | ||
204 | discover :: SwarmSession -> P2P () -> IO () | 186 | discover :: SwarmSession -> P2P () -> IO () |
205 | discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do | 187 | discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do |
206 | port <- listenerPort clientSession | 188 | port <- getListenerPort clientSession |
207 | 189 | ||
208 | let conn = TConnection { | 190 | let conn = TConnection { |
209 | tconnAnnounce = tAnnounce torrentMeta | 191 | tconnAnnounce = tAnnounce torrentMeta |
@@ -382,10 +364,6 @@ sendClientStatus (sock, PeerSession {..}) = do | |||
382 | cbf <- readTVarIO $ clientBitfield $ swarmSession | 364 | cbf <- readTVarIO $ clientBitfield $ swarmSession |
383 | sendAll sock $ encode $ Bitfield cbf | 365 | sendAll sock $ encode $ Bitfield cbf |
384 | 366 | ||
385 | port <- dhtPort $ clientSession swarmSession | ||
386 | when (ExtDHT `elem` enabledExtensions) $ do | ||
387 | sendAll sock $ encode $ Port port | ||
388 | |||
389 | -- | Exchange action depends on session and socket, whereas session depends | 367 | -- | Exchange action depends on session and socket, whereas session depends |
390 | -- on socket: | 368 | -- on socket: |
391 | -- | 369 | -- |
diff --git a/src/Network/BitTorrent/Sessions/Types.lhs b/src/Network/BitTorrent/Sessions/Types.lhs index 855e9a08..f3a3e789 100644 --- a/src/Network/BitTorrent/Sessions/Types.lhs +++ b/src/Network/BitTorrent/Sessions/Types.lhs | |||
@@ -259,7 +259,6 @@ and different enabled extensions at the same time. | |||
259 | > , allowedExtensions :: [Extension] | 259 | > , allowedExtensions :: [Extension] |
260 | 260 | ||
261 | > , peerListener :: !(MVar ClientService) | 261 | > , peerListener :: !(MVar ClientService) |
262 | > , nodeListener :: !(MVar ClientService) | ||
263 | 262 | ||
264 | > -- | Semaphor used to bound number of active P2P sessions. | 263 | > -- | Semaphor used to bound number of active P2P sessions. |
265 | > , activeThreads :: !(MSem ThreadCount) | 264 | > , activeThreads :: !(MSem ThreadCount) |