# Conflicts:
#	FastTunnel.Server/Program.cs
This commit is contained in:
SpringHgui 2020-08-18 09:41:09 +08:00
commit 52c28f0fbd
7 changed files with 44 additions and 36 deletions

View File

@ -30,7 +30,7 @@ namespace FastTunnel.Client
{
var servicesProvider = new Host().Config(Config).Build();
RunAsync(servicesProvider);
Run(servicesProvider);
while (true)
{
@ -50,40 +50,40 @@ namespace FastTunnel.Client
}
}
private static async Task RunAsync(IServiceProvider servicesProvider)
private static void Run(IServiceProvider servicesProvider)
{
var client = servicesProvider.GetRequiredService<FastTunnelClient>();
var config = servicesProvider.GetRequiredService<ClientConfig>();
await client.LoginAsync(Task.Run(() =>
client.Login(() =>
{
Connecter _client;
Connecter _client;
try
{
// 连接到的目标IP
_client = new Connecter(config.Common.ServerAddr, config.Common.ServerPort);
_client.Connect();
}
catch (Exception ex)
{
Thread.Sleep(5000);
throw;
}
try
{
// 连接到的目标IP
_client = new Connecter(config.Common.ServerAddr, config.Common.ServerPort);
_client.Connect();
}
catch (Exception ex)
{
Thread.Sleep(5000);
throw;
}
// 登录
_client.Send(new Message<LogInMassage>
{
MessageType = MessageType.C_LogIn,
Content = new LogInMassage
{
Webs = config.Webs,
SSH = config.SSH
}
});
// 登录
_client.Send(new Message<LogInMassage>
{
MessageType = MessageType.C_LogIn,
Content = new LogInMassage
{
Webs = config.Webs,
SSH = config.SSH
}
});
return _client;
}), config.Common);
return _client;
}, config.Common);
while (true)
{

View File

@ -20,7 +20,7 @@
"LocalIp": "127.0.0.1",
//
"LocalPort": 8001,
"LocalPort": 80,
// , 访url http://{SubDomain}.{Domain}:{ProxyPort_HTTP}/
"SubDomain": "test" // test.test.cc

View File

@ -21,8 +21,10 @@ namespace FastTunnel.Core
Socket listener;
T _data;
bool Shutdown { get; set; }
// Thread signal.
public ManualResetEvent allDone = new ManualResetEvent(false);
ManualResetEvent allDone = new ManualResetEvent(false);
public AsyncListener(string ip, int port, ILogger<object> logerr, T data)
{
@ -56,7 +58,7 @@ namespace FastTunnel.Core
allDone.Reset();
// Start an asynchronous socket to listen for connections.
Console.WriteLine("Waiting for a connection...");
_logerr.LogDebug($"Waiting for a connection {listener.Handle}");
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
// Wait until a connection is made before continuing.
@ -73,6 +75,9 @@ namespace FastTunnel.Core
void AcceptCallback(IAsyncResult ar)
{
if (Shutdown)
return;
// Signal the main thread to continue.
allDone.Set();
@ -156,6 +161,7 @@ namespace FastTunnel.Core
public void ShutdownAndClose()
{
Shutdown = true;
try
{
listener.Shutdown(SocketShutdown.Both);

View File

@ -24,6 +24,7 @@ namespace FastTunnel.Core
if (sendTimeout.HasValue)
{
Socket.ReceiveTimeout = sendTimeout.Value;
Socket.SendTimeout = sendTimeout.Value;
}
else

View File

@ -27,7 +27,7 @@ namespace FastTunnel.Core.Core
System.Timers.Timer timer_timeout;
System.Timers.Timer timer_heart;
Task<Connecter> login;
Func<Connecter> lastLogin;
double heartInterval = 10 * 1000; // 10 秒心跳
public DateTime lastHeart;
Thread th;
@ -92,7 +92,7 @@ namespace FastTunnel.Core.Core
Close();
try
{
_client = await login;
_client = lastLogin.Invoke();
}
catch (Exception ex)
{
@ -124,14 +124,14 @@ namespace FastTunnel.Core.Core
}
}
public async Task LoginAsync(Task<Connecter> fun, SuiDaoServer serverConfig)
public void Login(Func<Connecter> login, SuiDaoServer serverConfig)
{
_serverConfig = serverConfig;
lastLogin = login;
login = fun;
try
{
_client = await login;
_client = lastLogin.Invoke();
}
catch (Exception ex)
{

View File

@ -227,6 +227,7 @@ namespace FastTunnel.Core.Core
catch (Exception ex)
{
_logger.LogError($"接收客户端异常 -> 退出登录 {ex.Message}");
if (client.Connected)
{
client.Close();

View File

@ -17,7 +17,7 @@ namespace FastTunnel.Core.Handlers.Client
connecter_ssh.Connect();
connecter_ssh.Send(new Message<SwapMassage> { MessageType = MessageType.C_SwapMsg, Content = new SwapMassage(request_ssh.MsgId) });
var localConnecter_ssh = new Connecter(request_ssh.SSHConfig.LocalIp, request_ssh.SSHConfig.LocalPort);
var localConnecter_ssh = new Connecter(request_ssh.SSHConfig.LocalIp, request_ssh.SSHConfig.LocalPort, 5000);
localConnecter_ssh.Connect();
new SocketSwap(connecter_ssh.Socket, localConnecter_ssh.Socket).StartSwap();