summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Session.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:47:11 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:47:11 +0400
commit1864fb2106c29b64af0cb80bebd91209b67d5fd3 (patch)
tree428627ef2b0a447c814d713de1d9e2cb00d6c1a8 /src/Network/BitTorrent/Exchange/Session.hs
parent0cd2099b36aa0382ec7363537ac9e2a8ca5831a9 (diff)
Add broadcast channel for P2P messaging
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs6
1 files changed, 5 insertions, 1 deletions
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
42 , storage :: Storage 42 , storage :: Storage
43 , unchoked :: [PeerAddr IP] 43 , unchoked :: [PeerAddr IP]
44 , connections :: MVar (Map (PeerAddr IP) (Connection Session)) 44 , connections :: MVar (Map (PeerAddr IP) (Connection Session))
45 , broadcast :: Chan Message
45 } 46 }
46 47
47newSession :: PeerAddr (Maybe IP) -- ^ /external/ address of this peer; 48newSession :: PeerAddr (Maybe IP) -- ^ /external/ address of this peer;
@@ -51,6 +52,7 @@ newSession :: PeerAddr (Maybe IP) -- ^ /external/ address of this peer;
51newSession addr rootPath dict = do 52newSession addr rootPath dict = do
52 connVar <- newMVar M.empty 53 connVar <- newMVar M.empty
53 store <- openInfoDict ReadWriteEx rootPath dict 54 store <- openInfoDict ReadWriteEx rootPath dict
55 chan <- newChan
54 return Session 56 return Session
55 { tpeerId = fromMaybe (error "newSession: impossible") (peerId addr) 57 { tpeerId = fromMaybe (error "newSession: impossible") (peerId addr)
56 , infohash = idInfoHash dict 58 , infohash = idInfoHash dict
@@ -59,6 +61,7 @@ newSession addr rootPath dict = do
59 , storage = store 61 , storage = store
60 , unchoked = [] 62 , unchoked = []
61 , connections = connVar 63 , connections = connVar
64 , broadcast = chan
62 } 65 }
63 66
64closeSession :: Session -> IO () 67closeSession :: Session -> IO ()
@@ -72,7 +75,8 @@ insert addr ses @ Session {..} = do
72 let caps = def 75 let caps = def
73 let ecaps = def 76 let ecaps = def
74 let hs = Handshake def caps infohash tpeerId 77 let hs = Handshake def caps infohash tpeerId
75 connectWire ses hs addr ecaps $ do 78 chan <- dupChan broadcast
79 connectWire ses hs addr ecaps chan $ do
76 conn <- getConnection 80 conn <- getConnection
77-- liftIO $ modifyMVar_ connections $ pure . M.insert addr conn 81-- liftIO $ modifyMVar_ connections $ pure . M.insert addr conn
78 exchange 82 exchange