forked from shadowsocks/shadowsocks-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐚 Shadowsocks.CLI and Shadowsocks.Protocol
- CLI: client, server, utilities (unfinished) - Merge v5/pipelines by @studentmain into main (unfinished)
- Loading branch information
1 parent
73bc7ea
commit 4bdb134
Showing
37 changed files
with
1,957 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Shadowsocks.Protocol; | ||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shadowsocks.CLI | ||
{ | ||
internal class Program | ||
{ | ||
private static Task<int> Main(string[] args) | ||
{ | ||
var clientCommand = new Command("client", "Shadowsocks client."); | ||
clientCommand.AddAlias("c"); | ||
clientCommand.AddOption(new Option<string?>("--listen", "The address and port to listen on for both SOCKS5 and HTTP proxy.")); | ||
clientCommand.AddOption(new Option<string?>("--listen-socks", "The address and port to listen on for SOCKS5 proxy.")); | ||
clientCommand.AddOption(new Option<string?>("--listen-http", "The address and port to listen on for HTTP proxy.")); | ||
clientCommand.AddOption(new Option<string>("--server-address", "Address of the remote Shadowsocks server to connect to.")); | ||
clientCommand.AddOption(new Option<int>("--server-port", "Port of the remote Shadowsocks server to connect to.")); | ||
clientCommand.AddOption(new Option<string>("--method", "Encryption method to use for the remote Shadowsocks server.")); | ||
clientCommand.AddOption(new Option<string?>("--password", "Password to use for the remote Shadowsocks server.")); | ||
clientCommand.AddOption(new Option<string?>("--key", "Encryption key (NOT password!) to use for the remote Shadowsocks server.")); | ||
clientCommand.AddOption(new Option<string?>("--plugin", "Plugin binary path.")); | ||
clientCommand.AddOption(new Option<string?>("--plugin-opts", "Plugin options.")); | ||
clientCommand.AddOption(new Option<string?>("--plugin-args", "Plugin startup arguments.")); | ||
clientCommand.Handler = CommandHandler.Create( | ||
async (string? listen, string? listenSocks, string? listenHttp, string serverAddress, int serverPort, string method, string? password, string? key, string? plugin, string? pluginOpts, string? pluginArgs) => | ||
{ | ||
// TODO | ||
var localEP = IPEndPoint.Parse(listenSocks); | ||
var remoteEp = new DnsEndPoint(serverAddress, serverPort); | ||
byte[]? mainKey = null; | ||
if (!string.IsNullOrEmpty(key)) | ||
mainKey = Encoding.UTF8.GetBytes(key); | ||
var tcpPipeListener = new TcpPipeListener(localEP); | ||
tcpPipeListener.Start(localEP, remoteEp, method, password, mainKey).Wait(); | ||
}); | ||
|
||
var serverCommand = new Command("server", "Shadowsocks server."); | ||
serverCommand.AddAlias("s"); | ||
serverCommand.Handler = CommandHandler.Create( | ||
() => | ||
{ | ||
Console.WriteLine("Not implemented."); | ||
}); | ||
|
||
var utilitiesCommand = new Command("utilities", "Shadowsocks-related utilities."); | ||
utilitiesCommand.AddAlias("u"); | ||
utilitiesCommand.AddAlias("util"); | ||
utilitiesCommand.AddAlias("utils"); | ||
|
||
var rootCommand = new RootCommand("CLI for Shadowsocks server and client implementation in C#.") | ||
{ | ||
clientCommand, | ||
serverCommand, | ||
utilitiesCommand, | ||
}; | ||
|
||
Console.OutputEncoding = Encoding.UTF8; | ||
return rootCommand.InvokeAsync(args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<AssemblyName>sscli</AssemblyName> | ||
<PackageId>Shadowsocks.CLI</PackageId> | ||
<Authors>Clowwindy & The Community</Authors> | ||
<Product>Shadowsocks CLI</Product> | ||
<Description>CLI for Shadowsocks server and client implementation in C#.</Description> | ||
<Copyright>© 2021 Clowwindy & The Community</Copyright> | ||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile> | ||
<PackageProjectUrl>https://github.com/shadowsocks/shadowsocks-windows</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/shadowsocks/shadowsocks-windows</RepositoryUrl> | ||
<RepositoryType>Public</RepositoryType> | ||
<PackageIcon>ssw128.png</PackageIcon> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\LICENSE.txt"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
<None Include="..\Shadowsocks.WPF\Resources\ssw128.png"> | ||
<Pack>True</Pack> | ||
<PackagePath></PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shadowsocks.Interop\Shadowsocks.Interop.csproj" /> | ||
<ProjectReference Include="..\Shadowsocks.Protocol\Shadowsocks.Protocol.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.IO.Pipelines; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shadowsocks.Protocol.Direct | ||
{ | ||
public class PortForwardService : IStreamService | ||
{ | ||
public async Task<IDuplexPipe> Handle(IDuplexPipe pipe) => await Task.FromResult<IDuplexPipe>(null); | ||
|
||
public Task<bool> IsMyClient(IDuplexPipe pipe) => Task.FromResult(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.IO.Pipelines; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shadowsocks.Protocol | ||
{ | ||
class DuplexPipe : IDuplexPipe | ||
{ | ||
public PipeReader Input { get; set; } | ||
public PipeWriter Output { get; set; } | ||
|
||
public static Task CopyDuplexPipe(IDuplexPipe p1, IDuplexPipe p2) | ||
{ | ||
var t1 = p1.Input.CopyToAsync(p2.Output); | ||
var t2 = p2.Input.CopyToAsync(p1.Output); | ||
|
||
return Task.WhenAll(t1, t2); | ||
} | ||
} | ||
} |
Oops, something went wrong.