summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
blob: c37129cb64317ea8e2a7a63d3cf9a3067ca335bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- |
--   Copyright   :  (c) Sam T. 2013
--   License     :  MIT
--   Maintainer  :  pxqr.sta@gmail.com
--   Stability   :  experimental
--   Portability :  portable
--
{-# LANGUAGE RecordWildCards #-}
module Network.BitTorrent
       ( module BT
       , module Data.Torrent

         -- * Tracker

         -- * P2P
       , ClientSession, newClient
       , SwarmSession, newLeacher, newSeeder
       , PeerSession
       , discover
       ) where

import Data.IORef

import Data.Torrent
import Network.BitTorrent.Internal
import Network.BitTorrent.Extension as BT
import Network.BitTorrent.Peer as BT
import Network.BitTorrent.Exchange as BT
import Network.BitTorrent.Tracker as BT

-- discover should hide tracker and DHT communication under the hood
-- thus we can obtain unified interface

discover :: SwarmSession -> (TSession -> IO a) -> IO a
discover SwarmSession {..} action = do
  let conn = TConnection (tAnnounce torrentMeta) (tInfoHash torrentMeta)
                         (clientPeerID clientSession) port
  progress <- readIORef (currentProgress clientSession)
  withTracker progress conn action

port = 10000