Browse Source

delay libtorrent initialization until we have valid blocks

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
a4695ba9e1
  1. 2
      libtorrent/src/kademlia/node.cpp
  2. 2
      src/init.cpp
  3. 13
      src/twister.cpp

2
libtorrent/src/kademlia/node.cpp

@ -1249,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;
} }

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