summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client/Swarm.hs
blob: bd48f8a4fda06fe68bac0513ad6d2fccaee070b0 (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
42
43
44
45
46
47
48
49
50
51
52
module Network.BitTorrent.Client.Swarm
       ( Swarm
       , newLeecher
       , askPeers
       ) where

import Data.Default
import Data.Maybe
import Network

import Data.Torrent
import Data.Torrent.InfoHash
import Network.BitTorrent.Core
import Network.BitTorrent.Tracker.Message
import Network.BitTorrent.Tracker.RPC as RPC


data Swarm = Swarm
  { swarmTopic   :: InfoHash
  , thisPeerId   :: PeerId
  , listenerPort :: PortNumber
  }

newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm
newLeecher pid port Torrent {..} = do
  return Swarm
    { swarmTopic   = idInfoHash tInfoDict
    , thisPeerId   = pid
    , listenerPort = port
    }

getAnnounceQuery :: Swarm -> AnnounceQuery
getAnnounceQuery Swarm {..} = AnnounceQuery
  { reqInfoHash = swarmTopic
  , reqPeerId   = thisPeerId
  , reqPort     = listenerPort
  , reqProgress = def
  , reqIP       = Nothing
  , reqNumWant  = Nothing
  , reqEvent    = Nothing
  }

askPeers :: Swarm -> IO [PeerAddr IP]
askPeers s @ Swarm {..} = do
--  AnnounceInfo {..} <- RPC.announce (getAnnounceQuery s) trackerConn
  return [] -- (getPeerList respPeers)

--reannounce :: HTracker -> IO ()
--reannounce = undefined

--forceReannounce :: HTracker -> IO ()
--forceReannounce = undefined