Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return of the Banman #14605

Merged
merged 12 commits into from Jan 21, 2019
Merged

Return of the Banman #14605

merged 12 commits into from Jan 21, 2019

Conversation

@dongcarl
Copy link
Contributor

@dongcarl dongcarl commented Oct 30, 2018

Old English à la Beowulf

Banman wæs bréme    --blaéd wíde sprang--
Connmanes eafera    Coreum in.
aéglaéca            léodum forstandan
Swá bealdode        bearn Connmanes
guma gúðum cúð      gódum daédum·
dréah æfter dóme·   nealles druncne slóg

Modern English Translation

Banman was famed              --his renown spread wide--
Conman's hier,                in Core-land.
against the evil creature     defend the people
Thus he was bold,             the son of Connman
man famed in war,             for good deeds;
he led his life for glory,    never, having drunk, slew

--

With @theuni's blessing, here is Banman, rebased. Original PR: #11457

--

Followup PRs:

  1. Give CNode a Disconnect method (source)
  2. Add a comment to std::atomic_bool fDisconnect in net.h that setting this to true will cause the node to be disconnected the next time DisconnectNodes() runs (source)
@fanquake fanquake added the P2P label Oct 30, 2018
@DrahtBot
Copy link
Contributor

@DrahtBot DrahtBot commented Oct 30, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14987 (RPCHelpMan: Pass through Result and Examples by MarcoFalke)
  • #14929 (net: Allow connections from misbehavior banned peers by gmaxwell)
  • #14897 (randomize GETDATA(tx) request order and introduce bias toward outbound by naumenkogs)
  • #14856 (net: remove more CConnman globals (theuni) by dongcarl)
  • #14464 (refactor: make checkqueue manage the threads by itself (also removed some boost dependencies) by ken2812221)
  • #10785 (Serialization improvements by sipa)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

if(stats) {
// Find possible nodes, ban it and clear the selected node
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
if(stats) {
Copy link
Member

@MarcoFalke MarcoFalke Oct 30, 2018

Accidental changes in the first commit?

src/addrdb.cpp Outdated
@@ -105,9 +105,8 @@ bool DeserializeFileDB(const fs::path& path, Data& data)

}

CBanDB::CBanDB()
CBanDB::CBanDB(fs::path ban_file) : pathBanlist(std::move(ban_file))
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Make sure parameter name matches between declaration and definition :-)

