Fix: vmess handshake block (#117)

This commit is contained in:
beyondkmp 2019-02-15 21:55:15 +08:00 committed by Dreamacro
parent c295c5e412
commit 287ad5bc53
2 changed files with 7 additions and 13 deletions

View file

@ -35,20 +35,10 @@ type Conn struct {
respV byte respV byte
security byte security byte
sent bool
received bool received bool
} }
func (vc *Conn) Write(b []byte) (int, error) { func (vc *Conn) Write(b []byte) (int, error) {
if vc.sent {
return vc.writer.Write(b)
}
if err := vc.sendRequest(); err != nil {
return 0, err
}
vc.sent = true
return vc.writer.Write(b) return vc.writer.Write(b)
} }
@ -153,7 +143,7 @@ func hashTimestamp(t time.Time) []byte {
} }
// newConn return a Conn instance // newConn return a Conn instance
func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security) *Conn { func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security) (*Conn, error) {
randBytes := make([]byte, 33) randBytes := make([]byte, 33)
rand.Read(randBytes) rand.Read(randBytes)
reqBodyIV := make([]byte, 16) reqBodyIV := make([]byte, 16)
@ -196,7 +186,7 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security) *Conn {
reader = newAEADReader(conn, aead, respBodyIV[:]) reader = newAEADReader(conn, aead, respBodyIV[:])
} }
return &Conn{ c := &Conn{
Conn: conn, Conn: conn,
id: id, id: id,
dst: dst, dst: dst,
@ -209,4 +199,8 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security) *Conn {
writer: writer, writer: writer,
security: security, security: security,
} }
if err := c.sendRequest(); err != nil {
return nil, err
}
return c, nil
} }

View file

@ -100,7 +100,7 @@ func (c *Client) New(conn net.Conn, dst *DstAddr) (net.Conn, error) {
} else if c.tls { } else if c.tls {
conn = tls.Client(conn, c.tlsConfig) conn = tls.Client(conn, c.tlsConfig)
} }
return newConn(conn, c.user[r], dst, c.security), nil return newConn(conn, c.user[r], dst, c.security)
} }
// NewClient return Client instance // NewClient return Client instance