# Architecture proposal: blocking peers
Petar Radovic
2020-08-18
## Overview
This should be a very small document describing the blocking of peers funcionality, how it fits the system, along with a simple usage example.
## Context
Blocking a specific peer is a functionality which performs 2 steps:
- Peer is disconnected
- All inbound or outbound connections to this peer are forbidden while the peer is blocked, based on the peers overlay address
The goal is to implement a possibility to block a peer, indefinitely or for some period of time, in one of the following ways:
- from some protocol handlers, inside p2p layer
- using and API, as part of p2p interface
## Architecture
In order to meet requirements described in context, the idea was to implement:
- specific `BlockPeerError{duration time.Duration, err Error}`, to be returned by protocol handlers in order to block a peer. This one is similar to a `DisconnectError` that is already implemented.
- call in p2p interface - `BlockPeer(duration time.Duration) error`
Both ways should result in the same behavior. The peer will be disconnected and it will be added in the blocked peers structure (map with expiration), based on it's address (overlay, `swarm.Address`). If the provided duration is 0, then the peer will be blocked "forever". libp2p will use this map to determine weather to stop incoming connections from this peer.
The overlay address is know only after the handshake, so it means that if the hanshake is sucessuful but the peer appears in blocklist, it will be immediately disconnected, before it is added to the peer registry.
# Questions
- do we need to persist the blocklist?
- do we need to block peer for only a single protocol?