diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-02 22:27:28 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-02 22:27:28 +0400 |
commit | 469b2c84af865863a852bda5137640a2463c9a8b (patch) | |
tree | 4ca03913a1e1eae6271ea5d45a3fb3efda2b54dc /src/Network/BitTorrent/DHT | |
parent | ab565965354a238bc57b95bd56135ecce40751c6 (diff) |
Add bucket count option
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 6 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 18 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index 4897a22e..f6926cb1 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -325,8 +325,10 @@ instance Pretty (Table ip) where | |||
325 | ss = shape t | 325 | ss = shape t |
326 | 326 | ||
327 | -- | Empty table with specified /spine/ node id. | 327 | -- | Empty table with specified /spine/ node id. |
328 | nullTable :: Eq ip => NodeId -> Table ip | 328 | nullTable :: Eq ip => NodeId -> BucketCount -> Table ip |
329 | nullTable nid = Tip nid defaultBucketCount PSQ.empty | 329 | nullTable nid n = Tip nid (bucketCount (pred n)) PSQ.empty |
330 | where | ||
331 | bucketCount x = max 0 (min 160 x) | ||
330 | 332 | ||
331 | -- | Get the /spine/ node id. | 333 | -- | Get the /spine/ node id. |
332 | thisId :: Table ip -> NodeId | 334 | thisId :: Table ip -> NodeId |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index 55e66a7e..c47f7491 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -96,13 +96,16 @@ defaultAlpha = 3 | |||
96 | 96 | ||
97 | data Options = Options | 97 | data Options = Options |
98 | { -- | the degree of parallelism in 'find_node' queries. | 98 | { -- | the degree of parallelism in 'find_node' queries. |
99 | optAlpha :: {-# UNPACK #-} !Alpha | 99 | optAlpha :: {-# UNPACK #-} !Alpha |
100 | 100 | ||
101 | -- | number of nodes to return in 'find_node' responses. | 101 | -- | number of nodes to return in 'find_node' responses. |
102 | , optK :: {-# UNPACK #-} !K | 102 | , optK :: {-# UNPACK #-} !K |
103 | |||
104 | -- | Number of buckets to maintain. | ||
105 | , optBucketCount :: {-# UNPACK #-} !BucketCount | ||
103 | 106 | ||
104 | -- | RPC timeout. | 107 | -- | RPC timeout. |
105 | , optTimeout :: !NominalDiffTime | 108 | , optTimeout :: !NominalDiffTime |
106 | 109 | ||
107 | -- , optReannounceInterval :: NominalDiffTime | 110 | -- , optReannounceInterval :: NominalDiffTime |
108 | -- , optDataExpiredTimeout :: NominalDiffTime | 111 | -- , optDataExpiredTimeout :: NominalDiffTime |
@@ -110,9 +113,10 @@ data Options = Options | |||
110 | 113 | ||
111 | instance Default Options where | 114 | instance Default Options where |
112 | def = Options | 115 | def = Options |
113 | { optAlpha = defaultAlpha | 116 | { optAlpha = defaultAlpha |
114 | , optK = defaultK | 117 | , optK = defaultK |
115 | , optTimeout = 5 -- seconds | 118 | , optBucketCount = defaultBucketCount |
119 | , optTimeout = 5 -- seconds | ||
116 | } | 120 | } |
117 | 121 | ||
118 | microseconds :: NominalDiffTime -> Int | 122 | microseconds :: NominalDiffTime -> Int |
@@ -194,7 +198,7 @@ runDHT handlers opts naddr action = runResourceT $ do | |||
194 | (_, m) <- allocate (newManager (toSockAddr naddr) handlers) closeManager | 198 | (_, m) <- allocate (newManager (toSockAddr naddr) handlers) closeManager |
195 | myId <- liftIO genNodeId | 199 | myId <- liftIO genNodeId |
196 | node <- liftIO $ Node opts m | 200 | node <- liftIO $ Node opts m |
197 | <$> newMVar (nullTable myId) | 201 | <$> newMVar (nullTable myId (optBucketCount opts)) |
198 | <*> newTVarIO def | 202 | <*> newTVarIO def |
199 | <*> (newTVarIO =<< nullSessionTokens) | 203 | <*> (newTVarIO =<< nullSessionTokens) |
200 | <*> pure logger | 204 | <*> pure logger |