Refactor shadowsocks

This commit is contained in:
世界 2022-04-10 22:51:29 +08:00
parent 3f23b25edf
commit 00cd0d4b8f
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
75 changed files with 3169 additions and 1318 deletions

View file

@ -4,6 +4,7 @@ import (
"crypto/rand"
"fmt"
"io"
"net"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/list"
@ -188,6 +189,18 @@ func (b *Buffer) ReadFrom(r io.Reader) (int64, error) {
return int64(n), nil
}
func (b *Buffer) ReadPacketFrom(r net.PacketConn) (int64, net.Addr, error) {
if b.IsFull() {
return 0, nil, io.ErrShortBuffer
}
n, addr, err := r.ReadFrom(b.FreeBytes())
if err != nil {
return 0, nil, err
}
b.end += n
return int64(n), addr, nil
}
func (b *Buffer) ReadAtLeastFrom(r io.Reader, min int) (int64, error) {
if min <= 0 {
return b.ReadFrom(r)