mirror of
https://github.com/snltty/linker.git
synced 2025-10-18 15:10:43 +08:00
sync
This commit is contained in:
@@ -18,7 +18,7 @@ namespace linker.libs
|
|||||||
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||||
AppDomain.CurrentDomain.ProcessExit += (sender, e) => cancellationTokenSource.Cancel();
|
AppDomain.CurrentDomain.ProcessExit += (sender, e) => cancellationTokenSource.Cancel();
|
||||||
Console.CancelKeyPress += (sender, e) => cancellationTokenSource.Cancel();
|
Console.CancelKeyPress += (sender, e) => cancellationTokenSource.Cancel();
|
||||||
await Task.Delay(-1, cancellationTokenSource.Token);
|
await Task.Delay(-1, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DateTime startTime = new DateTime(1970, 1, 1);
|
static DateTime startTime = new DateTime(1970, 1, 1);
|
||||||
|
@@ -33,7 +33,7 @@ namespace linker.libs
|
|||||||
OnLogger?.Invoke(model);
|
OnLogger?.Invoke(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Task.Delay(15);
|
await Task.Delay(15).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -424,7 +424,7 @@ namespace linker.libs.winapis
|
|||||||
ntpData[0] = 0x1B;
|
ntpData[0] = 0x1B;
|
||||||
|
|
||||||
// 发送请求包并接收响应
|
// 发送请求包并接收响应
|
||||||
await client.SendAsync(ntpData, ntpData.Length);
|
await client.SendAsync(ntpData, ntpData.Length).ConfigureAwait(false);
|
||||||
byte[] responseData = client.Receive(ref endPoint);
|
byte[] responseData = client.Receive(ref endPoint);
|
||||||
|
|
||||||
// 关闭 UDP 客户端
|
// 关闭 UDP 客户端
|
||||||
|
@@ -44,7 +44,7 @@ namespace linker.service
|
|||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -157,7 +157,7 @@ namespace linker.tunnel
|
|||||||
ProtocolType = wanPortProtocol.ProtocolType,
|
ProtocolType = wanPortProtocol.ProtocolType,
|
||||||
Type = wanPortProtocol.Type,
|
Type = wanPortProtocol.Type,
|
||||||
});
|
});
|
||||||
await Task.WhenAll(localInfo, remoteInfo);
|
await Task.WhenAll(localInfo, remoteInfo).ConfigureAwait(false);
|
||||||
|
|
||||||
if (localInfo.Result == null)
|
if (localInfo.Result == null)
|
||||||
{
|
{
|
||||||
@@ -186,7 +186,7 @@ namespace linker.tunnel
|
|||||||
};
|
};
|
||||||
OnConnecting(tunnelTransportInfo);
|
OnConnecting(tunnelTransportInfo);
|
||||||
ParseRemoteEndPoint(tunnelTransportInfo);
|
ParseRemoteEndPoint(tunnelTransportInfo);
|
||||||
ITunnelConnection connection = await transport.ConnectAsync(tunnelTransportInfo);
|
ITunnelConnection connection = await transport.ConnectAsync(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
_OnConnected(connection);
|
_OnConnected(connection);
|
||||||
@@ -290,7 +290,7 @@ namespace linker.tunnel
|
|||||||
public async Task<TunnelTransportWanPortInfo> GetWanPort(TunnelWanPortProtocolInfo _info)
|
public async Task<TunnelTransportWanPortInfo> GetWanPort(TunnelWanPortProtocolInfo _info)
|
||||||
{
|
{
|
||||||
TunnelWanPortInfo info = tunnelAdapter.GetTunnelWanPortProtocols().FirstOrDefault(c => c.Type == _info.Type && c.ProtocolType == _info.ProtocolType);
|
TunnelWanPortInfo info = tunnelAdapter.GetTunnelWanPortProtocols().FirstOrDefault(c => c.Type == _info.Type && c.ProtocolType == _info.ProtocolType);
|
||||||
return await GetLocalInfo(info);
|
return await GetLocalInfo(info).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -299,7 +299,7 @@ namespace linker.tunnel
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<TunnelTransportWanPortInfo> GetLocalInfo(TunnelWanPortInfo info)
|
private async Task<TunnelTransportWanPortInfo> GetLocalInfo(TunnelWanPortInfo info)
|
||||||
{
|
{
|
||||||
TunnelWanPortEndPoint ip = await compactTransfer.GetWanPortAsync(tunnelAdapter.LocalIP, info);
|
TunnelWanPortEndPoint ip = await compactTransfer.GetWanPortAsync(tunnelAdapter.LocalIP, info).ConfigureAwait(false);
|
||||||
if (ip != null)
|
if (ip != null)
|
||||||
{
|
{
|
||||||
var config = tunnelAdapter.GetLocalConfig();
|
var config = tunnelAdapter.GetLocalConfig();
|
||||||
|
@@ -88,7 +88,7 @@ namespace linker.tunnel.connection
|
|||||||
{
|
{
|
||||||
while (cancellationTokenSource.IsCancellationRequested == false)
|
while (cancellationTokenSource.IsCancellationRequested == false)
|
||||||
{
|
{
|
||||||
int length = await Stream.ReadAsync(buffer, cancellationTokenSource.Token);
|
int length = await Stream.ReadAsync(buffer, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
ReceiveBytes += length;
|
ReceiveBytes += length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
@@ -153,7 +153,7 @@ namespace linker.tunnel.connection
|
|||||||
{
|
{
|
||||||
if (packet.Span.SequenceEqual(pingBytes))
|
if (packet.Span.SequenceEqual(pingBytes))
|
||||||
{
|
{
|
||||||
await SendPingPong(pongBytes);
|
await SendPingPong(pongBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (packet.Span.SequenceEqual(pongBytes))
|
else if (packet.Span.SequenceEqual(pongBytes))
|
||||||
{
|
{
|
||||||
@@ -182,9 +182,9 @@ namespace linker.tunnel.connection
|
|||||||
if (Environment.TickCount64 - ticks > 3000)
|
if (Environment.TickCount64 - ticks > 3000)
|
||||||
{
|
{
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -199,10 +199,10 @@ namespace linker.tunnel.connection
|
|||||||
data.Length.ToBytes(heartData);
|
data.Length.ToBytes(heartData);
|
||||||
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
||||||
|
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Stream.WriteAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token);
|
await Stream.WriteAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -222,15 +222,15 @@ namespace linker.tunnel.connection
|
|||||||
if (pong == false) return;
|
if (pong == false) return;
|
||||||
pong = false;
|
pong = false;
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
private SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1);
|
private SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1);
|
||||||
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
||||||
{
|
{
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Stream.WriteAsync(data, cancellationTokenSource.Token);
|
await Stream.WriteAsync(data, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
SendBytes += data.Length;
|
SendBytes += data.Length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -82,7 +82,7 @@ namespace linker.tunnel.connection
|
|||||||
|
|
||||||
if (Stream != null)
|
if (Stream != null)
|
||||||
{
|
{
|
||||||
length = await Stream.ReadAsync(buffer);
|
length = await Stream.ReadAsync(buffer).ConfigureAwait(false);
|
||||||
if (length == 0) break;
|
if (length == 0) break;
|
||||||
ReceiveBytes += length;
|
ReceiveBytes += length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
@@ -90,7 +90,7 @@ namespace linker.tunnel.connection
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
length = await Socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None);
|
length = await Socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None).ConfigureAwait(false);
|
||||||
if (length == 0) break;
|
if (length == 0) break;
|
||||||
ReceiveBytes += length;
|
ReceiveBytes += length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
@@ -161,7 +161,7 @@ namespace linker.tunnel.connection
|
|||||||
{
|
{
|
||||||
if (packet.Span.SequenceEqual(pingBytes))
|
if (packet.Span.SequenceEqual(pingBytes))
|
||||||
{
|
{
|
||||||
await SendPingPong(pongBytes);
|
await SendPingPong(pongBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (packet.Span.SequenceEqual(pongBytes))
|
else if (packet.Span.SequenceEqual(pongBytes))
|
||||||
{
|
{
|
||||||
@@ -189,10 +189,10 @@ namespace linker.tunnel.connection
|
|||||||
if (Environment.TickCount64 - ticks > 3000)
|
if (Environment.TickCount64 - ticks > 3000)
|
||||||
{
|
{
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -207,17 +207,17 @@ namespace linker.tunnel.connection
|
|||||||
data.Length.ToBytes(heartData);
|
data.Length.ToBytes(heartData);
|
||||||
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
||||||
|
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Stream != null)
|
if (Stream != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
await Stream.WriteAsync(heartData.AsMemory(0, length));
|
await Stream.WriteAsync(heartData.AsMemory(0, length)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Socket.SendAsync(heartData.AsMemory(0, length));
|
await Socket.SendAsync(heartData.AsMemory(0, length)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -240,23 +240,23 @@ namespace linker.tunnel.connection
|
|||||||
if (pong == false) return;
|
if (pong == false) return;
|
||||||
pong = false;
|
pong = false;
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
||||||
{
|
{
|
||||||
if (callback == null) return false;
|
if (callback == null) return false;
|
||||||
|
|
||||||
if (Stream != null)
|
if (Stream != null)
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Stream != null)
|
if (Stream != null)
|
||||||
{
|
{
|
||||||
await Stream.WriteAsync(data);
|
await Stream.WriteAsync(data).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Socket.SendAsync(data, SocketFlags.None);
|
await Socket.SendAsync(data, SocketFlags.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
SendBytes += data.Length;
|
SendBytes += data.Length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
|
@@ -72,7 +72,7 @@ namespace linker.tunnel.connection
|
|||||||
{
|
{
|
||||||
while (cancellationTokenSource.IsCancellationRequested == false)
|
while (cancellationTokenSource.IsCancellationRequested == false)
|
||||||
{
|
{
|
||||||
UdpReceiveResult result = await UdpClient.ReceiveAsync(cancellationTokenSource.Token);
|
UdpReceiveResult result = await UdpClient.ReceiveAsync(cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
ReceiveBytes += result.Buffer.Length;
|
ReceiveBytes += result.Buffer.Length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
if (result.Buffer.Length == 0)
|
if (result.Buffer.Length == 0)
|
||||||
@@ -102,7 +102,7 @@ namespace linker.tunnel.connection
|
|||||||
{
|
{
|
||||||
if (packet.Span.SequenceEqual(pingBytes))
|
if (packet.Span.SequenceEqual(pingBytes))
|
||||||
{
|
{
|
||||||
await SendPingPong(pongBytes);
|
await SendPingPong(pongBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (packet.Span.SequenceEqual(pongBytes))
|
else if (packet.Span.SequenceEqual(pongBytes))
|
||||||
{
|
{
|
||||||
@@ -131,9 +131,9 @@ namespace linker.tunnel.connection
|
|||||||
if (Environment.TickCount64 - ticks > 3000)
|
if (Environment.TickCount64 - ticks > 3000)
|
||||||
{
|
{
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -150,7 +150,7 @@ namespace linker.tunnel.connection
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await UdpClient.SendAsync(heartData.AsMemory(0, length), IPEndPoint, cancellationTokenSource.Token);
|
await UdpClient.SendAsync(heartData.AsMemory(0, length), IPEndPoint, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -169,13 +169,13 @@ namespace linker.tunnel.connection
|
|||||||
if (pong == false) return;
|
if (pong == false) return;
|
||||||
pong = false;
|
pong = false;
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
public async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await UdpClient.SendAsync(data, IPEndPoint, cancellationTokenSource.Token);
|
await UdpClient.SendAsync(data, IPEndPoint, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
SendBytes += data.Length;
|
SendBytes += data.Length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -54,7 +54,7 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Socket socket = await token.Socket.AcceptAsync();
|
Socket socket = await token.Socket.AcceptAsync().ConfigureAwait(false);
|
||||||
ProcessAccept(token, socket);
|
ProcessAccept(token, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ namespace linker.tunnel.proxy
|
|||||||
}
|
}
|
||||||
private async Task BeginReceive(AsyncUserToken token)
|
private async Task BeginReceive(AsyncUserToken token)
|
||||||
{
|
{
|
||||||
int length = await token.Socket.ReceiveAsync(token.Buffer.AsMemory(), SocketFlags.None);
|
int length = await token.Socket.ReceiveAsync(token.Buffer.AsMemory(), SocketFlags.None).ConfigureAwait(false);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
{
|
{
|
||||||
CloseClientSocket(token);
|
CloseClientSocket(token);
|
||||||
@@ -128,7 +128,7 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int length = await token.Socket.ReceiveAsync(token.Buffer.AsMemory(), SocketFlags.None);
|
int length = await token.Socket.ReceiveAsync(token.Buffer.AsMemory(), SocketFlags.None).ConfigureAwait(false);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -265,7 +265,7 @@ namespace linker.tunnel.proxy
|
|||||||
|
|
||||||
if (state.Data.Length > 0)
|
if (state.Data.Length > 0)
|
||||||
{
|
{
|
||||||
await token.Socket.SendAsync(state.Data.AsMemory(0, state.Length), SocketFlags.None);
|
await token.Socket.SendAsync(state.Data.AsMemory(0, state.Length), SocketFlags.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
tcpConnections.TryAdd(new ConnectId(token.Proxy.ConnectId, token.Connection.GetHashCode(), (byte)ProxyDirection.Forward), token);
|
tcpConnections.TryAdd(new ConnectId(token.Proxy.ConnectId, token.Connection.GetHashCode(), (byte)ProxyDirection.Forward), token);
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await token1.Socket.SendAsync(tunnelToken.Proxy.Data, SocketFlags.None).ConfigureAwait(false);
|
await token1.Socket.SendAsync(tunnelToken.Proxy.Data, SocketFlags.None).AsTask().WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@@ -48,11 +48,11 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await token.SourceSocket.ReceiveFromAsync(bytes, TempRemoteEP);
|
SocketReceiveFromResult result = await token.SourceSocket.ReceiveFromAsync(bytes, TempRemoteEP).ConfigureAwait(false);
|
||||||
|
|
||||||
token.Proxy.SourceEP = result.RemoteEndPoint as IPEndPoint;
|
token.Proxy.SourceEP = result.RemoteEndPoint as IPEndPoint;
|
||||||
token.Proxy.Data = bytes.AsMemory(0, result.ReceivedBytes);
|
token.Proxy.Data = bytes.AsMemory(0, result.ReceivedBytes);
|
||||||
await ConnectTunnelConnection(token);
|
await ConnectTunnelConnection(token).ConfigureAwait(false);
|
||||||
if (token.Proxy.TargetEP != null)
|
if (token.Proxy.TargetEP != null)
|
||||||
{
|
{
|
||||||
if (token.Connection != null)
|
if (token.Connection != null)
|
||||||
@@ -87,7 +87,7 @@ namespace linker.tunnel.proxy
|
|||||||
if (token.Connection == null) return;
|
if (token.Connection == null) return;
|
||||||
|
|
||||||
SemaphoreSlim semaphoreSlim = token.Proxy.Direction == ProxyDirection.Forward ? semaphoreSlimForward : semaphoreSlimReverse;
|
SemaphoreSlim semaphoreSlim = token.Proxy.Direction == ProxyDirection.Forward ? semaphoreSlimForward : semaphoreSlimReverse;
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
byte[] connectData = token.Proxy.ToBytes(out int length);
|
byte[] connectData = token.Proxy.ToBytes(out int length);
|
||||||
try
|
try
|
||||||
@@ -116,7 +116,7 @@ namespace linker.tunnel.proxy
|
|||||||
private async Task SendToConnections(AsyncUserUdpToken token)
|
private async Task SendToConnections(AsyncUserUdpToken token)
|
||||||
{
|
{
|
||||||
SemaphoreSlim semaphoreSlim = token.Proxy.Direction == ProxyDirection.Forward ? semaphoreSlimForward : semaphoreSlimReverse;
|
SemaphoreSlim semaphoreSlim = token.Proxy.Direction == ProxyDirection.Forward ? semaphoreSlimForward : semaphoreSlimReverse;
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
byte[] connectData = token.Proxy.ToBytes(out int length);
|
byte[] connectData = token.Proxy.ToBytes(out int length);
|
||||||
try
|
try
|
||||||
@@ -160,7 +160,7 @@ namespace linker.tunnel.proxy
|
|||||||
if (udpConnections.TryGetValue(connectId, out AsyncUserUdpTokenTarget token))
|
if (udpConnections.TryGetValue(connectId, out AsyncUserUdpTokenTarget token))
|
||||||
{
|
{
|
||||||
token.Connection = tunnelToken.Connection;
|
token.Connection = tunnelToken.Connection;
|
||||||
await token.TargetSocket.SendToAsync(tunnelToken.Proxy.Data, target);
|
await token.TargetSocket.SendToAsync(tunnelToken.Proxy.Data, target).ConfigureAwait(false);
|
||||||
token.Update();
|
token.Update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -185,9 +185,9 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (await ConnectionReceiveUdp(tunnelToken, asyncUserUdpToken) == false)
|
if (await ConnectionReceiveUdp(tunnelToken, asyncUserUdpToken).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
await asyncUserUdpToken.SourceSocket.SendToAsync(tunnelToken.Proxy.Data, tunnelToken.Proxy.SourceEP);
|
await asyncUserUdpToken.SourceSocket.SendToAsync(tunnelToken.Proxy.Data, tunnelToken.Proxy.SourceEP).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -204,7 +204,7 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
Socket socket = new Socket(target.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
|
Socket socket = new Socket(target.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
|
||||||
socket.WindowsUdpBug();
|
socket.WindowsUdpBug();
|
||||||
await socket.SendToAsync(tunnelToken.Proxy.Data, target);
|
await socket.SendToAsync(tunnelToken.Proxy.Data, target).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
||||||
ConnectIdUdp connectId = new ConnectIdUdp(tunnelToken.Proxy.ConnectId, tunnelToken.Proxy.SourceEP, tunnelToken.Connection.GetHashCode());
|
ConnectIdUdp connectId = new ConnectIdUdp(tunnelToken.Proxy.ConnectId, tunnelToken.Proxy.SourceEP, tunnelToken.Connection.GetHashCode());
|
||||||
@@ -233,10 +233,10 @@ namespace linker.tunnel.proxy
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await socket.ReceiveFromAsync(udpToken.Buffer, SocketFlags.None, target);
|
SocketReceiveFromResult result = await socket.ReceiveFromAsync(udpToken.Buffer, SocketFlags.None, target).ConfigureAwait(false);
|
||||||
udpToken.Proxy.Data = udpToken.Buffer.AsMemory(0, result.ReceivedBytes);
|
udpToken.Proxy.Data = udpToken.Buffer.AsMemory(0, result.ReceivedBytes);
|
||||||
udpToken.Update();
|
udpToken.Update();
|
||||||
await SendToConnection(udpToken);
|
await SendToConnection(udpToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -318,7 +318,7 @@ namespace linker.tunnel.proxy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -77,13 +77,13 @@ namespace linker.tunnel.transport
|
|||||||
if (QuicListener.IsSupported == false)
|
if (QuicListener.IsSupported == false)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (tunnelAdapter.Certificate == null)
|
if (tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
LoggerHelper.Instance.Error($"msquic need ssl");
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,15 +91,15 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
||||||
{
|
{
|
||||||
//正向连接
|
//正向连接
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,21 +108,21 @@ namespace linker.tunnel.transport
|
|||||||
//反向连接
|
//反向连接
|
||||||
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
||||||
_ = ListenRemoteConnect(tunnelTransportInfo.BufferSize, tunnelTransportInfo1.Local.Local, quicListenEP, tunnelTransportInfo1);
|
_ = ListenRemoteConnect(tunnelTransportInfo.BufferSize, tunnelTransportInfo1.Local.Local, quicListenEP, tunnelTransportInfo1);
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
BindAndTTL(tunnelTransportInfo1);
|
BindAndTTL(tunnelTransportInfo1);
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo1) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo1).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1);
|
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -137,34 +137,34 @@ namespace linker.tunnel.transport
|
|||||||
if (QuicListener.IsSupported == false)
|
if (QuicListener.IsSupported == false)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
LoggerHelper.Instance.Error($"msquic not supported, need win11+,or linux");
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tunnelAdapter.Certificate == null)
|
if (tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"msquic need ssl");
|
LoggerHelper.Instance.Error($"msquic need ssl");
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
||||||
{
|
{
|
||||||
_ = ListenRemoteConnect(tunnelTransportInfo.BufferSize, tunnelTransportInfo.Local.Local, quicListenEP, tunnelTransportInfo);
|
_ = ListenRemoteConnect(tunnelTransportInfo.BufferSize, tunnelTransportInfo.Local.Local, quicListenEP, tunnelTransportInfo);
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
BindAndTTL(tunnelTransportInfo);
|
BindAndTTL(tunnelTransportInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
OnConnected(connection);
|
OnConnected(connection);
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,9 +196,9 @@ namespace linker.tunnel.transport
|
|||||||
}
|
}
|
||||||
if (ep.AddressFamily == AddressFamily.InterNetwork)
|
if (ep.AddressFamily == AddressFamily.InterNetwork)
|
||||||
{
|
{
|
||||||
await remoteUdp.SendToAsync(authBytes, ep);
|
await remoteUdp.SendToAsync(authBytes, ep).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -211,7 +211,7 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IPEndPoint remoteEP = await taskCompletionSource.Task.WaitAsync(TimeSpan.FromMilliseconds(500));
|
IPEndPoint remoteEP = await taskCompletionSource.Task.WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
//绑定一个udp,用来给QUIC链接
|
//绑定一个udp,用来给QUIC链接
|
||||||
Socket quicUdp = ListenQuicConnect(tunnelTransportInfo.BufferSize, remoteUdp, remoteEP);
|
Socket quicUdp = ListenQuicConnect(tunnelTransportInfo.BufferSize, remoteUdp, remoteEP);
|
||||||
QuicConnection connection = connection = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions
|
QuicConnection connection = connection = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions
|
||||||
@@ -230,8 +230,8 @@ namespace linker.tunnel.transport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).AsTask().WaitAsync(TimeSpan.FromMilliseconds(5000));
|
}).AsTask().WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
||||||
QuicStream quicStream = await connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional);
|
QuicStream quicStream = await connection.OpenOutboundStreamAsync(QuicStreamType.Bidirectional).ConfigureAwait(false);
|
||||||
return new TunnelConnectionMsQuic
|
return new TunnelConnectionMsQuic
|
||||||
{
|
{
|
||||||
QuicUdp = quicUdp,
|
QuicUdp = quicUdp,
|
||||||
@@ -329,7 +329,7 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(10000));
|
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(10000)).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -363,10 +363,10 @@ namespace linker.tunnel.transport
|
|||||||
IPEndPoint tempEp = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort);
|
IPEndPoint tempEp = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort);
|
||||||
|
|
||||||
//收到远端的消息,表明对方已收到,再给它发个结束消息,表示可以正常通信了
|
//收到远端的消息,表明对方已收到,再给它发个结束消息,表示可以正常通信了
|
||||||
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer.AsMemory(), tempEp);
|
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer.AsMemory(), tempEp).ConfigureAwait(false);
|
||||||
IPEndPoint ep = result.RemoteEndPoint as IPEndPoint;
|
IPEndPoint ep = result.RemoteEndPoint as IPEndPoint;
|
||||||
|
|
||||||
await socketUdp.SendToAsync(endBytes, ep);
|
await socketUdp.SendToAsync(endBytes, ep).ConfigureAwait(false);
|
||||||
tcs.SetResult(ep);
|
tcs.SetResult(ep);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -459,7 +459,7 @@ namespace linker.tunnel.transport
|
|||||||
udpClient.WindowsUdpBug();
|
udpClient.WindowsUdpBug();
|
||||||
_ = WaitAuth(bufferSize, token, tcs);
|
_ = WaitAuth(bufferSize, token, tcs);
|
||||||
|
|
||||||
AddressFamily af = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(30000));
|
AddressFamily af = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(30000)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -695,23 +695,23 @@ namespace linker.tunnel.transport
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
quicListenEP = new IPEndPoint(IPAddress.Loopback, listener.LocalEndPoint.Port);
|
quicListenEP = new IPEndPoint(IPAddress.Loopback, listener.LocalEndPoint.Port);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QuicConnection quicConnection = await listener.AcceptConnectionAsync();
|
QuicConnection quicConnection = await listener.AcceptConnectionAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
QuicStream quicStream = await quicConnection.AcceptInboundStreamAsync();
|
QuicStream quicStream = await quicConnection.AcceptInboundStreamAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
if (stateDic.TryRemove(quicConnection.RemoteEndPoint.Port, out ListenAsyncToken token))
|
if (stateDic.TryRemove(quicConnection.RemoteEndPoint.Port, out ListenAsyncToken token))
|
||||||
{
|
{
|
||||||
await OnUdpConnected(token.State, token.RemoteUdp, token.QuicUdp, token.RemoteEP, quicConnection, quicStream);
|
await OnUdpConnected(token.State, token.RemoteUdp, token.QuicUdp, token.RemoteEP, quicConnection, quicStream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -60,15 +60,15 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
||||||
{
|
{
|
||||||
//正向连接
|
//正向连接
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await Task.Delay(500);
|
await Task.Delay(500).ConfigureAwait(false);
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,21 +78,21 @@ namespace linker.tunnel.transport
|
|||||||
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
||||||
_ = StartListen(tunnelTransportInfo1.Local.Local, tunnelTransportInfo1);
|
_ = StartListen(tunnelTransportInfo1.Local.Local, tunnelTransportInfo1);
|
||||||
BindAndTTL(tunnelTransportInfo1);
|
BindAndTTL(tunnelTransportInfo1);
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo1) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo1).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//等待对方连接,如果连接成功,我会收到一个socket,并且创建一个连接对象,失败的话会超时,那就是null
|
//等待对方连接,如果连接成功,我会收到一个socket,并且创建一个连接对象,失败的话会超时,那就是null
|
||||||
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1);
|
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -104,7 +104,7 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.SSL && tunnelAdapter.Certificate == null)
|
if (tunnelTransportInfo.SSL && tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"{Name}->ssl Certificate not found");
|
LoggerHelper.Instance.Error($"{Name}->ssl Certificate not found");
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//正向连接,也就是它要连接我,那我就监听
|
//正向连接,也就是它要连接我,那我就监听
|
||||||
@@ -120,15 +120,15 @@ namespace linker.tunnel.transport
|
|||||||
//我要连它,那就连接
|
//我要连它,那就连接
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
OnConnected(connection);
|
OnConnected(connection);
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,14 +169,14 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"{Name} connect to {tunnelTransportInfo.Remote.MachineId}->{tunnelTransportInfo.Remote.MachineName} {ep}");
|
LoggerHelper.Instance.Warning($"{Name} connect to {tunnelTransportInfo.Remote.MachineId}->{tunnelTransportInfo.Remote.MachineName} {ep}");
|
||||||
}
|
}
|
||||||
await targetSocket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(ep.Address.Equals(tunnelTransportInfo.Remote.Remote.Address) ? 500 : 100));
|
await targetSocket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(ep.Address.Equals(tunnelTransportInfo.Remote.Remote.Address) ? 500 : 100)).ConfigureAwait(false);
|
||||||
|
|
||||||
//需要ssl
|
//需要ssl
|
||||||
SslStream sslStream = null;
|
SslStream sslStream = null;
|
||||||
if (tunnelTransportInfo.SSL)
|
if (tunnelTransportInfo.SSL)
|
||||||
{
|
{
|
||||||
sslStream = new SslStream(new NetworkStream(targetSocket, false), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
sslStream = new SslStream(new NetworkStream(targetSocket, false), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
||||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13 });
|
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13 }).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TunnelConnectionTcp
|
return new TunnelConnectionTcp
|
||||||
@@ -241,7 +241,7 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(5000));
|
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -272,7 +272,7 @@ namespace linker.tunnel.transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
sslStream = new SslStream(new NetworkStream(socket, false), false);
|
sslStream = new SslStream(new NetworkStream(socket, false), false);
|
||||||
await sslStream.AuthenticateAsServerAsync(tunnelAdapter.Certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
await sslStream.AuthenticateAsServerAsync(tunnelAdapter.Certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
TunnelConnectionTcp result = new TunnelConnectionTcp
|
TunnelConnectionTcp result = new TunnelConnectionTcp
|
||||||
@@ -326,8 +326,8 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Socket client = await socket.AcceptAsync().WaitAsync(TimeSpan.FromMilliseconds(30000));
|
Socket client = await socket.AcceptAsync().WaitAsync(TimeSpan.FromMilliseconds(30000)).ConfigureAwait(false);
|
||||||
await OnTcpConnected(tunnelTransportInfo, client);
|
await OnTcpConnected(tunnelTransportInfo, client).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@@ -61,19 +61,19 @@ namespace linker.tunnel.transport
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<ITunnelConnection> ConnectAsync(TunnelTransportInfo tunnelTransportInfo)
|
public async Task<ITunnelConnection> ConnectAsync(TunnelTransportInfo tunnelTransportInfo)
|
||||||
{
|
{
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo, TunnelMode.Client);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo, TunnelMode.Client).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,18 +85,18 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.SSL && tunnelAdapter.Certificate == null)
|
if (tunnelTransportInfo.SSL && tunnelAdapter.Certificate == null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"{Name}->ssl Certificate not found");
|
LoggerHelper.Instance.Error($"{Name}->ssl Certificate not found");
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo, TunnelMode.Server);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo, TunnelMode.Server).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
OnConnected(connection);
|
OnConnected(connection);
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,13 +126,13 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"{Name} connect to {tunnelTransportInfo.Remote.MachineId}->{tunnelTransportInfo.Remote.MachineName} {ep}");
|
LoggerHelper.Instance.Warning($"{Name} connect to {tunnelTransportInfo.Remote.MachineId}->{tunnelTransportInfo.Remote.MachineName} {ep}");
|
||||||
}
|
}
|
||||||
await targetSocket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(500));
|
await targetSocket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
|
|
||||||
if (mode == TunnelMode.Client)
|
if (mode == TunnelMode.Client)
|
||||||
{
|
{
|
||||||
return await TcpClient(tunnelTransportInfo, targetSocket);
|
return await TcpClient(tunnelTransportInfo, targetSocket).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return await TcpServer(tunnelTransportInfo, targetSocket);
|
return await TcpServer(tunnelTransportInfo, targetSocket).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -148,9 +148,9 @@ namespace linker.tunnel.transport
|
|||||||
private async Task<ITunnelConnection> TcpClient(TunnelTransportInfo state, Socket socket)
|
private async Task<ITunnelConnection> TcpClient(TunnelTransportInfo state, Socket socket)
|
||||||
{
|
{
|
||||||
//随便发个消息看对方有没有收到
|
//随便发个消息看对方有没有收到
|
||||||
await socket.SendAsync(authBytes);
|
await socket.SendAsync(authBytes).ConfigureAwait(false);
|
||||||
//如果对方收到,会回个消息,不管是啥,回了就行
|
//如果对方收到,会回个消息,不管是啥,回了就行
|
||||||
int length = await socket.ReceiveAsync(new byte[1024]);
|
int length = await socket.ReceiveAsync(new byte[1024]).ConfigureAwait(false);
|
||||||
if (length == 0) return null;
|
if (length == 0) return null;
|
||||||
|
|
||||||
//需要ssl
|
//需要ssl
|
||||||
@@ -158,7 +158,7 @@ namespace linker.tunnel.transport
|
|||||||
if (state.SSL)
|
if (state.SSL)
|
||||||
{
|
{
|
||||||
sslStream = new SslStream(new NetworkStream(socket, false), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
sslStream = new SslStream(new NetworkStream(socket, false), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
||||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13 });
|
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13 }).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TunnelConnectionTcp
|
return new TunnelConnectionTcp
|
||||||
@@ -184,13 +184,13 @@ namespace linker.tunnel.transport
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
//对方会随便发个消息,不管是啥
|
//对方会随便发个消息,不管是啥
|
||||||
int length = await socket.ReceiveAsync(new byte[1024]);
|
int length = await socket.ReceiveAsync(new byte[1024]).ConfigureAwait(false);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//回个消息给它就完了
|
//回个消息给它就完了
|
||||||
await socket.SendAsync(endBytes);
|
await socket.SendAsync(endBytes).ConfigureAwait(false);
|
||||||
|
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
SslStream sslStream = null;
|
SslStream sslStream = null;
|
||||||
@@ -204,7 +204,7 @@ namespace linker.tunnel.transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
sslStream = new SslStream(new NetworkStream(socket, false), false);
|
sslStream = new SslStream(new NetworkStream(socket, false), false);
|
||||||
await sslStream.AuthenticateAsServerAsync(tunnelAdapter.Certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
await sslStream.AuthenticateAsServerAsync(tunnelAdapter.Certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TunnelConnectionTcp
|
return new TunnelConnectionTcp
|
||||||
|
@@ -45,15 +45,15 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
||||||
{
|
{
|
||||||
//正向连接
|
//正向连接
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await Task.Delay(500);
|
await Task.Delay(500).ConfigureAwait(false);
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,21 +62,21 @@ namespace linker.tunnel.transport
|
|||||||
//反向连接
|
//反向连接
|
||||||
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
TunnelTransportInfo tunnelTransportInfo1 = tunnelTransportInfo.ToJsonFormat().DeJson<TunnelTransportInfo>();
|
||||||
_ = BindListen(tunnelTransportInfo1.Local.Local, tunnelTransportInfo1);
|
_ = BindListen(tunnelTransportInfo1.Local.Local, tunnelTransportInfo1);
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
BindAndTTL(tunnelTransportInfo1);
|
BindAndTTL(tunnelTransportInfo1);
|
||||||
if (await OnSendConnectBegin(tunnelTransportInfo1) == false)
|
if (await OnSendConnectBegin(tunnelTransportInfo1).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1);
|
ITunnelConnection connection = await WaitReverse(tunnelTransportInfo1).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public async Task OnBegin(TunnelTransportInfo tunnelTransportInfo)
|
public async Task OnBegin(TunnelTransportInfo tunnelTransportInfo)
|
||||||
@@ -84,21 +84,21 @@ namespace linker.tunnel.transport
|
|||||||
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
if (tunnelTransportInfo.Direction == TunnelDirection.Forward)
|
||||||
{
|
{
|
||||||
_ = BindListen(tunnelTransportInfo.Local.Local, tunnelTransportInfo);
|
_ = BindListen(tunnelTransportInfo.Local.Local, tunnelTransportInfo);
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
BindAndTTL(tunnelTransportInfo);
|
BindAndTTL(tunnelTransportInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo);
|
ITunnelConnection connection = await ConnectForward(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
OnConnected(connection);
|
OnConnected(connection);
|
||||||
await OnSendConnectSuccess(tunnelTransportInfo);
|
await OnSendConnectSuccess(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await OnSendConnectFail(tunnelTransportInfo);
|
await OnSendConnectFail(tunnelTransportInfo).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
remoteUdp6.Send(authBytes, ep);
|
remoteUdp6.Send(authBytes, ep);
|
||||||
}
|
}
|
||||||
await Task.Delay(50);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -146,7 +146,7 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IPEndPoint remoteEP = await taskCompletionSource.Task.WaitAsync(TimeSpan.FromMilliseconds(500));
|
IPEndPoint remoteEP = await taskCompletionSource.Task.WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
//绑定一个udp,用来给QUIC链接
|
//绑定一个udp,用来给QUIC链接
|
||||||
UdpClient localUdp = remoteEP.AddressFamily == AddressFamily.InterNetwork ? remoteUdp : remoteUdp6;
|
UdpClient localUdp = remoteEP.AddressFamily == AddressFamily.InterNetwork ? remoteUdp : remoteUdp6;
|
||||||
if (remoteEP.AddressFamily == AddressFamily.InterNetwork)
|
if (remoteEP.AddressFamily == AddressFamily.InterNetwork)
|
||||||
@@ -261,7 +261,7 @@ namespace linker.tunnel.transport
|
|||||||
};
|
};
|
||||||
_ = ListenReceiveCallback(token6);
|
_ = ListenReceiveCallback(token6);
|
||||||
|
|
||||||
AddressFamily af = await token.Tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(30000));
|
AddressFamily af = await token.Tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(30000)).ConfigureAwait(false);
|
||||||
|
|
||||||
if (af == AddressFamily.InterNetwork)
|
if (af == AddressFamily.InterNetwork)
|
||||||
{
|
{
|
||||||
@@ -290,7 +290,7 @@ namespace linker.tunnel.transport
|
|||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
UdpReceiveResult result = await token.LocalUdp.ReceiveAsync();
|
UdpReceiveResult result = await token.LocalUdp.ReceiveAsync().ConfigureAwait(false);
|
||||||
if (result.Buffer.Length == 0) break;
|
if (result.Buffer.Length == 0) break;
|
||||||
|
|
||||||
if (result.Buffer.Length == endBytes.Length && result.Buffer.AsSpan().SequenceEqual(endBytes))
|
if (result.Buffer.Length == endBytes.Length && result.Buffer.AsSpan().SequenceEqual(endBytes))
|
||||||
@@ -298,7 +298,7 @@ namespace linker.tunnel.transport
|
|||||||
if (token.Tcs != null && token.Tcs.Task.IsCompleted == false)
|
if (token.Tcs != null && token.Tcs.Task.IsCompleted == false)
|
||||||
{
|
{
|
||||||
token.Tcs.SetResult(result.RemoteEndPoint.AddressFamily);
|
token.Tcs.SetResult(result.RemoteEndPoint.AddressFamily);
|
||||||
await OnUdpConnected(token.State, token.LocalUdp, result.RemoteEndPoint);
|
await OnUdpConnected(token.State, token.LocalUdp, result.RemoteEndPoint).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ namespace linker.tunnel.transport
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(5000));
|
ITunnelConnection connection = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@@ -27,8 +27,8 @@ namespace linker.tunnel.wanport
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await udpClient.SendAsync(new byte[1] { 0 }, server);
|
await udpClient.SendAsync(new byte[1] { 0 }, server).ConfigureAwait(false);
|
||||||
UdpReceiveResult result = await udpClient.ReceiveAsync().WaitAsync(TimeSpan.FromMilliseconds(500));
|
UdpReceiveResult result = await udpClient.ReceiveAsync().WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
if (result.Buffer.Length == 0)
|
if (result.Buffer.Length == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -75,10 +75,10 @@ namespace linker.tunnel.wanport
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Socket socket = new Socket(server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
Socket socket = new Socket(server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
||||||
await socket.ConnectAsync(server);
|
await socket.ConnectAsync(server).ConfigureAwait(false);
|
||||||
|
|
||||||
await socket.SendAsync(new byte[] { 0 });
|
await socket.SendAsync(new byte[] { 0 });
|
||||||
int length = await socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None);
|
int length = await socket.ReceiveAsync(buffer.AsMemory(), SocketFlags.None).ConfigureAwait(false);
|
||||||
|
|
||||||
for (int j = 0; j < length; j++)
|
for (int j = 0; j < length; j++)
|
||||||
{
|
{
|
||||||
|
@@ -30,10 +30,10 @@ namespace linker.tunnel.wanport
|
|||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||||
0x00,0x01,0x00,0x00
|
0x00,0x01,0x00,0x00
|
||||||
};
|
};
|
||||||
await udpClient.SendAsync(stunRequest, stunRequest.Length);
|
await udpClient.SendAsync(stunRequest, stunRequest.Length).ConfigureAwait(false);
|
||||||
|
|
||||||
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
|
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
|
||||||
UdpReceiveResult stunResponse = await udpClient.ReceiveAsync();
|
UdpReceiveResult stunResponse = await udpClient.ReceiveAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
Memory<byte> data = stunResponse.Buffer.AsMemory(20);
|
Memory<byte> data = stunResponse.Buffer.AsMemory(20);
|
||||||
ushort attrTyoe = BitConverter.ToUInt16(data.Span);
|
ushort attrTyoe = BitConverter.ToUInt16(data.Span);
|
||||||
|
@@ -49,7 +49,7 @@ namespace linker.tunnel.wanport
|
|||||||
{
|
{
|
||||||
LoggerHelper.Instance.Warning($"get domain ip time:{sw.ElapsedMilliseconds}ms");
|
LoggerHelper.Instance.Warning($"get domain ip time:{sw.ElapsedMilliseconds}ms");
|
||||||
}
|
}
|
||||||
TunnelWanPortEndPoint WanPort = await tunnelWanPort.GetAsync(server);
|
TunnelWanPortEndPoint WanPort = await tunnelWanPort.GetAsync(server).ConfigureAwait(false);
|
||||||
if (WanPort != null)
|
if (WanPort != null)
|
||||||
{
|
{
|
||||||
WanPort.Local.Address = localIP;
|
WanPort.Local.Address = localIP;
|
||||||
|
@@ -11,7 +11,7 @@ namespace linker
|
|||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
Run(args);
|
Run(args);
|
||||||
await Helper.Await();
|
await Helper.Await().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Run(string[] args)
|
public static void Run(string[] args)
|
||||||
|
@@ -50,7 +50,7 @@ namespace linker.client
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await SignIn();
|
await SignIn().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -58,7 +58,7 @@ namespace linker.client
|
|||||||
LoggerHelper.Instance.Error(ex);
|
LoggerHelper.Instance.Error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Task.Delay(10000);
|
await Task.Delay(10000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -85,16 +85,16 @@ namespace linker.client
|
|||||||
|
|
||||||
IPEndPoint ip = NetworkHelper.GetEndPoint(config.Data.Client.Server, 1802);
|
IPEndPoint ip = NetworkHelper.GetEndPoint(config.Data.Client.Server, 1802);
|
||||||
|
|
||||||
if (await ConnectServer(ip) == false)
|
if (await ConnectServer(ip).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await SignIn2Server() == false)
|
if (await SignIn2Server().ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await GetServerVersion();
|
await GetServerVersion().ConfigureAwait(false);
|
||||||
|
|
||||||
GCHelper.FlushMemory();
|
GCHelper.FlushMemory();
|
||||||
clientSignInState.PushNetworkEnabled();
|
clientSignInState.PushNetworkEnabled();
|
||||||
@@ -189,7 +189,7 @@ namespace linker.client
|
|||||||
Socket socket = new Socket(remote.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
Socket socket = new Socket(remote.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
await socket.ConnectAsync(remote).WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
await socket.ConnectAsync(remote).WaitAsync(TimeSpan.FromMilliseconds(5000)).ConfigureAwait(false);
|
||||||
clientSignInState.Connection = await tcpServer.BeginReceive(socket);
|
clientSignInState.Connection = await tcpServer.BeginReceive(socket).ConfigureAwait(false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ namespace linker.client
|
|||||||
Args = args,
|
Args = args,
|
||||||
GroupId = config.Data.Client.GroupId,
|
GroupId = config.Data.Client.GroupId,
|
||||||
})
|
})
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code == MessageResponeCodes.OK)
|
if (resp.Code == MessageResponeCodes.OK)
|
||||||
{
|
{
|
||||||
if (resp.Data.Span.SequenceEqual(Helper.FalseArray) == false)
|
if (resp.Data.Span.SequenceEqual(Helper.FalseArray) == false)
|
||||||
@@ -238,7 +238,7 @@ namespace linker.client
|
|||||||
{
|
{
|
||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.Version,
|
MessengerId = (ushort)SignInMessengerIds.Version,
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code == MessageResponeCodes.OK)
|
if (resp.Code == MessageResponeCodes.OK)
|
||||||
{
|
{
|
||||||
clientSignInState.Version = MemoryPackSerializer.Deserialize<string>(resp.Data.Span);
|
clientSignInState.Version = MemoryPackSerializer.Deserialize<string>(resp.Data.Span);
|
||||||
|
@@ -51,7 +51,7 @@ namespace linker.client.config
|
|||||||
Save();
|
Save();
|
||||||
Data.Updated--;
|
Data.Updated--;
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ namespace linker.plugins.forward
|
|||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
Stop();
|
Stop();
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
Start();
|
Start();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ namespace linker.plugins.forward
|
|||||||
public async Task<Dictionary<IPEndPoint, string>> Test(ForwardTestInfo forwardTestInfo)
|
public async Task<Dictionary<IPEndPoint, string>> Test(ForwardTestInfo forwardTestInfo)
|
||||||
{
|
{
|
||||||
var results = forwardTestInfo.EndPoints.Select(ConnectAsync);
|
var results = forwardTestInfo.EndPoints.Select(ConnectAsync);
|
||||||
await Task.Delay(200);
|
await Task.Delay(200).ConfigureAwait(false);
|
||||||
return results.Select(c => c.Result).Where(c => string.IsNullOrWhiteSpace(c.Item2) == false).ToDictionary(c => c.Item1, d => d.Item2);
|
return results.Select(c => c.Result).Where(c => string.IsNullOrWhiteSpace(c.Item2) == false).ToDictionary(c => c.Item1, d => d.Item2);
|
||||||
|
|
||||||
async Task<(IPEndPoint, string)> ConnectAsync(IPEndPoint ep)
|
async Task<(IPEndPoint, string)> ConnectAsync(IPEndPoint ep)
|
||||||
@@ -182,7 +182,7 @@ namespace linker.plugins.forward
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100));
|
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
|
||||||
socket.SafeClose();
|
socket.SafeClose();
|
||||||
return (ep, string.Empty);
|
return (ep, string.Empty);
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ namespace linker.plugins.forward
|
|||||||
{
|
{
|
||||||
foreach (var item in running.Data.Forwards.Where(c => c.Port > 0))
|
foreach (var item in running.Data.Forwards.Where(c => c.Port > 0))
|
||||||
{
|
{
|
||||||
string msg = await ConnectAsync(new IPEndPoint(item.BindIPAddress, item.Port));
|
string msg = await ConnectAsync(new IPEndPoint(item.BindIPAddress, item.Port)).ConfigureAwait(false);
|
||||||
item.Msg = msg;
|
item.Msg = msg;
|
||||||
if (string.IsNullOrWhiteSpace(msg) == false)
|
if (string.IsNullOrWhiteSpace(msg) == false)
|
||||||
{
|
{
|
||||||
@@ -235,7 +235,7 @@ namespace linker.plugins.forward
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100));
|
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
|
||||||
socket.SafeClose();
|
socket.SafeClose();
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
@@ -40,7 +40,7 @@ namespace linker.plugins.forward.messenger
|
|||||||
RequestId = requestid,
|
RequestId = requestid,
|
||||||
Connection = connection,
|
Connection = connection,
|
||||||
Payload = result.Result.Data
|
Payload = result.Result.Data
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ namespace linker.plugins.forward.messenger
|
|||||||
RequestId = requestid,
|
RequestId = requestid,
|
||||||
Connection = connection,
|
Connection = connection,
|
||||||
Payload = MemoryPackSerializer.Serialize(result.Result)
|
Payload = MemoryPackSerializer.Serialize(result.Result)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ namespace linker.plugins.forward.proxy
|
|||||||
if (caches.TryGetValue(token.ListenPort, out ForwardProxyCacheInfo cache))
|
if (caches.TryGetValue(token.ListenPort, out ForwardProxyCacheInfo cache))
|
||||||
{
|
{
|
||||||
token.Proxy.TargetEP = cache.TargetEP;
|
token.Proxy.TargetEP = cache.TargetEP;
|
||||||
cache.Connection = await ConnectTunnel(cache.MachineId);
|
cache.Connection = await ConnectTunnel(cache.MachineId).ConfigureAwait(false);
|
||||||
token.Connection = cache.Connection;
|
token.Connection = cache.Connection;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -66,7 +66,7 @@ namespace linker.plugins.forward.proxy
|
|||||||
if (caches.TryGetValue(token.ListenPort, out ForwardProxyCacheInfo cache))
|
if (caches.TryGetValue(token.ListenPort, out ForwardProxyCacheInfo cache))
|
||||||
{
|
{
|
||||||
token.Proxy.TargetEP = cache.TargetEP;
|
token.Proxy.TargetEP = cache.TargetEP;
|
||||||
cache.Connection = await ConnectTunnel(cache.MachineId);
|
cache.Connection = await ConnectTunnel(cache.MachineId).ConfigureAwait(false);
|
||||||
token.Connection = cache.Connection;
|
token.Connection = cache.Connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,14 +86,14 @@ namespace linker.plugins.forward.proxy
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
//不要同时去连太多,锁以下
|
//不要同时去连太多,锁以下
|
||||||
await slimGlobal.WaitAsync();
|
await slimGlobal.WaitAsync().ConfigureAwait(false);
|
||||||
if (locks.TryGetValue(machineId, out SemaphoreSlim slim) == false)
|
if (locks.TryGetValue(machineId, out SemaphoreSlim slim) == false)
|
||||||
{
|
{
|
||||||
slim = new SemaphoreSlim(1);
|
slim = new SemaphoreSlim(1);
|
||||||
locks.TryAdd(machineId, slim);
|
locks.TryAdd(machineId, slim);
|
||||||
}
|
}
|
||||||
slimGlobal.Release();
|
slimGlobal.Release();
|
||||||
await slim.WaitAsync();
|
await slim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//获得锁之前再次看看之前有没有连接成功
|
//获得锁之前再次看看之前有没有连接成功
|
||||||
@@ -104,7 +104,7 @@ namespace linker.plugins.forward.proxy
|
|||||||
|
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward tunnel to {machineId}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward tunnel to {machineId}");
|
||||||
//打洞
|
//打洞
|
||||||
connection = await tunnelTransfer.ConnectAsync(machineId, "forward");
|
connection = await tunnelTransfer.ConnectAsync(machineId, "forward").ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward tunnel to {machineId} success");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward tunnel to {machineId} success");
|
||||||
@@ -114,7 +114,7 @@ namespace linker.plugins.forward.proxy
|
|||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward relay to {machineId}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward relay to {machineId}");
|
||||||
//尝试中继
|
//尝试中继
|
||||||
connection = await relayTransfer.ConnectAsync(config.Data.Client.Id, machineId, "forward");
|
connection = await relayTransfer.ConnectAsync(config.Data.Client.Id, machineId, "forward").ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward relay to {machineId} success");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"forward relay to {machineId} success");
|
||||||
|
@@ -53,7 +53,7 @@ namespace linker.plugins.relay
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)RelayMessengerIds.ServersForward,
|
MessengerId = (ushort)RelayMessengerIds.ServersForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info.List)
|
Payload = MemoryPackSerializer.Serialize(info.List)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -137,7 +137,7 @@ namespace linker.plugins.relay
|
|||||||
};
|
};
|
||||||
|
|
||||||
LoggerHelper.Instance.Info($"relay to {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} {relayInfo.ToJson()}");
|
LoggerHelper.Instance.Info($"relay to {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} {relayInfo.ToJson()}");
|
||||||
ITunnelConnection connection = await transport.RelayAsync(relayInfo);
|
ITunnelConnection connection = await transport.RelayAsync(relayInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Debug($"relay to {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} success,{relayInfo.ToJson()}");
|
LoggerHelper.Instance.Debug($"relay to {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} success,{relayInfo.ToJson()}");
|
||||||
@@ -178,7 +178,7 @@ namespace linker.plugins.relay
|
|||||||
ITransport _transports = transports.FirstOrDefault(c => c.Name == relayInfo.TransportName);
|
ITransport _transports = transports.FirstOrDefault(c => c.Name == relayInfo.TransportName);
|
||||||
if (_transports != null)
|
if (_transports != null)
|
||||||
{
|
{
|
||||||
ITunnelConnection connection = await _transports.OnBeginAsync(relayInfo);
|
ITunnelConnection connection = await _transports.OnBeginAsync(relayInfo).ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Debug($"relay from {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} success,{relayInfo.ToJson()}");
|
LoggerHelper.Instance.Debug($"relay from {relayInfo.RemoteMachineId}->{relayInfo.RemoteMachineName} success,{relayInfo.ToJson()}");
|
||||||
|
@@ -28,7 +28,7 @@ namespace linker.plugins.relay.messenger
|
|||||||
public async Task Relay(IConnection connection)
|
public async Task Relay(IConnection connection)
|
||||||
{
|
{
|
||||||
RelayInfo info = MemoryPackSerializer.Deserialize<RelayInfo>(connection.ReceiveRequestWrap.Payload.Span);
|
RelayInfo info = MemoryPackSerializer.Deserialize<RelayInfo>(connection.ReceiveRequestWrap.Payload.Span);
|
||||||
bool res = await relayTransfer.OnBeginAsync(info);
|
bool res = await relayTransfer.OnBeginAsync(info).ConfigureAwait(false);
|
||||||
connection.Write(res ? Helper.TrueArray : Helper.FalseArray);
|
connection.Write(res ? Helper.TrueArray : Helper.FalseArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ namespace linker.plugins.relay.messenger
|
|||||||
Connection = item.Connection,
|
Connection = item.Connection,
|
||||||
MessengerId = (ushort)RelayMessengerIds.Servers,
|
MessengerId = (ushort)RelayMessengerIds.Servers,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,14 +132,14 @@ namespace linker.plugins.relay.messenger
|
|||||||
Connection = cacheTo.Connection,
|
Connection = cacheTo.Connection,
|
||||||
MessengerId = (ushort)RelayMessengerIds.Relay,
|
MessengerId = (ushort)RelayMessengerIds.Relay,
|
||||||
Payload = MemoryPackSerializer.Serialize(info)
|
Payload = MemoryPackSerializer.Serialize(info)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (res == false)
|
if (res == false)
|
||||||
{
|
{
|
||||||
connection.Write(Helper.FalseArray);
|
connection.Write(Helper.FalseArray);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IConnection targetConnection = await tcsWrap.Tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(3000));
|
IConnection targetConnection = await tcsWrap.Tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(3000)).ConfigureAwait(false);
|
||||||
|
|
||||||
_ = Relay(connection, targetConnection, info.SecretKey);
|
_ = Relay(connection, targetConnection, info.SecretKey);
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ namespace linker.plugins.relay.messenger
|
|||||||
|
|
||||||
private async Task Relay(IConnection source, IConnection target, string secretKey)
|
private async Task Relay(IConnection source, IConnection target, string secretKey)
|
||||||
{
|
{
|
||||||
await Task.Delay(100);
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
|
|
||||||
source.TargetStream = target.SourceStream;
|
source.TargetStream = target.SourceStream;
|
||||||
source.TargetSocket = target.SourceSocket;
|
source.TargetSocket = target.SourceSocket;
|
||||||
@@ -185,9 +185,9 @@ namespace linker.plugins.relay.messenger
|
|||||||
source.Cancel();
|
source.Cancel();
|
||||||
target.Cancel();
|
target.Cancel();
|
||||||
|
|
||||||
await Task.Delay(200);
|
await Task.Delay(200).ConfigureAwait(false);
|
||||||
|
|
||||||
await Task.WhenAll(source.RelayAsync(config.Data.Server.Relay.BufferSize), target.RelayAsync(config.Data.Server.Relay.BufferSize));
|
await Task.WhenAll(source.RelayAsync(config.Data.Server.Relay.BufferSize), target.RelayAsync(config.Data.Server.Relay.BufferSize)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class TcsWrap
|
public sealed class TcsWrap
|
||||||
|
@@ -44,7 +44,7 @@ namespace linker.plugins.relay.transport
|
|||||||
{
|
{
|
||||||
Socket socket = new Socket(relayInfo.Server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
Socket socket = new Socket(relayInfo.Server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
await socket.ConnectAsync(relayInfo.Server).WaitAsync(TimeSpan.FromMilliseconds(500));
|
await socket.ConnectAsync(relayInfo.Server).WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
|
|
||||||
IConnection connection = await tcpServer.BeginReceive(socket);
|
IConnection connection = await tcpServer.BeginReceive(socket);
|
||||||
MessageResponeInfo resp = await messengerSender.SendReply(new MessageRequestWrap
|
MessageResponeInfo resp = await messengerSender.SendReply(new MessageRequestWrap
|
||||||
@@ -53,7 +53,7 @@ namespace linker.plugins.relay.transport
|
|||||||
MessengerId = (ushort)RelayMessengerIds.RelayForward,
|
MessengerId = (ushort)RelayMessengerIds.RelayForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(relayInfo),
|
Payload = MemoryPackSerializer.Serialize(relayInfo),
|
||||||
Timeout = 2000
|
Timeout = 2000
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code != MessageResponeCodes.OK || resp.Data.Span.SequenceEqual(Helper.TrueArray) == false)
|
if (resp.Code != MessageResponeCodes.OK || resp.Data.Span.SequenceEqual(Helper.TrueArray) == false)
|
||||||
{
|
{
|
||||||
connection.Disponse(7);
|
connection.Disponse(7);
|
||||||
@@ -61,7 +61,7 @@ namespace linker.plugins.relay.transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
connection.Cancel();
|
connection.Cancel();
|
||||||
await Task.Delay(500);
|
await Task.Delay(500).ConfigureAwait(false);
|
||||||
ClearSocket(socket);
|
ClearSocket(socket);
|
||||||
|
|
||||||
SslStream sslStream = null;
|
SslStream sslStream = null;
|
||||||
@@ -71,7 +71,7 @@ namespace linker.plugins.relay.transport
|
|||||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
||||||
{
|
{
|
||||||
EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13
|
EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TunnelConnectionTcp
|
return new TunnelConnectionTcp
|
||||||
@@ -112,7 +112,7 @@ namespace linker.plugins.relay.transport
|
|||||||
{
|
{
|
||||||
Socket socket = new Socket(relayInfo.Server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
Socket socket = new Socket(relayInfo.Server.AddressFamily, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
await socket.ConnectAsync(relayInfo.Server).WaitAsync(TimeSpan.FromMilliseconds(500));
|
await socket.ConnectAsync(relayInfo.Server).WaitAsync(TimeSpan.FromMilliseconds(500)).ConfigureAwait(false);
|
||||||
|
|
||||||
IConnection connection = await tcpServer.BeginReceive(socket);
|
IConnection connection = await tcpServer.BeginReceive(socket);
|
||||||
await messengerSender.SendOnly(new MessageRequestWrap
|
await messengerSender.SendOnly(new MessageRequestWrap
|
||||||
@@ -120,9 +120,9 @@ namespace linker.plugins.relay.transport
|
|||||||
Connection = connection,
|
Connection = connection,
|
||||||
MessengerId = (ushort)RelayMessengerIds.RelayForward,
|
MessengerId = (ushort)RelayMessengerIds.RelayForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(relayInfo)
|
Payload = MemoryPackSerializer.Serialize(relayInfo)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
connection.Cancel();
|
connection.Cancel();
|
||||||
await Task.Delay(100);
|
await Task.Delay(100).ConfigureAwait(false);
|
||||||
ClearSocket(socket);
|
ClearSocket(socket);
|
||||||
|
|
||||||
SslStream sslStream = null;
|
SslStream sslStream = null;
|
||||||
@@ -134,7 +134,7 @@ namespace linker.plugins.relay.transport
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
sslStream = new SslStream(connection.SourceNetworkStream, false);
|
sslStream = new SslStream(connection.SourceNetworkStream, false);
|
||||||
await sslStream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
await sslStream.AuthenticateAsServerAsync(certificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return new TunnelConnectionTcp
|
return new TunnelConnectionTcp
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ namespace linker.plugins.sforward
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SForwardMessengerIds.SecretKeyForward,
|
MessengerId = (ushort)SForwardMessengerIds.SecretKeyForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info.SForwardSecretKey)
|
Payload = MemoryPackSerializer.Serialize(info.SForwardSecretKey)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -136,7 +136,7 @@ namespace linker.plugins.sforward
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var results = running.Data.SForwards.Select(c => c.LocalEP).Select(ConnectAsync);
|
var results = running.Data.SForwards.Select(c => c.LocalEP).Select(ConnectAsync);
|
||||||
await Task.Delay(200);
|
await Task.Delay(200).ConfigureAwait(false);
|
||||||
|
|
||||||
foreach (var item in results.Select(c => c.Result))
|
foreach (var item in results.Select(c => c.Result))
|
||||||
{
|
{
|
||||||
@@ -158,7 +158,7 @@ namespace linker.plugins.sforward
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100));
|
await socket.ConnectAsync(ep).WaitAsync(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
|
||||||
socket.SafeClose();
|
socket.SafeClose();
|
||||||
return (ep, string.Empty);
|
return (ep, string.Empty);
|
||||||
}
|
}
|
||||||
|
@@ -166,7 +166,7 @@ namespace linker.plugins.sforward.messenger
|
|||||||
Connection = item.Connection,
|
Connection = item.Connection,
|
||||||
MessengerId = (ushort)SForwardMessengerIds.SecretKey,
|
MessengerId = (ushort)SForwardMessengerIds.SecretKey,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ namespace linker.plugins.sforward.messenger
|
|||||||
Connection = sign.Connection,
|
Connection = sign.Connection,
|
||||||
MessengerId = (ushort)SForwardMessengerIds.Proxy,
|
MessengerId = (ushort)SForwardMessengerIds.Proxy,
|
||||||
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { Domain = host, RemotePort = port, Id = id, BufferSize= configWrap.Data.Server.SForward.BufferSize })
|
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { Domain = host, RemotePort = port, Id = id, BufferSize= configWrap.Data.Server.SForward.BufferSize })
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ namespace linker.plugins.sforward.messenger
|
|||||||
Connection = sign.Connection,
|
Connection = sign.Connection,
|
||||||
MessengerId = (ushort)SForwardMessengerIds.Proxy,
|
MessengerId = (ushort)SForwardMessengerIds.Proxy,
|
||||||
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { RemotePort = port, Id = id, BufferSize = configWrap.Data.Server.SForward.BufferSize })
|
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { RemotePort = port, Id = id, BufferSize = configWrap.Data.Server.SForward.BufferSize })
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ namespace linker.plugins.sforward.messenger
|
|||||||
Connection = sign.Connection,
|
Connection = sign.Connection,
|
||||||
MessengerId = (ushort)SForwardMessengerIds.ProxyUdp,
|
MessengerId = (ushort)SForwardMessengerIds.ProxyUdp,
|
||||||
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { RemotePort = port, Id = id, BufferSize = configWrap.Data.Server.SForward.BufferSize })
|
Payload = MemoryPackSerializer.Serialize(new SForwardProxyInfo { RemotePort = port, Id = id, BufferSize = configWrap.Data.Server.SForward.BufferSize })
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -106,7 +106,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
byte[] buffer2 = new byte[(1 << token.BufferSize) * 1024];
|
byte[] buffer2 = new byte[(1 << token.BufferSize) * 1024];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int length = await token.SourceSocket.ReceiveAsync(buffer1.AsMemory(), SocketFlags.None);
|
int length = await token.SourceSocket.ReceiveAsync(buffer1.AsMemory(), SocketFlags.None).ConfigureAwait(false);
|
||||||
if (length > flagBytes.Length && buffer1.AsSpan(0, flagBytes.Length).SequenceEqual(flagBytes))
|
if (length > flagBytes.Length && buffer1.AsSpan(0, flagBytes.Length).SequenceEqual(flagBytes))
|
||||||
{
|
{
|
||||||
ulong _id = buffer1.AsSpan(flagBytes.Length).ToUInt64();
|
ulong _id = buffer1.AsSpan(flagBytes.Length).ToUInt64();
|
||||||
@@ -126,7 +126,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
CloseClientSocket(token);
|
CloseClientSocket(token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (await WebConnect(token.Host, token.ListenPort, id) == false)
|
if (await WebConnect(token.Host, token.ListenPort, id).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
CloseClientSocket(token);
|
CloseClientSocket(token);
|
||||||
return;
|
return;
|
||||||
@@ -134,7 +134,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (await TunnelConnect(token.ListenPort, id) == false)
|
if (await TunnelConnect(token.ListenPort, id).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
CloseClientSocket(token);
|
CloseClientSocket(token);
|
||||||
return;
|
return;
|
||||||
@@ -145,8 +145,8 @@ namespace linker.plugins.sforward.proxy
|
|||||||
tcpConnections.TryAdd(id, tcs);
|
tcpConnections.TryAdd(id, tcs);
|
||||||
token.TargetSocket = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(2000)).ConfigureAwait(false);
|
token.TargetSocket = await tcs.Task.WaitAsync(TimeSpan.FromMilliseconds(2000)).ConfigureAwait(false);
|
||||||
|
|
||||||
await token.TargetSocket.SendAsync(buffer1.AsMemory(0, length));
|
await token.TargetSocket.SendAsync(buffer1.AsMemory(0, length)).ConfigureAwait(false);
|
||||||
await Task.WhenAll(CopyToAsync(buffer1, token.SourceSocket, token.TargetSocket), CopyToAsync(buffer2, token.TargetSocket, token.SourceSocket));
|
await Task.WhenAll(CopyToAsync(buffer1, token.SourceSocket, token.TargetSocket), CopyToAsync(buffer2, token.TargetSocket, token.SourceSocket)).ConfigureAwait(false);
|
||||||
|
|
||||||
CloseClientSocket(token);
|
CloseClientSocket(token);
|
||||||
}
|
}
|
||||||
@@ -172,17 +172,17 @@ namespace linker.plugins.sforward.proxy
|
|||||||
{
|
{
|
||||||
sourceSocket = new Socket(server.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
sourceSocket = new Socket(server.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
sourceSocket.IPv6Only(server.AddressFamily, false);
|
sourceSocket.IPv6Only(server.AddressFamily, false);
|
||||||
await sourceSocket.ConnectAsync(server);
|
await sourceSocket.ConnectAsync(server).ConfigureAwait(false);
|
||||||
|
|
||||||
targetSocket = new Socket(service.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
targetSocket = new Socket(service.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
targetSocket.IPv6Only(service.AddressFamily, false);
|
targetSocket.IPv6Only(service.AddressFamily, false);
|
||||||
await targetSocket.ConnectAsync(service);
|
await targetSocket.ConnectAsync(service).ConfigureAwait(false);
|
||||||
|
|
||||||
flagBytes.AsMemory().CopyTo(buffer1);
|
flagBytes.AsMemory().CopyTo(buffer1);
|
||||||
id.ToBytes(buffer1.AsMemory(flagBytes.Length));
|
id.ToBytes(buffer1.AsMemory(flagBytes.Length));
|
||||||
await sourceSocket.SendAsync(buffer1.AsMemory(0, flagBytes.Length + 8));
|
await sourceSocket.SendAsync(buffer1.AsMemory(0, flagBytes.Length + 8)).ConfigureAwait(false);
|
||||||
|
|
||||||
await Task.WhenAll(CopyToAsync(buffer1, sourceSocket, targetSocket), CopyToAsync(buffer2, targetSocket, sourceSocket));
|
await Task.WhenAll(CopyToAsync(buffer1, sourceSocket, targetSocket), CopyToAsync(buffer2, targetSocket, sourceSocket)).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@@ -41,7 +41,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
IPEndPoint tempRemoteEP = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort);
|
IPEndPoint tempRemoteEP = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await token.SourceSocket.ReceiveFromAsync(buffer, tempRemoteEP);
|
SocketReceiveFromResult result = await token.SourceSocket.ReceiveFromAsync(buffer, tempRemoteEP).ConfigureAwait(false);
|
||||||
if (result.ReceivedBytes == 0)
|
if (result.ReceivedBytes == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -51,7 +51,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
//已经连接
|
//已经连接
|
||||||
if (udpConnections.TryGetValue(result.RemoteEndPoint as IPEndPoint, out UdpTargetCache cache) && cache != null)
|
if (udpConnections.TryGetValue(result.RemoteEndPoint as IPEndPoint, out UdpTargetCache cache) && cache != null)
|
||||||
{
|
{
|
||||||
await token.SourceSocket.SendToAsync(memory, cache.IPEndPoint);
|
await token.SourceSocket.SendToAsync(memory, cache.IPEndPoint).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -83,7 +83,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
ulong id = ns.Increment();
|
ulong id = ns.Increment();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (await UdpConnect(token.ListenPort, id))
|
if (await UdpConnect(token.ListenPort, id).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
TaskCompletionSource<IPEndPoint> tcs = new TaskCompletionSource<IPEndPoint>();
|
TaskCompletionSource<IPEndPoint> tcs = new TaskCompletionSource<IPEndPoint>();
|
||||||
udptcss.TryAdd(id, tcs);
|
udptcss.TryAdd(id, tcs);
|
||||||
@@ -94,7 +94,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
udpConnections.TryAdd(source, new UdpTargetCache { IPEndPoint = remote });
|
udpConnections.TryAdd(source, new UdpTargetCache { IPEndPoint = remote });
|
||||||
udpConnections.TryAdd(remote, new UdpTargetCache { IPEndPoint = source });
|
udpConnections.TryAdd(remote, new UdpTargetCache { IPEndPoint = source });
|
||||||
|
|
||||||
await token.SourceSocket.SendToAsync(buf.AsMemory(0, length), remote);
|
await token.SourceSocket.SendToAsync(buf.AsMemory(0, length), remote).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -134,7 +134,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
flagBytes.AsMemory().CopyTo(buffer);
|
flagBytes.AsMemory().CopyTo(buffer);
|
||||||
id.ToBytes(buffer.AsMemory(flagBytes.Length));
|
id.ToBytes(buffer.AsMemory(flagBytes.Length));
|
||||||
|
|
||||||
await socketUdp.SendToAsync(buffer, server);
|
await socketUdp.SendToAsync(buffer, server).ConfigureAwait(false);
|
||||||
|
|
||||||
Socket serviceUdp = null;
|
Socket serviceUdp = null;
|
||||||
buffer = new byte[(1 << bufferSize) * 1024];
|
buffer = new byte[(1 << bufferSize) * 1024];
|
||||||
@@ -143,7 +143,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer, tempEp);
|
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer, tempEp).ConfigureAwait(false);
|
||||||
if (result.ReceivedBytes == 0)
|
if (result.ReceivedBytes == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -154,7 +154,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
{
|
{
|
||||||
serviceUdp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
serviceUdp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||||
serviceUdp.WindowsUdpBug();
|
serviceUdp.WindowsUdpBug();
|
||||||
await serviceUdp.SendToAsync(memory, service);
|
await serviceUdp.SendToAsync(memory, service).ConfigureAwait(false);
|
||||||
|
|
||||||
udpConnectds.TryAdd(id, new UdpConnectedCache { SourceSocket = socketUdp, TargetSocket = serviceUdp });
|
udpConnectds.TryAdd(id, new UdpConnectedCache { SourceSocket = socketUdp, TargetSocket = serviceUdp });
|
||||||
|
|
||||||
@@ -166,9 +166,9 @@ namespace linker.plugins.sforward.proxy
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await serviceUdp.ReceiveFromAsync(buffer, tempEp);
|
SocketReceiveFromResult result = await serviceUdp.ReceiveFromAsync(buffer, tempEp).ConfigureAwait(false);
|
||||||
if (result.ReceivedBytes == 0) break;
|
if (result.ReceivedBytes == 0) break;
|
||||||
await socketUdp.SendToAsync(buffer.AsMemory(0, result.ReceivedBytes), server);
|
await socketUdp.SendToAsync(buffer.AsMemory(0, result.ReceivedBytes), server).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -189,7 +189,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await serviceUdp.SendToAsync(memory, service);
|
await serviceUdp.SendToAsync(memory, service).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -228,7 +228,7 @@ namespace linker.plugins.sforward.proxy
|
|||||||
cache.Clear();
|
cache.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,7 @@ namespace linker.plugins.signin
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.ServersForward,
|
MessengerId = (ushort)SignInMessengerIds.ServersForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(configUpdateServersInfo.List)
|
Payload = MemoryPackSerializer.Serialize(configUpdateServersInfo.List)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ namespace linker.plugins.signin
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.Delete,
|
MessengerId = (ushort)SignInMessengerIds.Delete,
|
||||||
Payload = MemoryPackSerializer.Serialize(param.Content)
|
Payload = MemoryPackSerializer.Serialize(param.Content)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task<SignInListResponseInfo> List(ApiControllerParamsInfo param)
|
public async Task<SignInListResponseInfo> List(ApiControllerParamsInfo param)
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,7 @@ namespace linker.plugins.signin
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.List,
|
MessengerId = (ushort)SignInMessengerIds.List,
|
||||||
Payload = MemoryPackSerializer.Serialize(request)
|
Payload = MemoryPackSerializer.Serialize(request)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code == MessageResponeCodes.OK)
|
if (resp.Code == MessageResponeCodes.OK)
|
||||||
{
|
{
|
||||||
return MemoryPackSerializer.Deserialize<SignInListResponseInfo>(resp.Data.Span);
|
return MemoryPackSerializer.Deserialize<SignInListResponseInfo>(resp.Data.Span);
|
||||||
@@ -97,7 +97,7 @@ namespace linker.plugins.signin
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.NameForward,
|
MessengerId = (ushort)SignInMessengerIds.NameForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info)
|
Payload = MemoryPackSerializer.Serialize(info)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (info.Id == config.Data.Client.Id)
|
if (info.Id == config.Data.Client.Id)
|
||||||
{
|
{
|
||||||
clientSignInTransfer.UpdateName(info.NewName);
|
clientSignInTransfer.UpdateName(info.NewName);
|
||||||
|
@@ -100,7 +100,7 @@ namespace linker.plugins.signin.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.Name,
|
MessengerId = (ushort)SignInMessengerIds.Name,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload,
|
Payload = connection.ReceiveRequestWrap.Payload,
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ namespace linker.plugins.signin.messenger
|
|||||||
Connection = info.Connection,
|
Connection = info.Connection,
|
||||||
MessengerId = (ushort)SignInMessengerIds.Servers,
|
MessengerId = (ushort)SignInMessengerIds.Servers,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload,
|
Payload = connection.ReceiveRequestWrap.Payload,
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.InfoForward,
|
MessengerId = (ushort)TunnelMessengerIds.InfoForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info)
|
Payload = MemoryPackSerializer.Serialize(info)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code == MessageResponeCodes.OK && resp.Data.Length > 0)
|
if (resp.Code == MessageResponeCodes.OK && resp.Data.Length > 0)
|
||||||
{
|
{
|
||||||
return MemoryPackSerializer.Deserialize<TunnelTransportWanPortInfo>(resp.Data.Span);
|
return MemoryPackSerializer.Deserialize<TunnelTransportWanPortInfo>(resp.Data.Span);
|
||||||
@@ -110,7 +110,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.BeginForward,
|
MessengerId = (ushort)TunnelMessengerIds.BeginForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
return resp.Code == MessageResponeCodes.OK && resp.Data.Span.SequenceEqual(Helper.TrueArray);
|
return resp.Code == MessageResponeCodes.OK && resp.Data.Span.SequenceEqual(Helper.TrueArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.FailForward,
|
MessengerId = (ushort)TunnelMessengerIds.FailForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.SuccessForward,
|
MessengerId = (ushort)TunnelMessengerIds.SuccessForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
Payload = MemoryPackSerializer.Serialize(tunnelTransportInfo)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.ServersForward,
|
MessengerId = (ushort)TunnelMessengerIds.ServersForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info.List)
|
Payload = MemoryPackSerializer.Serialize(info.List)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -116,7 +116,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.RouteLevelForward,
|
MessengerId = (ushort)TunnelMessengerIds.RouteLevelForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(tunnelTransportConfigWrapInfo)
|
Payload = MemoryPackSerializer.Serialize(tunnelTransportConfigWrapInfo)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -146,7 +146,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.TransportForward,
|
MessengerId = (ushort)TunnelMessengerIds.TransportForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info.List)
|
Payload = MemoryPackSerializer.Serialize(info.List)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ namespace linker.plugins.tunnel
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.ExcludeIPsForward,
|
MessengerId = (ushort)TunnelMessengerIds.ExcludeIPsForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info.List)
|
Payload = MemoryPackSerializer.Serialize(info.List)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
public async Task Info(IConnection connection)
|
public async Task Info(IConnection connection)
|
||||||
{
|
{
|
||||||
TunnelWanPortProtocolInfo info = MemoryPackSerializer.Deserialize<TunnelWanPortProtocolInfo>(connection.ReceiveRequestWrap.Payload.Span);
|
TunnelWanPortProtocolInfo info = MemoryPackSerializer.Deserialize<TunnelWanPortProtocolInfo>(connection.ReceiveRequestWrap.Payload.Span);
|
||||||
TunnelTransportWanPortInfo tunnelTransportPortInfo = await tunnel.GetWanPort(info);
|
TunnelTransportWanPortInfo tunnelTransportPortInfo = await tunnel.GetWanPort(info).ConfigureAwait(false);
|
||||||
if (tunnelTransportPortInfo != null)
|
if (tunnelTransportPortInfo != null)
|
||||||
{
|
{
|
||||||
connection.Write(MemoryPackSerializer.Serialize(tunnelTransportPortInfo));
|
connection.Write(MemoryPackSerializer.Serialize(tunnelTransportPortInfo));
|
||||||
@@ -138,7 +138,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = connection,
|
Connection = connection,
|
||||||
Payload = MemoryPackSerializer.Serialize(MemoryPackSerializer.Deserialize<TunnelTransportWanPortInfo>(result.Result.Data.Span)),
|
Payload = MemoryPackSerializer.Serialize(MemoryPackSerializer.Deserialize<TunnelTransportWanPortInfo>(result.Result.Data.Span)),
|
||||||
RequestId = requestid,
|
RequestId = requestid,
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.Begin,
|
MessengerId = (ushort)TunnelMessengerIds.Begin,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
connection.Write(Helper.TrueArray);
|
connection.Write(Helper.TrueArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.Fail,
|
MessengerId = (ushort)TunnelMessengerIds.Fail,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.Success,
|
MessengerId = (ushort)TunnelMessengerIds.Success,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.RouteLevel,
|
MessengerId = (ushort)TunnelMessengerIds.RouteLevel,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -240,7 +240,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = connection,
|
Connection = connection,
|
||||||
Payload = MemoryPackSerializer.Serialize(results),
|
Payload = MemoryPackSerializer.Serialize(results),
|
||||||
RequestId = requestid,
|
RequestId = requestid,
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = item.Connection,
|
Connection = item.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.Transport,
|
MessengerId = (ushort)TunnelMessengerIds.Transport,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = item.Connection,
|
Connection = item.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.Servers,
|
MessengerId = (ushort)TunnelMessengerIds.Servers,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ namespace linker.plugins.tunnel.messenger
|
|||||||
Connection = item.Connection,
|
Connection = item.Connection,
|
||||||
MessengerId = (ushort)TunnelMessengerIds.ExcludeIPs,
|
MessengerId = (ushort)TunnelMessengerIds.ExcludeIPs,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,7 @@ namespace linker.plugins.tuntap
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.RunForward,
|
MessengerId = (ushort)TuntapMessengerIds.RunForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(param.Content)
|
Payload = MemoryPackSerializer.Serialize(param.Content)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ namespace linker.plugins.tuntap
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.StopForward,
|
MessengerId = (ushort)TuntapMessengerIds.StopForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(param.Content)
|
Payload = MemoryPackSerializer.Serialize(param.Content)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -135,7 +135,7 @@ namespace linker.plugins.tuntap
|
|||||||
Connection = clientSignInState.Connection,
|
Connection = clientSignInState.Connection,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.UpdateForward,
|
MessengerId = (ushort)TuntapMessengerIds.UpdateForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info)
|
Payload = MemoryPackSerializer.Serialize(info)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -97,10 +97,10 @@ namespace linker.plugins.tuntap
|
|||||||
tuntapProxy.Start();
|
tuntapProxy.Start();
|
||||||
while (tuntapProxy.LocalEndpoint == null)
|
while (tuntapProxy.LocalEndpoint == null)
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = await tuntapVea.Run(tuntapProxy.LocalEndpoint.Port, runningConfig.Data.Tuntap.IP);
|
bool result = await tuntapVea.Run(tuntapProxy.LocalEndpoint.Port, runningConfig.Data.Tuntap.IP).ConfigureAwait(false);
|
||||||
runningConfig.Data.Tuntap.Running = Status == TuntapStatus.Running;
|
runningConfig.Data.Tuntap.Running = Status == TuntapStatus.Running;
|
||||||
runningConfig.Data.Update();
|
runningConfig.Data.Update();
|
||||||
if (result == false)
|
if (result == false)
|
||||||
@@ -251,7 +251,7 @@ namespace linker.plugins.tuntap
|
|||||||
MessengerId = (ushort)TuntapMessengerIds.ConfigForward,
|
MessengerId = (ushort)TuntapMessengerIds.ConfigForward,
|
||||||
Payload = MemoryPackSerializer.Serialize(info),
|
Payload = MemoryPackSerializer.Serialize(info),
|
||||||
Timeout = 3000
|
Timeout = 3000
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
if (resp.Code != MessageResponeCodes.OK)
|
if (resp.Code != MessageResponeCodes.OK)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -354,16 +354,16 @@ namespace linker.plugins.tuntap
|
|||||||
{
|
{
|
||||||
if (tuntapVea.Running)
|
if (tuntapVea.Running)
|
||||||
{
|
{
|
||||||
await CheckProxy();
|
await CheckProxy().ConfigureAwait(false);
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
await CheckInterface();
|
await CheckInterface().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(15000);
|
await Task.Delay(15000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async Task CheckInterface()
|
private async Task CheckInterface()
|
||||||
@@ -373,7 +373,7 @@ namespace linker.plugins.tuntap
|
|||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"tuntap inerface {tuntapVea.InterfaceName} is {networkInterface.OperationalStatus}, restarting");
|
LoggerHelper.Instance.Error($"tuntap inerface {tuntapVea.InterfaceName} is {networkInterface.OperationalStatus}, restarting");
|
||||||
Stop();
|
Stop();
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,14 +383,14 @@ namespace linker.plugins.tuntap
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var socket = new Socket(tuntapProxy.LocalEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
var socket = new Socket(tuntapProxy.LocalEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, tuntapProxy.LocalEndpoint.Port)).WaitAsync(TimeSpan.FromMilliseconds(100));
|
await socket.ConnectAsync(new IPEndPoint(IPAddress.Loopback, tuntapProxy.LocalEndpoint.Port)).WaitAsync(TimeSpan.FromMilliseconds(100)).ConfigureAwait(false);
|
||||||
socket.SafeClose();
|
socket.SafeClose();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LoggerHelper.Instance.Error($"tuntap proxy {ex.Message}, restarting");
|
LoggerHelper.Instance.Error($"tuntap proxy {ex.Message}, restarting");
|
||||||
Stop();
|
Stop();
|
||||||
await Task.Delay(5000);
|
await Task.Delay(5000).ConfigureAwait(false);
|
||||||
Run();
|
Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -86,7 +86,7 @@ namespace linker.plugins.tuntap.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
Timeout = 3000,
|
Timeout = 3000,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.Run
|
MessengerId = (ushort)TuntapMessengerIds.Run
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ namespace linker.plugins.tuntap.messenger
|
|||||||
Connection = cache.Connection,
|
Connection = cache.Connection,
|
||||||
Timeout = 3000,
|
Timeout = 3000,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.Stop
|
MessengerId = (ushort)TuntapMessengerIds.Stop
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ namespace linker.plugins.tuntap.messenger
|
|||||||
Timeout = 3000,
|
Timeout = 3000,
|
||||||
MessengerId = (ushort)TuntapMessengerIds.Update,
|
MessengerId = (ushort)TuntapMessengerIds.Update,
|
||||||
Payload = connection.ReceiveRequestWrap.Payload
|
Payload = connection.ReceiveRequestWrap.Payload
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ namespace linker.plugins.tuntap.messenger
|
|||||||
RequestId = requiestid,
|
RequestId = requiestid,
|
||||||
Connection = connection,
|
Connection = connection,
|
||||||
Payload = MemoryPackSerializer.Serialize(results)
|
Payload = MemoryPackSerializer.Serialize(results)
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -99,12 +99,12 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
//步骤,request
|
//步骤,request
|
||||||
bool result = await ReceiveCommandData(token);
|
bool result = await ReceiveCommandData(token);
|
||||||
if (result == false) return true;
|
if (result == false) return true;
|
||||||
await token.Socket.SendAsync(new byte[] { 0x05, 0x00 });
|
await token.Socket.SendAsync(new byte[] { 0x05, 0x00 }).ConfigureAwait(false);
|
||||||
token.Proxy.Rsv = (byte)Socks5EnumStep.Command;
|
token.Proxy.Rsv = (byte)Socks5EnumStep.Command;
|
||||||
token.Proxy.Data = Helper.EmptyArray;
|
token.Proxy.Data = Helper.EmptyArray;
|
||||||
|
|
||||||
//步骤,command
|
//步骤,command
|
||||||
result = await ReceiveCommandData(token);
|
result = await ReceiveCommandData(token).ConfigureAwait(false);
|
||||||
if (result == false)
|
if (result == false)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -117,7 +117,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
if (addressType == Socks5EnumAddressType.Domain || addressType == Socks5EnumAddressType.IPV6)
|
if (addressType == Socks5EnumAddressType.Domain || addressType == Socks5EnumAddressType.IPV6)
|
||||||
{
|
{
|
||||||
byte[] response1 = Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)Socks5EnumResponseCommand.AddressNotAllow);
|
byte[] response1 = Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)Socks5EnumResponseCommand.AddressNotAllow);
|
||||||
await token.Socket.SendAsync(response1.AsMemory());
|
await token.Socket.SendAsync(response1.AsMemory()).ConfigureAwait(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,16 +127,16 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
//是UDP中继,不做连接操作,等UDP数据过去的时候再绑定
|
//是UDP中继,不做连接操作,等UDP数据过去的时候再绑定
|
||||||
if (token.TargetIP == 0 || command == Socks5EnumRequestCommand.UdpAssociate)
|
if (token.TargetIP == 0 || command == Socks5EnumRequestCommand.UdpAssociate)
|
||||||
{
|
{
|
||||||
await token.Socket.SendAsync(Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)Socks5EnumResponseCommand.ConnecSuccess).AsMemory());
|
await token.Socket.SendAsync(Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)Socks5EnumResponseCommand.ConnecSuccess).AsMemory()).ConfigureAwait(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
token.Proxy.TargetEP = new IPEndPoint(new IPAddress(ipArray.Span), port);
|
token.Proxy.TargetEP = new IPEndPoint(new IPAddress(ipArray.Span), port);
|
||||||
token.Connection = await ConnectTunnel(token.TargetIP);
|
token.Connection = await ConnectTunnel(token.TargetIP).ConfigureAwait(false);
|
||||||
|
|
||||||
Socks5EnumResponseCommand resp = token.Connection != null && token.Connection.Connected ? Socks5EnumResponseCommand.ConnecSuccess : Socks5EnumResponseCommand.NetworkError;
|
Socks5EnumResponseCommand resp = token.Connection != null && token.Connection.Connected ? Socks5EnumResponseCommand.ConnecSuccess : Socks5EnumResponseCommand.NetworkError;
|
||||||
byte[] response = Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)resp);
|
byte[] response = Socks5Parser.MakeConnectResponse(new IPEndPoint(IPAddress.Any, 0), (byte)resp);
|
||||||
await token.Socket.SendAsync(response.AsMemory());
|
await token.Socket.SendAsync(response.AsMemory()).ConfigureAwait(false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
token.Proxy.TargetEP = new IPEndPoint(new IPAddress(ipArray.Span), port);
|
token.Proxy.TargetEP = new IPEndPoint(new IPAddress(ipArray.Span), port);
|
||||||
//解析出udp包的数据部分
|
//解析出udp包的数据部分
|
||||||
token.Proxy.Data = Socks5Parser.GetUdpData(token.Proxy.Data);
|
token.Proxy.Data = Socks5Parser.GetUdpData(token.Proxy.Data);
|
||||||
token.Connection = await ConnectTunnel(token.TargetIP);
|
token.Connection = await ConnectTunnel(token.TargetIP).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -171,7 +171,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
byte[] data = Socks5Parser.MakeUdpResponse(token.Proxy.TargetEP, token.Proxy.Data, out int length);
|
byte[] data = Socks5Parser.MakeUdpResponse(token.Proxy.TargetEP, token.Proxy.Data, out int length);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await asyncUserUdpToken.SourceSocket.SendToAsync(data.AsMemory(0, length), token.Proxy.SourceEP);
|
await asyncUserUdpToken.SourceSocket.SendToAsync(data.AsMemory(0, length), token.Proxy.SourceEP).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -201,7 +201,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return await ConnectTunnel(machineId);
|
return await ConnectTunnel(machineId).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 打洞或者中继
|
/// 打洞或者中继
|
||||||
@@ -220,7 +220,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
await slimGlobal.WaitAsync();
|
await slimGlobal.WaitAsync().ConfigureAwait(false);
|
||||||
if (dicLocks.TryGetValue(machineId, out SemaphoreSlim slim) == false)
|
if (dicLocks.TryGetValue(machineId, out SemaphoreSlim slim) == false)
|
||||||
{
|
{
|
||||||
slim = new SemaphoreSlim(1);
|
slim = new SemaphoreSlim(1);
|
||||||
@@ -228,7 +228,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
}
|
}
|
||||||
slimGlobal.Release();
|
slimGlobal.Release();
|
||||||
|
|
||||||
await slim.WaitAsync();
|
await slim.WaitAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -240,7 +240,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
|
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap tunnel to {machineId}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap tunnel to {machineId}");
|
||||||
|
|
||||||
connection = await tunnelTransfer.ConnectAsync(machineId, "tuntap");
|
connection = await tunnelTransfer.ConnectAsync(machineId, "tuntap").ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap tunnel success,{connection.ToString()}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap tunnel success,{connection.ToString()}");
|
||||||
@@ -249,7 +249,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap relay to {machineId}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap relay to {machineId}");
|
||||||
|
|
||||||
connection = await relayTransfer.ConnectAsync(config.Data.Client.Id, machineId, "tuntap");
|
connection = await relayTransfer.ConnectAsync(config.Data.Client.Id, machineId, "tuntap").ConfigureAwait(false);
|
||||||
if (connection != null)
|
if (connection != null)
|
||||||
{
|
{
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap relay success,{connection.ToString()}");
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG) LoggerHelper.Instance.Debug($"tuntap relay success,{connection.ToString()}");
|
||||||
@@ -282,7 +282,7 @@ namespace linker.plugins.tuntap.proxy
|
|||||||
//太短
|
//太短
|
||||||
while ((validate & EnumProxyValidateDataResult.TooShort) == EnumProxyValidateDataResult.TooShort)
|
while ((validate & EnumProxyValidateDataResult.TooShort) == EnumProxyValidateDataResult.TooShort)
|
||||||
{
|
{
|
||||||
totalLength += await token.Socket.ReceiveAsync(token.Buffer.AsMemory(totalLength), SocketFlags.None);
|
totalLength += await token.Socket.ReceiveAsync(token.Buffer.AsMemory(totalLength), SocketFlags.None).ConfigureAwait(false);
|
||||||
token.Proxy.Data = token.Buffer.AsMemory(0, totalLength);
|
token.Proxy.Data = token.Buffer.AsMemory(0, totalLength);
|
||||||
validate = ValidateData(token.Proxy);
|
validate = ValidateData(token.Proxy);
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
public async Task<bool> Run(int proxyPort, IPAddress ip)
|
public async Task<bool> Run(int proxyPort, IPAddress ip)
|
||||||
{
|
{
|
||||||
CommandHelper.Linux(string.Empty, new string[] { $"ip tuntap add mode tun dev {InterfaceName}" });
|
CommandHelper.Linux(string.Empty, new string[] { $"ip tuntap add mode tun dev {InterfaceName}" });
|
||||||
await SetIp(ip);
|
await SetIp(ip).ConfigureAwait(false);
|
||||||
string str = CommandHelper.Linux(string.Empty, new string[] { $"ifconfig" });
|
string str = CommandHelper.Linux(string.Empty, new string[] { $"ifconfig" });
|
||||||
if (str.Contains(InterfaceName) == false)
|
if (str.Contains(InterfaceName) == false)
|
||||||
{
|
{
|
||||||
@@ -47,7 +47,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
LoggerHelper.Instance.Error(Error);
|
LoggerHelper.Instance.Error(Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Task.Delay(10);
|
await Task.Delay(10).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -66,7 +66,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
}
|
}
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
CommandHelper.Linux(string.Empty, new string[] { $"ip addr add {ip}/24 dev {InterfaceName}", $"ip link set dev {InterfaceName} up" });
|
CommandHelper.Linux(string.Empty, new string[] { $"ip addr add {ip}/24 dev {InterfaceName}", $"ip link set dev {InterfaceName} up" });
|
||||||
return await Task.FromResult(true);
|
return await Task.FromResult(true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Kill()
|
public void Kill()
|
||||||
|
@@ -46,10 +46,10 @@ namespace linker.plugins.tuntap.vea
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SetIp(ip);
|
await SetIp(ip).ConfigureAwait(false);
|
||||||
|
|
||||||
return string.IsNullOrWhiteSpace(interfaceOsx) == false;
|
return string.IsNullOrWhiteSpace(interfaceOsx) == false;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
|
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
CommandHelper.Osx(string.Empty, new string[] { $"ifconfig {InterfaceName} {ip} {ip} up" });
|
CommandHelper.Osx(string.Empty, new string[] { $"ifconfig {InterfaceName} {ip} {ip} up" });
|
||||||
await Task.Delay(10);
|
await Task.Delay(10).ConfigureAwait(false);
|
||||||
|
|
||||||
var ipBytes = ip.GetAddressBytes();
|
var ipBytes = ip.GetAddressBytes();
|
||||||
ipBytes[^1] = 0;
|
ipBytes[^1] = 0;
|
||||||
|
@@ -35,23 +35,23 @@ namespace linker.plugins.tuntap.vea
|
|||||||
Kill();
|
Kill();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (await GetWindowsHasInterface(InterfaceName) == false)
|
if (await GetWindowsHasInterface(InterfaceName).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
Kill();
|
Kill();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (await GetWindowsInterfaceNum() == false)
|
if (await GetWindowsInterfaceNum().ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
Kill();
|
Kill();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (await SetIp(ip) == false)
|
if (await SetIp(ip).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
Kill();
|
Kill();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await GetWindowsHasRoute(ip) == false)
|
if (await GetWindowsHasRoute(ip).ConfigureAwait(false) == false)
|
||||||
{
|
{
|
||||||
Kill();
|
Kill();
|
||||||
return false;
|
return false;
|
||||||
@@ -89,7 +89,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||||
{
|
{
|
||||||
@@ -192,7 +192,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||||
{
|
{
|
||||||
@@ -219,7 +219,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
if (LoggerHelper.Instance.LoggerLevel <= LoggerTypes.DEBUG)
|
||||||
{
|
{
|
||||||
@@ -232,7 +232,7 @@ namespace linker.plugins.tuntap.vea
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000).ConfigureAwait(false);
|
||||||
string output = CommandHelper.Windows(string.Empty, new string[] { "route print" });
|
string output = CommandHelper.Windows(string.Empty, new string[] { "route print" });
|
||||||
if (output.Contains("IPv4") == false)
|
if (output.Contains("IPv4") == false)
|
||||||
{
|
{
|
||||||
|
@@ -316,11 +316,11 @@ namespace linker.server
|
|||||||
{
|
{
|
||||||
if (SourceStream != null)
|
if (SourceStream != null)
|
||||||
{
|
{
|
||||||
length = await SourceStream.ReadAsync(buffer, cancellationTokenSource.Token);
|
length = await SourceStream.ReadAsync(buffer, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
length = await SourceSocket.ReceiveAsync(buffer, SocketFlags.None, cancellationTokenSource.Token);
|
length = await SourceSocket.ReceiveAsync(buffer, SocketFlags.None, cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
{
|
{
|
||||||
@@ -329,7 +329,7 @@ namespace linker.server
|
|||||||
}
|
}
|
||||||
ReceiveBytes += length;
|
ReceiveBytes += length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
await ReadPacket(buffer.AsMemory(0, length));
|
await ReadPacket(buffer.AsMemory(0, length)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
@@ -393,7 +393,7 @@ namespace linker.server
|
|||||||
{
|
{
|
||||||
if (packet.Span.SequenceEqual(pingBytes))
|
if (packet.Span.SequenceEqual(pingBytes))
|
||||||
{
|
{
|
||||||
await SendPingPong(pongBytes);
|
await SendPingPong(pongBytes).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (packet.Span.SequenceEqual(pongBytes))
|
else if (packet.Span.SequenceEqual(pongBytes))
|
||||||
{
|
{
|
||||||
@@ -422,10 +422,10 @@ namespace linker.server
|
|||||||
if (Environment.TickCount64 - ticks > 3000)
|
if (Environment.TickCount64 - ticks > 3000)
|
||||||
{
|
{
|
||||||
pingStart = Environment.TickCount64;
|
pingStart = Environment.TickCount64;
|
||||||
await SendPingPong(pingBytes);
|
await SendPingPong(pingBytes).ConfigureAwait(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -442,16 +442,16 @@ namespace linker.server
|
|||||||
data.Length.ToBytes(heartData);
|
data.Length.ToBytes(heartData);
|
||||||
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
data.AsMemory().CopyTo(heartData.AsMemory(4));
|
||||||
|
|
||||||
await semaphoreSlim.WaitAsync();
|
await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (SourceStream != null)
|
if (SourceStream != null)
|
||||||
{
|
{
|
||||||
await SourceStream.WriteAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token);
|
await SourceStream.WriteAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await SourceSocket.SendAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token);
|
await SourceSocket.SendAsync(heartData.AsMemory(0, length), cancellationTokenSource.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -475,13 +475,13 @@ namespace linker.server
|
|||||||
}
|
}
|
||||||
public override async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
public override async Task<bool> SendAsync(ReadOnlyMemory<byte> data)
|
||||||
{
|
{
|
||||||
if (SourceStream != null) await semaphoreSlim.WaitAsync();
|
if (SourceStream != null) await semaphoreSlim.WaitAsync().ConfigureAwait(false);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (SourceStream != null)
|
if (SourceStream != null)
|
||||||
await SourceStream.WriteAsync(data, cancellationTokenSourceWrite.Token);
|
await SourceStream.WriteAsync(data, cancellationTokenSourceWrite.Token).ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await SourceSocket.SendAsync(data, cancellationTokenSourceWrite.Token);
|
await SourceSocket.SendAsync(data, cancellationTokenSourceWrite.Token).ConfigureAwait(false);
|
||||||
SendBytes += data.Length;
|
SendBytes += data.Length;
|
||||||
ticks = Environment.TickCount64;
|
ticks = Environment.TickCount64;
|
||||||
}
|
}
|
||||||
@@ -505,14 +505,14 @@ namespace linker.server
|
|||||||
}
|
}
|
||||||
public override async Task<bool> SendAsync(byte[] data, int length)
|
public override async Task<bool> SendAsync(byte[] data, int length)
|
||||||
{
|
{
|
||||||
return await SendAsync(data.AsMemory(0, length));
|
return await SendAsync(data.AsMemory(0, length)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task RelayAsync(byte bufferSize)
|
public override async Task RelayAsync(byte bufferSize)
|
||||||
{
|
{
|
||||||
if (TargetNetworkStream != null)
|
if (TargetNetworkStream != null)
|
||||||
{
|
{
|
||||||
await CopyToAsync(bufferSize, SourceNetworkStream, TargetNetworkStream);
|
await CopyToAsync(bufferSize, SourceNetworkStream, TargetNetworkStream).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async Task CopyToAsync(byte bufferSize, NetworkStream source, NetworkStream destination)
|
private async Task CopyToAsync(byte bufferSize, NetworkStream source, NetworkStream destination)
|
||||||
@@ -529,7 +529,7 @@ namespace linker.server
|
|||||||
TryLimit(ref length);
|
TryLimit(ref length);
|
||||||
while (length > 0)
|
while (length > 0)
|
||||||
{
|
{
|
||||||
await Task.Delay(30);
|
await Task.Delay(30).ConfigureAwait(false);
|
||||||
TryLimit(ref length);
|
TryLimit(ref length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -120,7 +120,7 @@ namespace linker.server
|
|||||||
}
|
}
|
||||||
else if (plugin.TaskMethod != null)
|
else if (plugin.TaskMethod != null)
|
||||||
{
|
{
|
||||||
await plugin.TaskMethod(connection);
|
await plugin.TaskMethod(connection).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
//有需要回复的
|
//有需要回复的
|
||||||
if (requestWrap.Reply == true && connection.ResponseData.Length > 0)
|
if (requestWrap.Reply == true && connection.ResponseData.Length > 0)
|
||||||
|
@@ -92,13 +92,13 @@ namespace linker.server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer, SocketFlags.None, endPoint);
|
SocketReceiveFromResult result = await socketUdp.ReceiveFromAsync(buffer, SocketFlags.None, endPoint).ConfigureAwait(false);
|
||||||
IPEndPoint ep = result.RemoteEndPoint as IPEndPoint;
|
IPEndPoint ep = result.RemoteEndPoint as IPEndPoint;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Memory<byte> memory = BuildSendData(sendData, ep);
|
Memory<byte> memory = BuildSendData(sendData, ep);
|
||||||
|
|
||||||
await socketUdp.SendToAsync(memory, ep);
|
await socketUdp.SendToAsync(memory, ep).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@@ -152,12 +152,12 @@ namespace linker.server
|
|||||||
byte[] sendData = ArrayPool<byte>.Shared.Rent(20);
|
byte[] sendData = ArrayPool<byte>.Shared.Rent(20);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await socket.ReceiveAsync(sendData.AsMemory(0, 1), SocketFlags.None);
|
await socket.ReceiveAsync(sendData.AsMemory(0, 1), SocketFlags.None).ConfigureAwait(false);
|
||||||
byte type = sendData[0];
|
byte type = sendData[0];
|
||||||
if (type == 0)
|
if (type == 0)
|
||||||
{
|
{
|
||||||
Memory<byte> memory = BuildSendData(sendData, socket.RemoteEndPoint as IPEndPoint);
|
Memory<byte> memory = BuildSendData(sendData, socket.RemoteEndPoint as IPEndPoint);
|
||||||
await socket.SendAsync(memory, SocketFlags.None);
|
await socket.SendAsync(memory, SocketFlags.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -180,14 +180,14 @@ namespace linker.server
|
|||||||
}
|
}
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
|
|
||||||
if (await ReceiveType(socket) == 0)
|
if (await ReceiveType(socket).ConfigureAwait(false) == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkStream networkStream = new NetworkStream(socket, false);
|
NetworkStream networkStream = new NetworkStream(socket, false);
|
||||||
SslStream sslStream = new SslStream(networkStream, true);
|
SslStream sslStream = new SslStream(networkStream, true);
|
||||||
await sslStream.AuthenticateAsServerAsync(serverCertificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
await sslStream.AuthenticateAsServerAsync(serverCertificate, false, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, false).ConfigureAwait(false);
|
||||||
IConnection connection = CreateConnection(sslStream, networkStream, socket, socket.LocalEndPoint as IPEndPoint, socket.RemoteEndPoint as IPEndPoint);
|
IConnection connection = CreateConnection(sslStream, networkStream, socket, socket.LocalEndPoint as IPEndPoint, socket.RemoteEndPoint as IPEndPoint);
|
||||||
|
|
||||||
|
|
||||||
@@ -213,14 +213,14 @@ namespace linker.server
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
socket.KeepAlive();
|
socket.KeepAlive();
|
||||||
await socket.SendAsync(new byte[] { 1 });
|
await socket.SendAsync(new byte[] { 1 }).ConfigureAwait(false);
|
||||||
NetworkStream networkStream = new NetworkStream(socket, false);
|
NetworkStream networkStream = new NetworkStream(socket, false);
|
||||||
SslStream sslStream = new SslStream(networkStream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
SslStream sslStream = new SslStream(networkStream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
|
||||||
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
|
||||||
{
|
{
|
||||||
AllowRenegotiation = true,
|
AllowRenegotiation = true,
|
||||||
EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13
|
EnabledSslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13
|
||||||
});
|
}).ConfigureAwait(false);
|
||||||
IConnection connection = CreateConnection(sslStream, networkStream, socket, socket.LocalEndPoint as IPEndPoint, socket.RemoteEndPoint as IPEndPoint);
|
IConnection connection = CreateConnection(sslStream, networkStream, socket, socket.LocalEndPoint as IPEndPoint, socket.RemoteEndPoint as IPEndPoint);
|
||||||
|
|
||||||
connection.BeginReceive(connectionReceiveCallback, null, true);
|
connection.BeginReceive(connectionReceiveCallback, null, true);
|
||||||
|
Reference in New Issue
Block a user