mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-02 09:54:29 +00:00
remove refresh_per_tick_limit based logic in flavour of 100ms delay
This commit is contained in:
parent
dc7c4e5627
commit
79be353eed
@ -52,9 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <boost/random.hpp>
|
|
||||||
#include <boost/nondet_random.hpp>
|
|
||||||
#include <boost/random/mersenne_twister.hpp>
|
|
||||||
|
|
||||||
#include "libtorrent/socket.hpp"
|
#include "libtorrent/socket.hpp"
|
||||||
|
|
||||||
@ -273,8 +270,6 @@ public:
|
|||||||
|
|
||||||
dht_settings const& settings() const { return m_settings; }
|
dht_settings const& settings() const { return m_settings; }
|
||||||
|
|
||||||
double getRandom() { return m_random(); }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void lookup_peers(sha1_hash const& info_hash, int prefix, entry& reply
|
void lookup_peers(sha1_hash const& info_hash, int prefix, entry& reply
|
||||||
@ -313,10 +308,6 @@ private:
|
|||||||
|
|
||||||
alert_dispatcher* m_post_alert;
|
alert_dispatcher* m_post_alert;
|
||||||
udp_socket_interface* m_sock;
|
udp_socket_interface* m_sock;
|
||||||
|
|
||||||
boost::mt19937 m_random_seed;
|
|
||||||
boost::uniform_real<double> m_random_dist;
|
|
||||||
boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > m_random;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/function/function1.hpp>
|
#include <boost/function/function1.hpp>
|
||||||
//#include <boost/date_time/posix_time/time_formatters_limited.hpp>
|
//#include <boost/date_time/posix_time/time_formatters_limited.hpp>
|
||||||
|
#include <boost/random.hpp>
|
||||||
|
#include <boost/nondet_random.hpp>
|
||||||
|
#include <boost/random/mersenne_twister.hpp>
|
||||||
|
|
||||||
#include "libtorrent/io.hpp"
|
#include "libtorrent/io.hpp"
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
@ -109,8 +112,6 @@ node_impl::node_impl(alert_dispatcher* alert_disp
|
|||||||
, m_next_storage_refresh(time_now())
|
, m_next_storage_refresh(time_now())
|
||||||
, m_post_alert(alert_disp)
|
, m_post_alert(alert_disp)
|
||||||
, m_sock(sock)
|
, m_sock(sock)
|
||||||
, m_random_dist(0.0, 1.0)
|
|
||||||
, m_random(m_random_seed, m_random_dist)
|
|
||||||
{
|
{
|
||||||
m_secret[0] = random();
|
m_secret[0] = random();
|
||||||
m_secret[1] = std::rand();
|
m_secret[1] = std::rand();
|
||||||
@ -309,11 +310,31 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double getRandom()
|
||||||
|
{
|
||||||
|
static boost::mt19937 m_random_seed;
|
||||||
|
static boost::uniform_real<double> m_random_dist(0.0, 1.0);
|
||||||
|
static boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > m_random(m_random_seed, m_random_dist);
|
||||||
|
|
||||||
|
return m_random();
|
||||||
|
}
|
||||||
|
|
||||||
|
ptime getNextRefreshTime(bool confirmed = true)
|
||||||
|
{
|
||||||
|
static ptime nextRefreshTime[2] = { ptime(0) };
|
||||||
|
nextRefreshTime[confirmed] = std::max(
|
||||||
|
nextRefreshTime[confirmed] + milliseconds(100),
|
||||||
|
// add +/-10% diffusion to next refresh time
|
||||||
|
time_now() + minutes(confirmed ? 60 : 1) * ( 0.9 + 0.2 * getRandom() )
|
||||||
|
);
|
||||||
|
return nextRefreshTime[confirmed];
|
||||||
|
}
|
||||||
|
|
||||||
void putData_confirm(entry::list_type const& values_list, dht_storage_item& item)
|
void putData_confirm(entry::list_type const& values_list, dht_storage_item& item)
|
||||||
{
|
{
|
||||||
if( !item.confirmed && !values_list.empty() ) {
|
if( !item.confirmed && !values_list.empty() ) {
|
||||||
item.confirmed = true;
|
item.confirmed = true;
|
||||||
item.next_refresh_time = time_now() + minutes(60);
|
item.next_refresh_time = getNextRefreshTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,7 +570,6 @@ bool node_impl::refresh_storage() {
|
|||||||
ptime const now = time_now();
|
ptime const now = time_now();
|
||||||
m_next_storage_refresh = now + minutes(60);
|
m_next_storage_refresh = now + minutes(60);
|
||||||
|
|
||||||
int refresh_per_tick_limit = 20;
|
|
||||||
|
|
||||||
for (dht_storage_table_t::iterator i = m_storage_table.begin(),
|
for (dht_storage_table_t::iterator i = m_storage_table.begin(),
|
||||||
end(m_storage_table.end()); i != end; ++i )
|
end(m_storage_table.end()); i != end; ++i )
|
||||||
@ -572,7 +592,6 @@ bool node_impl::refresh_storage() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( refresh_per_tick_limit > 0) {
|
|
||||||
|
|
||||||
lazy_entry p;
|
lazy_entry p;
|
||||||
int pos;
|
int pos;
|
||||||
@ -615,11 +634,7 @@ bool node_impl::refresh_storage() {
|
|||||||
ta->start();
|
ta->start();
|
||||||
did_something = true;
|
did_something = true;
|
||||||
|
|
||||||
--refresh_per_tick_limit;
|
item.next_refresh_time = getNextRefreshTime(item.confirmed);
|
||||||
|
|
||||||
// add +/-10% diffusion to next refresh time
|
|
||||||
item.next_refresh_time = now + minutes(item.confirmed ? 60 : 1) * ( 0.9 + 0.2 * getRandom() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_next_storage_refresh > item.next_refresh_time ) {
|
if( m_next_storage_refresh > item.next_refresh_time ) {
|
||||||
@ -1510,7 +1525,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
|||||||
void node_impl::store_dht_item(dht_storage_item &item, const big_number &target,
|
void node_impl::store_dht_item(dht_storage_item &item, const big_number &target,
|
||||||
bool multi, int seq, int height, std::pair<char const*, int> &bufv)
|
bool multi, int seq, int height, std::pair<char const*, int> &bufv)
|
||||||
{
|
{
|
||||||
item.next_refresh_time = time_now() + minutes(item.confirmed ? 60 : 1);
|
item.next_refresh_time = getNextRefreshTime(item.confirmed);
|
||||||
if( m_next_storage_refresh > item.next_refresh_time ) {
|
if( m_next_storage_refresh > item.next_refresh_time ) {
|
||||||
m_next_storage_refresh = item.next_refresh_time;
|
m_next_storage_refresh = item.next_refresh_time;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user