Skip to content

Commit

Permalink
Add mtu setting 4 Wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 15, 2024
1 parent 69cbdbd commit 08c7396
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions v2rayN/v2rayN/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ public static string Base64Decode(string plainText)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static int ToInt(object obj)
public static int ToInt(object? obj)
{
try
{
return Convert.ToInt32(obj);
return Convert.ToInt32(obj ?? string.Empty);
}
catch //(Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ internal class Global
public static readonly List<string> LogLevels = new() { "debug", "info", "warning", "error", "none" };
public static readonly List<string> InboundTags = new() { "socks", "http", "socks2", "http2" };
public static readonly List<string> RuleProtocols = new() { "http", "tls", "bittorrent" };
public static readonly List<string> TunMtus = new() { "9000", "1500" };
public static readonly List<string> TunMtus = new() { "1280", "1408", "1500", "9000" };
public static readonly List<string> TunStacks = new() { "gvisor", "system" };
public static readonly List<string> PresetMsgFilters = new() { "proxy", "direct", "block", "" };
public static readonly List<string> SingboxMuxs = new() { "h2mux", "smux", "yamux", "" };
Expand Down
4 changes: 4 additions & 0 deletions v2rayN/v2rayN/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,10 @@ public static int AddWireguardServer(Config config, ProfileItem profileItem, boo
profileItem.path = profileItem.path.TrimEx();
profileItem.requestHost = profileItem.requestHost.TrimEx();
profileItem.network = string.Empty;
if (profileItem.shortId.IsNullOrEmpty())
{
profileItem.shortId = Global.TunMtus.FirstOrDefault();
}

if (profileItem.id.IsNullOrEmpty())
{
Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Handler/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private int GenOutbound(ProfileItem node, Outbound4Sbox outbound)
outbound.peer_public_key = node.publicKey;
outbound.reserved = Utils.String2List(node.path).Select(int.Parse).ToArray();
outbound.local_address = [.. Utils.String2List(node.requestHost)];

outbound.mtu = Utils.ToInt(node.shortId.IsNullOrEmpty() ? Global.TunMtus.FirstOrDefault() : node.shortId);
GenOutboundMux(node, outbound);
}

Expand Down
25 changes: 21 additions & 4 deletions v2rayN/v2rayN/Views/AddServerWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow
x:Class="v2rayN.Views.AddServerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net"
xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuServers}"
Expand Down Expand Up @@ -520,6 +520,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180" />
Expand Down Expand Up @@ -586,6 +587,22 @@
Width="400"
Margin="{StaticResource ServerItemMargin}"
Style="{StaticResource DefTextBox}" />

<TextBlock
Grid.Row="5"
Grid.Column="0"
Margin="{StaticResource ServerItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="Mtu" />
<TextBox
x:Name="txtShortId9"
Grid.Row="5"
Grid.Column="1"
Width="100"
Margin="{StaticResource ServerItemMargin}"
HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" />
</Grid>

<Separator
Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Views/AddServerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public AddServerWindow(ProfileItem profileItem)
this.Bind(ViewModel, vm => vm.SelectedSource.publicKey, v => v.txtPublicKey9.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.path, v => v.txtPath9.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.requestHost, v => v.txtRequestHost9.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource.shortId, v => v.txtShortId9.Text).DisposeWith(disposables);
break;
}
this.Bind(ViewModel, vm => vm.SelectedSource.network, v => v.cmbNetwork.Text).DisposeWith(disposables);
Expand Down

0 comments on commit 08c7396

Please sign in to comment.