diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerAddr.hs | 1 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 20 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index b145c0d9..e58aaa89 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs | |||
@@ -35,7 +35,6 @@ import Network.Socket | |||
35 | import Text.PrettyPrint | 35 | import Text.PrettyPrint |
36 | import Text.PrettyPrint.Class | 36 | import Text.PrettyPrint.Class |
37 | 37 | ||
38 | import Data.Torrent.Client | ||
39 | import Network.BitTorrent.Core.PeerId | 38 | import Network.BitTorrent.Core.PeerId |
40 | 39 | ||
41 | 40 | ||
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 9ce2e67b..046f7e57 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -46,11 +46,10 @@ module Network.BitTorrent.Tracker.Message | |||
46 | where | 46 | where |
47 | 47 | ||
48 | import Control.Applicative | 48 | import Control.Applicative |
49 | import Control.Exception | ||
50 | import Control.Monad | 49 | import Control.Monad |
51 | import Data.Aeson (ToJSON(..), FromJSON(..)) | 50 | import Data.Aeson (ToJSON(..), FromJSON(..)) |
52 | import Data.Aeson.TH | 51 | import Data.Aeson.TH |
53 | import Data.BEncode as BE | 52 | import Data.BEncode as BE hiding (Result) |
54 | import Data.BEncode.BDict as BE | 53 | import Data.BEncode.BDict as BE |
55 | import Data.ByteString as BS | 54 | import Data.ByteString as BS |
56 | import Data.ByteString.Char8 as BC | 55 | import Data.ByteString.Char8 as BC |
@@ -59,7 +58,6 @@ import Data.Convertible | |||
59 | import Data.List as L | 58 | import Data.List as L |
60 | import Data.Map as M | 59 | import Data.Map as M |
61 | import Data.Maybe | 60 | import Data.Maybe |
62 | import Data.Monoid | ||
63 | import Data.Serialize as S hiding (Result) | 61 | import Data.Serialize as S hiding (Result) |
64 | import Data.Text (Text) | 62 | import Data.Text (Text) |
65 | import Data.Text.Encoding | 63 | import Data.Text.Encoding |
@@ -70,7 +68,6 @@ import Network.HTTP.Types.QueryLike | |||
70 | import Network.HTTP.Types.URI hiding (urlEncode) | 68 | import Network.HTTP.Types.URI hiding (urlEncode) |
71 | import Network.HTTP.Types.Status | 69 | import Network.HTTP.Types.Status |
72 | import Network.Socket | 70 | import Network.Socket |
73 | import Network.URI | ||
74 | import Text.Read (readMaybe) | 71 | import Text.Read (readMaybe) |
75 | 72 | ||
76 | import Data.Torrent.InfoHash | 73 | import Data.Torrent.InfoHash |
@@ -232,7 +229,7 @@ renderAnnounceQuery = filterMaybes . toQuery | |||
232 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] | 229 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] |
233 | filterMaybes = catMaybes . L.map f | 230 | filterMaybes = catMaybes . L.map f |
234 | where | 231 | where |
235 | f (a, Nothing) = Nothing | 232 | f (_, Nothing) = Nothing |
236 | f (a, Just b ) = Just (a, b) | 233 | f (a, Just b ) = Just (a, b) |
237 | 234 | ||
238 | data QueryParam | 235 | data QueryParam |
@@ -289,18 +286,23 @@ instance FromParam Event where | |||
289 | Nothing -> Nothing | 286 | Nothing -> Nothing |
290 | Just (x, xs) -> readMaybe $ BC.unpack $ BC.cons (Char.toUpper x) xs | 287 | Just (x, xs) -> readMaybe $ BC.unpack $ BC.cons (Char.toUpper x) xs |
291 | 288 | ||
289 | type Result = Either ParamParseFailure | ||
290 | |||
291 | withError :: ParamParseFailure -> Maybe a -> Result a | ||
292 | withError e = maybe (Left e) Right | 292 | withError e = maybe (Left e) Right |
293 | 293 | ||
294 | reqParam :: FromParam a => QueryParam -> SimpleQuery -> Result a | ||
294 | reqParam param xs = do | 295 | reqParam param xs = do |
295 | val <- withError (Missing param) $ L.lookup (paramName param) xs | 296 | val <- withError (Missing param) $ L.lookup (paramName param) xs |
296 | withError (Invalid param val) (fromParam val) | 297 | withError (Invalid param val) (fromParam val) |
297 | 298 | ||
299 | optParam :: FromParam a => QueryParam -> SimpleQuery -> Result (Maybe a) | ||
298 | optParam param ps | 300 | optParam param ps |
299 | | Just x <- L.lookup (paramName param) ps | 301 | | Just x <- L.lookup (paramName param) ps |
300 | = pure <$> withError (Invalid param x) (fromParam x) | 302 | = pure <$> withError (Invalid param x) (fromParam x) |
301 | | otherwise = pure Nothing | 303 | | otherwise = pure Nothing |
302 | 304 | ||
303 | parseProgress :: SimpleQuery -> Either ParamParseFailure Progress | 305 | parseProgress :: SimpleQuery -> Result Progress |
304 | parseProgress params = Progress | 306 | parseProgress params = Progress |
305 | <$> reqParam ParamDownloaded params | 307 | <$> reqParam ParamDownloaded params |
306 | <*> reqParam ParamLeft params | 308 | <*> reqParam ParamLeft params |
@@ -318,7 +320,7 @@ parseAnnounceQuery params = AnnounceQuery | |||
318 | <*> optParam ParamEvent params | 320 | <*> optParam ParamEvent params |
319 | 321 | ||
320 | -- TODO add extension datatype | 322 | -- TODO add extension datatype |
321 | type AnnounceRequest = () | 323 | --type AnnounceRequest = () |
322 | 324 | ||
323 | {----------------------------------------------------------------------- | 325 | {----------------------------------------------------------------------- |
324 | -- Announce response | 326 | -- Announce response |
@@ -471,8 +473,8 @@ parseFailureMessage e = BS.concat $ case e of | |||
471 | parseFailureStatus :: ParamParseFailure -> Status | 473 | parseFailureStatus :: ParamParseFailure -> Status |
472 | parseFailureStatus = mkStatus <$> parseFailureCode <*> parseFailureMessage | 474 | parseFailureStatus = mkStatus <$> parseFailureCode <*> parseFailureMessage |
473 | 475 | ||
474 | type AnnounceResponse = Either Status AnnounceInfo -- TODO | 476 | --type AnnounceResponse = Either Status AnnounceInfo -- TODO |
475 | type TrackerResponse = () -- TODO | 477 | --type TrackerResponse = () -- TODO |
476 | 478 | ||
477 | {----------------------------------------------------------------------- | 479 | {----------------------------------------------------------------------- |
478 | Scrape message | 480 | Scrape message |