summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-13 14:05:00 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-13 14:05:00 +0400
commit2027b99f7a12986c6c0cb9d3205e0893fba17c9a (patch)
tree042e0471bcfc4a125ce479dff17df4fc89aee008 /src/Network/BitTorrent/Client
parent8ddb71a490ec862d1df626b7eb9300d9ddb782f3 (diff)
Update client example
Diffstat (limited to 'src/Network/BitTorrent/Client')
-rw-r--r--src/Network/BitTorrent/Client/Swarm.hs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Client/Swarm.hs b/src/Network/BitTorrent/Client/Swarm.hs
new file mode 100644
index 00000000..a9dca048
--- /dev/null
+++ b/src/Network/BitTorrent/Client/Swarm.hs
@@ -0,0 +1,49 @@
1module Network.BitTorrent.Client.Swarm
2 ( Swarm
3 , newLeecher
4 , askPeers
5 ) where
6
7import Data.Default
8import Network
9
10import Data.Torrent
11import Data.Torrent.InfoHash
12import Network.BitTorrent.Core
13import Network.BitTorrent.Tracker.Message
14import Network.BitTorrent.Tracker.RPC as RPC
15
16
17data Swarm = Swarm
18 { swarmTopic :: InfoHash
19 , thisPeerId :: PeerId
20 , listenerPort :: PortNumber
21 , trackerConn :: Tracker
22-- , infoDict ::
23 }
24
25newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm
26newLeecher pid port Torrent {..} = do
27 tracker <- connect tAnnounce
28 return Swarm
29 { swarmTopic = idInfoHash tInfoDict
30 , thisPeerId = pid
31 , listenerPort = port
32 , trackerConn = tracker
33 }
34
35getAnnounceQuery :: Swarm -> AnnounceQuery
36getAnnounceQuery Swarm {..} = AnnounceQuery
37 { reqInfoHash = swarmTopic
38 , reqPeerId = thisPeerId
39 , reqPort = listenerPort
40 , reqProgress = def
41 , reqIP = Nothing
42 , reqNumWant = Nothing
43 , reqEvent = Nothing
44 }
45
46askPeers :: Swarm -> IO [PeerAddr]
47askPeers s @ Swarm {..} = do
48 AnnounceInfo {..} <- RPC.announce (getAnnounceQuery s) trackerConn
49 return (getPeerList respPeers)