summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/Torrent/Tracker.hs58
1 files changed, 42 insertions, 16 deletions
diff --git a/src/Network/Torrent/Tracker.hs b/src/Network/Torrent/Tracker.hs
index 9c925c0f..007f69e7 100644
--- a/src/Network/Torrent/Tracker.hs
+++ b/src/Network/Torrent/Tracker.hs
@@ -1,3 +1,4 @@
1-- TODO: add "compact" field
1{-# OPTIONS -fno-warn-orphans #-} 2{-# OPTIONS -fno-warn-orphans #-}
2{-# LANGUAGE OverloadedStrings #-} 3{-# LANGUAGE OverloadedStrings #-}
3module Network.Torrent.Tracker 4module Network.Torrent.Tracker
@@ -161,26 +162,51 @@ encodeRequest req = URL.urlEncode req
161defaultPorts :: [PortNumber] 162defaultPorts :: [PortNumber]
162defaultPorts = [6881..6889] 163defaultPorts = [6881..6889]
163 164
164defaultRequest :: URI -> InfoHash -> PeerID -> TRequest 165defaultNumWant :: Int
165defaultRequest announce hash pid = 166defaultNumWant = 25
166 TRequest { 167
167 reqAnnounce = announce 168-- | 'TSession' (shorthand for Tracker session) combines tracker request
168 , reqInfoHash = hash 169-- fields neccessary for tracker, torrent and client identification.
169 , reqPeerID = pid 170-- This data is considered as static within one session.
170 , reqPort = L.head defaultPorts 171--
171 , reqUploaded = 0 172data TSession = TSession {
172 , reqDownloaded = 0 173 tsesAnnounce :: URI -- ^ Announce URL.
173 , reqLeft = 0 174 , tsesInfoHash :: InfoHash -- ^ Hash of info part of current .torrent file.
174 , reqIP = Nothing 175 , tsesPeerID :: PeerID -- ^ Client peer ID.
175 , reqNumWant = Just 25 176 , tsesPort :: PortNumber -- ^ The port number the client is listenning on.
176 , reqEvent = Just Started 177 } deriving Show
177 } 178
179-- | 'Progress' contains upload/download/left stats about
180-- current client state.
181-- This data is considered as dynamic within one session.
182--
183data Progress = Progress {
184 prUploaded :: Int -- ^ Total amount of bytes uploaded.
185 , prDownloaded :: Int -- ^ Total amount of bytes downloaded.
186 , prLeft :: Int -- ^ Total amount of bytes left.
187 } deriving Show
188
189
178 190
179-- | The first request to the tracker that should be created is 'startedReq'. 191-- | The first request to the tracker that should be created is 'startedReq'.
180-- It includes necessary 'Started' event field. 192-- It includes necessary 'Started' event field.
181-- 193--
182startedReq :: TRequest 194startedReq :: TSession -> Progress -> TRequest
183startedReq = undefined 195startedReq ses pr =
196 TRequest {
197 reqAnnounce = tsesAnnounce ses
198 , reqInfoHash = tsesInfoHash ses
199 , reqPeerID = tsesPeerID ses
200 , reqPort = tsesPort ses
201
202 , reqUploaded = prUploaded pr
203 , reqDownloaded = prDownloaded pr
204 , reqLeft = prLeft pr
205
206 , reqIP = Nothing
207 , reqNumWant = Just defaultNumWant
208 , reqEvent = Just Started
209 }
184 210
185-- | Regular request must be sent to keep track new peers and 211-- | Regular request must be sent to keep track new peers and
186-- notify tracker about current state of the client 212-- notify tracker about current state of the client