X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2FFuncTorrent%2FServer.hs;h=3827aa2bc35673110f379901ac139090e2fd3bcf;hb=9beb0fb9814b33725f6adfa5adabb3225a54277b;hp=b78be297b935628a90bf10101f8dd836d0578042;hpb=9d4aab0d9382c070bfaf965ddfe139affa64dcd5;p=functorrent.git diff --git a/src/FuncTorrent/Server.hs b/src/FuncTorrent/Server.hs index b78be29..3827aa2 100644 --- a/src/FuncTorrent/Server.hs +++ b/src/FuncTorrent/Server.hs @@ -1,4 +1,24 @@ +{- + - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan + - + - 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 + -} + {-# LANGUAGE OverloadedStrings #-} + module FuncTorrent.Server where import Control.Concurrent (forkIO) @@ -7,7 +27,9 @@ import Network (withSocketsDo, listenOn, accept, Socket, PortID ( PortNumber )) import System.IO (hSetBuffering, BufferMode ( NoBuffering )) import FuncTorrent.Metainfo (Metainfo) -import FuncTorrent.Peer (handlePeerMsgs, Peer(..), PieceMap) +import FuncTorrent.Peer (handlePeerMsgs, PieceMap) +import FuncTorrent.PeerMsgs (Peer(..)) +import qualified FuncTorrent.FileSystem as FS (MsgChannel) -- server is listening on any port from 6881 - 6889 -- return the port number used @@ -17,9 +39,9 @@ start = withSocketsDo $ do sock <- listenOn $ PortNumber $ fromIntegral (head portnums) return (sock, PortNumber $ head portnums) -run :: Socket -> String -> Metainfo -> PieceMap -> IO () -run listenSock peerid m pieceMap = 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) + let peer = Peer ip (fromIntegral port) hSetBuffering handle NoBuffering - forkIO $ handlePeerMsgs peer peerid m pieceMap + forkIO $ handlePeerMsgs peer peerid m pieceMap False c