diff --git a/libtorrent/src/kademlia/node.cpp b/libtorrent/src/kademlia/node.cpp index 9a322108..226e1d31 100644 --- a/libtorrent/src/kademlia/node.cpp +++ b/libtorrent/src/kademlia/node.cpp @@ -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; } diff --git a/src/init.cpp b/src/init.cpp index 6307a288..9c5397dd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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; } diff --git a/src/twister.cpp b/src/twister.cpp index 9f427524..22903200 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -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() { 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 } 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) 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;