<p>When <code>state-&gt;fShouldBan</code> is set, the network thread will disconnect the node, and cleanup memory. As a result, the <code>state</code> object disappears entirely. Because of that, there is no need to ever unset <code>fShouldBan</code>.</p>

<p>What does happen is that when the actual ban happens (not just the setting of the <code>fShouldBan</code> field), it is added to the ban table (which is IP based). Entries in this table have an expiration time. The default expiration time for newly banned nodes is controlled by the <code>-bantime</code> option and defaults to 24 hours in the future.</p>

CC BY-SA 3.0
2017-05-31T07:39:29.653Z
So as I understand the `state` object is created when a node receives a message from another node, right? And if `fShouldBan` is set to `true`, this process is cut. On the other hand, I didn't exactly get when the actual ban happens. Isn't it right after `fShouldBan=true;`?
Önder Gürcan
CC BY-SA 3.0
2017-05-31T07:43:19.617Z
A second remark about the IP-based banning. Is it really a good idea? A node can easily change its IP address, no?
Önder Gürcan
CC BY-SA 3.0
2017-05-31T15:59:58.660Z
The actual ban happens elsewhere, see the connman.Ban in SendRejectsAndCheckIfBanned in net_processing.cpp. A node can indeed easily change their IP address, but they do need to reconnect first, and IP addresses do have a non-zero cost.
Pieter Wuille
CC BY-SA 3.0
2017-05-30T16:53:27.553Z
2017-05-30T16:59:46.497Z
2017-05-30T16:59:46.497Z
Pieter Wuille
<p>Bans last for as many seconds as <code>bantime</code> (in <code>bitcoin.conf</code>) is set to:</p>

<pre><code>-bantime=&lt;n&gt; Number of seconds to keep misbehaving peers from reconnecting (default: 86400)
</code></pre>

<p>86400 seconds is 1 day.</p>

CC BY-SA 3.0
2017-05-31T07:42:06.047Z
Can you explain more about `banscore`? I was thinking that it is a threshold for deciding if a node should be banned or not, not about the time.
Önder Gürcan
CC BY-SA 3.0
2017-05-31T17:22:42.690Z
@ÖnderGürcan You're right! I've edited my answer.
Geremia
CC BY-SA 3.0
2017-05-30T17:41:18.620Z
2017-05-31T17:22:32.623Z
2017-05-31T17:22:32.623Z
Geremia
<p>I read somewhere that a node is banned for 24 hours.</p>

<p>However I found the <a href="https://github.com/bitcoin/bitcoin/blob/239d4198645434542b01916dae5eebc7a3a7bbcc/src/main.cpp#L1685" rel="nofollow noreferrer">Misbehaving()</a> function which makes <code>state-&gt;fShouldBan = true;</code>. But I could not find any other function that makes <code>state-&gt;fShouldBan = false;</code>. It seems that banning is forever.</p>

<p>If banning is forever, I guess the node also removes the misbehaving peer from its neighbor list, right? But I could not find it.</p>

CC BY-SA 3.0
2017-05-30T16:58:25.713Z
What do you mean by 'neighbor list'?
Pieter Wuille
CC BY-SA 3.0
2017-05-30T22:59:14.007Z
Nodes are not keeping a list of neighbors to get data from?
Önder Gürcan
CC BY-SA 3.0
2017-05-31T00:18:43.963Z
Bitcoin Core maintains a database of possible IP addresses of nodes to consider connecting to, called addrman. I was just confused by your usage of the term 'neighbor'.
Pieter Wuille
<validation><banscore><midstate>
What is the duration of a ban?
Önder Gürcan
# What is the duration of a ban?

(Asked by: username_0 on 2017-05-30)

I read somewhere that a node is banned for 24 hours.

However I found the [Misbehaving()](https://github.com/bitcoin/bitcoin/blob/239d4198645434542b01916dae5eebc7a3a7bbcc/src/main.cpp#L1685) function which makes `state->fShouldBan = true;`. But I could not find any other function that makes `state->fShouldBan = false;`. It seems that banning is forever.

If banning is forever, I guess the node also removes the misbehaving peer from its neighbor list, right? But I could not find it.

**Tags:** validation, banscore, midstate

> **Comments:**
> **username_1**: What do you mean by 'neighbor list'?  
> **username_0**: Nodes are not keeping a list of neighbors to get data from?  
> **username_1**: Bitcoin Core maintains a database of possible IP addresses of nodes to consider connecting to, called addrman. I was just confused by your usage of the term 'neighbor'.  

---

## 2 answers

### Answer by username_1 on 2017-05-30. Score: 2

When `state->fShouldBan` is set, the network thread will disconnect the node, and cleanup memory. As a result, the `state` object disappears entirely. Because of that, there is no need to ever unset `fShouldBan`.

What does happen is that when the actual ban happens (not just the setting of the `fShouldBan` field), it is added to the ban table (which is IP based). Entries in this table have an expiration time. The default expiration time for newly banned nodes is controlled by the `-bantime` option and defaults to 24 hours in the future.

> **Comments:**
> **username_0**: So as I understand the `state` object is created when a node receives a message from another node, right? And if `fShouldBan` is set to `true`, this process is cut. On the other hand, I didn't exactly get when the actual ban happens. Isn't it right after `fShouldBan=true;`?  
> **username_0**: A second remark about the IP-based banning. Is it really a good idea? A node can easily change its IP address, no?  
> **username_1**: The actual ban happens elsewhere, see the connman.Ban in SendRejectsAndCheckIfBanned in net_processing.cpp. A node can indeed easily change their IP address, but they do need to reconnect first, and IP addresses do have a non-zero cost.  

---

### Answer by username_2 on 2017-05-30. Score: 0

Bans last for as many seconds as `bantime` (in `bitcoin.conf`) is set to:

```
-bantime=<n> Number of seconds to keep misbehaving peers from reconnecting (default: 86400)

```

86400 seconds is 1 day.

> **Comments:**
> **username_0**: Can you explain more about `banscore`? I was thinking that it is a threshold for deciding if a node should be banned or not, not about the time.  
> **username_2**: @username_0 You're right! I've edited my answer.  

---

