Skip to content

Commit 6dad878

Browse files
committed
[同步]1. 同步主库代码。时间为 2025-04-21 05:40:09 版本号:f68fe7960b000d7d808dd4bb954a36e5d24d4188
1 parent e4b7c2e commit 6dad878

File tree

122 files changed

+7388
-3837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+7388
-3837
lines changed
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
using System.Net;
2-
3-
namespace GameFrameX.SuperSocket.Client.Proxy
4-
{
5-
public abstract class ProxyConnectorBase : ConnectorBase
6-
{
7-
private EndPoint _proxyEndPoint;
8-
9-
public ProxyConnectorBase(EndPoint proxyEndPoint)
10-
{
11-
_proxyEndPoint = proxyEndPoint;
12-
}
13-
14-
protected abstract ValueTask<ConnectState> ConnectProxyAsync(EndPoint remoteEndPoint, ConnectState state, CancellationToken cancellationToken);
15-
16-
protected override async ValueTask<ConnectState> ConnectAsync(EndPoint remoteEndPoint, ConnectState state, CancellationToken cancellationToken)
17-
{
18-
var socketConnector = new SocketConnector() as IConnector;
19-
var proxyEndPoint = _proxyEndPoint;
20-
21-
ConnectState result;
22-
23-
try
24-
{
25-
result = await socketConnector.ConnectAsync(proxyEndPoint, null, cancellationToken);
26-
27-
if (!result.Result)
28-
return result;
29-
}
30-
catch (Exception e)
31-
{
32-
return new ConnectState
33-
{
34-
Result = false,
35-
Exception = e
36-
};
37-
}
38-
39-
return await ConnectProxyAsync(remoteEndPoint, state, cancellationToken);
40-
}
41-
}
1+
using System.Net;
2+
3+
namespace GameFrameX.SuperSocket.Client.Proxy
4+
{
5+
public abstract class ProxyConnectorBase : ConnectorBase
6+
{
7+
private EndPoint _proxyEndPoint;
8+
9+
public ProxyConnectorBase(EndPoint proxyEndPoint)
10+
{
11+
_proxyEndPoint = proxyEndPoint;
12+
}
13+
14+
protected abstract ValueTask<ConnectState> ConnectProxyAsync(EndPoint remoteEndPoint, ConnectState state, CancellationToken cancellationToken);
15+
16+
protected override async ValueTask<ConnectState> ConnectAsync(EndPoint remoteEndPoint, ConnectState state, CancellationToken cancellationToken)
17+
{
18+
var socketConnector = new SocketConnector() as IConnector;
19+
var proxyEndPoint = _proxyEndPoint;
20+
21+
ConnectState result;
22+
23+
try
24+
{
25+
result = await socketConnector.ConnectAsync(proxyEndPoint, null, cancellationToken);
26+
27+
if (!result.Result)
28+
return result;
29+
}
30+
catch (Exception e)
31+
{
32+
return new ConnectState
33+
{
34+
Result = false,
35+
Exception = e
36+
};
37+
}
38+
39+
return await ConnectProxyAsync(remoteEndPoint, result, cancellationToken);
40+
}
41+
}
4242
}

src/GameFrameX.SuperSocket.Client.Proxy/Socks5Connector.cs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,61 @@
88
namespace GameFrameX.SuperSocket.Client.Proxy
99
{
1010
/// <summary>
11-
/// https://tools.ietf.org/html/rfc1928
12-
/// https://en.wikipedia.org/wiki/SOCKS
11+
/// Represents a connector for SOCKS5 proxy connections.
1312
/// </summary>
13+
/// <remarks>
14+
/// Implements the SOCKS5 protocol as defined in RFC 1928.
15+
/// </remarks>
1416
public class Socks5Connector : ProxyConnectorBase
1517
{
1618
private string _username;
1719

1820
private string _password;
1921

20-
readonly static byte[] _authenHandshakeRequest = new byte[] { 0x05, 0x02, 0x00, 0x02 };
22+
private readonly byte[] _authenHandshakeRequest;
23+
private static readonly byte[] Handshake = new byte[] { 0x05, 0x01, 0x00 };
24+
private static readonly byte[] AuthenHandshake = new byte[] { 0x05, 0x02, 0x00, 0x02 };
2125

26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="Socks5Connector"/> class with the specified proxy endpoint.
28+
/// </summary>
29+
/// <param name="proxyEndPoint">The endpoint of the SOCKS5 proxy server.</param>
2230
public Socks5Connector(EndPoint proxyEndPoint)
2331
: base(proxyEndPoint)
2432
{
33+
_authenHandshakeRequest = Handshake;
2534
}
2635

36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="Socks5Connector"/> class with the specified proxy endpoint, username, and password.
38+
/// </summary>
39+
/// <param name="proxyEndPoint">The endpoint of the SOCKS5 proxy server.</param>
40+
/// <param name="username">The username for authentication.</param>
41+
/// <param name="password">The password for authentication.</param>
2742
public Socks5Connector(EndPoint proxyEndPoint, string username, string password)
2843
: this(proxyEndPoint)
2944
{
3045
_username = username;
3146
_password = password;
47+
_authenHandshakeRequest = AuthenHandshake;
3248
}
3349

3450
protected override async ValueTask<ConnectState> ConnectProxyAsync(EndPoint remoteEndPoint, ConnectState state, CancellationToken cancellationToken)
3551
{
3652
var connection = state.CreateConnection(new ConnectionOptions { ReadAsDemand = true });
3753

38-
var packStream = connection.GetPackageStream(new Socks5AuthPipelineFilter());
54+
var pipeLineFilter = new Socks5AuthPipelineFilter();
55+
56+
if (string.IsNullOrWhiteSpace(_username) || string.IsNullOrWhiteSpace(_password))
57+
{
58+
pipeLineFilter.AuthStep = 1;
59+
}
60+
else
61+
{
62+
pipeLineFilter.AuthStep = 0;
63+
}
64+
65+
var packStream = connection.GetPackageStream(pipeLineFilter);
3966

4067
await connection.SendAsync(_authenHandshakeRequest);
4168

@@ -227,7 +254,7 @@ private byte[] GetEndPointBytes(EndPoint remoteEndPoint)
227254

228255
port = endPoint.Port;
229256

230-
var maxLen = 7 + Encoding.ASCII.GetMaxByteCount(endPoint.Host.Length);
257+
var maxLen = 6 + Encoding.ASCII.GetMaxByteCount(endPoint.Host.Length);
231258
buffer = new byte[maxLen];
232259

233260
buffer[3] = 0x03;

src/GameFrameX.SuperSocket.Client/ConnectState.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
2-
using System.IO;
31
using System.Net.Sockets;
42
using GameFrameX.SuperSocket.Connection;
5-
using GameFrameX.SuperSocket.ProtoBase;
3+
using GameFrameX.SuperSocket.Connection.Sockets;
4+
using Microsoft.Extensions.ObjectPool;
65

76
namespace GameFrameX.SuperSocket.Client
87
{
@@ -29,6 +28,13 @@ private ConnectState(bool cancelled)
2928

3029
public static readonly ConnectState CancelledState = new ConnectState(false);
3130

31+
private static Lazy<ObjectPool<SocketSender>> _socketSenderPool = new Lazy<ObjectPool<SocketSender>>(() =>
32+
{
33+
var policy = new DefaultPooledObjectPolicy<SocketSender>();
34+
var pool = new DefaultObjectPool<SocketSender>(policy, EasyClient.SocketSenderPoolSize ?? EasyClient.DefaultSocketSenderPoolSize);
35+
return pool;
36+
});
37+
3238
public IConnection CreateConnection(ConnectionOptions connectionOptions)
3339
{
3440
var stream = this.Stream;
@@ -40,7 +46,7 @@ public IConnection CreateConnection(ConnectionOptions connectionOptions)
4046
}
4147
else
4248
{
43-
return new TcpPipeConnection(socket, connectionOptions);
49+
return new TcpPipeConnection(socket, connectionOptions, _socketSenderPool.Value);
4450
}
4551
}
4652
}

0 commit comments

Comments
 (0)