Skip to content

Commit

Permalink
Set default tunnel MaxDatagramChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Dec 20, 2021
1 parent 0337e12 commit c5c8490
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VpnHood.Server.Access/SessionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SessionOptions
[JsonConverter(typeof(TimeSpanConverter))]
public TimeSpan IcmpTimeout { get; set; } = TimeSpan.FromSeconds(30);
public long SyncCacheSize { get; set; } = 100 * 1000000; // 100 MB
public int MaxDatagramChannelCount { get; set; } = 8;
public int MaxDatagramChannelCount { get; set; }
public int MaxUdpPortCount { get; set; }
public int TcpBufferSize { get; set; }
}
Expand Down
10 changes: 5 additions & 5 deletions VpnHood.Server/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ internal Session(IAccessServer accessServer, SessionResponse sessionResponse, So
SessionResponse = new ResponseBase(sessionResponse);
SessionId = sessionResponse.SessionId;
SessionKey = sessionResponse.SessionKey ?? throw new InvalidOperationException($"{nameof(sessionResponse)} does not have {nameof(sessionResponse.SessionKey)}!");
Tunnel = new Tunnel(new TunnelOptions
{
MaxDatagramChannelCount = options.MaxDatagramChannelCount,
TcpTimeout = options.TcpTimeout
});

var tunnelOptions = new TunnelOptions();
if (options.MaxDatagramChannelCount > 0) tunnelOptions.MaxDatagramChannelCount = options.MaxDatagramChannelCount;
if (options.TcpTimeout != TimeSpan.Zero) tunnelOptions.TcpTimeout = options.TcpTimeout;
Tunnel = new Tunnel(tunnelOptions);
Tunnel.OnPacketReceived += Tunnel_OnPacketReceived;
Tunnel.OnTrafficChanged += Tunnel_OnTrafficChanged;

Expand Down
4 changes: 4 additions & 0 deletions VpnHood.Server/VpnHoodServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ private async Task SendStatusToAccessServer()
VhLogger.Instance.LogError(ex, "Could not send server status!");
}

//todo: debug
GC.Collect();
GC.WaitForPendingFinalizers();

// reconfigure
if (configurationCode != null)
{
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Tunneling/TunnelOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace VpnHood.Tunneling
public class TunnelOptions
{
public TimeSpan TcpTimeout { get; set; }
public int MaxDatagramChannelCount { get; set; } = 1;
public int MaxDatagramChannelCount { get; set; } = 8;
}
}
2 changes: 1 addition & 1 deletion VpnHood.ZTest/Tests/TunnelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void UdpChannel_via_Tunnel()
};

// send packet to server through tunnel
clientTunnel.SendPacket(packets.ToArray());
clientTunnel.SendPacket(packets.ToArray()).Wait();
waitHandle.WaitOne(5000);
Assert.AreEqual(packets.Count, serverReceivedPackets.Length);
Assert.AreEqual(packets.Count, clientReceivedPackets.Length);
Expand Down

0 comments on commit c5c8490

Please sign in to comment.