修复host解析失败问题

This commit is contained in:
SpringHgui 2021-06-20 11:35:21 +08:00
parent 98eb26bd6d
commit eb0d54e033
6 changed files with 70 additions and 6 deletions

View File

@ -28,7 +28,7 @@ namespace FastTunnel.Core.Dispatchers
_fastTunnelServer = fastTunnelServer;
}
static string pattern = @"[hH]ost:.+[\r\n]";
static string pattern = @"[hH]ost:.+";
public void Dispatch(AsyncUserToken token, string words)
{
@ -60,7 +60,7 @@ namespace FastTunnel.Core.Dispatchers
MatchCollection collection = Regex.Matches(words, pattern);
if (collection.Count == 0)
{
_logger.LogError($"Host异常{words}");
_logger.LogError($"Host异常{words}");
// 返回错误页
HandlerHostRequired(token.Socket);

View File

@ -57,7 +57,18 @@ namespace FastTunnel.Core.Listener
private bool handle(AsyncUserToken token, string words)
{
Message<JObject> msg = JsonConvert.DeserializeObject<Message<JObject>>(words);
Message<JObject> msg;
try
{
msg = JsonConvert.DeserializeObject<Message<JObject>>(words);
}
catch (Exception ex)
{
_logger.LogCritical(ex, $"【异常的指令】{words}");
token.Socket.Close();
return false;
}
IClientMessageHandler handler = null;
switch (msg.MessageType)

View File

@ -47,8 +47,17 @@ namespace FastTunnel.Core.Listener
private bool handle(AsyncUserToken token, string words)
{
Console.WriteLine(words);
_requestDispatcher.Dispatch(token, words);
try
{
Console.WriteLine(words);
_requestDispatcher.Dispatch(token, words);
return false;
}
catch (Exception ex)
{
_logger.LogCritical(ex, $"【处理HTTP请求异常】{words}");
}
return false;
}

View File

@ -42,7 +42,7 @@ namespace FastTunnel.Core.Server
m_numConnections = numConnections;
m_receiveBufferSize = receiveBufferSize;
// allocate buffers such that the maximum number of sockets can have one outstanding read and
//write posted to the socket simultaneously
// write posted to the socket simultaneously
m_bufferManager = new BufferManager(receiveBufferSize * numConnections * opsToPreAlloc,
receiveBufferSize);

View File

@ -7,6 +7,9 @@ using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Runtime.ExceptionServices;
using System.IO;
namespace FastTunnel.Core.Services
{
@ -19,6 +22,9 @@ namespace FastTunnel.Core.Services
{
_logger = logger;
_fastTunnelClient = fastTunnelClient;
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
public Task StartAsync(CancellationToken cancellationToken)
@ -34,5 +40,39 @@ namespace FastTunnel.Core.Services
_logger.LogInformation("===== FastTunnel Client Stoping =====");
return Task.CompletedTask;
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
_logger.LogError("【UnhandledException】" + e.ExceptionObject);
_logger.LogError("【UnhandledException】" + JsonConvert.SerializeObject(e.ExceptionObject));
var type = e.ExceptionObject.GetType();
_logger.LogError("ExceptionObject GetType " + type);
}
catch
{
}
}
private void CurrentDomain_FirstChanceException(object sender, FirstChanceExceptionEventArgs e)
{
if (e.Exception is DirectoryNotFoundException)
{
// nlog第一次找不到文件的错误跳过
}
else if (e.Exception is PlatformNotSupportedException)
{
// log4net
}
else if (e.Exception is IOException && e.Exception.Source == "System.Net.Security")
{
}
else
{
_logger.LogError(e.Exception, "【FirstChanceException】");
}
}
}
}

View File

@ -55,6 +55,10 @@ namespace FastTunnel.Core.Services
{
// nlog第一次找不到文件的错误跳过
}
else if (e.Exception is PlatformNotSupportedException)
{
// log4net
}
else if (e.Exception is IOException && e.Exception.Source == "System.Net.Security")
{
}