mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
Merge branch 'master' of https://github.com/SpringHgui/FastTunnel
# Conflicts: # FastTunnel.Server/Program.cs
This commit is contained in:
commit
52c28f0fbd
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"LocalIp": "127.0.0.1",
|
||||
|
||||
// 站点监听的端口号
|
||||
"LocalPort": 8001,
|
||||
"LocalPort": 80,
|
||||
|
||||
// 子域名, 访问本站点时的url为 http://{SubDomain}.{Domain}:{ProxyPort_HTTP}/
|
||||
"SubDomain": "test" // test.test.cc
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace FastTunnel.Core
|
|||
|
||||
if (sendTimeout.HasValue)
|
||||
{
|
||||
Socket.ReceiveTimeout = sendTimeout.Value;
|
||||
Socket.SendTimeout = sendTimeout.Value;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -227,6 +227,7 @@ namespace FastTunnel.Core.Core
|
|||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"接收客户端异常 -> 退出登录 {ex.Message}");
|
||||
|
||||
if (client.Connected)
|
||||
{
|
||||
client.Close();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user