diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT.hs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index bdb76c76..7cc7e803 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs | |||
@@ -1,3 +1,5 @@ | |||
1 | {-# LANGUAGE FlexibleInstances #-} | ||
2 | {-# LANGUAGE TemplateHaskell #-} | ||
1 | module Network.BitTorrent.DHT | 3 | module Network.BitTorrent.DHT |
2 | ( dht | 4 | ( dht |
3 | , ping | 5 | , ping |
@@ -8,9 +10,13 @@ module Network.BitTorrent.DHT | |||
8 | 10 | ||
9 | import Control.Applicative | 11 | import Control.Applicative |
10 | import Control.Monad | 12 | import Control.Monad |
11 | import Control.Monad.Reader | 13 | import Control.Monad.Logger |
12 | import Data.List as L | 14 | import Data.List as L |
15 | import Data.Monoid | ||
16 | import Data.Text as T | ||
13 | import Network.Socket (PortNumber) | 17 | import Network.Socket (PortNumber) |
18 | import Text.PrettyPrint as PP hiding ((<>)) | ||
19 | import Text.PrettyPrint.Class | ||
14 | 20 | ||
15 | import Data.Torrent.InfoHash | 21 | import Data.Torrent.InfoHash |
16 | import Network.BitTorrent.Core | 22 | import Network.BitTorrent.Core |
@@ -59,11 +65,16 @@ ping addr = do | |||
59 | 65 | ||
60 | -- | One good node may be sufficient. <note about 'Data.Torrent.tNodes'> | 66 | -- | One good node may be sufficient. <note about 'Data.Torrent.tNodes'> |
61 | bootstrap :: Address ip => [NodeAddr ip] -> DHT ip () | 67 | bootstrap :: Address ip => [NodeAddr ip] -> DHT ip () |
62 | bootstrap = mapM_ insertClosest | 68 | bootstrap startNodes = do |
69 | $(logInfoS) "bootstrap" "Start node bootstrapping" | ||
70 | mapM_ insertClosest startNodes | ||
71 | $(logInfoS) "bootstrap" "Node bootstrapping finished" | ||
63 | where | 72 | where |
64 | insertClosest addr = do | 73 | insertClosest addr = do |
65 | nid <- getNodeId | 74 | nid <- getNodeId |
66 | NodeFound closest <- FindNode nid <@> addr | 75 | NodeFound closest <- FindNode nid <@> addr |
76 | $(logDebug) ("Get a list of closest nodes: " <> | ||
77 | T.pack (PP.render (pretty closest))) | ||
67 | forM_ closest insertNode | 78 | forM_ closest insertNode |
68 | 79 | ||
69 | -- | Get list of peers which downloading | 80 | -- | Get list of peers which downloading |