(Info(..),
Metainfo(..),
mkInfo,
- mkMetaInfo
+ torrentToMetainfo
) where
import Prelude hiding (lookup)
import Crypto.Hash.SHA1 (hash)
import Data.Maybe (maybeToList)
-import FuncTorrent.Bencode (BVal(..), encode, bstrToString, bValToInteger)
+import FuncTorrent.Bencode (BVal(..), encode, decode, bstrToString, bValToInteger)
-- only single file mode supported for the time being.
data Info = Info { pieceLength :: !Integer
_ -> "") l
getAnnounceList (Just (Bdict _)) = []
+
+torrentToMetainfo :: ByteString -> Either String Metainfo
+torrentToMetainfo s =
+ case (decode s) of
+ Right d ->
+ mkMetaInfo d
+ Left e ->
+ Left $ show e
import System.Exit (exitSuccess)
import System.Directory (doesFileExist)
-import FuncTorrent.Bencode (decode)
import FuncTorrent.Logger (initLogger, logMessage, logStop)
-import FuncTorrent.Metainfo (Info(..), Metainfo(..), mkMetaInfo)
+import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo)
import FuncTorrent.Peer (handShake, msgLoop)
import FuncTorrent.Tracker (peers, getTrackerResponse)
else error "file does not exist"
parse _ = exit
-torrentToMetaInfo :: ByteString -> Either String Metainfo
-torrentToMetaInfo s =
- case (decode s) of
- Right d ->
- mkMetaInfo d
- Left e ->
- Left $ show e
-
main :: IO ()
main = do
args <- getArgs
log "Starting up functorrent"
log $ "Parsing arguments " ++ concat args
torrentStr <- parse args
- case (torrentToMetaInfo torrentStr) of
+ case (torrentToMetainfo torrentStr) of
Right m -> do
log "Input File OK"
log $ "Downloading file : " ++ name (info m)