cabal-version: >=1.18
library
- exposed-modules: FuncTorrent
- FuncTorrent.Bencode,
+ exposed-modules: FuncTorrent.Bencode,
+ FuncTorrent.Fileops,
FuncTorrent.Logger,
FuncTorrent.Metainfo,
FuncTorrent.Network
FuncTorrent.Peer,
- FuncTorrent.Tracker
+ FuncTorrent.PeerMsgs,
+ FuncTorrent.Tracker,
+ FuncTorrent.Utils
- other-modules: FuncTorrent.Utils
other-extensions: OverloadedStrings
hs-source-dirs: src
ghc-options: -Wall -fwarn-incomplete-patterns -fno-warn-orphans
executable functorrent
main-is: Main.hs
other-extensions: OverloadedStrings
- hs-source-dirs: src
+ hs-source-dirs: src/main
ghc-options: -Wall -fwarn-incomplete-patterns -optc-Os -fno-warn-orphans
default-language: Haskell2010
build-depends: base,
containers,
cryptohash,
directory,
+ functorrent,
HTTP,
mtl,
network,
+++ /dev/null
-module FuncTorrent
- (BVal(..),
- Info(..),
- Metainfo(..),
- Peer,
- TrackerResponse(..),
- getTrackerResponse,
- decode,
- encode,
- handlePeerMsgs,
- initLogger,
- logMessage,
- logStop,
- mkInfo,
- torrentToMetainfo
- ) where
-
-import FuncTorrent.Bencode
-import FuncTorrent.Logger
-import FuncTorrent.Metainfo
-import FuncTorrent.Peer
-import FuncTorrent.Tracker
+++ /dev/null
-{-# LANGUAGE OverloadedStrings #-}
-module Main where
-
-import Prelude hiding (log, length, readFile, getContents)
-import Data.ByteString.Char8 (ByteString, getContents, readFile, unpack)
-import System.Environment (getArgs)
-import System.Exit (exitSuccess)
-import System.Directory (doesFileExist)
-
-import FuncTorrent.Logger (initLogger, logMessage, logStop)
-import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo)
-import FuncTorrent.Peer (handlePeerMsgs)
-import FuncTorrent.Tracker (peers, getTrackerResponse)
-
-logError :: String -> (String -> IO ()) -> IO ()
-logError e logMsg = logMsg $ "parse error: \n" ++ e
-
-peerId :: String
-peerId = "-HS0001-*-*-20150215"
-
-exit :: IO ByteString
-exit = exitSuccess
-
-usage :: IO ()
-usage = putStrLn "usage: functorrent torrent-file"
-
-parse :: [String] -> IO ByteString
-parse [] = getContents
-parse [a] = do
- fileExist <- doesFileExist a
- if fileExist
- then readFile a
- else error "file does not exist"
-parse _ = exit
-
-main :: IO ()
-main = do
- args <- getArgs
- logR <- initLogger
- let log = logMessage logR
- log "Starting up functorrent"
- log $ "Parsing arguments " ++ concat args
- torrentStr <- parse args
- case torrentToMetainfo torrentStr of
- Left e -> logError e log
- Right m -> do
- log "Input File OK"
- log $ "Downloading file : " ++ name (info m)
- log "Trying to fetch peers"
-
- log $ "Trackers: " ++ head (announceList m)
- trackerResp <- getTrackerResponse m peerId
- case trackerResp of
- Left e -> log $ "Error" ++ unpack e
- Right peerList -> do
- log $ "Peers List : " ++ (show . peers $ peerList)
- let p1 = head (peers peerList)
- handlePeerMsgs p1 m peerId
- logStop logR
--- /dev/null
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+import Prelude hiding (log, length, readFile, getContents)
+import Data.ByteString.Char8 (ByteString, getContents, readFile, unpack)
+import System.Environment (getArgs)
+import System.Exit (exitSuccess)
+import System.Directory (doesFileExist)
+
+import FuncTorrent.Logger (initLogger, logMessage, logStop)
+import FuncTorrent.Metainfo (Info(..), Metainfo(..), torrentToMetainfo)
+import FuncTorrent.Peer (handlePeerMsgs)
+import FuncTorrent.Tracker (peers, getTrackerResponse)
+
+logError :: String -> (String -> IO ()) -> IO ()
+logError e logMsg = logMsg $ "parse error: \n" ++ e
+
+peerId :: String
+peerId = "-HS0001-*-*-20150215"
+
+exit :: IO ByteString
+exit = exitSuccess
+
+usage :: IO ()
+usage = putStrLn "usage: functorrent torrent-file"
+
+parse :: [String] -> IO ByteString
+parse [] = getContents
+parse [a] = do
+ fileExist <- doesFileExist a
+ if fileExist
+ then readFile a
+ else error "file does not exist"
+parse _ = exit
+
+main :: IO ()
+main = do
+ args <- getArgs
+ logR <- initLogger
+ let log = logMessage logR
+ log "Starting up functorrent"
+ log $ "Parsing arguments " ++ concat args
+ torrentStr <- parse args
+ case torrentToMetainfo torrentStr of
+ Left e -> logError e log
+ Right m -> do
+ log "Input File OK"
+ log $ "Downloading file : " ++ name (info m)
+ log "Trying to fetch peers"
+
+ log $ "Trackers: " ++ head (announceList m)
+ trackerResp <- getTrackerResponse m peerId
+ case trackerResp of
+ Left e -> log $ "Error" ++ unpack e
+ Right peerList -> do
+ log $ "Peers List : " ++ (show . peers $ peerList)
+ let p1 = head (peers peerList)
+ handlePeerMsgs p1 m peerId
+ logStop logR