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