@@ -20,38 +20,38 @@ import (
2020 N "github.com/sagernet/sing/common/network"
2121)
2222
23- type NaiveClientConfig struct {
24- Context context.Context
25- ServerAddress M.Socksaddr
26- ServerName string
27- Username string
28- Password string
29- Concurrency int
30- ExtraHeaders map [string ]string
31-
32- TrustedRootCertificates string // PEM format
33- CertificatePublicKeySHA256 [][]byte // SPKI SHA256 hashes
34-
35- Dialer N.Dialer
36- }
23+ var _ N.Dialer = (* NaiveClient )(nil )
3724
3825type NaiveClient struct {
39- ctx context.Context
40- dialer N.Dialer
41- serverAddress M.Socksaddr
42- serverName string
43- serverURL string
44- authorization string
45- extraHeaders map [string ]string
46- trustedRootCertificates string
47- certificatePublicKeySHA256 [][]byte
48- concurrency int
49- counter atomic.Uint64
50- engine Engine
51- streamEngine StreamEngine
52- activeConnections sync.WaitGroup
53- proxyWaitGroup sync.WaitGroup
54- proxyCancel context.CancelFunc
26+ ctx context.Context
27+ dialer N.Dialer
28+ serverAddress M.Socksaddr
29+ serverName string
30+ serverURL string
31+ authorization string
32+ extraHeaders map [string ]string
33+ trustedRootCertificates string
34+ trustedCertificatePublicKeySHA256 [][]byte
35+ concurrency int
36+ counter atomic.Uint64
37+ engine Engine
38+ streamEngine StreamEngine
39+ activeConnections sync.WaitGroup
40+ proxyWaitGroup sync.WaitGroup
41+ proxyCancel context.CancelFunc
42+ }
43+
44+ type NaiveClientConfig struct {
45+ Context context.Context
46+ ServerAddress M.Socksaddr
47+ ServerName string
48+ Username string
49+ Password string
50+ InsecureConcurrency int
51+ ExtraHeaders map [string ]string
52+ TrustedRootCertificates string // PEM format
53+ TrustedCertificatePublicKeySHA256 [][]byte // SPKI SHA256 hashes
54+ Dialer N.Dialer
5555}
5656
5757func NewNaiveClient (config NaiveClientConfig ) (* NaiveClient , error ) {
@@ -79,7 +79,7 @@ func NewNaiveClient(config NaiveClientConfig) (*NaiveClient, error) {
7979 []byte (config .Username + ":" + config .Password ))
8080 }
8181
82- concurrency := config .Concurrency
82+ concurrency := config .InsecureConcurrency
8383 if concurrency < 1 {
8484 concurrency = 1
8585 }
@@ -95,24 +95,24 @@ func NewNaiveClient(config NaiveClientConfig) (*NaiveClient, error) {
9595 }
9696
9797 return & NaiveClient {
98- ctx : ctx ,
99- dialer : dialer ,
100- serverAddress : config .ServerAddress ,
101- serverName : serverName ,
102- serverURL : serverURL .String (),
103- authorization : authorization ,
104- extraHeaders : config .ExtraHeaders ,
105- trustedRootCertificates : config .TrustedRootCertificates ,
106- certificatePublicKeySHA256 : config .CertificatePublicKeySHA256 ,
107- concurrency : concurrency ,
98+ ctx : ctx ,
99+ dialer : dialer ,
100+ serverAddress : config .ServerAddress ,
101+ serverName : serverName ,
102+ serverURL : serverURL .String (),
103+ authorization : authorization ,
104+ extraHeaders : config .ExtraHeaders ,
105+ trustedRootCertificates : config .TrustedRootCertificates ,
106+ trustedCertificatePublicKeySHA256 : config .TrustedCertificatePublicKeySHA256 ,
107+ concurrency : concurrency ,
108108 }, nil
109109}
110110
111111func (c * NaiveClient ) Start () error {
112112 engine := NewEngine ()
113113
114- if len (c .certificatePublicKeySHA256 ) > 0 {
115- if ! engine .SetCertVerifierWithPublicKeySHA256 (c .certificatePublicKeySHA256 ) {
114+ if len (c .trustedCertificatePublicKeySHA256 ) > 0 {
115+ if ! engine .SetCertVerifierWithPublicKeySHA256 (c .trustedCertificatePublicKeySHA256 ) {
116116 return E .New ("failed to set certificate public key SHA256 verifier" )
117117 }
118118 } else if c .trustedRootCertificates != "" {
@@ -220,7 +220,10 @@ func (c *NaiveClient) DialEarly(destination M.Socksaddr) (NaiveConn, error) {
220220 }, nil
221221}
222222
223- func (c * NaiveClient ) DialContext (ctx context.Context , destination M.Socksaddr ) (NaiveConn , error ) {
223+ func (c * NaiveClient ) DialContext (ctx context.Context , network string , destination M.Socksaddr ) (net.Conn , error ) {
224+ if N .NetworkName (network ) != N .NetworkTCP {
225+ return nil , os .ErrInvalid
226+ }
224227 conn , err := c .DialEarly (destination )
225228 if err != nil {
226229 return nil , err
@@ -233,6 +236,10 @@ func (c *NaiveClient) DialContext(ctx context.Context, destination M.Socksaddr)
233236 return conn , nil
234237}
235238
239+ func (c * NaiveClient ) ListenPacket (ctx context.Context , destination M.Socksaddr ) (net.PacketConn , error ) {
240+ return nil , os .ErrInvalid
241+ }
242+
236243func (c * NaiveClient ) Close () error {
237244 if c .proxyCancel != nil {
238245 c .proxyCancel ()
0 commit comments