summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/GetTorrent.hs5
-rw-r--r--examples/MkTorrent.hs2
-rw-r--r--src/Data/Torrent.hs16
-rw-r--r--src/Data/Torrent/Magnet.hs2
-rw-r--r--src/Network/BitTorrent/Client/Swarm.hs2
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
55fakeTracker :: URI
56fakeTracker = fromJust $ parseURI "http://foo.org"
57
58exchangeTorrent :: PeerAddr IP -> InfoHash -> IO InfoDict 55exchangeTorrent :: PeerAddr IP -> InfoHash -> IO InfoDict
59exchangeTorrent addr ih = do 56exchangeTorrent 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
122type Amend = Torrent -> Torrent 122type Amend = Torrent -> Torrent
123 123
124fields :: [(Text, IO Amend)] 124fields :: [(Text, IO Amend)]
125fields = [ ("announce", set announce <$> askURI) 125fields = [ ("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.
193data Torrent = Torrent 193data 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
285instance BEncode Torrent where 285instance 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.
344nullTorrent :: URI -> InfoDict -> Torrent 344nullTorrent :: InfoDict -> Torrent
345nullTorrent ann info = Torrent 345nullTorrent 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.
350typeTorrent :: BS.ByteString 350typeTorrent :: 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
326detailedMagnet t @ Torrent {tInfoDict = InfoDict {..}, tAnnounce} 326detailedMagnet 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
25newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm 25newLeecher :: PeerId -> PortNumber -> Torrent -> IO Swarm
26newLeecher pid port Torrent {..} = do 26newLeecher 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