def connection_closed(self, connection: WSGreenBerryConnection, ban_time: int):
    if (is_localhost(connection.peer_host) and (ban_time != 0)):
        self.log.warning(f'Trying to ban localhost for {ban_time}, but will not ban')
        ban_time = 0
    self.log.info(f'Connection closed: {connection.peer_host}, node id: {connection.peer_node_id}')
    if (ban_time > 0):
        ban_until: float = (time.time() + ban_time)
        self.log.warning(f'Banning {connection.peer_host} for {ban_time} seconds')
        if (connection.peer_host in self.banned_peers):
            if (ban_until > self.banned_peers[connection.peer_host]):
                self.banned_peers[connection.peer_host] = ban_until
        else:
            self.banned_peers[connection.peer_host] = ban_until
    if (connection.peer_node_id in self.all_connections):
        self.all_connections.pop(connection.peer_node_id)
    if (connection.connection_type is not None):
        if (connection.peer_node_id in self.connection_by_type[connection.connection_type]):
            self.connection_by_type[connection.connection_type].pop(connection.peer_node_id)
    else:
        self.log.debug(f'Invalid connection type for connection {connection.peer_host}, while closing. Handshake never finished.')
    on_disconnect = getattr(self.node, 'on_disconnect', None)
    if (on_disconnect is not None):
        on_disconnect(connection)
    self.cancel_tasks_from_peer(connection.peer_node_id)
def connection_closed(self, connection: WSGreenBerryConnection, ban_time: int):
    if (is_localhost(connection.peer_host) and (ban_time != 0)):
        self.log.warning(f'Trying to ban localhost for {ban_time}, but will not ban')
        ban_time = 0
    self.log.info(f'Connection closed: {connection.peer_host}, node id: {connection.peer_node_id}')
    if (ban_time > 0):
        ban_until: float = (time.time() + ban_time)
        self.log.warning(f'Banning {connection.peer_host} for {ban_time} seconds')
        if (connection.peer_host in self.banned_peers):
            if (ban_until > self.banned_peers[connection.peer_host]):
                self.banned_peers[connection.peer_host] = ban_until
        else:
            self.banned_peers[connection.peer_host] = ban_until
    if (connection.peer_node_id in self.all_connections):
        self.all_connections.pop(connection.peer_node_id)
    if (connection.connection_type is not None):
        if (connection.peer_node_id in self.connection_by_type[connection.connection_type]):
            self.connection_by_type[connection.connection_type].pop(connection.peer_node_id)
    else:
        self.log.debug(f'Invalid connection type for connection {connection.peer_host}, while closing. Handshake never finished.')
    on_disconnect = getattr(self.node, 'on_disconnect', None)
    if (on_disconnect is not None):
        on_disconnect(connection)
    self.cancel_tasks_from_peer(connection.peer_node_id)