|
81 | 81 |
|
82 | 82 | DEFAULT_BAN_DURATION_HOURS = 12 |
83 | 83 |
|
| 84 | +# Custom disconnection reason to send to peers when banning them. We don't want the default |
| 85 | +# "Your address is banned" to be sent, because it sounds like the peer's node is faulty. |
| 86 | +# We also don't want to be too specific, e.g. the peer doesn't need to know thar something |
| 87 | +# called "fork detector" is running somewhere. So we choose a reason that is somewhat vague. |
| 88 | +# Also note that since we ban peers when networking is already disabled, the peer can only |
| 89 | +# get this message when attempting an outbound connectiion to the detector's node. |
| 90 | +BAN_REASON_STRING = "Cannot accept connections at this moment" |
| 91 | + |
84 | 92 | # We use Queue.shutdown which is only available since Python v3.13 |
85 | 93 | MIN_PYTHON_VERSION_MAJOR = 3 |
86 | 94 | MIN_PYTHON_VERSION_MINOR = 13 |
|
89 | 97 | PERMABAN_DURATION_DAYS = 30 |
90 | 98 | PERMABAN_DURATION_SECS = 3600 * 24 * PERMABAN_DURATION_DAYS |
91 | 99 |
|
92 | | - |
93 | 100 | class Handler(): |
94 | 101 | def __init__(self, args, email_sender): |
95 | 102 | CONSOLE_PRINTER.set_status("Initializing") |
@@ -135,6 +142,7 @@ def __init__(self, args, email_sender): |
135 | 142 | "--rpc-bind-address", args.node_rpc_bind_address, |
136 | 143 | "--rpc-username", NODE_RPC_USER, |
137 | 144 | "--rpc-password", NODE_RPC_PWD, |
| 145 | + "--p2p-custom-disconnection-reason-for-banning", BAN_REASON_STRING |
138 | 146 | ] |
139 | 147 | log.info(f"Node run command: {self.node_cmd}") |
140 | 148 |
|
@@ -315,10 +323,8 @@ def on_attempt_completion(): |
315 | 323 |
|
316 | 324 | peer_ips_to_ban = self.get_node_peer_ip_addrs_to_ban() |
317 | 325 |
|
318 | | - # Before banning, force the disconnection of all peers by disabling networking, |
319 | | - # to avoid sending them the "scary" disconnection reason "Your address is banned" |
320 | | - # (though nodes may still see this reason if they try connecting to our node |
321 | | - # during the next attempt). |
| 326 | + # Before banning, disable networking; this will disconnect all peers and prevent them |
| 327 | + # from reconnecting again. |
322 | 328 | self.node_rpc_client.enable_networking(False) |
323 | 329 | # Give the node some time to actually disconnect all peers. |
324 | 330 | time.sleep(2) |
|
0 commit comments