Make server address optional

This commit is contained in:
世界 2023-02-21 21:05:04 +08:00
parent 78e50cd7b5
commit dac782ca09
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -42,9 +42,7 @@ func NewClient(config ClientConfig) (*Client, error) {
tlsHandshake: config.TLSHandshake,
logger: config.Logger,
}
if !client.server.IsValid() || client.dialer == nil {
return nil, os.ErrInvalid
}
switch client.version {
case 1, 2, 3:
default:
@ -61,10 +59,17 @@ func (c *Client) SetHandshakeFunc(handshakeFunc TLSHandshakeFunc) {
}
func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
if !c.server.IsValid() {
return nil, os.ErrInvalid
}
conn, err := c.dialer.DialContext(ctx, N.NetworkTCP, c.server)
if err != nil {
return nil, err
}
return c.DialContextConn(ctx, conn)
}
func (c *Client) DialContextConn(ctx context.Context, conn net.Conn) (net.Conn, error) {
if c.tlsHandshake == nil {
return nil, os.ErrInvalid
}
@ -72,7 +77,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
default:
fallthrough
case 1:
err = c.tlsHandshake(ctx, conn, nil)
err := c.tlsHandshake(ctx, conn, nil)
if err != nil {
return nil, err
}
@ -80,7 +85,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
return conn, nil
case 2:
hashConn := newHashReadConn(conn, c.password)
err = c.tlsHandshake(ctx, hashConn, nil)
err := c.tlsHandshake(ctx, hashConn, nil)
if err != nil {
return nil, err
}
@ -88,7 +93,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
return newClientConn(hashConn), nil
case 3:
stream := newStreamWrapper(conn, c.password)
err = c.tlsHandshake(ctx, stream, generateSessionID(c.password))
err := c.tlsHandshake(ctx, stream, generateSessionID(c.password))
if err != nil {
return nil, err
}