diff options
-rw-r--r-- | examples/GetTorrent.hs | 5 | ||||
-rw-r--r-- | examples/MkTorrent.hs | 2 | ||||
-rw-r--r-- | src/Data/Torrent.hs | 16 | ||||
-rw-r--r-- | src/Data/Torrent/Magnet.hs | 2 | ||||
-rw-r--r-- | src/Network/BitTorrent/Client/Swarm.hs | 2 |
5 files changed, 12 insertions, 15 deletions
diff --git a/examples/GetTorrent.hs b/examples/GetTorrent.hs index 5e624fa1..db52263d 100644 --- a/examples/GetTorrent.hs +++ b/examples/GetTorrent.hs | |||
@@ -52,9 +52,6 @@ programInfo = info (helper <*> paramsParser) | |||
52 | <> header "gettorrent - get torrent file by infohash" | 52 | <> header "gettorrent - get torrent file by infohash" |
53 | ) | 53 | ) |
54 | 54 | ||
55 | fakeTracker :: URI | ||
56 | fakeTracker = fromJust $ parseURI "http://foo.org" | ||
57 | |||
58 | exchangeTorrent :: PeerAddr IP -> InfoHash -> IO InfoDict | 55 | exchangeTorrent :: PeerAddr IP -> InfoHash -> IO InfoDict |
59 | exchangeTorrent addr ih = do | 56 | exchangeTorrent addr ih = do |
60 | pid <- genPeerId | 57 | pid <- genPeerId |
@@ -72,7 +69,7 @@ getTorrent Params {..} = do | |||
72 | DHT.lookup topic $$ C.mapM_ $ \ peers -> do | 69 | DHT.lookup topic $$ C.mapM_ $ \ peers -> do |
73 | liftIO $ forM_ peers $ \ peer -> do | 70 | liftIO $ forM_ peers $ \ peer -> do |
74 | infodict <- exchangeTorrent (IPv4 <$> peer) topic | 71 | infodict <- exchangeTorrent (IPv4 <$> peer) topic |
75 | let torrent = nullTorrent fakeTracker infodict | 72 | let torrent = nullTorrent infodict -- TODO add tNodes, tCreated, etc? |
76 | toFile (show topic <.> torrentExt) torrent | 73 | toFile (show topic <.> torrentExt) torrent |
77 | exitSuccess | 74 | exitSuccess |
78 | 75 | ||
diff --git a/examples/MkTorrent.hs b/examples/MkTorrent.hs index 9eda3a52..7bf8b513 100644 --- a/examples/MkTorrent.hs +++ b/examples/MkTorrent.hs | |||
@@ -122,7 +122,7 @@ amendInfo = info (helper <*> parser) modifier | |||
122 | type Amend = Torrent -> Torrent | 122 | type Amend = Torrent -> Torrent |
123 | 123 | ||
124 | fields :: [(Text, IO Amend)] | 124 | fields :: [(Text, IO Amend)] |
125 | fields = [ ("announce", set announce <$> askURI) | 125 | fields = [ ("announce", set announce . Just <$> askURI) |
126 | , ("comment", set comment . Just <$> askFreeform) | 126 | , ("comment", set comment . Just <$> askFreeform) |
127 | , ("created by", set createdBy . Just <$> askFreeform) | 127 | , ("created by", set createdBy . Just <$> askFreeform) |
128 | , ("publisher url", set publisherURL . Just <$> askURI) | 128 | , ("publisher url", set publisherURL . Just <$> askURI) |
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index db7f38eb..497a96d3 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -191,7 +191,7 @@ instance Pretty InfoDict where | |||
191 | 191 | ||
192 | -- | Metainfo about particular torrent. | 192 | -- | Metainfo about particular torrent. |
193 | data Torrent = Torrent | 193 | data Torrent = Torrent |
194 | { tAnnounce :: !URI | 194 | { tAnnounce :: !(Maybe URI) |
195 | -- ^ The URL of the tracker. | 195 | -- ^ The URL of the tracker. |
196 | 196 | ||
197 | , tAnnounceList :: !(Maybe [[URI]]) | 197 | , tAnnounceList :: !(Maybe [[URI]]) |
@@ -215,7 +215,7 @@ data Torrent = Torrent | |||
215 | , tInfoDict :: !InfoDict | 215 | , tInfoDict :: !InfoDict |
216 | -- ^ Info about each content file. | 216 | -- ^ Info about each content file. |
217 | 217 | ||
218 | , tNodes :: Maybe [NodeAddr ByteString] | 218 | , tNodes :: !(Maybe [NodeAddr ByteString]) |
219 | -- ^ This key should be set to the /K closest/ nodes in the | 219 | -- ^ This key should be set to the /K closest/ nodes in the |
220 | -- torrent generating client's routing table. Alternatively, the | 220 | -- torrent generating client's routing table. Alternatively, the |
221 | -- key could be set to a known good 'Network.BitTorrent.Core.Node' | 221 | -- key could be set to a known good 'Network.BitTorrent.Core.Node' |
@@ -284,7 +284,7 @@ instance BEncode POSIXTime where | |||
284 | 284 | ||
285 | instance BEncode Torrent where | 285 | instance BEncode Torrent where |
286 | toBEncode Torrent {..} = toDict $ | 286 | toBEncode Torrent {..} = toDict $ |
287 | "announce" .=! tAnnounce | 287 | "announce" .=? tAnnounce |
288 | .: "announce-list" .=? tAnnounceList | 288 | .: "announce-list" .=? tAnnounceList |
289 | .: "comment" .=? tComment | 289 | .: "comment" .=? tComment |
290 | .: "created by" .=? tCreatedBy | 290 | .: "created by" .=? tCreatedBy |
@@ -298,7 +298,7 @@ instance BEncode Torrent where | |||
298 | .: endDict | 298 | .: endDict |
299 | 299 | ||
300 | fromBEncode = fromDict $ do | 300 | fromBEncode = fromDict $ do |
301 | Torrent <$>! "announce" | 301 | Torrent <$>? "announce" |
302 | <*>? "announce-list" | 302 | <*>? "announce-list" |
303 | <*>? "comment" | 303 | <*>? "comment" |
304 | <*>? "created by" | 304 | <*>? "created by" |
@@ -341,10 +341,10 @@ instance Pretty Torrent where | |||
341 | "Signature" <:>? ((text . show) <$> tSignature) | 341 | "Signature" <:>? ((text . show) <$> tSignature) |
342 | 342 | ||
343 | -- | A simple torrent contains only required fields. | 343 | -- | A simple torrent contains only required fields. |
344 | nullTorrent :: URI -> InfoDict -> Torrent | 344 | nullTorrent :: InfoDict -> Torrent |
345 | nullTorrent ann info = Torrent | 345 | nullTorrent info = Torrent |
346 | ann Nothing Nothing Nothing Nothing Nothing | 346 | Nothing Nothing Nothing Nothing Nothing Nothing |
347 | info Nothing Nothing Nothing Nothing | 347 | info Nothing Nothing Nothing Nothing |
348 | 348 | ||
349 | -- | Mime type of torrent files. | 349 | -- | Mime type of torrent files. |
350 | typeTorrent :: BS.ByteString | 350 | typeTorrent :: BS.ByteString |
diff --git a/src/Data/Torrent/Magnet.hs b/src/Data/Torrent/Magnet.hs index ae4e134b..ae6a8dc5 100644 --- a/src/Data/Torrent/Magnet.hs +++ b/src/Data/Torrent/Magnet.hs | |||
@@ -326,7 +326,7 @@ detailedMagnet :: Torrent -> Magnet | |||
326 | detailedMagnet t @ Torrent {tInfoDict = InfoDict {..}, tAnnounce} | 326 | detailedMagnet t @ Torrent {tInfoDict = InfoDict {..}, tAnnounce} |
327 | = (simpleMagnet t) | 327 | = (simpleMagnet t) |
328 | { exactLength = Just $ fromIntegral $ contentLength idLayoutInfo | 328 | { exactLength = Just $ fromIntegral $ contentLength idLayoutInfo |
329 | , tracker = Just tAnnounce | 329 | , tracker = tAnnounce |
330 | } | 330 | } |
331 | 331 | ||
332 | {----------------------------------------------------------------------- | 332 | {----------------------------------------------------------------------- |
diff --git a/src/Network/BitTorrent/Client/Swarm.hs b/src/Network/BitTorrent/Client/Swarm.hs index 1901905c..7fdd1f2f 100644 --- a/src/Network/BitTorrent/Client/Swarm.hs +++ b/src/Network/BitTorrent/Client/Swarm.hs | |||
@@ -24,7 +24,7 @@ data Swarm = Swarm | |||
24 | 24 | ||
25 | newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm | 25 | newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm |
26 | newLeecher pid port Torrent {..} = do | 26 | newLeecher pid port Torrent {..} = do |
27 | tracker <- connect tAnnounce | 27 | tracker <- connect undefined |
28 | return Swarm | 28 | return Swarm |
29 | { swarmTopic = idInfoHash tInfoDict | 29 | { swarmTopic = idInfoHash tInfoDict |
30 | , thisPeerId = pid | 30 | , thisPeerId = pid |