Update network handler usages

This commit is contained in:
世界 2024-10-20 14:23:34 +08:00
parent 5c2a0c4fa6
commit 54badfa885
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 68 additions and 29 deletions

View file

@ -10,7 +10,7 @@ import (
"github.com/sagernet/sing/common/buf"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw"
"github.com/sagernet/sing/common/varbin"
)
type serverConn struct {
@ -24,11 +24,11 @@ func (c *serverConn) NeedHandshake() bool {
func (c *serverConn) HandshakeFailure(err error) error {
errMessage := err.Error()
buffer := buf.NewSize(1 + rw.UVariantLen(uint64(len(errMessage))) + len(errMessage))
buffer := buf.NewSize(1 + varbin.UvarintLen(uint64(len(errMessage))) + len(errMessage))
defer buffer.Release()
common.Must(
buffer.WriteByte(statusError),
rw.WriteVString(buffer, errMessage),
varbin.Write(buffer, binary.BigEndian, errMessage),
)
return common.Error(c.ExtendedConn.Write(buffer.Bytes()))
}
@ -88,11 +88,11 @@ func (c *serverPacketConn) NeedHandshake() bool {
func (c *serverPacketConn) HandshakeFailure(err error) error {
errMessage := err.Error()
buffer := buf.NewSize(1 + rw.UVariantLen(uint64(len(errMessage))) + len(errMessage))
buffer := buf.NewSize(1 + varbin.UvarintLen(uint64(len(errMessage))) + len(errMessage))
defer buffer.Release()
common.Must(
buffer.WriteByte(statusError),
rw.WriteVString(buffer, errMessage),
varbin.Write(buffer, binary.BigEndian, errMessage),
)
return common.Error(c.ExtendedConn.Write(buffer.Bytes()))
}
@ -188,11 +188,11 @@ func (c *serverPacketAddrConn) NeedHandshake() bool {
func (c *serverPacketAddrConn) HandshakeFailure(err error) error {
errMessage := err.Error()
buffer := buf.NewSize(1 + rw.UVariantLen(uint64(len(errMessage))) + len(errMessage))
buffer := buf.NewSize(1 + varbin.UvarintLen(uint64(len(errMessage))) + len(errMessage))
defer buffer.Release()
common.Must(
buffer.WriteByte(statusError),
rw.WriteVString(buffer, errMessage),
varbin.Write(buffer, binary.BigEndian, errMessage),
)
return common.Error(c.ExtendedConn.Write(buffer.Bytes()))
}