summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Tracker/Protocol.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-12 07:34:34 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-12 07:34:34 +0400
commit5c3c114e0e84339f88892e08010bd8b1408431d1 (patch)
tree70763a0fa0fc3c9f7ecbf1242b479a55b07cf1e2 /src/Network/BitTorrent/Tracker/Protocol.hs
parent8b005c4eb0f58db974c342efe0821240f39a6331 (diff)
~ Minor fixes.
* Annotate all required fields as strict. These are always used and there is no reason to keep them lazy. * Augment user errors with location.
Diffstat (limited to 'src/Network/BitTorrent/Tracker/Protocol.hs')
-rw-r--r--src/Network/BitTorrent/Tracker/Protocol.hs33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/Network/BitTorrent/Tracker/Protocol.hs b/src/Network/BitTorrent/Tracker/Protocol.hs
index c94a2dfc..13127e7c 100644
--- a/src/Network/BitTorrent/Tracker/Protocol.hs
+++ b/src/Network/BitTorrent/Tracker/Protocol.hs
@@ -67,28 +67,28 @@ data Event = Started
67-- to keep track lists of active peer for a particular torrent. 67-- to keep track lists of active peer for a particular torrent.
68-- 68--
69data TRequest = TRequest { -- TODO peer here -- TODO detach announce 69data TRequest = TRequest { -- TODO peer here -- TODO detach announce
70 reqAnnounce :: URI 70 reqAnnounce :: !URI
71 -- ^ Announce url of the torrent usually obtained from 'Torrent'. 71 -- ^ Announce url of the torrent usually obtained from 'Torrent'.
72 72
73 , reqInfoHash :: InfoHash 73 , reqInfoHash :: !InfoHash
74 -- ^ Hash of info part of the torrent usually obtained from 74 -- ^ Hash of info part of the torrent usually obtained from
75 -- 'Torrent'. 75 -- 'Torrent'.
76 76
77 , reqPeerID :: PeerID 77 , reqPeerID :: !PeerID
78 -- ^ ID of the peer doing request. 78 -- ^ ID of the peer doing request.
79 79
80 , reqPort :: PortNumber 80 , reqPort :: !PortNumber
81 -- ^ Port to listen to for connections from other 81 -- ^ Port to listen to for connections from other
82 -- peers. Normally, tracker should respond with this port when 82 -- peers. Normally, tracker should respond with this port when
83 -- some peer request the tracker with the same info hash. 83 -- some peer request the tracker with the same info hash.
84 84
85 , reqUploaded :: Integer 85 , reqUploaded :: !Integer
86 -- ^ Number of bytes that the peer has uploaded in the swarm. 86 -- ^ Number of bytes that the peer has uploaded in the swarm.
87 87
88 , reqDownloaded :: Integer 88 , reqDownloaded :: !Integer
89 -- ^ Number of bytes downloaded in the swarm by the peer. 89 -- ^ Number of bytes downloaded in the swarm by the peer.
90 90
91 , reqLeft :: Integer 91 , reqLeft :: !Integer
92 -- ^ Number of bytes needed in order to complete download. 92 -- ^ Number of bytes needed in order to complete download.
93 93
94 , reqIP :: Maybe HostAddress 94 , reqIP :: Maybe HostAddress
@@ -111,25 +111,25 @@ data TRequest = TRequest { -- TODO peer here -- TODO detach announce
111data TResponse = 111data TResponse =
112 Failure Text -- ^ Failure reason in human readable form. 112 Failure Text -- ^ Failure reason in human readable form.
113 | OK { 113 | OK {
114 respWarning :: Maybe Text 114 respWarning :: Maybe Text
115 -- ^ Human readable warning. 115 -- ^ Human readable warning.
116 116
117 , respInterval :: Int 117 , respInterval :: !Int
118 -- ^ Recommended interval to wait between requests. 118 -- ^ Recommended interval to wait between requests.
119 119
120 , respMinInterval :: Maybe Int 120 , respMinInterval :: Maybe Int
121 -- ^ Minimal amount of time between requests. A peer /should/ 121 -- ^ Minimal amount of time between requests. A peer /should/
122 -- make timeout with at least 'respMinInterval' value, 122 -- make timeout with at least 'respMinInterval' value,
123 -- otherwise tracker might not respond. If not specified the 123 -- otherwise tracker might not respond. If not specified the
124 -- same applies to 'respInterval'. 124 -- same applies to 'respInterval'.
125 125
126 , respComplete :: Maybe Int 126 , respComplete :: Maybe Int
127 -- ^ Number of peers completed the torrent. (seeders) 127 -- ^ Number of peers completed the torrent. (seeders)
128 128
129 , respIncomplete :: Maybe Int 129 , respIncomplete :: Maybe Int
130 -- ^ Number of peers downloading the torrent. (leechers) 130 -- ^ Number of peers downloading the torrent. (leechers)
131 131
132 , respPeers :: [PeerAddr] 132 , respPeers :: ![PeerAddr]
133 -- ^ Peers that must be contacted. 133 -- ^ Peers that must be contacted.
134 } deriving Show 134 } deriving Show
135 135
@@ -227,11 +227,14 @@ askTracker req = do
227 227
228 rawResp <- simpleHTTP r 228 rawResp <- simpleHTTP r
229 respBody <- getResponseBody rawResp 229 respBody <- getResponseBody rawResp
230 print $ respBody
230 checkResult $ decoded respBody 231 checkResult $ decoded respBody
231 where 232 where
232 mkHTTPRequest :: URI -> Request ByteString 233 mkHTTPRequest :: URI -> Request ByteString
233 mkHTTPRequest uri = Request uri GET [] "" 234 mkHTTPRequest uri = Request uri GET [] ""
234 235
235 checkResult (Left err) = ioError (userError err) 236 checkResult (Left err)
236 checkResult (Right (Failure err)) = ioError (userError (show err)) 237 = ioError $ userError $ err ++ " in tracker response"
238 checkResult (Right (Failure err))
239 = ioError $ userError $ show err ++ " in tracker response"
237 checkResult (Right resp) = return resp 240 checkResult (Right resp) = return resp