X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2FFuncTorrent%2FPeer.hs;h=f7ccfcfcee4889bb36c674eff015b9cbc664dd9a;hb=5b606c972c65d9b7df3e415c2cfc0f0c3585e71c;hp=baf9ce8d7fce2f381bd26d8446647e0bd859b726;hpb=968ccbf7652c3718fca087d3c2610cd56f6cf2b4;p=functorrent.git diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index baf9ce8..f7ccfcf 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -4,10 +4,10 @@ module FuncTorrent.Peer handlePeerMsgs ) where -import Prelude hiding (lookup, concat, replicate, splitAt, writeFile, take) +import Prelude hiding (lookup, concat, replicate, splitAt, take) -import System.IO (Handle, BufferMode(..), IOMode(..), SeekMode(..), withFile, hSeek, hSetBuffering) -import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton, writeFile, take, empty) +import System.IO (Handle, BufferMode(..), hSetBuffering) +import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton, take, empty) import Data.ByteString.Lazy (fromStrict, fromChunks, toStrict) import qualified Data.ByteString.Char8 as BC (replicate, pack, length) import Network (connectTo, PortID(..)) @@ -23,6 +23,7 @@ import qualified Crypto.Hash.SHA1 as SHA1 (hash) import FuncTorrent.Metainfo (Info(..), Metainfo(..)) import FuncTorrent.Utils (splitN, splitNum) +import FuncTorrent.Fileops (createDummyFile, writeFileAtOffset) type ID = String type IP = String @@ -185,17 +186,6 @@ bitfieldToList bs = go bs 0 in setBits ++ go bs' (pos + 1) -createDummyFile :: FilePath -> Int -> IO () -createDummyFile path size = - writeFile path (BC.replicate size '\0') - --- write into a file at a specific offet -writeFileAtOffset :: FilePath -> Integer -> ByteString -> IO () -writeFileAtOffset path offset block = - withFile path ReadWriteMode (\h -> do - _ <- hSeek h AbsoluteSeek offset - hPut h block) - -- recvMsg :: Peer -> Handle -> Msg msgLoop :: PeerState -> PieceMap -> IO () msgLoop pState pieceStatus | not (meInterested pState) && heChoking pState = do