feat: 目前完成了订阅功能和 Xray-Core 的更新管理.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Proxd_man.Config.Stream;
|
||||
using Proxd_man.Config.TransportLayerSecurity;
|
||||
|
||||
namespace Proxd_man.Config.Outbound;
|
||||
|
||||
/// <summary>
|
||||
/// 基本的出站代理配置类.
|
||||
///
|
||||
/// 所有协议的出站配置都要继承这个类.
|
||||
/// </summary>
|
||||
public abstract class BaseOutboundSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// 出站配置名称.
|
||||
///
|
||||
/// 便于管理的名字, 可以直接从订阅中获取.
|
||||
/// </summary>
|
||||
public required string Name { get; init; }
|
||||
/// <summary>
|
||||
/// 发送出站数据所使用的网卡地址.
|
||||
/// </summary>
|
||||
public string BindAddress { get; init; } = "0.0.0.0";
|
||||
/// <summary>
|
||||
/// 出站代理协议类型.
|
||||
/// </summary>
|
||||
public required OutboundProtocolType Protocol { get; init; }
|
||||
|
||||
public BaseStreamSetting StreamSetting { get; init; } = new RawStreamSetting();
|
||||
|
||||
public BaseTransportLayerSecuritySetting TransportLayerSecuritySetting { get; init; } = new NoneSecuritySetting();
|
||||
|
||||
public string? NextOutboundTag { get; init; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 根据<a href="https://xtls.github.io/config/outbound.html">Xray-Core 的配置文件格式</a>,
|
||||
/// 生成对应的 OutboundObject JSON 配置.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public JsonObject ToJsonSetting()
|
||||
{
|
||||
var root = new JsonObject
|
||||
{
|
||||
{ "sendThrough", BindAddress },
|
||||
{ "protocol", Protocol.ToString().ToLower() },
|
||||
{ "tag", GetTag() },
|
||||
{ "settings", GetProtocolSetting() }
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(NextOutboundTag))
|
||||
{
|
||||
root.Add("proxySettings", new JsonObject
|
||||
{
|
||||
{ "tag", NextOutboundTag }
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
var streamSetting = StreamSetting.ToJsonSetting();
|
||||
TransportLayerSecuritySetting.ApplyJsonSetting(streamSetting);
|
||||
root.Add("streamSettings", streamSetting);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实现依据配置内容, 生成对应的 Outbound Tag.
|
||||
/// </summary>
|
||||
/// <returns>返回该 Outbound 的 Tag, 最好唯一.</returns>
|
||||
public abstract string GetTag();
|
||||
|
||||
/// <summary>
|
||||
/// 实现类依据自身对应协议类型的设定, 生成对应的 V2Ray/Xray-Core Outbound Protocol Setting JSON 对象.
|
||||
/// </summary>
|
||||
/// <returns>返回协议配置的 JSON 对象.</returns>
|
||||
protected abstract JsonObject? GetProtocolSetting();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user