Fix: vmess handshake block (#117)

This commit is contained in:
gVisor bot 2019-02-15 21:55:15 +08:00
parent 0d9bbcc50c
commit 8b57524bc9
2 changed files with 7 additions and 13 deletions

View file

@ -35,20 +35,10 @@ type Conn struct {
respV byte
security byte
sent bool
received bool
}
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)
}
@ -153,7 +143,7 @@ func hashTimestamp(t time.Time) []byte {
}
// 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)
rand.Read(randBytes)
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[:])
}
return &Conn{
c := &Conn{
Conn: conn,
id: id,
dst: dst,
@ -209,4 +199,8 @@ func newConn(conn net.Conn, id *ID, dst *DstAddr, security Security) *Conn {
writer: writer,
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 {
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