From c5175e52e93884aaccf1878ef77a5f77844116c5 Mon Sep 17 00:00:00 2001
From: SpringHgui <740360381@qq.com>
Date: Mon, 16 Dec 2019 10:29:06 +0800
Subject: [PATCH] init project
---
.gitignore | 3 +
FastTunnel.Client/Appsettings.cs | 14 ++
FastTunnel.Client/FastTunnel.Client.csproj | 27 +++
FastTunnel.Client/Program.cs | 40 ++++
FastTunnel.Client/SuiDao.Client.csproj.user | 6 +
FastTunnel.Client/appsettings.json | 31 +++
FastTunnel.Core/Client/SuiDaoClient.cs | 126 +++++++++++
FastTunnel.Core/Config/ClientConfig.cs | 22 ++
FastTunnel.Core/Config/ServerConfig.cs | 17 ++
FastTunnel.Core/Connecter.cs | 44 ++++
.../Exceptions/ClienOffLineException.cs | 14 ++
.../Extensions/MessageExtension.cs | 16 ++
FastTunnel.Core/Extensions/SocketExtension.cs | 16 ++
FastTunnel.Core/FastTunnel.Core.csproj | 14 ++
FastTunnel.Core/Listener.cs | 57 +++++
FastTunnel.Core/Logger/ConsoleLogger.cs | 29 +++
FastTunnel.Core/Logger/ILogger.cs | 17 ++
FastTunnel.Core/Models/LogInRequest.cs | 11 +
FastTunnel.Core/Models/Message.cs | 24 ++
FastTunnel.Core/Models/NewCustomerRequest.cs | 13 ++
FastTunnel.Core/Models/NewRequest.cs | 13 ++
FastTunnel.Core/Models/WebConfig.cs | 15 ++
FastTunnel.Core/Models/WebInfo.cs | 13 ++
FastTunnel.Core/Server/SuiDaoServer.cs | 205 ++++++++++++++++++
FastTunnel.Core/SocketSwap.cs | 94 ++++++++
FastTunnel.Core/SuiDao.Core.csproj.user | 6 +
FastTunnel.Server/Appsettings.cs | 15 ++
FastTunnel.Server/FastTunnel.Server.csproj | 25 +++
FastTunnel.Server/Program.cs | 40 ++++
FastTunnel.Server/SuiDao.Server.csproj.user | 6 +
FastTunnel.Server/appsettings.json | 16 ++
FastTunnel.sln | 37 ++++
LICENSE | 201 +++++++++++++++++
README.md | 7 +
34 files changed, 1234 insertions(+)
create mode 100644 .gitignore
create mode 100644 FastTunnel.Client/Appsettings.cs
create mode 100644 FastTunnel.Client/FastTunnel.Client.csproj
create mode 100644 FastTunnel.Client/Program.cs
create mode 100644 FastTunnel.Client/SuiDao.Client.csproj.user
create mode 100644 FastTunnel.Client/appsettings.json
create mode 100644 FastTunnel.Core/Client/SuiDaoClient.cs
create mode 100644 FastTunnel.Core/Config/ClientConfig.cs
create mode 100644 FastTunnel.Core/Config/ServerConfig.cs
create mode 100644 FastTunnel.Core/Connecter.cs
create mode 100644 FastTunnel.Core/Exceptions/ClienOffLineException.cs
create mode 100644 FastTunnel.Core/Extensions/MessageExtension.cs
create mode 100644 FastTunnel.Core/Extensions/SocketExtension.cs
create mode 100644 FastTunnel.Core/FastTunnel.Core.csproj
create mode 100644 FastTunnel.Core/Listener.cs
create mode 100644 FastTunnel.Core/Logger/ConsoleLogger.cs
create mode 100644 FastTunnel.Core/Logger/ILogger.cs
create mode 100644 FastTunnel.Core/Models/LogInRequest.cs
create mode 100644 FastTunnel.Core/Models/Message.cs
create mode 100644 FastTunnel.Core/Models/NewCustomerRequest.cs
create mode 100644 FastTunnel.Core/Models/NewRequest.cs
create mode 100644 FastTunnel.Core/Models/WebConfig.cs
create mode 100644 FastTunnel.Core/Models/WebInfo.cs
create mode 100644 FastTunnel.Core/Server/SuiDaoServer.cs
create mode 100644 FastTunnel.Core/SocketSwap.cs
create mode 100644 FastTunnel.Core/SuiDao.Core.csproj.user
create mode 100644 FastTunnel.Server/Appsettings.cs
create mode 100644 FastTunnel.Server/FastTunnel.Server.csproj
create mode 100644 FastTunnel.Server/Program.cs
create mode 100644 FastTunnel.Server/SuiDao.Server.csproj.user
create mode 100644 FastTunnel.Server/appsettings.json
create mode 100644 FastTunnel.sln
create mode 100644 LICENSE
create mode 100644 README.md
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2cd48b4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+bin
+obj
+.vs
diff --git a/FastTunnel.Client/Appsettings.cs b/FastTunnel.Client/Appsettings.cs
new file mode 100644
index 0000000..63c3286
--- /dev/null
+++ b/FastTunnel.Client/Appsettings.cs
@@ -0,0 +1,14 @@
+using FastTunnel.Core.Client;
+using FastTunnel.Core.Config;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Client
+{
+ public class Appsettings
+ {
+ public ClientConfig ClientSettings { get; set; }
+ }
+}
diff --git a/FastTunnel.Client/FastTunnel.Client.csproj b/FastTunnel.Client/FastTunnel.Client.csproj
new file mode 100644
index 0000000..5785046
--- /dev/null
+++ b/FastTunnel.Client/FastTunnel.Client.csproj
@@ -0,0 +1,27 @@
+
+
+
+ Exe
+ netcoreapp3.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
+
diff --git a/FastTunnel.Client/Program.cs b/FastTunnel.Client/Program.cs
new file mode 100644
index 0000000..f2ac9a9
--- /dev/null
+++ b/FastTunnel.Client/Program.cs
@@ -0,0 +1,40 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using FastTunnel.Core;
+using FastTunnel.Core.Client;
+using FastTunnel.Core.Logger;
+using System;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Client
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Client Start!");
+
+ var conf = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", true, true)
+ .Build();
+
+ var settings = conf.Get();
+
+ Run(settings);
+ }
+
+ private static void Run(Appsettings settings)
+ {
+ var FastTunnelClient = new FastTunnelClient(settings.ClientSettings, new ConsoleLogger());
+ FastTunnelClient.Login();
+
+ Console.ReadLine();
+ }
+ }
+}
diff --git a/FastTunnel.Client/SuiDao.Client.csproj.user b/FastTunnel.Client/SuiDao.Client.csproj.user
new file mode 100644
index 0000000..966b4ff
--- /dev/null
+++ b/FastTunnel.Client/SuiDao.Client.csproj.user
@@ -0,0 +1,6 @@
+
+
+
+ true
+
+
\ No newline at end of file
diff --git a/FastTunnel.Client/appsettings.json b/FastTunnel.Client/appsettings.json
new file mode 100644
index 0000000..309bf91
--- /dev/null
+++ b/FastTunnel.Client/appsettings.json
@@ -0,0 +1,31 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft": "Warning",
+ "Microsoft.Hosting.Lifetime": "Information"
+ }
+ },
+ "ClientSettings": {
+ "Common": {
+ // 服务端公网ip
+ "ServerAddr": "127.0.0.1",
+
+ // 服务端通信端口
+ "ServerPort": 1271
+ },
+ "Webs": [
+ {
+ // 本地站点所在内网的ip
+ "LocalIp": "127.0.0.1",
+
+ // 站点监听的端口号
+ "LocalPort": 9000,
+
+ // 子域名
+ "SubDomain": "test"
+ }
+ ]
+
+ }
+}
\ No newline at end of file
diff --git a/FastTunnel.Core/Client/SuiDaoClient.cs b/FastTunnel.Core/Client/SuiDaoClient.cs
new file mode 100644
index 0000000..a1aaba3
--- /dev/null
+++ b/FastTunnel.Core/Client/SuiDaoClient.cs
@@ -0,0 +1,126 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using FastTunnel.Core.Config;
+using FastTunnel.Core.Logger;
+using FastTunnel.Core.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace FastTunnel.Core.Client
+{
+ public class FastTunnelClient
+ {
+ ClientConfig _clientConfig;
+
+ Connecter connecter;
+
+ ILogger _logger;
+
+ public FastTunnelClient(ClientConfig clientConfig, ILogger logger)
+ {
+ _logger = logger;
+ _clientConfig = clientConfig;
+ connecter = new Connecter(_clientConfig.Common.ServerAddr, _clientConfig.Common.ServerPort);
+ }
+
+ public void Login()
+ {
+ //连接到的目标IP
+ connecter.Connect();
+
+ // 登录
+ connecter.Send(new Message { MessageType = MessageType.C_LogIn, Content = new LogInRequest { WebList = _clientConfig.Webs } });
+
+ _logger.Info("登录成功");
+ Thread th = new Thread(ReceiveServer);
+ th.IsBackground = true;
+ th.Start(connecter.Client);
+ }
+
+ private void ReceiveServer(object obj)
+ {
+ var client = obj as Socket;
+ byte[] buffer = new byte[1024];
+
+ string lastBuffer = string.Empty;
+ while (true)
+ {
+ int n = client.Receive(buffer);
+ string words = Encoding.UTF8.GetString(buffer, 0, n);
+ if (!string.IsNullOrEmpty(lastBuffer))
+ {
+ words = lastBuffer + words;
+ lastBuffer = null;
+ }
+
+ _logger.Info($"收到服务端 {words}");
+ var msgs = words.Split("\n");
+
+ try
+ {
+ foreach (var item in msgs)
+ {
+ if (!string.IsNullOrEmpty(item))
+ {
+ if (item.EndsWith("}"))
+ {
+ HandleServerRequest(item);
+ }
+ else
+ {
+ lastBuffer = item;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.Error(ex.Message);
+ continue;
+ }
+ }
+ }
+
+ private void HandleServerRequest(string words)
+ {
+ Message