]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Server.hs
*.hs: add GPLv3 License text and copyright notice
[functorrent.git] / src / FuncTorrent / Server.hs
index e675c6c1c4ee44ff9f460fb9b9bb48803814e4df..fe92344b705abf7c1a6eff8275bea06e8c62bf07 100644 (file)
@@ -1,4 +1,23 @@
 {-# LANGUAGE OverloadedStrings #-}
+{-
+Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
+
+This file is part of FuncTorrent.
+
+FuncTorrent is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+FuncTorrent is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with FuncTorrent; if not,  see <http://www.gnu.org/licenses/>
+-}
+
 module FuncTorrent.Server where
 
 import Control.Concurrent (forkIO)
@@ -7,7 +26,8 @@ import Network (withSocketsDo, listenOn, accept, Socket, PortID ( PortNumber ))
 import System.IO (hSetBuffering, BufferMode ( NoBuffering ))
 
 import FuncTorrent.Metainfo (Metainfo)
-import FuncTorrent.Peer (handlePeerMsgs, Peer(..))
+import FuncTorrent.Peer (handlePeerMsgs, Peer(..), PieceMap)
+import qualified FuncTorrent.FileSystem as FS (MsgChannel)
 
 -- server is listening on any port from 6881 - 6889
 -- return the port number used
@@ -17,9 +37,9 @@ start = withSocketsDo $ do
   sock <- listenOn $ PortNumber $ fromIntegral (head portnums)
   return (sock, PortNumber $ head portnums)
 
-run :: Socket -> String -> Metainfo -> IO ()
-run listenSock peerid m = forever $ do
+run :: Socket -> String -> Metainfo -> PieceMap -> FS.MsgChannel -> IO ()
+run listenSock peerid m pieceMap c = forever $ do
   (handle, ip, port) <- accept listenSock
   let peer = Peer "" ip (fromIntegral port)
   hSetBuffering handle NoBuffering
-  forkIO $ handlePeerMsgs peer peerid m
+  forkIO $ handlePeerMsgs peer peerid m pieceMap False c