summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--network-bittorrent.cabal3
-rw-r--r--src/Data/Torrent.hs16
-rw-r--r--tests/client.hs1
3 files changed, 10 insertions, 10 deletions
diff --git a/network-bittorrent.cabal b/network-bittorrent.cabal
index 2a4b28b0..a926d82e 100644
--- a/network-bittorrent.cabal
+++ b/network-bittorrent.cabal
@@ -28,12 +28,11 @@ library
28 , bencoding >= 0.1.0.0 28 , bencoding >= 0.1.0.0
29 , network >= 2.4.1.2 29 , network >= 2.4.1.2
30 , HTTP >= 4000.2.8 30 , HTTP >= 4000.2.8
31 , url >= 2.1.3
32 , urlencoded >= 0.4.0 31 , urlencoded >= 0.4.0
33 , cereal >= 0.3.5.2 32 , cereal >= 0.3.5.2
34 , cryptohash 33 , cryptohash
35 , text >= 0.11.2.3 34 , text >= 0.11.2.3
36 , directory-tree >= 0.11.0 35
37 extensions: PatternGuards 36 extensions: PatternGuards
38 hs-source-dirs: src 37 hs-source-dirs: src
39 38
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs
index 53ec4ff8..128c1c7c 100644
--- a/src/Data/Torrent.hs
+++ b/src/Data/Torrent.hs
@@ -15,7 +15,7 @@ import qualified Data.ByteString.Char8 as BC (pack, unpack)
15import Data.Text (Text) 15import Data.Text (Text)
16import Crypto.Hash.SHA1 16import Crypto.Hash.SHA1
17import Data.BEncode 17import Data.BEncode
18import Network.URL 18import Network.URI
19 19
20type Time = Text 20type Time = Text
21 21
@@ -23,15 +23,15 @@ type Time = Text
23-- TODO more convenient form of torrent info. 23-- TODO more convenient form of torrent info.
24data Torrent = Torrent { 24data Torrent = Torrent {
25 tInfoHash :: ByteString 25 tInfoHash :: ByteString
26 , tAnnounce :: URL 26 , tAnnounce :: URI
27 , tAnnounceList :: Maybe [[URL]] 27 , tAnnounceList :: Maybe [[URI]]
28 , tComment :: Maybe Text 28 , tComment :: Maybe Text
29 , tCreatedBy :: Maybe ByteString 29 , tCreatedBy :: Maybe ByteString
30 , tCreationDate :: Maybe Time 30 , tCreationDate :: Maybe Time
31 , tEncoding :: Maybe ByteString 31 , tEncoding :: Maybe ByteString
32 , tInfo :: TorrentInfo 32 , tInfo :: TorrentInfo
33 , tPublisher :: Maybe URL 33 , tPublisher :: Maybe URI
34 , tPublisherURL :: Maybe URL 34 , tPublisherURL :: Maybe URI
35 } deriving Show 35 } deriving Show
36 36
37data TorrentInfo = 37data TorrentInfo =
@@ -59,11 +59,11 @@ data TorrentFile = TorrentFile {
59 , tfPath :: [ByteString] 59 , tfPath :: [ByteString]
60 } deriving (Show, Read, Eq) 60 } deriving (Show, Read, Eq)
61 61
62instance BEncodable URL where 62instance BEncodable URI where
63 toBEncode = toBEncode . BC.pack . exportURL -- TODO utf8 encoding 63 toBEncode uri = toBEncode (BC.pack (uriToString id uri ""))
64 {-# INLINE toBEncode #-} 64 {-# INLINE toBEncode #-}
65 65
66 fromBEncode (BString s) | Just url <- importURL (BC.unpack s) = return url 66 fromBEncode (BString s) | Just url <- parseURI (BC.unpack s) = return url
67 fromBEncode b = decodingError $ "url <" ++ show b ++ ">" 67 fromBEncode b = decodingError $ "url <" ++ show b ++ ">"
68 {-# INLINE fromBEncode #-} 68 {-# INLINE fromBEncode #-}
69 69
diff --git a/tests/client.hs b/tests/client.hs
index 5697d18a..2b626241 100644
--- a/tests/client.hs
+++ b/tests/client.hs
@@ -22,6 +22,7 @@ main = do
22 let Right b = decode contents 22 let Right b = decode contents
23 let Right t = fromBEncode b 23 let Right t = fromBEncode b
24 24
25
25 let req = defaultRequest (tAnnounce t) (tInfoHash t) 26 let req = defaultRequest (tAnnounce t) (tInfoHash t)
26 resp <- sendRequest req 27 resp <- sendRequest req
27 print resp 28 print resp