mirror of
https://github.com/2dust/v2rayN.git
synced 2026-08-05 14:52:05 +03:00
Refactor Transport (#9004)
* Refactor transport * Rename tcp to raw * Fix * Fix Fix raw http ui Fill xhttp default mode Fix share uri Remove RawHost Fix singbox tcp http path Fix vmess share uri * Tidy Resx * Fix * Rename TransportExtra to TransportExtraItem --------- Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
This commit is contained in:
@@ -73,6 +73,163 @@ public class AddServerViewModel : MyReactiveObject
|
||||
[Reactive]
|
||||
public bool NaiveQuic { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string RawHeaderType { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string Host { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string Path { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string XhttpMode { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string XhttpExtra { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string GrpcAuthority { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string GrpcServiceName { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string GrpcMode { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string KcpHeaderType { get; set; }
|
||||
|
||||
[Reactive]
|
||||
public string KcpSeed { get; set; }
|
||||
|
||||
public string TransportHeaderType
|
||||
{
|
||||
get => SelectedSource.GetNetwork() switch
|
||||
{
|
||||
nameof(ETransport.raw) => RawHeaderType,
|
||||
nameof(ETransport.kcp) => KcpHeaderType,
|
||||
nameof(ETransport.xhttp) => XhttpMode,
|
||||
nameof(ETransport.grpc) => GrpcMode,
|
||||
_ => string.Empty,
|
||||
};
|
||||
set
|
||||
{
|
||||
switch (SelectedSource.GetNetwork())
|
||||
{
|
||||
case nameof(ETransport.raw):
|
||||
RawHeaderType = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.kcp):
|
||||
KcpHeaderType = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.xhttp):
|
||||
XhttpMode = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.grpc):
|
||||
GrpcMode = value;
|
||||
break;
|
||||
}
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string TransportHost
|
||||
{
|
||||
get => SelectedSource.GetNetwork() switch
|
||||
{
|
||||
nameof(ETransport.raw) => Host,
|
||||
nameof(ETransport.ws) => Host,
|
||||
nameof(ETransport.httpupgrade) => Host,
|
||||
nameof(ETransport.xhttp) => Host,
|
||||
nameof(ETransport.grpc) => GrpcAuthority,
|
||||
_ => string.Empty,
|
||||
};
|
||||
set
|
||||
{
|
||||
switch (SelectedSource.GetNetwork())
|
||||
{
|
||||
case nameof(ETransport.raw):
|
||||
Host = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.ws):
|
||||
Host = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.httpupgrade):
|
||||
Host = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.xhttp):
|
||||
Host = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.grpc):
|
||||
GrpcAuthority = value;
|
||||
break;
|
||||
}
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string TransportPath
|
||||
{
|
||||
get => SelectedSource.GetNetwork() switch
|
||||
{
|
||||
nameof(ETransport.kcp) => KcpSeed,
|
||||
nameof(ETransport.ws) => Path,
|
||||
nameof(ETransport.httpupgrade) => Path,
|
||||
nameof(ETransport.xhttp) => Path,
|
||||
nameof(ETransport.grpc) => GrpcServiceName,
|
||||
_ => string.Empty,
|
||||
};
|
||||
set
|
||||
{
|
||||
switch (SelectedSource.GetNetwork())
|
||||
{
|
||||
case nameof(ETransport.kcp):
|
||||
KcpSeed = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.ws):
|
||||
Path = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.httpupgrade):
|
||||
Path = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.xhttp):
|
||||
Path = value;
|
||||
break;
|
||||
|
||||
case nameof(ETransport.grpc):
|
||||
GrpcServiceName = value;
|
||||
break;
|
||||
}
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string TransportExtraText
|
||||
{
|
||||
get => SelectedSource.GetNetwork() == nameof(ETransport.xhttp)
|
||||
? XhttpExtra
|
||||
: string.Empty;
|
||||
set
|
||||
{
|
||||
if (SelectedSource.GetNetwork() == nameof(ETransport.xhttp))
|
||||
{
|
||||
XhttpExtra = value;
|
||||
}
|
||||
this.RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ReactiveCommand<Unit, Unit> FetchCertCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> FetchCertChainCmd { get; }
|
||||
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
||||
@@ -101,14 +258,21 @@ public class AddServerViewModel : MyReactiveObject
|
||||
this.WhenAnyValue(x => x.CertSha)
|
||||
.Subscribe(_ => UpdateCertTip());
|
||||
|
||||
this.WhenAnyValue(x => x.SelectedSource.Network)
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
this.RaisePropertyChanged(nameof(TransportHeaderType));
|
||||
this.RaisePropertyChanged(nameof(TransportHost));
|
||||
this.RaisePropertyChanged(nameof(TransportPath));
|
||||
this.RaisePropertyChanged(nameof(TransportExtraText));
|
||||
});
|
||||
|
||||
this.WhenAnyValue(x => x.Cert)
|
||||
.Subscribe(_ => UpdateCertSha());
|
||||
|
||||
if (profileItem.IndexId.IsNullOrEmpty())
|
||||
{
|
||||
profileItem.Network = Global.DefaultNetwork;
|
||||
profileItem.HeaderType = Global.None;
|
||||
profileItem.RequestHost = "";
|
||||
profileItem.StreamSecurity = "";
|
||||
SelectedSource = profileItem;
|
||||
}
|
||||
@@ -121,6 +285,7 @@ public class AddServerViewModel : MyReactiveObject
|
||||
CertSha = SelectedSource?.CertSha?.ToString() ?? string.Empty;
|
||||
|
||||
var protocolExtra = SelectedSource?.GetProtocolExtra();
|
||||
var transport = SelectedSource?.GetTransportExtra();
|
||||
Ports = protocolExtra?.Ports ?? string.Empty;
|
||||
AlterId = int.TryParse(protocolExtra?.AlterId, out var result) ? result : 0;
|
||||
Flow = protocolExtra?.Flow ?? string.Empty;
|
||||
@@ -139,6 +304,17 @@ public class AddServerViewModel : MyReactiveObject
|
||||
CongestionControl = protocolExtra?.CongestionControl ?? string.Empty;
|
||||
InsecureConcurrency = protocolExtra?.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null;
|
||||
NaiveQuic = protocolExtra?.NaiveQuic ?? false;
|
||||
|
||||
RawHeaderType = transport.RawHeaderType ?? Global.None;
|
||||
Host = transport.Host ?? string.Empty;
|
||||
Path = transport.Path ?? string.Empty;
|
||||
XhttpMode = transport.XhttpMode ?? Global.DefaultXhttpMode;
|
||||
XhttpExtra = transport.XhttpExtra ?? string.Empty;
|
||||
GrpcAuthority = transport.GrpcAuthority ?? string.Empty;
|
||||
GrpcServiceName = transport.GrpcServiceName ?? string.Empty;
|
||||
GrpcMode = transport.GrpcMode.IsNullOrEmpty() ? Global.GrpcGunMode : transport.GrpcMode;
|
||||
KcpHeaderType = transport.KcpHeaderType.IsNullOrEmpty() ? Global.None : transport.KcpHeaderType;
|
||||
KcpSeed = transport.KcpSeed ?? string.Empty;
|
||||
}
|
||||
|
||||
private async Task SaveServerAsync()
|
||||
@@ -185,6 +361,25 @@ public class AddServerViewModel : MyReactiveObject
|
||||
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
|
||||
SelectedSource.Cert = Cert.IsNullOrEmpty() ? string.Empty : Cert;
|
||||
SelectedSource.CertSha = CertSha.IsNullOrEmpty() ? string.Empty : CertSha;
|
||||
if (!Global.Networks.Contains(SelectedSource.Network))
|
||||
{
|
||||
SelectedSource.Network = Global.DefaultNetwork;
|
||||
}
|
||||
|
||||
var transport = new TransportExtraItem
|
||||
{
|
||||
RawHeaderType = RawHeaderType.NullIfEmpty(),
|
||||
Host = Host.NullIfEmpty(),
|
||||
Path = Path.NullIfEmpty(),
|
||||
XhttpMode = XhttpMode.NullIfEmpty(),
|
||||
XhttpExtra = XhttpExtra.NullIfEmpty(),
|
||||
GrpcAuthority = GrpcAuthority.NullIfEmpty(),
|
||||
GrpcServiceName = GrpcServiceName.NullIfEmpty(),
|
||||
GrpcMode = GrpcMode.NullIfEmpty(),
|
||||
KcpHeaderType = KcpHeaderType.NullIfEmpty(),
|
||||
KcpSeed = KcpSeed.NullIfEmpty(),
|
||||
};
|
||||
|
||||
SelectedSource.SetProtocolExtra(SelectedSource.GetProtocolExtra() with
|
||||
{
|
||||
Ports = Ports.NullIfEmpty(),
|
||||
@@ -206,6 +401,7 @@ public class AddServerViewModel : MyReactiveObject
|
||||
InsecureConcurrency = InsecureConcurrency > 0 ? InsecureConcurrency : null,
|
||||
NaiveQuic = NaiveQuic ? true : null,
|
||||
});
|
||||
SelectedSource.SetTransportExtra(transport);
|
||||
|
||||
if (await ConfigHandler.AddServer(_config, SelectedSource) == 0)
|
||||
{
|
||||
@@ -261,7 +457,7 @@ public class AddServerViewModel : MyReactiveObject
|
||||
var serverName = SelectedSource.Sni;
|
||||
if (serverName.IsNullOrEmpty())
|
||||
{
|
||||
serverName = SelectedSource.RequestHost;
|
||||
serverName = GetCurrentTransportHost();
|
||||
}
|
||||
if (serverName.IsNullOrEmpty())
|
||||
{
|
||||
@@ -286,7 +482,7 @@ public class AddServerViewModel : MyReactiveObject
|
||||
var serverName = SelectedSource.Sni;
|
||||
if (serverName.IsNullOrEmpty())
|
||||
{
|
||||
serverName = SelectedSource.RequestHost;
|
||||
serverName = GetCurrentTransportHost();
|
||||
}
|
||||
if (serverName.IsNullOrEmpty())
|
||||
{
|
||||
@@ -301,4 +497,17 @@ public class AddServerViewModel : MyReactiveObject
|
||||
Cert = CertPemManager.ConcatenatePemChain(certs);
|
||||
UpdateCertTip(certError);
|
||||
}
|
||||
|
||||
private string GetCurrentTransportHost()
|
||||
{
|
||||
return SelectedSource.GetNetwork() switch
|
||||
{
|
||||
nameof(ETransport.raw) => Host,
|
||||
nameof(ETransport.ws) => Host,
|
||||
nameof(ETransport.httpupgrade) => Host,
|
||||
nameof(ETransport.xhttp) => Host,
|
||||
nameof(ETransport.grpc) => GrpcAuthority,
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user