From: Ramakrishnan Muthukrishnan Date: Fri, 11 Sep 2015 08:03:11 +0000 (+0530) Subject: functorrent.cabal: avoid double compilation, one for lib, another for exe X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/statistics?a=commitdiff_plain;h=220cbc977a252c56eea15f2254c362c0d1ea5bdf;p=functorrent.git functorrent.cabal: avoid double compilation, one for lib, another for exe --- diff --git a/functorrent.cabal b/functorrent.cabal index 2ec81bb..b663ef9 100644 --- a/functorrent.cabal +++ b/functorrent.cabal @@ -16,15 +16,16 @@ extra-source-files: README.md 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 @@ -49,7 +50,7 @@ library 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, @@ -59,6 +60,7 @@ executable functorrent containers, cryptohash, directory, + functorrent, HTTP, mtl, network, diff --git a/src/FuncTorrent.hs b/src/FuncTorrent.hs deleted file mode 100644 index 2cded5b..0000000 --- a/src/FuncTorrent.hs +++ /dev/null @@ -1,22 +0,0 @@ -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 diff --git a/src/Main.hs b/src/Main.hs deleted file mode 100644 index 3aa6587..0000000 --- a/src/Main.hs +++ /dev/null @@ -1,59 +0,0 @@ -{-# 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 diff --git a/src/main/Main.hs b/src/main/Main.hs new file mode 100644 index 0000000..3aa6587 --- /dev/null +++ b/src/main/Main.hs @@ -0,0 +1,59 @@ +{-# 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