{"id":15107111,"url":"https://github.com/shadowsocks/shadowsocks-net","last_synced_at":"2025-04-12T02:13:16.785Z","repository":{"id":65979130,"uuid":"242752360","full_name":"shadowsocks/Shadowsocks-Net","owner":"shadowsocks","description":"✈ A light-weight, cross-platform, extensible Shadowsocks developed in C# (.NET Core).","archived":false,"fork":false,"pushed_at":"2024-07-09T21:17:15.000Z","size":623,"stargazers_count":100,"open_issues_count":6,"forks_count":32,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-12T02:13:05.008Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shadowsocks.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-24T14:07:37.000Z","updated_at":"2025-04-04T02:25:17.000Z","dependencies_parsed_at":"2024-09-16T07:03:04.192Z","dependency_job_id":null,"html_url":"https://github.com/shadowsocks/Shadowsocks-Net","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowsocks%2FShadowsocks-Net","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowsocks%2FShadowsocks-Net/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowsocks%2FShadowsocks-Net/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shadowsocks%2FShadowsocks-Net/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shadowsocks","download_url":"https://codeload.github.com/shadowsocks/Shadowsocks-Net/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505925,"owners_count":21115354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T21:04:34.673Z","updated_at":"2025-04-12T02:13:16.759Z","avatar_url":"https://github.com/shadowsocks.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿## Overview\n\nShadowsocks-Net是使用C#（.NET Core）开发的跨平台版本的Shadowsocks。\n\n\u003cbr/\u003e\n\n## 版本\nShadowsocks-Net计划会有多个发布版本，功能特性比较见下表。\n\n|完成度|版本                           |ss-local        |ss-remote       |local http\u003csup\u003e[1](#fn_local_http)\u003c/sup\u003e   |混淆|规则\u003cbr/\u003e过滤|服务器\u003cbr/\u003e选择策略     |图形\u003cbr/\u003e用户界面     |\n|-|-|-|-|-|-|-|-|-|\n| 90%    |Minimal-\u003cbr/\u003ecross-platform    |√              | √             |√                                         |    |           |                        |                      |\n| 10%    |Windows                        |√              |                |√                                         |√  |√         |√                      |√                    |\n| 1%     |Linux                          |√              | √             |√                                         |√  |√         |                        |                      |\n\n\n\nMinimal版现已可测试，支持的加密算法：\n\n```console\naes-256-gcm, aes-192-gcm, aes-128-gcm, chacha20-ietf-poly1305, xchacha20-ietf-poly1305\n```\n\n\u003cbr/\u003e\n\n\n\n\n## 开发说明\n\n#### 架构示意图\n![arch][shadowsocks_net_arch]\n\nShadowsocks-Net对网络编程部分做了简单封装，使得上层可以专注socks5协议。\n由于Shadowsocks主要实现了socks5协议，因此现在上层的代码很薄。socks5总的来说只做了两件事：1. 协商、2. 转发。Shadowsocks-Net试图让用C#开发Shadowsocks变得更有趣也更简单。\n\n\u003cbr/\u003e\n\n_Master分支是经典的Shadowsocks实现。\n[pluggable-tunnel](https://github.com/shadowsocks/Shadowsocks-Net/tree/pluggable-tunnel) 分支有一个稍微不同的架构，\n提供了集成多路复用隧道的灵活性。_\n\n\u003cbr/\u003e\n\n#### 添加加密算法的步骤\n\n1. 实现统一的加密接口`IShadowsocksAeadCipher`或者`IShadowsocksStreamCipher`\n```c#\nclass MyCipher : IShadowsocksAeadCipher\n{\n    //implementation\n}\n```\n\n2. 使用`Cipher`特性标记\n```c#\n[Cipher(\"my-cipher-name\")]\nclass MyCipher : IShadowsocksAeadCipher\n{\n    //implementation\n}\n```\n此时`MyCipher`已被识别。\n\n\u003cbr/\u003e\n\n#### 对混淆的支持\n混淆同加密一样，在Shadowsocks-Net中都是通过管道过滤器来工作的。相对于加密，混淆的逻辑可能更复杂。\n但由于其他部分已被封装，现在只需关注网络流的读写，实现自己的过滤器`ClientFilter`即可。\n```c#\npublic interface IClientReaderFilter\n{\n    ClientFilterResult OnReading(ClientFilterContext filterContext);\n}\n```\n```c#\npublic interface IClientWriterFilter\n{\n    ClientFilterResult OnWriting(ClientFilterContext filterContext);        \n}\n```\nShadowsocks-Net中加密、混淆、对UDP转发的封包都是通过过滤器实现的。过滤器是可插拔模块。所以也可以使用过滤器来解析自定义协议。\n\n下面这个过滤器每次在发送之前向数据开头插入四个字节`0x12, 0x34, 0xAB, 0xCD`，相应地读取时跳过了开头四个字节：\n```c#\nclass TestClientFilter : ClientFilter\n{\n    public override ClientFilterResult OnWriting(ClientFilterContext ctx)\n    {\n        byte[] data = ctx.Memory.ToArray();\n        byte[] newData = new byte[data.Length + 4];\n        newData[0] = 0x12;\n        newData[1] = 0x34;\n        newData[2] = 0xAB;\n        newData[3] = 0xCD;\n        Array.Copy(data, 0, newData, 4, data.Length);\n        return new ClientFilterResult(ctx.Client, newData, ...);\n    }\n\n    public override ClientFilterResult OnReading(ClientFilterContext ctx)\n    {\n        byte[] data = ctx.Memory.ToArray();\n        byte[] newData = data.Skip(4).ToArray();\n        return new ClientFilterResult(ctx.Client, newData, ...);\n    }\n}\n```\n\u003cbr/\u003e\n\n##### 创建过滤器的步骤\n\n1. 选择合适的`Category`和`Priority`，它们决定了过滤器在过滤器链中的顺序。框架预置了几个`Category`：\n```c#\n    public enum ClientFilterCategory\n    {\n        Obfuscation = 1,\n        Cipher = 2,\n        Encapsulation = 3,\n        Custom = 4\n    }\n```\n\n2. 继承`ClientFilter`\n```c#\n    public abstract class ClientFilter\n    {\n        public abstract ClientFilterResult OnReading(ClientFilterContext filterContext);\n        public abstract ClientFilterResult OnWriting(ClientFilterContext filterContext);\n    }\n```\n\n3. 将过滤器添加至管道\n```c#\n    DuplexPipe.AddFilter(IClient client, IClientFilter filter);\n```\n\n一个典型的例子：[UdpEncapsulationFilter.cs](Shadowsocks-Net/Shadowsocks/Local/UdpEncapsulationFilter.cs)。\n\u003cbr/\u003e\n\n#### 对TCP或UDP之外协议的支持\n由于设计上抽象出了接口，其他通信协议现在也可以集成进来。实现自己的`IClient`和`IServer`即可，无需修改其他部分。\n`IClient`和`IServer`也很简单：\n\n```c#\npublic partial interface IClient : IPeer\n{        \n    ValueTask\u003cint\u003e ReadAsync(Memory\u003cbyte\u003e buffer, CancellationToken cancellationToken = default);\n    ValueTask\u003cint\u003e WriteAsync(ReadOnlyMemory\u003cbyte\u003e buffer, CancellationToken cancellationToken = default);\n    \n    IPEndPoint LocalEndPoint { get; }\n    void Close();\n    event EventHandler\u003cClientEventArgs\u003e Closing;\n}\n```\n```c#\npublic interface IServer : IPeer\n{\n    void Listen();\n    void StopListen();\n}\npublic interface IServer\u003cTClient\u003e : IServer\n    where TClient : IClient\n{\n    Task\u003cTClient\u003e Accept();       \n}\n```\n例如把KCP协议集成进来实现`KcpClient`和`KcpServer`，这时Shadowsocks-Net就使用KCP作为传输层协议。\n\n\u003cbr/\u003e\n\n## 编译\n#### 编译环境\nVisual Studio 2019 Community， .NET Framework 4.6（暂时用来设计winform），.NET Standard 2.1 \u0026 .NET Core 5.0。\n#### 如何编译\n在Visual Studio中生成整个解决方案即可。整个工程目前是100% C#，核心是.NET Standard 2.1的类库。\n\u003cbr/\u003e\n或者使用.NET Core CLI的`dotnet build`命令。发布用`dotnet publish`，发布单独可执行文件使用`dotnet publish -r \u003cRID\u003e -p:PublishSingleFile=true`\n\u003cbr/\u003e\n\n## Roadmap\n#### 任务列表\n- ☑ 核心重写\n- ☐ Windows端\n- ☐ 统一规则过滤器\n- ☐ 目标IP、域名过滤\n- ☐ Linux端\n\n\u003cbr/\u003e\n\n\n\n## Usage\n与使用其他版本的Shadowsocks类似。Minimal版已在Windows和Debian10 x64上测试，运行参数通过配置文件修改。\n\n以Windows为例：\n服务端修改`config.json`后执行`shadowsocks-net-remote.exe`：\n```json\n{\n  //\"server_host\": null,\n  \"server_port\": 6666,\n  \"use_ipv6\": false,\n  \"timeout\": 5,\n  \"password\": \"password1\",\n  \"method\": \"aes-128-gcm\"\n}\n```\n\n\u003cbr/\u003e\n\n客户端修改`servers.json`和`app-config.json`后执行`shadowsocks-net-local.exe`：\n```json\n[\n  {\n    \"remarks\": \"Test Server\",\n    \"server\": \"10.10.10.102\",\n    \"server_port\": 6666,\n    \"password\": \"password1\",\n    \"method\": \"aes-128-gcm\",\n    \"obfs\": null,\n    \"category\": null\n  }\n]\n```\n```json\n{\n \"Socks5Proxy\": {\n    \"Port\": 2080,\n    \"UseIPv6Address\": false,\n    \"UseLoopbackAddress\": true\n  },\n  \"HttpProxy\": {\n    \"Port\": 8080,\n    \"UseIPv6Address\": false,\n    \"UseLoopbackAddress\": true\n  }\n}\n\n```\nLinux上雷同。 安装[.NET Core传送门](https://dotnet.microsoft.com/download)。\n\u003cbr/\u003e\n\n## Contribute\n还有很多代码等待被添加。\n\u003cbr/\u003e\n\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n---\n\u003ca name=\"fn_local_http\"\u003elocal http\u003c/a\u003e：即本地socks5转http。\n\n[libev版]:https://github.com/shadowsocks/shadowsocks-libev\n[shadowsocks-windows]: https://github.com/shadowsocks/shadowsocks-windows\n[shadowsocks_net_arch]: https://github.com/shadowsocks/Shadowsocks-Net/blob/master/ssarch.png?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadowsocks%2Fshadowsocks-net","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshadowsocks%2Fshadowsocks-net","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshadowsocks%2Fshadowsocks-net/lists"}