How to use the snitun.server.peer_manager.PeerManager function in snitun

To help you get started, we’ve selected a few snitun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_new_peer_with_removing():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    valid = datetime.utcnow() + timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    peer = manager.create_peer(fernet_token)
    assert peer.hostname == hostname
    assert not peer.is_ready

    manager.add_peer(peer)
    assert manager.get_peer(hostname)
    assert not manager.peer_available(hostname)
    assert hostname in manager._peers
    assert manager.connections == 1
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_new_peer_throttling():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS, throttling=500)

    valid = datetime.utcnow() + timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    peer = manager.create_peer(fernet_token)
    assert peer.hostname == hostname
    assert not peer.is_ready
    assert peer._throttling == 500

    manager.add_peer(peer)
    assert manager.get_peer(hostname)
    assert not manager.peer_available(hostname)
    assert hostname in manager._peers
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
async def test_init_dual_peer_with_multiplexer(multiplexer_client):
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    valid = datetime.utcnow() + timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    peer1 = manager.create_peer(fernet_token)
    peer2 = manager.create_peer(fernet_token)
    assert peer1.hostname == hostname
    assert peer2.hostname == hostname
    assert not peer1.is_ready
    assert not peer2.is_ready

    peer1._multiplexer = multiplexer_client
    assert peer1.is_ready
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_new_peer():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    valid = datetime.utcnow() + timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    peer = manager.create_peer(fernet_token)
    assert peer.hostname == hostname
    assert not peer.is_ready
    assert not manager.get_peer(hostname)
    assert not manager.peer_available(hostname)
    assert hostname not in manager._peers
    assert manager.connections == 0

    manager.add_peer(peer)
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_new_peer_invalid_fernet():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    with pytest.raises(SniTunInvalidPeer):
        manager.create_peer(os.urandom(100))
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_simple_init_peer_manager():
    """Simple init a peer manager."""
    manager = PeerManager(FERNET_TOKENS)

    assert manager._fernet
    assert not manager._peers
    assert manager._throttling is None
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_dual_peer_with_removing():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    valid = datetime.utcnow() + timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    peer1 = manager.create_peer(fernet_token)
    peer2 = manager.create_peer(fernet_token)
    assert peer1.hostname == hostname
    assert peer2.hostname == hostname
    assert not peer1.is_ready
    assert not peer2.is_ready

    manager.add_peer(peer1)
    assert manager.get_peer(hostname) == peer1
github NabuCasa / snitun / tests / server / test_peer_manager.py View on Github external
def test_init_new_peer_not_valid_time():
    """Init a new peer."""
    manager = PeerManager(FERNET_TOKENS)

    valid = datetime.utcnow() - timedelta(days=1)
    aes_key = os.urandom(32)
    aes_iv = os.urandom(16)
    hostname = "localhost"
    fernet_token = create_peer_config(valid.timestamp(), hostname, aes_key, aes_iv)

    with pytest.raises(SniTunInvalidPeer):
        manager.create_peer(fernet_token)
github NabuCasa / snitun / snitun / server / run.py View on Github external
def __init__(
        self,
        fernet_keys: List[str],
        sni_port=None,
        sni_host=None,
        peer_port=None,
        peer_host=None,
        throttling: Optional[int] = None,
    ):
        """Initialize SniTun Server."""
        self._peers = PeerManager(fernet_keys, throttling=throttling)
        self._list_sni = SNIProxy(self._peers, host=sni_host, port=sni_port)
        self._list_peer = PeerListener(self._peers, host=peer_host, port=peer_port)