async def connection_added(self, connection: WSGreenBerryConnection, on_connect=None):
    if (connection.peer_node_id in self.all_connections):
        con = self.all_connections[connection.peer_node_id]
        (await con.close())
    self.all_connections[connection.peer_node_id] = connection
    if (connection.connection_type is not None):
        self.connection_by_type[connection.connection_type][connection.peer_node_id] = connection
        if (on_connect is not None):
            (await on_connect(connection))
    else:
        self.log.error(f'Invalid connection type for connection {connection}')
async def connection_added(self, connection: WSGreenBerryConnection, on_connect=None):
    if (connection.peer_node_id in self.all_connections):
        con = self.all_connections[connection.peer_node_id]
        (await con.close())
    self.all_connections[connection.peer_node_id] = connection
    if (connection.connection_type is not None):
        self.connection_by_type[connection.connection_type][connection.peer_node_id] = connection
        if (on_connect is not None):
            (await on_connect(connection))
    else:
        self.log.error(f'Invalid connection type for connection {connection}')