Skip to content

Commit c4bd55a

Browse files
authored
Merge pull request #1537 from jamescowens/new_banning_system_time_decay
New banning misbehavior handling and Peers Tab on Debug Console
2 parents 409db6d + 52ceb1f commit c4bd55a

22 files changed

+2032
-89
lines changed

src/Makefile.qt.include

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ QT_MOC_CPP = \
9191
qt/moc_addressbookpage.cpp \
9292
qt/moc_addresstablemodel.cpp \
9393
qt/moc_askpassphrasedialog.cpp \
94+
qt/moc_bantablemodel.cpp \
9495
qt/moc_bitcoinaddressvalidator.cpp \
9596
qt/moc_bitcoinamountfield.cpp \
9697
qt/moc_bitcoingui.cpp \
@@ -109,6 +110,7 @@ QT_MOC_CPP = \
109110
qt/moc_optionsdialog.cpp \
110111
qt/moc_optionsmodel.cpp \
111112
qt/moc_overviewpage.cpp \
113+
qt/moc_peertablemodel.cpp \
112114
qt/moc_qvalidatedlineedit.cpp \
113115
qt/moc_qvaluecombobox.cpp \
114116
qt/moc_rpcconsole.cpp \
@@ -142,6 +144,7 @@ GRIDCOINRESEARCH_QT_H = \
142144
qt/addressbookpage.h \
143145
qt/addresstablemodel.h \
144146
qt/askpassphrasedialog.h \
147+
qt/bantablemodel.h \
145148
qt/bitcoinaddressvalidator.h \
146149
qt/bitcoinamountfield.h \
147150
qt/bitcoingui.h \
@@ -162,6 +165,7 @@ GRIDCOINRESEARCH_QT_H = \
162165
qt/optionsdialog.h \
163166
qt/optionsmodel.h \
164167
qt/overviewpage.h \
168+
qt/peertablemodel.h \
165169
qt/qtipcserver.h \
166170
qt/qvalidatedlineedit.h \
167171
qt/qvaluecombobox.h \
@@ -185,6 +189,7 @@ GRIDCOINRESEARCH_QT_CPP = \
185189
qt/addressbookpage.cpp \
186190
qt/addresstablemodel.cpp \
187191
qt/askpassphrasedialog.cpp \
192+
qt/bantablemodel.cpp \
188193
qt/bitcoinaddressvalidator.cpp \
189194
qt/bitcoinamountfield.cpp \
190195
qt/bitcoingui.cpp \
@@ -202,6 +207,7 @@ GRIDCOINRESEARCH_QT_CPP = \
202207
qt/optionsdialog.cpp \
203208
qt/optionsmodel.cpp \
204209
qt/overviewpage.cpp \
210+
qt/peertablemodel.cpp \
205211
qt/qtipcserver.cpp \
206212
qt/qvalidatedlineedit.cpp \
207213
qt/qvaluecombobox.cpp \

src/banman.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include "banman.h"
77

88
#include "netbase.h"
9+
#include "net.h"
910
#include "ui_interface.h"
1011
#include "util.h"
1112

