diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Database.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/Database.cpp b/src/Database.cpp index 492cc7d..cf72c6a 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -113,15 +113,29 @@ namespace odhtdb { if(ntpThread) delete ntpThread; + + const int ntpFetchTimestampRetries = 5; ntpThread = new thread([]() { ntp::NtpClient ntpClient("pool.ntp.org"); while(databaseCount > 0) { - ntp::NtpTimestamp ntpTimestamp = ntpClient.getTimestamp(); - timeOffset = time(nullptr) - ntpTimestamp.seconds; - timestampSynced = true; + for(int i = 0; i < ntpFetchTimestampRetries; ++i) + { + try + { + ntp::NtpTimestamp ntpTimestamp = ntpClient.getTimestamp(); + timeOffset = time(nullptr) - ntpTimestamp.seconds; + timestampSynced = true; + break; + } + catch(ntp::NtpClientException &e) + { + Log::warn("Failed to sync clock with ntp server, reason: %s. Try #%d", e.what(), i); + this_thread::sleep_for(500ms); + } + } // TODO: Also use timestamp fraction (milliseconds) this_thread::sleep_for(60s); } @@ -200,7 +214,7 @@ namespace odhtdb auto requestedData = databaseStorage.getStorage(*nodeToSeed.getRequestHash()); if(!requestedData) { - Log::warn("No data found for hash %s, unable to serve peer", nodeToSeed.getRequestHash()->toString().c_str()); + Log::debug("No data found for hash %s, unable to serve peer", nodeToSeed.getRequestHash()->toString().c_str()); return true; } @@ -212,7 +226,7 @@ namespace odhtdb node.put(requestResponseInfoHash, Value((u8*)requestedData->data.data, requestedData->data.size), [](bool ok) { if(!ok) - Log::warn("Failed to put response for old data for 'create' data"); + Log::error("Failed to put response for old data for 'create' data"); }); } @@ -221,7 +235,7 @@ namespace odhtdb node.put(requestResponseInfoHash, Value((u8*)requestedObject->data.data, requestedObject->data.size), [](bool ok) { if(!ok) - Log::warn("Failed to put response for old data for 'add' data"); + Log::error("Failed to put response for old data for 'add' data"); }); } } |