summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r--src/Network/BitTorrent.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index f7c4c004..7ec0a067 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -29,9 +29,14 @@ module Network.BitTorrent
29 , awaitEvent, yieldEvent 29 , awaitEvent, yieldEvent
30 ) where 30 ) where
31 31
32import Control.Concurrent
33import Control.Exception
32import Control.Monad 34import Control.Monad
35
33import Data.IORef 36import Data.IORef
34 37
38import Network
39
35import Data.Torrent 40import Data.Torrent
36import Network.BitTorrent.Internal 41import Network.BitTorrent.Internal
37import Network.BitTorrent.Exchange 42import Network.BitTorrent.Exchange
@@ -45,6 +50,8 @@ import Network.BitTorrent.Tracker
45 50
46discover :: SwarmSession -> P2P () -> IO () 51discover :: SwarmSession -> P2P () -> IO ()
47discover swarm action = do 52discover swarm action = do
53 port <- listener swarm action
54
48 let conn = TConnection (tAnnounce (torrentMeta swarm)) 55 let conn = TConnection (tAnnounce (torrentMeta swarm))
49 (tInfoHash (torrentMeta swarm)) 56 (tInfoHash (torrentMeta swarm))
50 (clientPeerID (clientSession swarm)) 57 (clientPeerID (clientSession swarm))
@@ -57,8 +64,14 @@ discover swarm action = do
57 forever $ do 64 forever $ do
58 addr <- getPeerAddr tses 65 addr <- getPeerAddr tses
59 putStrLn "connecting to peer" 66 putStrLn "connecting to peer"
60 withPeer swarm addr action 67 handle handler (withPeer swarm addr action)
61
62 68
69 where
70 handler :: IOException -> IO ()
71 handler _ = return ()
63 72
64port = 10000 73listener :: SwarmSession -> P2P () -> IO PortNumber
74listener _ _ = do
75 -- TODO:
76-- forkIO loop
77 return 10000