12-
1313
BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
1414
: m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time)
1515
{
@@ -59,6 +59,14 @@ void BanMan::ClearBanned()
5959
{
6060
{
6161
LOCK(m_cs_banned);
62+
63+
for (const auto& banentry : m_banned)
64+
{
65+
CSubNet sub_net = banentry.first;
66+
67+
ZeroMisbehavior(sub_net);
68+
}
69+
6270
m_banned.clear();
6371
m_is_dirty = true;
6472
}
@@ -160,6 +168,8 @@ bool BanMan::Unban(const CSubNet& sub_net)
160168
LOCK(m_cs_banned);
161169
if (m_banned.erase(sub_net) == 0) return false;
162170
m_is_dirty = true;
171+
172+
ZeroMisbehavior(sub_net);
163173
}
164174
if (m_client_interface) m_client_interface->BannedListChanged();
165175
DumpBanlist(); //store banlist to disk immediately
@@ -193,6 +203,9 @@ void BanMan::SweepBanned()
193203
CBanEntry ban_entry = (*it).second;
194204
if (now > ban_entry.nBanUntil) {
195205
m_banned.erase(it++);
206+
207+
ZeroMisbehavior(sub_net);
208+
196209
m_is_dirty = true;
197210
notify_ui = true;
198211
LogPrint("network", "%s: Removed banned node ip/subnet from banlist.dat: %s\n", __func__, sub_net.ToString());
@@ -217,3 +230,35 @@ void BanMan::SetBannedSetDirty(bool dirty)
217230
LOCK(m_cs_banned); //reuse m_banned lock for the m_is_dirty flag
218231
m_is_dirty = dirty;
219232
}
233+
234+
unsigned int BanMan::ZeroMisbehavior(CNetAddr net_addr)
235+
{
236+
CSubNet sub_net(net_addr);
237+
return ZeroMisbehavior(sub_net);
238+
}
239+
240+
unsigned int BanMan::ZeroMisbehavior(CSubNet sub_net)
241+
{
242+
unsigned int nZeroed = 0;
243+
244+
LOCK(CNode::cs_mapMisbehavior);
245+
246+
std::map<CAddress, std::pair<int, int64_t>>::iterator iMisbehavior;
247+
for (iMisbehavior = CNode::mapMisbehavior.begin(); iMisbehavior != CNode::mapMisbehavior.end();)
248+
{
249+
CAddress addr = iMisbehavior->first;
250+
251+
if (sub_net.Match(addr))
252+
{
253+
iMisbehavior = CNode::mapMisbehavior.erase(iMisbehavior);
254+
255+
++nZeroed;
256+
}
257+
else
258+
{
259+
++iMisbehavior;
260+
}
261+
}
262+
263+
return nZeroed;
264+
}

src/banman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class BanMan
5757
void SetBannedSetDirty(bool dirty = true);
5858
//!clean unused entries (if bantime has expired)
5959
void SweepBanned();
60+
unsigned int ZeroMisbehavior(CNetAddr net_addr);
61+
unsigned int ZeroMisbehavior(CSubNet sub_net);
6062

6163
CCriticalSection m_cs_banned;
6264
banmap_t m_banned GUARDED_BY(m_cs_banned);

src/init.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ std::string HelpMessage()
207207
" -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" +
208208
" -dblogsize=<n> " + _("Set database disk log size in megabytes (default: 100)") + "\n" +
209209
" -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" +
210+
" -peertimeout=<n> " + _("Specify p2p connection timeout in seconds. This option determines the amount of time a peer may be inactive before the connection to it is dropped. (minimum: 1, default: 45)") + "\n"
210211
" -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" +
211212
" -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
212213
" -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
@@ -511,11 +512,21 @@ bool AppInit2(ThreadHandlerPtr threads)
511512

512513
if (mapArgs.count("-timeout"))
513514
{
514-
int nNewTimeout = GetArg("-timeout", 4000);
515+
int nNewTimeout = GetArg("-timeout", 5000);
515516
if (nNewTimeout > 0 && nNewTimeout < 600000)
516517
nConnectTimeout = nNewTimeout;
517518
}
518519

520+
if (mapArgs.count("-peertimeout"))
521+
{
522+
int nNewPeerTimeout = GetArg("-timeout", 45);
523+
524+
if (nNewPeerTimeout <= 0)
525+
InitError(strprintf(_("Invalid amount for -peertimeout=<amount>: '%s'"), mapArgs["-peertimeout"]));
526+
527+
PEER_TIMEOUT = nNewPeerTimeout;
528+
}
529+
519530
if (mapArgs.count("-paytxfee"))
520531
{
521532
if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5655,6 +5655,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
56555655

56565656
// Moved the below from AddTimeData to here to follow bitcoin's approach.
56575657
int64_t nOffsetSample = nTime - GetTime();
5658+
pfrom->nTimeOffset = nOffsetSample;
56585659
if (GetBoolArg("-synctime", true))
56595660
AddTimeData(pfrom->addr, nOffsetSample);
56605661

@@ -6272,6 +6273,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
62726273
if (pingUsecTime > 0) {
62736274
// Successful ping time measurement, replace previous
62746275
pfrom->nPingUsecTime = pingUsecTime;
6276+
pfrom->nMinPingUsecTime = std::min(pfrom->nMinPingUsecTime.load(), pingUsecTime);
62756277
} else {
62766278
// This should never happen
62776279
sProblem = "Timing mishap";

0 commit comments

Comments
 (0)