summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-16 19:20:54 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-16 19:20:54 +0400
commit177aa03686ec7629e0cd42cb352fa5ee32d6c24e (patch)
treec8a20c0ee6313d065f3dbe91c9e5d5393b752e84 /src/Network
parent30ed5ec2dd5a60bf64da055c25c8ad86915bb14a (diff)
Add list of default bootstrap nodes
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/DHT.hs57
1 files changed, 49 insertions, 8 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs
index a97ebcf7..19f9a071 100644
--- a/src/Network/BitTorrent/DHT.hs
+++ b/src/Network/BitTorrent/DHT.hs
@@ -23,8 +23,13 @@ module Network.BitTorrent.DHT
23 , MonadDHT (..) 23 , MonadDHT (..)
24 , dht 24 , dht
25 25
26 -- * Initialization 26 -- * Bootstrapping
27 , tNodes
28 , defaultBootstrapNodes
29 , resolveHostName
27 , bootstrap 30 , bootstrap
31
32 -- * Initialization
28 , snapshot 33 , snapshot
29 , restore 34 , restore
30 35
@@ -48,8 +53,9 @@ import Control.Monad.Trans
48import Data.ByteString as BS 53import Data.ByteString as BS
49import Data.Conduit as C 54import Data.Conduit as C
50import Data.Conduit.List as C 55import Data.Conduit.List as C
51import Network.Socket (PortNumber) 56import Network.Socket
52 57
58import Data.Torrent (tNodes)
53import Data.Torrent.InfoHash 59import Data.Torrent.InfoHash
54import Network.BitTorrent.Core 60import Network.BitTorrent.Core
55import Network.BitTorrent.DHT.Session 61import Network.BitTorrent.DHT.Session
@@ -78,20 +84,51 @@ dht opts addr action = do
78{-# INLINE dht #-} 84{-# INLINE dht #-}
79 85
80{----------------------------------------------------------------------- 86{-----------------------------------------------------------------------
81-- Initialization 87-- Bootstrapping
82-----------------------------------------------------------------------} 88-----------------------------------------------------------------------}
83 89-- Do not include the following hosts in the default bootstrap nodes list:
84-- | One good node may be sufficient. The list of bootstrapping nodes
85-- usually obtained from 'Data.Torrent.tNodes' field. Bootstrapping
86-- process can take up to 5 minutes.
87-- 90--
88-- This operation is synchronous and do block, use 91-- * "dht.aelitis.com" and "dht6.azureusplatform.com" - since
92-- Azureus client have a different (and probably incompatible) DHT
93-- protocol implementation.
94--
95-- * "router.utorrent.com" since it is just an alias to
96-- "router.bittorrent.com".
97
98-- | List of bootstrap nodes maintained by different bittorrent
99-- software authors.
100defaultBootstrapNodes :: [NodeAddr HostName]
101defaultBootstrapNodes =
102 [ NodeAddr "router.bittorrent.com" 6881 -- by BitTorrent Inc.
103
104 -- doesn't work at the moment (use git blame) of commit
105 , NodeAddr "dht.transmissionbt.com" 6881 -- by Transmission project
106 ]
107
108-- TODO Multihomed hosts
109
110-- | Resolve either a numeric network address or a hostname to a
111-- numeric IP address of the node. Usually used to resolve
112-- 'defaultBootstrapNodes' or 'Data.Torrent.tNodes' lists.
113resolveHostName :: NodeAddr HostName -> IO (NodeAddr IPv4)
114resolveHostName NodeAddr {..} = do
115 let hints = defaultHints { addrFamily = AF_INET, addrSocketType = Datagram }
116 -- getAddrInfo throws exception on empty list, so the pattern matching never fail
117 info : _ <- getAddrInfo (Just hints) (Just nodeHost) (Just (show nodePort))
118 case fromSockAddr (addrAddress info) of
119 Nothing -> error "resolveNodeAddr: impossible"
120 Just addr -> return addr
121
122-- | One good node may be sufficient.
123--
124-- This operation do block, use
89-- 'Control.Concurrent.Async.Lifted.async' if needed. 125-- 'Control.Concurrent.Async.Lifted.async' if needed.
90-- 126--
91bootstrap :: Address ip => [NodeAddr ip] -> DHT ip () 127bootstrap :: Address ip => [NodeAddr ip] -> DHT ip ()
92bootstrap startNodes = do 128bootstrap startNodes = do
93 $(logInfoS) "bootstrap" "Start node bootstrapping" 129 $(logInfoS) "bootstrap" "Start node bootstrapping"
94 nid <- getNodeId 130 nid <- getNodeId
131 -- TODO filter duplicated in startNodes list
95 aliveNodes <- queryParallel (ping <$> startNodes) 132 aliveNodes <- queryParallel (ping <$> startNodes)
96 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume 133 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume
97 $(logInfoS) "bootstrap" "Node bootstrapping finished" 134 $(logInfoS) "bootstrap" "Node bootstrapping finished"
@@ -99,6 +136,10 @@ bootstrap startNodes = do
99-- unless (full t) $ do 136-- unless (full t) $ do
100-- nid <- getNodeId 137-- nid <- getNodeId
101 138
139{-----------------------------------------------------------------------
140-- Initialization
141-----------------------------------------------------------------------}
142
102-- | Load previous session. (corrupted - exception/ignore ?) 143-- | Load previous session. (corrupted - exception/ignore ?)
103-- 144--
104-- This is blocking operation, use 145-- This is blocking operation, use