#include "net.h"
#include "init.h"
#include "util.h"
+#include "ntp.h"
#include "ui_interface.h"
#include "checkpoints.h"
#include <boost/format.hpp>
if (fServer)
NewThread(ThreadRPCServer, NULL);
+ // ********************************************************* Step 12: add time data from four random NTP servers.
+ uiInterface.InitMessage(_("Synchronizing time through NTP..."));
+ printf("Synchronizing time through NTP...\n");
+ int i = 0;
+ while(i < 4) {
+ CNetAddr ip;
+ int64_t nTime = NtpGetTime(ip);
+
+ if (nTime > 0 && nTime != 2085978496) { // Skip the deliberately wrong timestamps
+ AddTimeData(ip, nTime);
+ printf("AddTimeData(%s, %" PRId64 ")\n", ip.ToString().c_str(), nTime);
+ }
+
+ i++;
+ }
+ uiInterface.InitMessage(_("Done"));
+ printf("Done\n");
// ********************************************************* Step 12: finished
uiInterface.InitMessage(_("Done loading"));
if (tx.nTime > GetAdjustedTime() || (fProofOfStake && tx.nTime > txCoinStake->nTime))
continue;
- // Simplify transaction fee - allow free = false
- int64_t nMinFee = tx.GetMinFee(nBlockSize, true, GMF_BLOCK, nTxSize);
-
// Skip free transactions if we're past the minimum block size:
if (fSortedByFee && (dFeePerKb < nMinTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
continue;
if (!tx.FetchInputs(txdb, mapTestPoolTmp, false, true, mapInputs, fInvalid))
continue;
+ // Transaction fee
int64_t nTxFees = tx.GetValueIn(mapInputs)-tx.GetValueOut();
+ int64_t nMinFee = tx.GetMinFee(nBlockSize, true, GMF_BLOCK, nTxSize);
if (nTxFees < nMinFee)
continue;
+ // Sigops accumulation
nTxSigOps += tx.GetP2SHSigOpCount(mapInputs);
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
continue;
uint8_t mac[5 * sizeof(uint32_t)]; /* mac */
};
-int nServersCount = 103;
+int nServersCount = 107;
-std::string NtpServers[103] = {
+std::string NtpServers[107] = {
// Microsoft
"time.windows.com",
"3.ru.pool.ntp.org",
// United States
+ "ntp-01.caltech.edu",
+ "ntp-02.caltech.edu",
+ "ntp-03.caltech.edu",
+ "ntp-04.caltech.edu",
"nist1-pa.ustiming.org",
"time-a.nist.gov ",
"time-b.nist.gov ",
}
fd_set fdset;
- struct timeval timeout = {5, 0};
+ struct timeval timeout = {10, 0};
FD_ZERO(&fdset);
FD_SET(sockfd, &fdset);
return nTime;
}
+int64_t NtpGetTime(CNetAddr& ip)
+{
+ struct sockaddr cliaddr;
+
+ SOCKET sockfd;
+ socklen_t servlen;
+
+ if (!InitWithRandom(sockfd, servlen, &cliaddr))
+ return -1;
+
+ ip = CNetAddr(((sockaddr_in *)&cliaddr)->sin_addr);
+ int64_t nTime = DoReq(sockfd, servlen, cliaddr);
+
+ closesocket(sockfd);
+
+ return nTime;
+}
+
int64_t NtpGetTime(std::string &strHostName)
{
struct sockaddr cliaddr;
+// Get time from random server.
int64_t NtpGetTime();
-int64_t NtpGetTime(std::string &strHostName);
+// Get time from random server and return server address.
+int64_t NtpGetTime(CNetAddr& ip);
+
+// Get time from provided server.
+int64_t NtpGetTime(std::string &strHostName);