src/banman.h Outdated
public:
~BanMan();
BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time);
void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Make sure parameter names match between:

    void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
    void BanMan::Ban(const CNetAddr& addr, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch) {

src/banman.h Outdated
~BanMan();
BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time);
void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Make sure these match:

    void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
    void BanMan::Ban(const CSubNet& subNet, const BanReason &banReason, int64_t bantimeoffset, bool sinceUnixEpoch) {

src/banman.h Outdated
void ClearBanned();
bool IsBanned(CNetAddr ip);
bool IsBanned(CSubNet subnet);
bool Unban(const CNetAddr &ip);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Make sure these match:

    bool Unban(const CNetAddr &ip);
    bool BanMan::Unban(const CNetAddr &addr) {

src/banman.h Outdated
bool IsBanned(CNetAddr ip);
bool IsBanned(CSubNet subnet);
bool Unban(const CNetAddr &ip);
bool Unban(const CSubNet &ip);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Same here:

    bool Unban(const CSubNet &ip);
    bool BanMan::Unban(const CSubNet &subNet) {

src/banman.h Outdated
bool IsBanned(CSubNet subnet);
bool Unban(const CNetAddr &ip);
bool Unban(const CSubNet &ip);
void GetBanned(banmap_t &banmap);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Same here:

    void GetBanned(banmap_t &banmap);
    void BanMan::GetBanned(banmap_t &banMap)

src/banman.h Outdated
void DumpBanlist();

private:
void SetBanned(const banmap_t &banmap);
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

And here :-)

    void SetBanned(const banmap_t &banmap);
    void BanMan::SetBanned(const banmap_t &banMap)

src/banman.cpp Outdated
bool BanMan::Unban(const CSubNet &subNet) {
{
LOCK(m_cs_banned);
if (!m_banned.erase(subNet))
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Nit: if (m_banned.erase(subNet) == 0) to increase readability and avoid implicit conversion?

src/banman.cpp Outdated
m_is_dirty = true;
}
DumpBanlist(); //store banlist to disk
if(m_client_interface)
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Since this is new code - please run all new C++ files through clang-format (using the project local settings) to get the expected formatting.

src/banman.cpp Outdated
if (bantimeoffset <= 0)
{
bantimeoffset = m_default_ban_time;
sinceUnixEpoch = false;
Copy link
Contributor

@practicalswift practicalswift Oct 30, 2018

Could this be re-formulated to avoid reassigning parameters?

Copy link
Contributor Author

@dongcarl dongcarl Oct 31, 2018

Reformulated in 36e6b24, let me know if you think that's good

Copy link
Contributor

@practicalswift practicalswift Nov 15, 2018

@dongcarl Nice! Thanks! :-)

@dongcarl dongcarl force-pushed the banman branch 2 times, most recently from 973d78f to 283dc16 Oct 31, 2018
@laanwj
Copy link
Member

@laanwj laanwj commented Oct 31, 2018

thank you for picking this up!
We welcome the Ban Man to our kingdom

Sjors
Sjors approved these changes Jan 16, 2019
Copy link
Member

@Sjors Sjors left a comment

tACK 95b495b9697502b2b478dda8cece0ae9ffb6818f

@ryanofsky wrote:

is there a description of what high level goal of this PR is? Is it cleanup geared towards making code maintenance easier? [...]

I think reducing the 3000 lines in net.cpp by 200 is almost worth it by itself :-)

From the original description in #11457:

This also makes testing easier as different implementations can be dropped in.

So this is a step towards being able to mock network code and e.g. test banning behavior for a large number of simulated nodes.

LOCK(cs_vNodes);
for (CNode* pnode : vNodes) {
if (subnet.Match(pnode->addr)) {
pnode->fDisconnect = true;
Copy link
Member

@Sjors Sjors Jan 16, 2019

Maybe add a comment to std::atomic_bool fDisconnect in net.h that setting this to true will cause the node to be disconnected the next time DisconnectNodes() runs.

Copy link
Contributor Author

@dongcarl dongcarl Jan 16, 2019

I think this belongs in another PR, but happy to do that PR :-)

src/net.cpp Outdated
// Dump addresses to peers.dat and banlist.dat every 15 minutes (900s)
#define DUMP_ADDRESSES_INTERVAL 900
// Dump addresses to peers.dat every 15 minutes (900s)
static constexpr int DUMP_PEERS_INTERVAL = 60 * 15;
Copy link
Member

@Sjors Sjors Jan 16, 2019

Nit: 15 * 60 to be consistent with other _INTERVAL constants.

Copy link
Contributor Author

@dongcarl dongcarl Jan 16, 2019

Done!

@@ -120,24 +120,24 @@ class NodeImpl : public Node
}
bool getBanned(banmap_t& banmap) override
{
if (g_connman) {
g_connman->GetBanned(banmap);
if (g_banman) {
Copy link
Member

@Sjors Sjors Jan 16, 2019

theuni and others added 10 commits Jan 16, 2019
Some say he has always been.
There's no need to hard-code the path here. Passing it in means that there are
no ordering concerns wrt establishing the datadir.
Removes the dependency on arg parsing.
-BEGIN VERIFY SCRIPT-
sed -i "s/clientInterface/m_client_interface/g" src/banman.h src/banman.cpp
sed -i "s/setBannedIsDirty/m_is_dirty/g" src/banman.h src/banman.cpp
sed -i "s/cs_setBanned/m_cs_banned/g" src/banman.h src/banman.cpp
sed -i "s/setBanned/m_banned/g" src/banman.h src/banman.cpp
-END VERIFY SCRIPT-
Also remove misleading comment. ClearBanned is used by rpc as well.
Avoid reassigning parameters.
-BEGIN VERIFY SCRIPT-
sed -i "s/banMap/banmap/g" src/banman.h src/banman.cpp
sed -i "s/netAddr/net_addr/g" src/banman.h src/banman.cpp
sed -i "s/sinceUnixEpoch/since_unix_epoch/g" src/banman.h src/banman.cpp
sed -i "s/bantimeoffset/ban_time_offset/g" src/banman.h src/banman.cpp
sed -i "s/subNet/sub_net/g" src/banman.h src/banman.cpp
sed -i "s/banReason/ban_reason/g" src/banman.h src/banman.cpp
sed -i "s/notifyUI/notify_ui/g" src/banman.h src/banman.cpp
sed -i "s/banEntry/ban_entry/g" src/banman.h src/banman.cpp
sed -i "s/nStart/n_start/g" src/banman.h src/banman.cpp
-END VERIFY SCRIPT-
@Sjors
Copy link
Member

@Sjors Sjors commented Jan 16, 2019

re-tACK 18185b5

laanwj added a commit that referenced this issue Jan 20, 2019
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: #14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
@laanwj
Copy link
Member

@laanwj laanwj commented Jan 21, 2019

re-utACK 18185b5

@laanwj laanwj merged commit 18185b5 into bitcoin:master Jan 21, 2019
2 checks passed
laanwj added a commit that referenced this issue Jan 21, 2019
18185b5 scripted-diff: batch-recase BanMan variables (Carl Dong)
c2e04d3 banman: Add, use CBanEntry ctor that takes ban reason (Carl Dong)
1ffa4ce banman: reformulate nBanUtil calculation (Carl Dong)
daae598 banman: add thread annotations and mark members const where possible (Cory Fields)
84fc3fb scripted-diff: batch-rename BanMan members (Cory Fields)
af3503d net: move BanMan to its own files (Cory Fields)
d0469b2 banman: pass in default ban time as a parameter (Cory Fields)
2e56702 banman: pass the banfile path in (Cory Fields)
4c0d961 banman: create and split out banman (Cory Fields)
83c1ea2 net: split up addresses/ban dumps in preparation for moving them (Cory Fields)
136bd79 tests: remove member connman/peerLogic in TestingSetup (Cory Fields)
7cc2b9f net: Break disconnecting out of Ban() (Cory Fields)

Pull request description:

  **Old English à la Beowulf**
  ```
  Banman wæs bréme    --blaéd wíde sprang--
  Connmanes eafera    Coreum in.
  aéglaéca            léodum forstandan
  Swá bealdode        bearn Connmanes
  guma gúðum cúð      gódum daédum·
  dréah æfter dóme·   nealles druncne slóg
  ```

  **Modern English Translation**
  ```
  Banman was famed              --his renown spread wide--
  Conman's hier,                in Core-land.
  against the evil creature     defend the people
  Thus he was bold,             the son of Connman
  man famed in war,             for good deeds;
  he led his life for glory,    never, having drunk, slew
  ```

  --

  With @theuni's blessing, here is Banman, rebased. Original PR: #11457

  --

  Followup PRs:
  1. Give `CNode` a `Disconnect` method ([source](#14605 (comment)))
  2. Add a comment to `std::atomic_bool fDisconnect` in `net.h` that setting this to true will cause the node to be disconnected the next time `DisconnectNodes()` runs ([source](#14605 (comment)))

Tree-SHA512: 9c207edbf577415c22c9811113e393322d936a843d4ff265186728152a67c057779ac4d4f27b895de9729f7a53e870f828b9ebc8bcdab757520c2aebe1e9be35
@fanquake fanquake moved this from In progress to Done in P2P refactor Jan 31, 2019
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this issue Jun 9, 2020
Summary:
5b4283cb81b5d3023b9868d121b22b1f387a50ca Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin/bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751

Backport of core PR15194.

Test Plan:
  ninja

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6474
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this issue Jul 18, 2021
18185b5 scripted-diff: batch-recase BanMan variables (Carl Dong)
c2e04d3 banman: Add, use CBanEntry ctor that takes ban reason (Carl Dong)
1ffa4ce banman: reformulate nBanUtil calculation (Carl Dong)
daae598 banman: add thread annotations and mark members const where possible (Cory Fields)
84fc3fb scripted-diff: batch-rename BanMan members (Cory Fields)
af3503d net: move BanMan to its own files (Cory Fields)
d0469b2 banman: pass in default ban time as a parameter (Cory Fields)
2e56702 banman: pass the banfile path in (Cory Fields)
4c0d961 banman: create and split out banman (Cory Fields)
83c1ea2 net: split up addresses/ban dumps in preparation for moving them (Cory Fields)
136bd79 tests: remove member connman/peerLogic in TestingSetup (Cory Fields)
7cc2b9f net: Break disconnecting out of Ban() (Cory Fields)

Pull request description:

  **Old English à la Beowulf**
  ```
  Banman wæs bréme    --blaéd wíde sprang--
  Connmanes eafera    Coreum in.
  aéglaéca            léodum forstandan
  Swá bealdode        bearn Connmanes
  guma gúðum cúð      gódum daédum·
  dréah æfter dóme·   nealles druncne slóg
  ```

  **Modern English Translation**
  ```
  Banman was famed              --his renown spread wide--
  Conman's hier,                in Core-land.
  against the evil creature     defend the people
  Thus he was bold,             the son of Connman
  man famed in war,             for good deeds;
  he led his life for glory,    never, having drunk, slew
  ```

  --

  With @theuni's blessing, here is Banman, rebased. Original PR: bitcoin#11457

  --

  Followup PRs:
  1. Give `CNode` a `Disconnect` method ([source](bitcoin#14605 (comment)))
  2. Add a comment to `std::atomic_bool fDisconnect` in `net.h` that setting this to true will cause the node to be disconnected the next time `DisconnectNodes()` runs ([source](bitcoin#14605 (comment)))

Tree-SHA512: 9c207edbf577415c22c9811113e393322d936a843d4ff265186728152a67c057779ac4d4f27b895de9729f7a53e870f828b9ebc8bcdab757520c2aebe1e9be35
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this issue Jul 18, 2021
18185b5 scripted-diff: batch-recase BanMan variables (Carl Dong)
c2e04d3 banman: Add, use CBanEntry ctor that takes ban reason (Carl Dong)
1ffa4ce banman: reformulate nBanUtil calculation (Carl Dong)
daae598 banman: add thread annotations and mark members const where possible (Cory Fields)
84fc3fb scripted-diff: batch-rename BanMan members (Cory Fields)
af3503d net: move BanMan to its own files (Cory Fields)
d0469b2 banman: pass in default ban time as a parameter (Cory Fields)
2e56702 banman: pass the banfile path in (Cory Fields)
4c0d961 banman: create and split out banman (Cory Fields)
83c1ea2 net: split up addresses/ban dumps in preparation for moving them (Cory Fields)
136bd79 tests: remove member connman/peerLogic in TestingSetup (Cory Fields)
7cc2b9f net: Break disconnecting out of Ban() (Cory Fields)

Pull request description:

  **Old English à la Beowulf**
  ```
  Banman wæs bréme    --blaéd wíde sprang--
  Connmanes eafera    Coreum in.
  aéglaéca            léodum forstandan
  Swá bealdode        bearn Connmanes
  guma gúðum cúð      gódum daédum·
  dréah æfter dóme·   nealles druncne slóg
  ```

  **Modern English Translation**
  ```
  Banman was famed              --his renown spread wide--
  Conman's hier,                in Core-land.
  against the evil creature     defend the people
  Thus he was bold,             the son of Connman
  man famed in war,             for good deeds;
  he led his life for glory,    never, having drunk, slew
  ```

  --

  With @theuni's blessing, here is Banman, rebased. Original PR: bitcoin#11457

  --

  Followup PRs:
  1. Give `CNode` a `Disconnect` method ([source](bitcoin#14605 (comment)))
  2. Add a comment to `std::atomic_bool fDisconnect` in `net.h` that setting this to true will cause the node to be disconnected the next time `DisconnectNodes()` runs ([source](bitcoin#14605 (comment)))

Tree-SHA512: 9c207edbf577415c22c9811113e393322d936a843d4ff265186728152a67c057779ac4d4f27b895de9729f7a53e870f828b9ebc8bcdab757520c2aebe1e9be35
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 21, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 23, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 24, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 24, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 24, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
UdjinM6 added a commit to UdjinM6/dash that referenced this issue Aug 24, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Munkybooty added a commit to Munkybooty/dash that referenced this issue Aug 24, 2021
5b4283c Add comment describing fDisconnect behavior (Carl Dong)

Pull request description:

  Motivated by @Sjors here: bitcoin#14605 (comment)

Tree-SHA512: 8fc52eb4d3b5651c19c49b47fad75e8fb939cf524ada647e88d8d5aad7726052d94e500c1ebdb2a41b67bc4669ee61ff151a5cff81a52c68c900da562ef21751
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Linked issues

Successfully merging this pull request may close these issues.

None yet