Browse Source

pass received url to controller

tags/4.2.0.0
Student Main database64128 5 years ago
parent
commit
e492bc02f4
2 changed files with 30 additions and 6 deletions
  1. +23
    -4
      shadowsocks-csharp/Controller/Service/PipeServer.cs
  2. +7
    -2
      shadowsocks-csharp/Program.cs

+ 23
- 4
shadowsocks-csharp/Controller/Service/PipeServer.cs View File

@@ -6,8 +6,20 @@ using System.Text;


namespace Shadowsocks.Controller namespace Shadowsocks.Controller
{ {
class RequestAddUrlEventArgs : EventArgs
{
public readonly string Url;

public RequestAddUrlEventArgs(string url)
{
this.Url = url;
}
}


internal class PipeServer internal class PipeServer
{ {
public event EventHandler<RequestAddUrlEventArgs> AddUrlRequested;
public async void Run(string path) public async void Run(string path)
{ {
byte[] buf = new byte[4096]; byte[] buf = new byte[4096];
@@ -17,10 +29,17 @@ namespace Shadowsocks.Controller
{ {
stream.WaitForConnection(); stream.WaitForConnection();
await stream.ReadAsync(buf, 0, 4); await stream.ReadAsync(buf, 0, 4);
int strlen = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buf, 0));
await stream.ReadAsync(buf, 0, strlen);
string url = Encoding.UTF8.GetString(buf, 0, strlen);
Console.WriteLine(url);
int opcode = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buf, 0));
if (opcode == 1)
{
await stream.ReadAsync(buf, 0, 4);
int strlen = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buf, 0));

await stream.ReadAsync(buf, 0, strlen);
string url = Encoding.UTF8.GetString(buf, 0, strlen);

AddUrlRequested?.Invoke(this, new RequestAddUrlEventArgs(url));
}
stream.Close(); stream.Close();
} }
} }


+ 7
- 2
shadowsocks-csharp/Program.cs View File

@@ -84,7 +84,9 @@ namespace Shadowsocks
if (!pipeExist) return; if (!pipeExist) return;


byte[] b = Encoding.UTF8.GetBytes(Args[urlidx]); byte[] b = Encoding.UTF8.GetBytes(Args[urlidx]);
byte[] opAddUrl = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(1));
byte[] blen = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(b.Length)); byte[] blen = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(b.Length));
pipe.Write(opAddUrl, 0, 4); // opcode addurl
pipe.Write(blen, 0, 4); pipe.Write(blen, 0, 4);
pipe.Write(b, 0, b.Length); pipe.Write(b, 0, b.Length);
pipe.Close(); pipe.Close();
@@ -105,8 +107,6 @@ namespace Shadowsocks
} }
} }


Task.Run(() => new PipeServer().Run(pipename));

Utils.ReleaseMemory(true); Utils.ReleaseMemory(true);


Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
@@ -133,6 +133,11 @@ namespace Shadowsocks
HotKeys.Init(MainController); HotKeys.Init(MainController);
MainController.Start(); MainController.Start();

PipeServer pipeServer = new PipeServer();
Task.Run(() => pipeServer.Run(pipename));
pipeServer.AddUrlRequested += (_1, e) => MainController.AddServerBySSURL(e.Url);

Application.Run(); Application.Run();
} }


Loading…
Cancel
Save