Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Jul 15, 2024
2 parents ebda10b + 07ddb80 commit 7616c4e
Show file tree
Hide file tree
Showing 193 changed files with 2,808 additions and 4,970 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# v4.6.544
### Client
* Fix: App Filter does not work when no app is selected
* Fix: Exclude the ad tracker from the tunnel
* Fix: Exclude My Country
* Fix: Could not set MTU error
* Fix: Android: InApp Update
* Fix: Android: VPN Service remains in memory after disconnect
* Feature: Report unreachable servers
* Feature: Add domain filtering to engine
* Feature: Add log to Android logcat
* Feature: Try to find a reachable server among endpoints
* Feature: Implement ChartBoost ads
* Update: Improve performance and memory usage
*
### Server
* Feature: Support multiple redirect endpoints
* Update: Use Cloudflare for detecting the server's public IP
* Update: Improve performance and memory usage

# v4.5.535
### Client
* Improve: App Filter page
Expand Down
4 changes: 2 additions & 2 deletions Pub/PubVersion.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "4.5.535",
"BumpTime": "2024-06-24T05:03:47.2884293Z",
"Version": "4.6.544",
"BumpTime": "2024-07-15T05:08:21.3508028Z",
"Prerelease": false,
"DeprecatedVersion": "4.0.00"
}
8 changes: 8 additions & 0 deletions Tests/VpnHood.Test/AccessManagers/TestAccessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TestAccessManager(string storagePath, FileAccessManagerOptions opti
public ServerInfo? LastServerInfo { get; private set; }
public ServerStatus? LastServerStatus { get; private set; }
public IPEndPoint? RedirectHostEndPoint { get; set; }
public IPEndPoint[]? RedirectHostEndPoints { get; set; }
public Dictionary<string, IPEndPoint?> ServerLocations { get; set; } = new();
public bool RejectAllAds { get; set; }

Expand Down Expand Up @@ -69,6 +70,13 @@ public override async Task<SessionResponseEx> Session_Create(SessionRequestEx se
ret.ErrorCode = SessionErrorCode.RedirectHost;
}

// manage new redirects
if (RedirectHostEndPoints != null)
{
ret.RedirectHostEndPoints = RedirectHostEndPoints;
ret.ErrorCode = SessionErrorCode.RedirectHost;
}

// manage region
if (sessionRequestEx.ServerLocation != null)
{
Expand Down
12 changes: 6 additions & 6 deletions Tests/VpnHood.Test/Device/TestDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@

namespace VpnHood.Test.Device;

internal class TestDevice(TestDeviceOptions? options = default) : IDevice
internal class TestDevice(TestDeviceOptions options, bool useNullPacketCapture) : IDevice
{
private readonly TestDeviceOptions _options = options ?? new TestDeviceOptions();

#pragma warning disable CS0067 // The event 'TestDevice.StartedAsService' is never used
public event EventHandler? StartedAsService;
#pragma warning restore CS0067 // The event 'TestDevice.StartedAsService' is never used
public IAppCultureService? CultureService => null;
public string OsInfo => Environment.OSVersion + ", " + (Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit");
public bool IsExcludeAppsSupported => false;
public bool IsIncludeAppsSupported => false;
public bool IsLogToConsoleSupported => true;
public bool IsAlwaysOnSupported => false;

public DeviceAppInfo[] InstalledApps => throw new NotSupportedException();

public Task<IPacketCapture> CreatePacketCapture(IUiContext? uiContext)
{
var res = new TestPacketCapture(_options);
return Task.FromResult((IPacketCapture)res);
IPacketCapture res = useNullPacketCapture
? new NullPacketCapture()
: new TestPacketCapture(options);

return Task.FromResult(res);
}
public void Dispose()
{
Expand Down
13 changes: 0 additions & 13 deletions Tests/VpnHood.Test/Device/TestPacketCapture.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Net;
using System.Net.Sockets;
using PacketDotNet;
using VpnHood.Client.Device.WinDivert;
using VpnHood.Test.Services;

namespace VpnHood.Test.Device;

Expand All @@ -25,7 +23,6 @@ public override IPAddress[]? DnsServers
}

public override bool CanSendPacketToOutbound => deviceOptions.CanSendPacketToOutbound;
public override bool CanProtectSocket => !deviceOptions.CanSendPacketToOutbound;

protected override void ProcessPacketReceivedFromInbound(IPPacket ipPacket)
{
Expand All @@ -36,20 +33,10 @@ protected override void ProcessPacketReceivedFromInbound(IPPacket ipPacket)
deviceOptions.CaptureDnsAddresses != null &&
deviceOptions.CaptureDnsAddresses.All(x => !x.Equals(ipPacket.DestinationAddress));

ignore |= TestSocketProtector.IsProtectedPacket(ipPacket);

// ignore protected packets
if (ignore)
SendPacketToOutbound(ipPacket);
else
base.ProcessPacketReceivedFromInbound(ipPacket);
}

public override void ProtectSocket(Socket socket)
{
if (CanProtectSocket)
TestSocketProtector.ProtectSocket(socket);
else
base.ProtectSocket(socket);
}
}
1 change: 1 addition & 0 deletions Tests/VpnHood.Test/Services/TestAdService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestAdService(TestAccessManager accessManager) : IAppAdService
public AppAdType AdType => AppAdType.InterstitialAd;
public bool IsCountrySupported(string countryCode) => true;
public DateTime? AdLoadedTime { get; private set; }
public TimeSpan AdLifeSpan { get; } = TimeSpan.FromMinutes(60);

public Task LoadAd(IUiContext uiContext, CancellationToken cancellationToken)
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/VpnHood.Test/Services/TestNetFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PacketDotNet;
using VpnHood.Server;
using VpnHood.Tunneling;
using VpnHood.Tunneling.Utils;

namespace VpnHood.Test.Services;

Expand Down
5 changes: 3 additions & 2 deletions Tests/VpnHood.Test/Services/TestSocketFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Sockets;
using VpnHood.Client.Device.WinDivert;
using VpnHood.Tunneling.Factory;

namespace VpnHood.Test.Services;
Expand All @@ -8,14 +9,14 @@ public class TestSocketFactory : SocketFactory
public override TcpClient CreateTcpClient(AddressFamily addressFamily)
{
var tcpClient = base.CreateTcpClient(addressFamily);
TestSocketProtector.ProtectSocket(tcpClient.Client);
tcpClient.Client.Ttl = WinDivertPacketCapture.ProtectedTtl;
return tcpClient;
}

public override UdpClient CreateUdpClient(AddressFamily addressFamily)
{
var udpClient = base.CreateUdpClient(addressFamily);
TestSocketProtector.ProtectSocket(udpClient.Client);
udpClient.Client.Ttl = WinDivertPacketCapture.ProtectedTtl;
return udpClient;
}
}
39 changes: 0 additions & 39 deletions Tests/VpnHood.Test/Services/TestSocketProtector.cs

This file was deleted.

27 changes: 27 additions & 0 deletions Tests/VpnHood.Test/Services/TestTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Ga4.Trackers;

namespace VpnHood.Test.Services;

internal class TestTracker : ITracker
{
public bool IsEnabled { get; set; }
public List<TrackEvent> TrackEvents { get; } = [];

public Task Track(IEnumerable<TrackEvent> trackEvents)
{
return Task.WhenAll(trackEvents.Select(Track));
}

public Task Track(TrackEvent trackEvent)
{
TrackEvents.Add(trackEvent);
return Task.CompletedTask;
}

public TrackEvent? FindEvent(string eventName, string parameterName, object parameterValue)
{
return TrackEvents.FirstOrDefault(e =>
e.EventName == eventName &&
e.Parameters.ContainsKey(parameterName) && e.Parameters[parameterName].Equals(parameterValue));
}
}
61 changes: 44 additions & 17 deletions Tests/VpnHood.Test/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,26 +269,26 @@ public static FileAccessManagerOptions CreateFileAccessManagerOptions(IPEndPoint
}

public static Task<VpnHoodServer> CreateServer(
IAccessManager? accessManager = null,
IAccessManager? accessManager = null,
bool autoStart = true, TimeSpan? configureInterval = null, bool useHttpAccessManager = true)
{
return CreateServer(accessManager, null,
autoStart: autoStart,
configureInterval: configureInterval,
return CreateServer(accessManager, null,
autoStart: autoStart,
configureInterval: configureInterval,
useHttpAccessManager: useHttpAccessManager);
}

public static Task<VpnHoodServer> CreateServer(FileAccessManagerOptions? options, bool autoStart = true,
public static Task<VpnHoodServer> CreateServer(FileAccessManagerOptions? options, bool autoStart = true,
TimeSpan? configureInterval = null, bool useHttpAccessManager = true)
{
return CreateServer(null, options,
autoStart: autoStart,
configureInterval: configureInterval,
return CreateServer(null, options,
autoStart: autoStart,
configureInterval: configureInterval,
useHttpAccessManager: useHttpAccessManager);
}

private static async Task<VpnHoodServer> CreateServer(IAccessManager? accessManager, FileAccessManagerOptions? fileAccessManagerOptions,
bool autoStart, TimeSpan? configureInterval = null, bool useHttpAccessManager = true)
private static async Task<VpnHoodServer> CreateServer(IAccessManager? accessManager, FileAccessManagerOptions? fileAccessManagerOptions,
bool autoStart, TimeSpan? configureInterval = null, bool useHttpAccessManager = true)
{
if (accessManager != null && fileAccessManagerOptions != null)
throw new InvalidOperationException($"Could not set both {nameof(accessManager)} and {nameof(fileAccessManagerOptions)}.");
Expand Down Expand Up @@ -329,11 +329,23 @@ private static async Task<VpnHoodServer> CreateServer(IAccessManager? accessMana
return server;
}

public static TestDeviceOptions CreateDeviceOptions()
{
return new TestDeviceOptions();
}

public static IDevice CreateDevice(TestDeviceOptions? options = default)
{
return new TestDevice(options);
options ??= new TestDeviceOptions();
return new TestDevice(options, false);
}

public static IDevice CreateNullDevice()
{
return new TestDevice(new TestDeviceOptions(), true);
}


public static IPacketCapture CreatePacketCapture(TestDeviceOptions? options = default)
{
return CreateDevice(options).CreatePacketCapture(null).Result;
Expand All @@ -343,8 +355,11 @@ public static ClientOptions CreateClientOptions(bool useUdp = false)
{
return new ClientOptions
{
AllowAnonymousTracker = true,
AllowEndPointTracker = true,
MaxDatagramChannelCount = 1,
UseUdpChannel = useUdp
UseUdpChannel = useUdp,
Tracker = new TestTracker()
};
}

Expand Down Expand Up @@ -384,32 +399,44 @@ public static async Task<VpnHoodClient> CreateClient(Token token,
return client;
}

public static AppOptions CreateClientAppOptions()
public static AppOptions CreateAppOptions()
{
var tracker = new TestTracker();
var appOptions = new AppOptions
{
StorageFolderPath = Path.Combine(WorkingPath, "AppData_" + Guid.NewGuid()),
SessionTimeout = TimeSpan.FromSeconds(2),
AppGa4MeasurementId = null,
Tracker = tracker,
UseInternalLocationService = false,
UseExternalLocationService = false,
LogVerbose = LogVerbose
AllowEndPointTracker = true,
LogVerbose = LogVerbose,
ServerQueryTimeout = TimeSpan.FromSeconds(2),
AutoDiagnose = false,
SingleLineConsoleLog = false,
AdOptions = new AppAdOptions
{
ShowAdPostDelay = TimeSpan.Zero,
LoadAdPostDelay = TimeSpan.Zero
}
};
return appOptions;
}

public static VpnHoodApp CreateClientApp(TestDeviceOptions? deviceOptions = default, AppOptions? appOptions = default)
{
//create app
appOptions ??= CreateClientAppOptions();
appOptions ??= CreateAppOptions();

var device = CreateDevice(deviceOptions);
var device = deviceOptions != null ? CreateDevice(deviceOptions) : CreateNullDevice();
var clientApp = VpnHoodApp.Init(device, appOptions);
clientApp.Diagnoser.HttpTimeout = 2000;
clientApp.Diagnoser.NsTimeout = 2000;
clientApp.UserSettings.PacketCaptureIncludeIpRanges = TestIpAddresses.Select(x => new IpRange(x)).ToArray();
clientApp.UserSettings.Logging.LogAnonymous = false;
clientApp.TcpTimeout = TimeSpan.FromSeconds(2);
clientApp.UiContext = new TestAppUiContext();
ActiveUiContext.Context = new TestAppUiContext();

return clientApp;
}
Expand Down
Loading

0 comments on commit 7616c4e

Please sign in to comment.