diff options
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs index 30b7ed0e..2bd275bd 100644 --- a/src/Network/BitTorrent/Exchange/Session.hs +++ b/src/Network/BitTorrent/Exchange/Session.hs | |||
@@ -16,6 +16,7 @@ module Network.BitTorrent.Exchange.Session | |||
16 | 16 | ||
17 | -- * Connection Set | 17 | -- * Connection Set |
18 | , connect | 18 | , connect |
19 | , connectSink | ||
19 | , establish | 20 | , establish |
20 | 21 | ||
21 | -- * Query | 22 | -- * Query |
@@ -29,12 +30,13 @@ import Control.Concurrent.Chan.Split as CS | |||
29 | import Control.Concurrent.STM | 30 | import Control.Concurrent.STM |
30 | import Control.Exception hiding (Handler) | 31 | import Control.Exception hiding (Handler) |
31 | import Control.Lens | 32 | import Control.Lens |
33 | import Control.Monad as M | ||
32 | import Control.Monad.Logger | 34 | import Control.Monad.Logger |
33 | import Control.Monad.Reader | 35 | import Control.Monad.Reader |
34 | import Data.ByteString as BS | 36 | import Data.ByteString as BS |
35 | import Data.ByteString.Lazy as BL | 37 | import Data.ByteString.Lazy as BL |
36 | import Data.Conduit | 38 | import Data.Conduit as C |
37 | import Data.Conduit.List as CL (iterM) | 39 | import Data.Conduit.List as C |
38 | import Data.Map as M | 40 | import Data.Map as M |
39 | import Data.Monoid | 41 | import Data.Monoid |
40 | import Data.Set as S | 42 | import Data.Set as S |
@@ -333,6 +335,12 @@ establish :: PendingConnection -> Session -> IO () | |||
333 | establish conn = runConnection (acceptWire conn) (closePending conn) | 335 | establish conn = runConnection (acceptWire conn) (closePending conn) |
334 | (pendingPeer conn) | 336 | (pendingPeer conn) |
335 | 337 | ||
338 | -- | Conduit version of 'connect'. | ||
339 | connectSink :: MonadIO m => Session -> Sink [PeerAddr IPv4] m () | ||
340 | connectSink s = C.mapM_ (liftIO . connectBatch) | ||
341 | where | ||
342 | connectBatch = M.mapM_ (\ addr -> connect (IPv4 <$> addr) s) | ||
343 | |||
336 | -- | Why do we need this message? | 344 | -- | Why do we need this message? |
337 | type BroadcastMessage = ExtendedCaps -> Message | 345 | type BroadcastMessage = ExtendedCaps -> Message |
338 | 346 | ||