Add kcp mtu (#9178)

* Add kcp mtu

* Typo
This commit is contained in:
DHR60 2026-04-25 02:39:39 +00:00 committed by GitHub
parent c4e071cac3
commit ee6ae3d91d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 76 additions and 26 deletions

View file

@ -119,6 +119,10 @@ public class BaseFmt
{ {
dicQuery.Add("seed", UrlEncodeSafe(transport.KcpSeed)); dicQuery.Add("seed", UrlEncodeSafe(transport.KcpSeed));
} }
if (transport.KcpMtu > 0)
{
dicQuery.Add("mtu", transport.KcpMtu.ToString());
}
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
@ -279,10 +283,13 @@ public class BaseFmt
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
var kcpSeed = GetQueryDecoded(query, "seed"); var kcpSeed = GetQueryDecoded(query, "seed");
var kcpMtuStr = GetQueryValue(query, "mtu");
var kcpMtu = int.TryParse(kcpMtuStr, out var mtu) ? mtu : 0;
transport = transport with transport = transport with
{ {
KcpHeaderType = GetQueryValue(query, "headerType", Global.None), KcpHeaderType = GetQueryValue(query, "headerType", Global.None),
KcpSeed = kcpSeed, KcpSeed = kcpSeed,
KcpMtu = kcpMtu > 0 ? mtu : null,
}; };
break; break;

View file

@ -15,4 +15,5 @@ public record TransportExtraItem
public string? KcpHeaderType { get; init; } public string? KcpHeaderType { get; init; }
public string? KcpSeed { get; init; } public string? KcpSeed { get; init; }
public int? KcpMtu { get; init; }
} }

View file

@ -328,6 +328,7 @@ public partial class CoreConfigV2rayService
var host = string.Empty; var host = string.Empty;
var path = string.Empty; var path = string.Empty;
var kcpSeed = string.Empty; var kcpSeed = string.Empty;
var kcpMtu = 0;
var headerType = string.Empty; var headerType = string.Empty;
var xhttpExtra = string.Empty; var xhttpExtra = string.Empty;
switch (network) switch (network)
@ -341,6 +342,7 @@ public partial class CoreConfigV2rayService
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
kcpSeed = transport.KcpSeed?.TrimEx() ?? string.Empty; kcpSeed = transport.KcpSeed?.TrimEx() ?? string.Empty;
headerType = transport.KcpHeaderType?.TrimEx() ?? string.Empty; headerType = transport.KcpHeaderType?.TrimEx() ?? string.Empty;
kcpMtu = transport.KcpMtu > 0 ? transport.KcpMtu!.Value : _config.KcpItem.Mtu;
break; break;
case nameof(ETransport.ws): case nameof(ETransport.ws):
@ -441,7 +443,7 @@ public partial class CoreConfigV2rayService
case nameof(ETransport.kcp): case nameof(ETransport.kcp):
KcpSettings4Ray kcpSettings = new() KcpSettings4Ray kcpSettings = new()
{ {
mtu = _config.KcpItem.Mtu, mtu = kcpMtu,
tti = _config.KcpItem.Tti tti = _config.KcpItem.Tti
}; };

View file

