]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Peer.hs
Main.hs: move peer handling into Peer module
[functorrent.git] / src / FuncTorrent / Peer.hs
index d04d886e7de7f429275809117bf0eacee6da8c32..817a9cde0652358370681a08be8b506f4701d080 100644 (file)
@@ -1,8 +1,7 @@
 {-# LANGUAGE OverloadedStrings #-}
 module FuncTorrent.Peer
     (Peer(..),
-     handShake,
-     msgLoop
+     handlePeerMsgs
     ) where
 
 import Prelude hiding (lookup, concat, replicate, splitAt, empty, writeFile)
@@ -20,6 +19,7 @@ import Control.Applicative ((<$>), liftA3)
 import Data.Bits
 import Data.Word (Word8)
 
+import FuncTorrent.Metainfo (Info(..), Metainfo(..))
 type ID = String
 type IP = String
 type Port = Integer
@@ -178,3 +178,10 @@ msgLoop h pieceHash =
         putStrLn (show pieceList)
         -- download each of the piece in order
       _ -> putStrLn (show msg)
+
+handlePeerMsgs :: Peer -> Metainfo -> String -> (String -> IO ()) -> IO ()
+handlePeerMsgs p m peerId logFn = do
+  h <- handShake p (infoHash m) peerId
+  logFn $ "handShake"
+  msgLoop h (pieces (info m))
+