summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-15 05:14:46 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-15 05:14:46 +0400
commitee4c3c7583d79beece46f65f360f5f6ae93c37ba (patch)
tree731110eba455612fb8c4aa8ea5a79ec22c29625d /src/Network/BitTorrent
parent3dc4e742c5c0cfca1efde1ef7391a626d1607dc2 (diff)
Add TorrentSource class
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Client.hs38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Client.hs b/src/Network/BitTorrent/Client.hs
index c6b4901a..5218c299 100644
--- a/src/Network/BitTorrent/Client.hs
+++ b/src/Network/BitTorrent/Client.hs
@@ -1,3 +1,5 @@
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE TypeSynonymInstances #-}
1{-# LANGUAGE GeneralizedNewtypeDeriving #-} 3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE TemplateHaskell #-} 4{-# LANGUAGE TemplateHaskell #-}
3module Network.BitTorrent.Client 5module Network.BitTorrent.Client
@@ -25,8 +27,7 @@ module Network.BitTorrent.Client
25 , getClient 27 , getClient
26 28
27 -- * Handle 29 -- * Handle
28 , openTorrent 30 , TorrentSource (..)
29 , openMagnet
30 , closeHandle 31 , closeHandle
31 32
32 , start 33 , start
@@ -37,6 +38,7 @@ module Network.BitTorrent.Client
37import Control.Exception 38import Control.Exception
38import Control.Concurrent 39import Control.Concurrent
39import Control.Monad.Logger 40import Control.Monad.Logger
41import Control.Monad.Trans
40import Control.Monad.Trans.Resource 42import Control.Monad.Trans.Resource
41 43
42import Data.Default 44import Data.Default
@@ -45,6 +47,9 @@ import Data.Maybe
45import Data.Text 47import Data.Text
46import Network 48import Network
47 49
50import Data.Torrent
51import Data.Torrent.InfoHash
52import Data.Torrent.Magnet
48import Network.BitTorrent.Client.Types 53import Network.BitTorrent.Client.Types
49import Network.BitTorrent.Client.Handle 54import Network.BitTorrent.Client.Handle
50import Network.BitTorrent.Core 55import Network.BitTorrent.Core
@@ -121,3 +126,32 @@ simpleClient :: BitTorrent () -> IO ()
121simpleClient m = do 126simpleClient m = do
122 runStderrLoggingT $ LoggingT $ \ logger -> do 127 runStderrLoggingT $ LoggingT $ \ logger -> do
123 withClient def logger (`runBitTorrent` m) 128 withClient def logger (`runBitTorrent` m)
129
130{-----------------------------------------------------------------------
131-- Torrent identifiers
132-----------------------------------------------------------------------}
133
134class TorrentSource s where
135 openHandle :: FilePath -> s -> BitTorrent Handle
136
137instance TorrentSource InfoHash where
138 openHandle path ih = openMagnet path (nullMagnet ih)
139 {-# INLINE openHandle #-}
140
141instance TorrentSource Magnet where
142 openHandle = openMagnet
143 {-# INLINE openHandle #-}
144
145instance TorrentSource InfoDict where
146 openHandle path dict = openTorrent path (nullTorrent dict)
147 {-# INLINE openHandle #-}
148
149instance TorrentSource Torrent where
150 openHandle = openTorrent
151 {-# INLINE openHandle #-}
152
153instance TorrentSource FilePath where
154 openHandle contentDir torrentPath = do
155 t <- liftIO $ fromFile torrentPath
156 openTorrent contentDir t
157 {-# INLINE openHandle #-} \ No newline at end of file