|
|
@ -8,6 +8,8 @@ using System.Threading; |
|
|
|
using System.IO; |
|
|
|
using System.Text; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Cryptography; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
namespace LTEMvcApp.Controllers |
|
|
|
{ |
|
|
@ -44,6 +46,19 @@ namespace LTEMvcApp.Controllers |
|
|
|
return address; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 工具方法:获取address的唯一hash
|
|
|
|
/// </summary>
|
|
|
|
private static string GetAddressHash(string address) |
|
|
|
{ |
|
|
|
using (var sha1 = SHA1.Create()) |
|
|
|
{ |
|
|
|
var bytes = Encoding.UTF8.GetBytes(address); |
|
|
|
var hashBytes = sha1.ComputeHash(bytes); |
|
|
|
return BitConverter.ToString(hashBytes).Replace("-", "").Substring(0, 8); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// SSE推送客户端消息流
|
|
|
|
/// </summary>
|
|
|
@ -75,10 +90,11 @@ namespace LTEMvcApp.Controllers |
|
|
|
int lastReceivedCount = 0; |
|
|
|
var cancellationToken = HttpContext.RequestAborted; |
|
|
|
|
|
|
|
// 使用安全文件名
|
|
|
|
// 使用安全文件名+唯一hash
|
|
|
|
var safeAddress = SanitizeFileName(address); |
|
|
|
var sentLogFilePath = Path.Combine(_logsDirectory, $"{safeAddress}_sent_messages.log"); |
|
|
|
var receivedLogFilePath = Path.Combine(_logsDirectory, $"{safeAddress}_received_messages.log"); |
|
|
|
var hash = GetAddressHash(address); |
|
|
|
var sentLogFilePath = Path.Combine(_logsDirectory, $"{safeAddress}_{hash}_sent_messages.log"); |
|
|
|
var receivedLogFilePath = Path.Combine(_logsDirectory, $"{safeAddress}_{hash}_received_messages.log"); |
|
|
|
|
|
|
|
while (!cancellationToken.IsCancellationRequested) |
|
|
|
{ |
|
|
|