summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-11 06:54:58 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-11 06:54:58 +0400
commitef2e4cc8b79ec88dd7ed06ca0438fd3288383141 (patch)
tree29c3056f7969ad1394c0eeb6c6d00e5352bb20a5
parentf5163a12b52c2adc9be6be2993443188f79b8bdf (diff)
Add options related to data republishing
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs60
1 files changed, 52 insertions, 8 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 3c37ea9a..e53639a3 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -89,33 +89,77 @@ import Network.BitTorrent.DHT.Token as T
89-- | Node lookups can proceed asynchronously. 89-- | Node lookups can proceed asynchronously.
90type Alpha = Int 90type Alpha = Int
91 91
92-- NOTE: libtorrent uses 5, azureus uses 10
92-- | The quantity of simultaneous lookups is typically three. 93-- | The quantity of simultaneous lookups is typically three.
93defaultAlpha :: Alpha 94defaultAlpha :: Alpha
94defaultAlpha = 3 95defaultAlpha = 3
95 96
97-- TODO add replication loop
98
99-- | Original Kamelia DHT uses term /publish/ . BitTorrent DHT uses
100-- term /announce/ since the purpose . Later in documentation, we use
101-- terms /publish/ and /announce/ interchangible.
96data Options = Options 102data Options = Options
97 { -- | the degree of parallelism in 'find_node' queries. 103 { -- | The degree of parallelism in 'find_node' queries. More
104 -- parallism lead to faster bootstrapping and lookup operations,
105 -- but also increase resource usage.
106 --
107 -- Normally this parameter should not exceed 'optK'.
98 optAlpha :: {-# UNPACK #-} !Alpha 108 optAlpha :: {-# UNPACK #-} !Alpha
99 109
100 -- | number of nodes to return in 'find_node' responses. 110 -- | /K/ parameter - number of nodes to return in 'find_node'
111 -- responses.
101 , optK :: {-# UNPACK #-} !K 112 , optK :: {-# UNPACK #-} !K
102 113
103 -- | Number of buckets to maintain. 114 -- | Number of buckets to maintain. This parameter depends on
115 -- amount of nodes in the DHT network.
104 , optBucketCount :: {-# UNPACK #-} !BucketCount 116 , optBucketCount :: {-# UNPACK #-} !BucketCount
105 117
106 -- | RPC timeout. 118 -- | RPC timeout.
107 , optTimeout :: !NominalDiffTime 119 , optTimeout :: !NominalDiffTime
108 120
109-- , optReannounceInterval :: NominalDiffTime 121 -- | /R/ parameter - how many target nodes the 'announce' query
110-- , optDataExpiredTimeout :: NominalDiffTime 122 -- should affect.
123 --
124 -- A large replica set compensates for inconsistent routing and
125 -- reduces the need to frequently republish data for
126 -- persistence. This comes at an increased cost for
127 -- 'Network.BitTorrent.DHT.insert' in terms of time, nodes
128 -- contacted, and storage.
129 , optReplication :: {-# UNPACK #-} !NodeCount
130
131 -- | How often this node should republish (or reannounce) its
132 -- data.
133 --
134 -- Large replica set ('optReplication') should require
135 -- smaller reannounce intervals ('optReannounce').
136 , optReannounce :: !NominalDiffTime
137
138 -- | The time it takes for data to expire in the
139 -- network. Publisher of the data should republish (or
140 -- reannounce) data to keep it in the network.
141 --
142 -- The /data expired timeout/ should be more than 'optReannounce'
143 -- interval.
144 , optDataExpired :: !NominalDiffTime
111 } deriving (Show, Eq) 145 } deriving (Show, Eq)
112 146
147-- | Optimal options for bittorrent client. For short-lifetime
148-- utilities you most likely need to tune 'optAlpha' and
149-- 'optBucketCount'.
113instance Default Options where 150instance Default Options where
114 def = Options 151 def = Options
115 { optAlpha = defaultAlpha 152 { optAlpha = defaultAlpha
116 , optK = defaultK 153 , optK = defaultK
154
155 -- see Fig.2 from "BitTorrent Mainline DHT Measurement" paper.
117 , optBucketCount = defaultBucketCount 156 , optBucketCount = defaultBucketCount
118 , optTimeout = 5 -- seconds 157
158 -- see Fig.4 from "Profiling a Million User DHT" paper.
159 , optTimeout = 5 -- seconds
160 , optReplication = 20 -- nodes
161 , optReannounce = 15 * 60
162 , optDataExpired = 60 * 60
119 } 163 }
120 164
121seconds :: NominalDiffTime -> Int 165seconds :: NominalDiffTime -> Int