]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Peer.hs
misc formatting
[functorrent.git] / src / FuncTorrent / Peer.hs
index 481f5dac0b92b72fc0b85ed21442badd7444af24..d04d886e7de7f429275809117bf0eacee6da8c32 100644 (file)
@@ -5,10 +5,10 @@ module FuncTorrent.Peer
      msgLoop
     ) where
 
-import Prelude hiding (lookup, concat, replicate, splitAt, empty)
+import Prelude hiding (lookup, concat, replicate, splitAt, empty, writeFile)
 
-import System.IO
-import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton)
+import System.IO (Handle, BufferMode(..), hSetBuffering)
+import Data.ByteString (ByteString, pack, unpack, concat, hGet, hPut, singleton, writeFile)
 import Data.ByteString.Lazy (fromStrict, fromChunks)
 import qualified Data.ByteString.Char8 as BC (replicate, pack, length)
 import Network (connectTo, PortID(..))
@@ -157,6 +157,12 @@ bitfieldToList bs = go bs 0
           in
            setBits ++ (go bs' (pos + 1))
 
+-- downloadPiece :: Integer -> Handle -> IO ()
+
+createDummyFile :: FilePath -> Int -> IO ()
+createDummyFile path size = do
+  writeFile path (BC.replicate size '\0')
+
 -- loop1 :: shake hands with all peers, find out the pieces they have, form PieceData.
 -- recvMsg :: Peer -> Handle -> Msg
 msgLoop :: Handle -> ByteString -> IO ()
@@ -168,7 +174,7 @@ msgLoop h pieceHash =
      putStrLn $ "got a " ++ show msg
      case msg of
       BitFieldMsg bss -> do
-                         let pieceList = bitfieldToList (unpack bss) 0
-                         putStrLn (show pieceList)
-                         -- doenload each of the piece
+        let pieceList = bitfieldToList (unpack bss)
+        putStrLn (show pieceList)
+        -- download each of the piece in order
       _ -> putStrLn (show msg)