private static VpnHostContract Map(VpnHost host) { return(new VpnHostContract { Name = host.Name, Ip = host.Ip }); }
private void InvokeConnecting() { VpnHost server = _servers.FirstOrDefault(); if (!server.IsEmpty()) { InvokeStateChanged(new VpnState(VpnStatus.Pinging, VpnError.None, string.Empty, server.Ip, _config.VpnProtocol, _config.OpenVpnAdapter, server.Label)); } }
private static VpnHostContract Map(VpnHost host) { return(new() { Name = host.Name, Ip = host.Ip, Label = host.Label, X25519PublicKey = host.X25519PublicKey != null ? new ServerPublicKeyContract(host.X25519PublicKey) : null, }); }
private IReadOnlyList <Task <VpnEndpoint> > EndpointCandidates(VpnHost server, VpnProtocol protocol) { _logger.Info($"Pinging VPN server {server.Ip} for {protocol} protocol"); var timeoutTask = Task.Delay(EndpointTimeout); return((from pair in _config.Ports where protocol == VpnProtocol.Auto || protocol == pair.Key from port in pair.Value select GetPortAlive(new VpnEndpoint(server, pair.Key, port), timeoutTask)).ToList()); }
public void IsEmpty_ShouldBeTrue_WhenNew() { // Arrange var host = new VpnHost("name.com", "0.0.0.0", string.Empty); // Act var result = host.IsEmpty(); // Assert result.Should().BeFalse(); }
public void IsEmpty_ShouldBeTrue_WhenDefault() { // Arrange VpnHost host = default; // Act var result = host.IsEmpty(); // Assert result.Should().BeTrue(); }
private VpnState WithFallbackRemoteServer(VpnState state, VpnHost remoteServer) { if (state.Status == VpnStatus.Disconnecting || state.Status == VpnStatus.Disconnected || !string.IsNullOrEmpty(state.RemoteIp)) { return(state); } return(state.WithRemoteIp(remoteServer.Ip, remoteServer.Label)); }
public void Ip_ShouldBe_Ip() { // Arrange const string expected = "44.55.66.77"; var host = new VpnHost("server-1.protonvpn.com", expected, string.Empty); // Act var result = host.Ip; // Assert result.Should().Be(expected); }
public void Name_ShouldBe_Name() { // Arrange const string expected = "server-1.protonvpn.com"; var host = new VpnHost(expected, "127.0.0.1", string.Empty); // Act var result = host.Name; // Assert result.Should().Be(expected); }
private VpnEndpoint HandleBestEndpoint(VpnEndpoint bestEndpoint, VpnHost server) { bool isResponding = bestEndpoint.Port != 0; if (isResponding) { _logger.Info($"The endpoint {bestEndpoint.Server.Ip}:{bestEndpoint.Port} was the fastest to respond."); return(bestEndpoint); } _logger.Info($"No VPN port has responded for {server.Ip}."); return(VpnEndpoint.Empty); }
private async Task <VpnEndpoint> BestEndpoint(VpnHost server, VpnProtocol protocol, CancellationToken cancellationToken) { switch (protocol) { case VpnProtocol.Auto: var bestEndpoint = await BestEndpoint(EndpointCandidates(server, VpnProtocol.OpenVpnUdp)); if (bestEndpoint.Port == 0 && !cancellationToken.IsCancellationRequested) { bestEndpoint = await BestEndpoint(EndpointCandidates(server, VpnProtocol.OpenVpnTcp)); } return(bestEndpoint); default: return(await BestEndpoint(EndpointCandidates(server, protocol))); } }
private static VpnEndpoint Endpoint(VpnHost server, VpnProtocol protocol) { return(server.IsEmpty() ? VpnEndpoint.EmptyEndpoint : new VpnEndpoint(server, protocol)); }
public VpnEndpoint(VpnHost server, VpnProtocol vpnProtocol, int port) : this(server, port) { VpnProtocol = vpnProtocol; }
public VpnEndpoint(VpnHost server, int port, bool isEmpty = false) { Server = server; Port = port; IsEmpty = isEmpty; }
public VpnEndpoint(VpnHost server, VpnProtocol vpnProtocol) : this(server, vpnProtocol, 0) { }
public VpnEndpoint(VpnHost server, VpnProtocol protocol, int port) { Server = server; Protocol = protocol; Port = port; }