Browse Source

Merge

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
1838558305
  1. 3
      libtorrent/include/libtorrent/kademlia/node.hpp
  2. 2
      libtorrent/src/kademlia/dht_get.cpp
  3. 47
      libtorrent/src/kademlia/node.cpp
  4. 2
      src/init.cpp
  5. 13
      src/twister.cpp

3
libtorrent/include/libtorrent/kademlia/node.hpp

@ -293,7 +293,8 @@ private:
dht_storage_table_t m_storage_table; dht_storage_table_t m_storage_table;
ptime m_last_tracker_tick; ptime m_last_tracker_tick;
ptime m_last_storage_refresh; ptime m_next_storage_refresh;
node_id m_last_refreshed_item;
// secret random numbers used to create write tokens // secret random numbers used to create write tokens
int m_secret[2]; int m_secret[2];

2
libtorrent/src/kademlia/dht_get.cpp

@ -85,7 +85,7 @@ void dht_get_observer::reply(msg const& m)
} }
// look for peers // look for peers
lazy_entry const* n = r->dict_find_list("values"); lazy_entry const* n = r->dict_find_list("data");
if (n) if (n)
{ {
#ifdef TORRENT_DHT_VERBOSE_LOGGING #ifdef TORRENT_DHT_VERBOSE_LOGGING

47
libtorrent/src/kademlia/node.cpp

@ -105,7 +105,8 @@ node_impl::node_impl(alert_dispatcher* alert_disp
, m_table(m_id, 8, settings) , m_table(m_id, 8, settings)
, m_rpc(m_id, m_table, sock, observer) , m_rpc(m_id, m_table, sock, observer)
, m_last_tracker_tick(time_now()) , m_last_tracker_tick(time_now())
, m_last_storage_refresh(time_now()) , m_next_storage_refresh(time_now())
, m_last_refreshed_item()
, m_post_alert(alert_disp) , m_post_alert(alert_disp)
, m_sock(sock) , m_sock(sock)
{ {
@ -482,23 +483,25 @@ void node_impl::tick()
refresh(target, boost::bind(&nop)); refresh(target, boost::bind(&nop));
ptime now = time_now(); ptime now = time_now();
if (now - m_last_storage_refresh > minutes(60)) { if (now > m_next_storage_refresh ) {
m_last_storage_refresh = now;
refresh_storage(); refresh_storage();
} }
} }
bool node_impl::refresh_storage() { bool node_impl::refresh_storage() {
bool did_something = false; bool did_something = false;
bool refresh_next_item = false;
if( m_storage_table.size() == 0 ) int num_refreshable = 0;
return did_something;
printf("node dht: refreshing storage...\n");
for (dht_storage_table_t::const_iterator i = m_storage_table.begin(), for (dht_storage_table_t::const_iterator i = m_storage_table.begin(),
end(m_storage_table.end()); i != end; ++i ) end(m_storage_table.end()); i != end; ++i )
{ {
if( i->first == m_last_refreshed_item ) {
refresh_next_item = true;
num_refreshable++;
continue;
}
dht_storage_list_t const& lsto = i->second; dht_storage_list_t const& lsto = i->second;
if( lsto.size() == 1 ) { if( lsto.size() == 1 ) {
dht_storage_item const& item = lsto.front(); dht_storage_item const& item = lsto.front();
@ -522,7 +525,13 @@ bool node_impl::refresh_storage() {
// refresh only signed single posts // refresh only signed single posts
if( !multi ) { if( !multi ) {
printf("refresh dht storage: [%s,%s,%s]\n", num_refreshable++;
if( refresh_next_item ) {
refresh_next_item = false;
m_last_refreshed_item = i->first;
printf("node dht: refreshing storage: [%s,%s,%s]\n",
username.c_str(), username.c_str(),
resource.c_str(), resource.c_str(),
target->dict_find_string_value("t").c_str()); target->dict_find_string_value("t").c_str());
@ -541,6 +550,20 @@ bool node_impl::refresh_storage() {
} }
} }
} }
}
if( !did_something && m_storage_table.size() ) {
m_last_refreshed_item = m_storage_table.begin()->first;
}
if( num_refreshable ) {
m_next_storage_refresh = minutes(60) / num_refreshable + time_now();
} else {
m_next_storage_refresh = minutes(1) + time_now();
}
printf("node dht: next storage refresh in %d seconds\n", (m_next_storage_refresh - time_now())/1000000 );
return did_something; return did_something;
} }
@ -1226,7 +1249,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
return; return;
} }
if (msg_keys[mk_height]->int_value() > getBestHeight() && getBestHeight()) { if (msg_keys[mk_height]->int_value() > getBestHeight() && getBestHeight() > 0) {
incoming_error(e, "height > getBestHeight"); incoming_error(e, "height > getBestHeight");
return; return;
} }
@ -1381,8 +1404,8 @@ void node_impl::incoming_request(msg const& m, entry& e)
if (i != m_storage_table.end()) if (i != m_storage_table.end())
{ {
hasData = true; hasData = true;
reply["values"] = entry::list_type(); reply["data"] = entry::list_type();
entry::list_type &values = reply["values"].list(); entry::list_type &values = reply["data"].list();
dht_storage_list_t const& lsto = i->second; dht_storage_list_t const& lsto = i->second;
for (dht_storage_list_t::const_iterator j = lsto.begin() for (dht_storage_list_t::const_iterator j = lsto.begin()

2
src/init.cpp

@ -727,7 +727,7 @@ bool AppInit2(boost::thread_group& threadGroup)
break; break;
} }
if( mapBlockIndex.size() > 1000 && nBestHeight == 0 ) { if( mapBlockIndex.size() > 1000 && nBestHeight <= 0 ) {
strLoadError = _("mapBlockIndex detected but nBestHeight still zero, trying to repair (reindex)"); strLoadError = _("mapBlockIndex detected but nBestHeight still zero, trying to repair (reindex)");
break; break;
} }

13
src/twister.cpp

@ -182,6 +182,11 @@ void ThreadWaitExtIP()
MilliSleep(500); MilliSleep(500);
} }
// delay libtorrent initialization until we have valid blocks
while( getBestHeight() <= 0 ) {
MilliSleep(500);
}
error_code ec; error_code ec;
int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET; int listen_port = GetListenPort() + LIBTORRENT_PORT_OFFSET;
std::string bind_to_interface = ""; std::string bind_to_interface = "";
@ -268,6 +273,10 @@ void ThreadMaintainDHTNodes()
{ {
RenameThread("maintain-dht-nodes"); RenameThread("maintain-dht-nodes");
while(!ses) {
MilliSleep(200);
}
while(1) { while(1) {
MilliSleep(5000); MilliSleep(5000);
@ -745,7 +754,7 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int
} else if( !validatePostNumberForUser(username, k) ) { } else if( !validatePostNumberForUser(username, k) ) {
sprintf(errbuf,"too much posts from user '%s' rejecting post", sprintf(errbuf,"too much posts from user '%s' rejecting post",
username.c_str()); username.c_str());
} else if( height < 0 || (height > getBestHeight() && getBestHeight()) ) { } else if( height < 0 || (height > getBestHeight() && getBestHeight() > 0) ) {
sprintf(errbuf,"post from future not accepted (height: %d > %d)", sprintf(errbuf,"post from future not accepted (height: %d > %d)",
height, getBestHeight()); height, getBestHeight());
} else if( msg.size() && msg.size() > 140 ) { } else if( msg.size() && msg.size() > 140 ) {
@ -808,7 +817,7 @@ bool validatePostNumberForUser(std::string const &username, int k)
if( k < 0 ) if( k < 0 )
return false; return false;
if( getBestHeight() && k > 2*(getBestHeight() - pblockindex->nHeight) + 20) if( getBestHeight() > 0 && k > 2*(getBestHeight() - pblockindex->nHeight) + 20)
return false; return false;
return true; return true;

Loading…
Cancel
Save