@ -106,6 +106,9 @@ public class AddServerViewModel : MyReactiveObject
[Reactive] [Reactive]
public string KcpSeed { get; set; } public string KcpSeed { get; set; }
[Reactive]
public int? KcpMtu { get; set; }
public string TransportHeaderType public string TransportHeaderType
{ {
get => SelectedSource.GetNetwork() switch get => SelectedSource.GetNetwork() switch
@ -287,26 +290,26 @@ public class AddServerViewModel : MyReactiveObject
Cert = SelectedSource?.Cert?.ToString() ?? string.Empty; Cert = SelectedSource?.Cert?.ToString() ?? string.Empty;
CertSha = SelectedSource?.CertSha?.ToString() ?? string.Empty; CertSha = SelectedSource?.CertSha?.ToString() ?? string.Empty;
var protocolExtra = SelectedSource?.GetProtocolExtra(); var protocolExtra = SelectedSource?.GetProtocolExtra() ?? new();
var transport = SelectedSource?.GetTransportExtra(); var transport = SelectedSource?.GetTransportExtra() ?? new();
Ports = protocolExtra?.Ports ?? string.Empty; Ports = protocolExtra.Ports ?? string.Empty;
AlterId = int.TryParse(protocolExtra?.AlterId, out var result) ? result : 0; AlterId = int.TryParse(protocolExtra.AlterId, out var result) ? result : 0;
Flow = protocolExtra?.Flow ?? string.Empty; Flow = protocolExtra.Flow ?? string.Empty;
SalamanderPass = protocolExtra?.SalamanderPass ?? string.Empty; SalamanderPass = protocolExtra.SalamanderPass ?? string.Empty;
UpMbps = protocolExtra?.UpMbps; UpMbps = protocolExtra.UpMbps;
DownMbps = protocolExtra?.DownMbps; DownMbps = protocolExtra.DownMbps;
HopInterval = protocolExtra?.HopInterval ?? string.Empty; HopInterval = protocolExtra.HopInterval ?? string.Empty;
VmessSecurity = protocolExtra?.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity; VmessSecurity = protocolExtra.VmessSecurity?.IsNullOrEmpty() == false ? protocolExtra.VmessSecurity : Global.DefaultSecurity;
VlessEncryption = protocolExtra?.VlessEncryption.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None; VlessEncryption = protocolExtra.VlessEncryption?.IsNullOrEmpty() == false ? protocolExtra.VlessEncryption : Global.None;
SsMethod = protocolExtra?.SsMethod ?? string.Empty; SsMethod = protocolExtra.SsMethod ?? string.Empty;
WgPublicKey = protocolExtra?.WgPublicKey ?? string.Empty; WgPublicKey = protocolExtra.WgPublicKey ?? string.Empty;
WgInterfaceAddress = protocolExtra?.WgInterfaceAddress ?? string.Empty; WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty;
WgReserved = protocolExtra?.WgReserved ?? string.Empty; WgReserved = protocolExtra.WgReserved ?? string.Empty;
WgMtu = protocolExtra?.WgMtu ?? 1280; WgMtu = protocolExtra.WgMtu ?? 1280;
Uot = protocolExtra?.Uot ?? false; Uot = protocolExtra.Uot ?? false;
CongestionControl = protocolExtra?.CongestionControl ?? string.Empty; CongestionControl = protocolExtra.CongestionControl ?? string.Empty;
InsecureConcurrency = protocolExtra?.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null; InsecureConcurrency = protocolExtra.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null;
NaiveQuic = protocolExtra?.NaiveQuic ?? false; NaiveQuic = protocolExtra.NaiveQuic ?? false;
RawHeaderType = transport.RawHeaderType ?? Global.None; RawHeaderType = transport.RawHeaderType ?? Global.None;
Host = transport.Host ?? string.Empty; Host = transport.Host ?? string.Empty;
@ -318,6 +321,7 @@ public class AddServerViewModel : MyReactiveObject
GrpcMode = transport.GrpcMode.IsNullOrEmpty() ? Global.GrpcGunMode : transport.GrpcMode; GrpcMode = transport.GrpcMode.IsNullOrEmpty() ? Global.GrpcGunMode : transport.GrpcMode;
KcpHeaderType = transport.KcpHeaderType.IsNullOrEmpty() ? Global.None : transport.KcpHeaderType; KcpHeaderType = transport.KcpHeaderType.IsNullOrEmpty() ? Global.None : transport.KcpHeaderType;
KcpSeed = transport.KcpSeed ?? string.Empty; KcpSeed = transport.KcpSeed ?? string.Empty;
KcpMtu = transport.KcpMtu;
} }
private async Task SaveServerAsync() private async Task SaveServerAsync()
@ -381,6 +385,7 @@ public class AddServerViewModel : MyReactiveObject
GrpcMode = GrpcMode.NullIfEmpty(), GrpcMode = GrpcMode.NullIfEmpty(),
KcpHeaderType = KcpHeaderType.NullIfEmpty(), KcpHeaderType = KcpHeaderType.NullIfEmpty(),
KcpSeed = KcpSeed.NullIfEmpty(), KcpSeed = KcpSeed.NullIfEmpty(),
KcpMtu = KcpMtu > 0 ? KcpMtu : null,
}; };
SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with

View file

@ -831,7 +831,7 @@
x:Name="gridTransportKcp" x:Name="gridTransportKcp"
ColumnDefinitions="300,Auto" ColumnDefinitions="300,Auto"
IsVisible="False" IsVisible="False"
RowDefinitions="Auto,Auto"> RowDefinitions="Auto,Auto,Auto">
<TextBlock <TextBlock
Grid.Row="0" Grid.Row="0"
Grid.Column="0" Grid.Column="0"
@ -843,19 +843,34 @@
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
Width="200" Width="200"
Margin="{StaticResource Margin4}" /> Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
Grid.Column="0" Grid.Column="0"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="MTU" />
<TextBox
x:Name="txtKcpMtu"
Grid.Row="1"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="Seed" /> Text="Seed" />
<TextBox <TextBox
x:Name="txtKcpSeed" x:Name="txtKcpSeed"
Grid.Row="1" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="{StaticResource Margin4}" /> Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
</Grid> </Grid>
<Grid <Grid

View file

@ -218,6 +218,7 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.SelectedValue).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpMtu, v => v.txtKcpMtu.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Host, v => v.txtRequestHostWs.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Host, v => v.txtRequestHostWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Path, v => v.txtPathWs.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Path, v => v.txtPathWs.Text).DisposeWith(disposables);

View file

@ -1096,6 +1096,7 @@
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock <TextBlock
Grid.Row="0" Grid.Row="0"
@ -1110,6 +1111,7 @@
Grid.Column="1" Grid.Column="1"
Width="200" Width="200"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
Style="{StaticResource DefComboBox}" /> Style="{StaticResource DefComboBox}" />
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
@ -1117,13 +1119,29 @@
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
VerticalAlignment="Center" VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}" Style="{StaticResource ToolbarTextBlock}"
Text="MTU" />
<TextBox
x:Name="txtKcpMtu"
Grid.Row="1"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="Seed" /> Text="Seed" />
<TextBox <TextBox
x:Name="txtKcpSeed" x:Name="txtKcpSeed"
Grid.Row="1" Grid.Row="2"
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
</Grid> </Grid>

View file

@ -216,6 +216,7 @@ public partial class AddServerWindow
this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpHeaderType, v => v.cmbHeaderTypeKcp.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.KcpSeed, v => v.txtKcpSeed.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.KcpMtu, v => v.txtKcpMtu.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Host, v => v.txtRequestHostWs.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Host, v => v.txtRequestHostWs.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Path, v => v.txtPathWs.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.Path, v => v.txtPathWs.Text).DisposeWith(disposables);