@Override
    public CompletableFuture<PeerConnection> connect(final Peer peer) {
      synchronized (network) {
        if (network.nodes.containsKey(peer)) {
          final PeerConnection connection = connections.get(peer);
          if (connection == null) {
            return CompletableFuture.completedFuture(network.connect(self, peer));
          } else {
            return CompletableFuture.completedFuture(connection);
          }
        } else {
          return CompletableFuture.supplyAsync(
              () -> {
                throw new IllegalStateException(
                    String.format("Tried to connect to unknown peer %s", peer));
              });
        }
      }
    }
Get the {@link P2PNetwork} that assumes a given {@link Peer} as the local node. This does not
connect {@link Peer} to any other peer. Any connections established by {@link #connect(Peer,
Peer)} require that both participating {@link Peer} have previously been passed to this method.

@param peer Peer to get {@link P2PNetwork} for
@return P2PNetwork as seen by {@link Peer}
ethereum/mock-p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/testing/MockNetwork.java