summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT.hs')
-rw-r--r--src/Network/BitTorrent/DHT.hs15
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 #-}
1module Network.BitTorrent.DHT 3module Network.BitTorrent.DHT
2 ( dht 4 ( dht
3 , ping 5 , ping
@@ -8,9 +10,13 @@ module Network.BitTorrent.DHT
8 10
9import Control.Applicative 11import Control.Applicative
10import Control.Monad 12import Control.Monad
11import Control.Monad.Reader 13import Control.Monad.Logger
12import Data.List as L 14import Data.List as L
15import Data.Monoid
16import Data.Text as T
13import Network.Socket (PortNumber) 17import Network.Socket (PortNumber)
18import Text.PrettyPrint as PP hiding ((<>))
19import Text.PrettyPrint.Class
14 20
15import Data.Torrent.InfoHash 21import Data.Torrent.InfoHash
16import Network.BitTorrent.Core 22import 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'>
61bootstrap :: Address ip => [NodeAddr ip] -> DHT ip () 67bootstrap :: Address ip => [NodeAddr ip] -> DHT ip ()
62bootstrap = mapM_ insertClosest 68bootstrap 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