From 1864fb2106c29b64af0cb80bebd91209b67d5fd3 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 12 Feb 2014 21:47:11 +0400 Subject: Add broadcast channel for P2P messaging --- src/Network/BitTorrent/Exchange/Session.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Network/BitTorrent/Exchange/Session.hs') diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs index dfb0355b..695ac18a 100644 --- a/src/Network/BitTorrent/Exchange/Session.hs +++ b/src/Network/BitTorrent/Exchange/Session.hs @@ -42,6 +42,7 @@ data Session = Session , storage :: Storage , unchoked :: [PeerAddr IP] , connections :: MVar (Map (PeerAddr IP) (Connection Session)) + , broadcast :: Chan Message } newSession :: PeerAddr (Maybe IP) -- ^ /external/ address of this peer; @@ -51,6 +52,7 @@ newSession :: PeerAddr (Maybe IP) -- ^ /external/ address of this peer; newSession addr rootPath dict = do connVar <- newMVar M.empty store <- openInfoDict ReadWriteEx rootPath dict + chan <- newChan return Session { tpeerId = fromMaybe (error "newSession: impossible") (peerId addr) , infohash = idInfoHash dict @@ -59,6 +61,7 @@ newSession addr rootPath dict = do , storage = store , unchoked = [] , connections = connVar + , broadcast = chan } closeSession :: Session -> IO () @@ -72,7 +75,8 @@ insert addr ses @ Session {..} = do let caps = def let ecaps = def let hs = Handshake def caps infohash tpeerId - connectWire ses hs addr ecaps $ do + chan <- dupChan broadcast + connectWire ses hs addr ecaps chan $ do conn <- getConnection -- liftIO $ modifyMVar_ connections $ pure . M.insert addr conn exchange -- cgit v1.2.3