mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 04:47:40 +03:00
Minor fixes
This commit is contained in:
parent
6d16497f03
commit
6a0987c52a
5 changed files with 20 additions and 9 deletions
|
@ -92,6 +92,16 @@ func FilterNotDefault[T comparable](arr []T) []T {
|
|||
})
|
||||
}
|
||||
|
||||
func FilterIndexed[T any](arr []T, block func(index int, it T) bool) []T {
|
||||
var retArr []T
|
||||
for i, it := range arr {
|
||||
if block(i, it) {
|
||||
retArr = append(retArr, it)
|
||||
}
|
||||
}
|
||||
return retArr
|
||||
}
|
||||
|
||||
func Find[T any](arr []T, block func(it T) bool) T {
|
||||
for _, it := range arr {
|
||||
if block(it) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package control
|
|||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func BindToInterface(interfaceName string) Func {
|
||||
|
@ -12,6 +12,6 @@ func BindToInterface(interfaceName string) Func {
|
|||
err := conn.Control(func(fd uintptr) {
|
||||
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
||||
})
|
||||
return common.AnyError(innerErr, err)
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package control
|
|||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func RoutingMark(mark int) Func {
|
||||
|
@ -12,6 +12,6 @@ func RoutingMark(mark int) Func {
|
|||
err := conn.Control(func(fd uintptr) {
|
||||
innerErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, mark)
|
||||
})
|
||||
return common.AnyError(innerErr, err)
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package control
|
|||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func ReuseAddr() Func {
|
||||
|
@ -11,11 +11,11 @@ func ReuseAddr() Func {
|
|||
var innerErr error
|
||||
err := conn.Control(func(fd uintptr) {
|
||||
const SO_REUSEPORT = 0xf
|
||||
innerErr = common.AnyError(
|
||||
innerErr = E.Errors(
|
||||
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1),
|
||||
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, SO_REUSEPORT, 1),
|
||||
)
|
||||
})
|
||||
return common.AnyError(innerErr, err)
|
||||
return E.Errors(innerErr, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,8 @@ func HandleConnection0(ctx context.Context, conn net.Conn, version byte, authent
|
|||
metadata.Destination = request.Destination
|
||||
return handler.NewConnection(ctx, conn, metadata)
|
||||
case socks5.CommandUDPAssociate:
|
||||
udpConn, err := net.ListenUDP(M.NetworkFromNetAddr("udp", M.AddrFromNetAddr(conn.LocalAddr())), net.UDPAddrFromAddrPort(netip.AddrPortFrom(M.AddrFromNetAddr(conn.LocalAddr()), 0)))
|
||||
var udpConn *net.UDPConn
|
||||
udpConn, err = net.ListenUDP(M.NetworkFromNetAddr("udp", M.AddrFromNetAddr(conn.LocalAddr())), net.UDPAddrFromAddrPort(netip.AddrPortFrom(M.AddrFromNetAddr(conn.LocalAddr()), 0)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -224,7 +225,7 @@ func HandleConnection0(ctx context.Context, conn net.Conn, version byte, authent
|
|||
close(done)
|
||||
}()
|
||||
err = common.Error(io.Copy(io.Discard, conn))
|
||||
return E.New(innerError, err)
|
||||
return E.Errors(innerError, err)
|
||||
default:
|
||||
err = socks5.WriteResponse(conn, socks5.Response{
|
||||
ReplyCode: socks5.ReplyCodeUnsupported,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue