XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

LumaTunnel

【WinUI】LumaTunnel 是一个面向个人多设备的 Windows 代理系统。客户端在本机提供 HTTP/HTTPS CONNECT 与 SOCKS5 TCP 代理,并通过一个受信任 TLS 证书保护的 WSS 会话,将多个 TCP 流复用到自建 Windows Server 节点。

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using System.Text.Json.Serialization;

namespace LumaTunnel.Shared.Protocol;

public sealed record TunnelOpenRequest(string Host, int Port);

public sealed record TunnelOpenError(TunnelErrorCode Code, string Message);

public static class TunnelMessageSerializer
{
    public static JsonSerializerOptions Options { get; } = new(JsonSerializerDefaults.Web)
    {
        PropertyNameCaseInsensitive = true,
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
    };

    public static byte[] Serialize<T>(T value) => JsonSerializer.SerializeToUtf8Bytes(value, Options);

    public static T Deserialize<T>(ReadOnlyMemory<byte> value) where T : class =>
        JsonSerializer.Deserialize<T>(value.Span, Options)
        ?? throw new TunnelProtocolException(TunnelErrorCode.MalformedFrame, $"Unable to deserialize {typeof(T).Name}.");
}