Remove dependency of ekyu.moe/leb128

This commit is contained in:
H1JK 2022-08-26 13:39:38 +08:00 committed by Hellojack
parent edf6800dda
commit e4973a90d9
3 changed files with 7 additions and 11 deletions

1
go.mod
View File

@ -4,7 +4,6 @@ go 1.18
require (
berty.tech/go-libtor v1.0.385
ekyu.moe/leb128 v0.0.0-20190626180622-d3722dc409a8
github.com/cretz/bine v0.2.0
github.com/database64128/tfo-go v1.1.2
github.com/dustin/go-humanize v1.0.0

2
go.sum
View File

@ -1,7 +1,5 @@
berty.tech/go-libtor v1.0.385 h1:RWK94C3hZj6Z2GdvePpHJLnWYobFr3bY/OdUJ5aoEXw=
berty.tech/go-libtor v1.0.385/go.mod h1:9swOOQVb+kmvuAlsgWUK/4c52pm69AdbJsxLzk+fJEw=
ekyu.moe/leb128 v0.0.0-20190626180622-d3722dc409a8 h1:zWcNapXDoFEobgJquW8jOgnVClkRLV9StPmi+LhtTGQ=
ekyu.moe/leb128 v0.0.0-20190626180622-d3722dc409a8/go.mod h1:hphPjsG3qJdFKRttMyBWptntD0vAUE3NUenOGL0914A=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=

View File

@ -16,8 +16,6 @@ import (
"github.com/sagernet/sing/common/buf"
"github.com/sagernet/sing/common/bufio"
E "github.com/sagernet/sing/common/exceptions"
"ekyu.moe/leb128"
)
var ErrInvalidLength = E.New("invalid length")
@ -63,7 +61,7 @@ func (c *GunConn) Read(b []byte) (n int, err error) {
return n, nil
}
buffer := buf.Get(5)
n, err = io.ReadFull(c.reader, buffer)
_, err = io.ReadFull(c.reader, buffer)
if err != nil {
return 0, err
}
@ -71,11 +69,11 @@ func (c *GunConn) Read(b []byte) (n int, err error) {
buf.Put(buffer)
buffer = buf.Get(int(grpcPayloadLen))
n, err = io.ReadFull(c.reader, buffer)
_, err = io.ReadFull(c.reader, buffer)
if err != nil {
return 0, io.ErrUnexpectedEOF
}
protobufPayloadLen, protobufLengthLen := leb128.DecodeUleb128(buffer[1:])
protobufPayloadLen, protobufLengthLen := binary.Uvarint(buffer[1:])
if protobufLengthLen == 0 {
return 0, ErrInvalidLength
}
@ -95,11 +93,12 @@ func (c *GunConn) Write(b []byte) (n int, err error) {
if c.isClosed() {
return 0, io.ErrClosedPipe
}
protobufHeader := leb128.AppendUleb128([]byte{0x0A}, uint64(len(b)))
protobufHeader := [1 + binary.MaxVarintLen64]byte{0x0A}
varuintLen := binary.PutUvarint(protobufHeader[1:], uint64(len(b)))
grpcHeader := buf.Get(5)
grpcPayloadLen := uint32(len(protobufHeader) + len(b))
grpcPayloadLen := uint32(1 + varuintLen + len(b))
binary.BigEndian.PutUint32(grpcHeader[1:5], grpcPayloadLen)
_, err = bufio.Copy(c.writer, io.MultiReader(bytes.NewReader(grpcHeader), bytes.NewReader(protobufHeader), bytes.NewReader(b)))
_, err = bufio.Copy(c.writer, io.MultiReader(bytes.NewReader(grpcHeader), bytes.NewReader(protobufHeader[:varuintLen+1]), bytes.NewReader(b)))
buf.Put(grpcHeader)
if f, ok := c.writer.(http.Flusher); ok {
f.Flush()