aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-01-02 17:47:08 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-01-02 17:54:21 +0100
commitc986972ad77242664c41c5e6fe07214e84aadd82 (patch)
treeade772431c84c3e839b5cb03161d57505d4c2766 /src
parent40d65eb66d0865aa64c410c3eb970dafcad71851 (diff)
parent73caf47dfe9c398aac75b5f6bcd1e0a644479a46 (diff)
downloadbitcoin-c986972ad77242664c41c5e6fe07214e84aadd82.tar.xz
Merge pull request #5476
73caf47 Display time offset in the debug window's Peers tab (Pavel Janík) 26a6bae Add time offset to getpeerinfo output (Pavel Janík)
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp4
-rw-r--r--src/net.cpp2
-rw-r--r--src/net.h2
-rw-r--r--src/qt/forms/rpcconsole.ui25
-rw-r--r--src/qt/guiutil.cpp5
-rw-r--r--src/qt/guiutil.h5
-rw-r--r--src/qt/rpcconsole.cpp1
-rw-r--r--src/rpcnet.cpp2
-rw-r--r--src/timedata.cpp4
9 files changed, 44 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 675b8afd1d..f02a6a12ef 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3548,7 +3548,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom->nStartingHeight, addrMe.ToString(), pfrom->id,
remoteAddr);
- AddTimeData(pfrom->addr, nTime);
+ int64_t nTimeOffset = nTime - GetTime();
+ pfrom->nTimeOffset = nTimeOffset;
+ AddTimeData(pfrom->addr, nTimeOffset);
}
diff --git a/src/net.cpp b/src/net.cpp
index 474a3e4288..6401ecbf83 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -522,6 +522,7 @@ void CNode::copyStats(CNodeStats &stats)
X(nLastSend);
X(nLastRecv);
X(nTimeConnected);
+ X(nTimeOffset);
X(addrName);
X(nVersion);
X(cleanSubVer);
@@ -1933,6 +1934,7 @@ CNode::CNode(SOCKET hSocketIn, CAddress addrIn, std::string addrNameIn, bool fIn
nSendBytes = 0;
nRecvBytes = 0;
nTimeConnected = GetTime();
+ nTimeOffset = 0;
addr = addrIn;
addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
nVersion = 0;
diff --git a/src/net.h b/src/net.h
index fed5a5959f..bdb1edd50b 100644
--- a/src/net.h
+++ b/src/net.h
@@ -154,6 +154,7 @@ public:
int64_t nLastSend;
int64_t nLastRecv;
int64_t nTimeConnected;
+ int64_t nTimeOffset;
std::string addrName;
int nVersion;
std::string cleanSubVer;
@@ -235,6 +236,7 @@ public:
int64_t nLastSend;
int64_t nLastRecv;
int64_t nTimeConnected;
+ int64_t nTimeOffset;
CAddress addr;
std::string addrName;
CService addrLocal;
diff --git a/src/qt/forms/rpcconsole.ui b/src/qt/forms/rpcconsole.ui
index eb7c92cfec..c1eb185501 100644
--- a/src/qt/forms/rpcconsole.ui
+++ b/src/qt/forms/rpcconsole.ui
@@ -1043,7 +1043,30 @@
</property>
</widget>
</item>
- <item row="14" column="1">
+ <item row="14" column="0">
+ <widget class="QLabel" name="label_timeoffset">
+ <property name="text">
+ <string>Time Offset</string>
+ </property>
+ </widget>
+ </item>
+ <item row="14" column="2">
+ <widget class="QLabel" name="timeoffset">
+ <property name="cursor">
+ <cursorShape>IBeamCursor</cursorShape>
+ </property>
+ <property name="text">
+ <string>N/A</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::PlainText</enum>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ <item row="15" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index a3ede9fd62..c675235cc2 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -843,4 +843,9 @@ QString formatPingTime(double dPingTime)
return dPingTime == 0 ? QObject::tr("N/A") : QString(QObject::tr("%1 ms")).arg(QString::number((int)(dPingTime * 1000), 10));
}
+QString formatTimeOffset(int64_t nTimeOffset)
+{
+ return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));
+}
+
} // namespace GUIUtil
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index 4f8c683147..a77036a194 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -188,7 +188,10 @@ namespace GUIUtil
/* Format a CNodeCombinedStats.dPingTime into a user-readable string or display N/A, if 0*/
QString formatPingTime(double dPingTime);
-
+
+ /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
+ QString formatTimeOffset(int64_t nTimeOffset);
+
#if defined(Q_OS_MAC) && QT_VERSION >= 0x050000
// workaround for Qt OSX Bug:
// https://bugreports.qt-project.org/browse/QTBUG-15631
diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index a5e3ae2b35..9f3991c4c5 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -610,6 +610,7 @@ void RPCConsole::updateNodeDetail(const CNodeCombinedStats *stats)
ui->peerBytesRecv->setText(FormatBytes(stats->nodeStats.nRecvBytes));
ui->peerConnTime->setText(GUIUtil::formatDurationStr(GetTime() - stats->nodeStats.nTimeConnected));
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.dPingTime));
+ ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));
ui->peerVersion->setText(QString("%1").arg(stats->nodeStats.nVersion));
ui->peerSubversion->setText(QString::fromStdString(stats->nodeStats.cleanSubVer));
ui->peerDirection->setText(stats->nodeStats.fInbound ? tr("Inbound") : tr("Outbound"));
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp
index 2886f7adab..f0fadb5987 100644
--- a/src/rpcnet.cpp
+++ b/src/rpcnet.cpp
@@ -91,6 +91,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
" \"bytessent\": n, (numeric) The total bytes sent\n"
" \"bytesrecv\": n, (numeric) The total bytes received\n"
" \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n"
+ " \"timeoffset\": ttt, (numeric) The time offset in seconds\n"
" \"pingtime\": n, (numeric) ping time\n"
" \"pingwait\": n, (numeric) ping wait\n"
" \"version\": v, (numeric) The peer version, such as 7001\n"
@@ -131,6 +132,7 @@ Value getpeerinfo(const Array& params, bool fHelp)
obj.push_back(Pair("bytessent", stats.nSendBytes));
obj.push_back(Pair("bytesrecv", stats.nRecvBytes));
obj.push_back(Pair("conntime", stats.nTimeConnected));
+ obj.push_back(Pair("timeoffset", stats.nTimeOffset));
obj.push_back(Pair("pingtime", stats.dPingTime));
if (stats.dPingWait > 0.0)
obj.push_back(Pair("pingwait", stats.dPingWait));
diff --git a/src/timedata.cpp b/src/timedata.cpp
index d04f3d2f78..c3e9c75f6e 100644
--- a/src/timedata.cpp
+++ b/src/timedata.cpp
@@ -40,10 +40,8 @@ static int64_t abs64(int64_t n)
return (n >= 0 ? n : -n);
}
-void AddTimeData(const CNetAddr& ip, int64_t nTime)
+void AddTimeData(const CNetAddr& ip, int64_t nOffsetSample)
{
- int64_t nOffsetSample = nTime - GetTime();
-
LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;