summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Sessions.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-14 19:54:29 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-14 19:54:29 +0400
commit33da2f459c0819b694f2ef21dba6d09167a5af6a (patch)
treee8c869c21c3a5a7d33e351d32127bd009f2274c6 /src/Network/BitTorrent/Sessions.hs
parent4427cb321a6927b2dd8119e95e09f4998ff8a226 (diff)
~ Move initial messages exchange to Exchange.
All exchange details should be in Exchange module, Sessions should handle handshakes only!
Diffstat (limited to 'src/Network/BitTorrent/Sessions.hs')
-rw-r--r--src/Network/BitTorrent/Sessions.hs11
1 files changed, 2 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs
index 4d4cf629..6d99213a 100644
--- a/src/Network/BitTorrent/Sessions.hs
+++ b/src/Network/BitTorrent/Sessions.hs
@@ -121,7 +121,7 @@ startListener cs @ ClientSession {..} port =
121 startService peerListener port $ listener cs $ \conn @ (sock, PeerSession{..}) -> do 121 startService peerListener port $ listener cs $ \conn @ (sock, PeerSession{..}) -> do
122 print "accepted" 122 print "accepted"
123 let storage = error "storage" 123 let storage = error "storage"
124 runP2P conn (exchange storage) 124 runP2P conn p2p
125 125
126-- | Create a new client session. The data passed to this function are 126-- | Create a new client session. The data passed to this function are
127-- usually loaded from configuration file. 127-- usually loaded from configuration file.
@@ -204,7 +204,7 @@ discover swarm @ SwarmSession {..} = {-# SCC discover #-} do
204 print addr 204 print addr
205 initiatePeerSession swarm addr $ \conn -> do 205 initiatePeerSession swarm addr $ \conn -> do
206 print addr 206 print addr
207 runP2P conn (exchange storage) 207 runP2P conn p2p
208 208
209registerSwarmSession :: SwarmSession -> STM () 209registerSwarmSession :: SwarmSession -> STM ()
210registerSwarmSession ss @ SwarmSession {..} = 210registerSwarmSession ss @ SwarmSession {..} =
@@ -348,11 +348,6 @@ closeSession = unregisterPeerSession
348type PeerConn = (Socket, PeerSession) 348type PeerConn = (Socket, PeerSession)
349type Exchange = PeerConn -> IO () 349type Exchange = PeerConn -> IO ()
350 350
351sendClientStatus :: PeerConn -> IO ()
352sendClientStatus (sock, PeerSession {..}) = do
353 cbf <- readTVarIO $ clientBitfield $ swarmSession
354 sendAll sock $ encode $ Bitfield cbf
355
356-- | Exchange action depends on session and socket, whereas session depends 351-- | Exchange action depends on session and socket, whereas session depends
357-- on socket: 352-- on socket:
358-- 353--
@@ -379,7 +374,6 @@ initiatePeerSession ss @ SwarmSession {..} addr
379 phs <- handshake sock (swarmHandshake ss) 374 phs <- handshake sock (swarmHandshake ss)
380 putStrLn "handshaked" 375 putStrLn "handshaked"
381 ps <- openSession ss addr phs 376 ps <- openSession ss addr phs
382 sendClientStatus (sock, ps)
383 return ps 377 return ps
384 378
385-- | Used the a peer want to connect to the client. 379-- | Used the a peer want to connect to the client.
@@ -396,7 +390,6 @@ acceptPeerSession cs@ClientSession {..} addr s = runSession (pure s) accepted
396 , hsInfoHash = hsInfoHash phs 390 , hsInfoHash = hsInfoHash phs
397 , hsPeerId = clientPeerId 391 , hsPeerId = clientPeerId
398 } 392 }
399 sendClientStatus (sock, ps)
400 return ps 393 return ps
401 394
402listener :: ClientSession -> Exchange -> PortNumber -> IO () 395listener :: ClientSession -> Exchange -> PortNumber -> IO ()