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) @@ -1249,7 +1249,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
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");
return;
}

2
src/init.cpp

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

13
src/twister.cpp

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

Loading…
Cancel
Save