mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-06 13:27:39 +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 {
|
func Find[T any](arr []T, block func(it T) bool) T {
|
||||||
for _, it := range arr {
|
for _, it := range arr {
|
||||||
if block(it) {
|
if block(it) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package control
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/sagernet/sing/common"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BindToInterface(interfaceName string) Func {
|
func BindToInterface(interfaceName string) Func {
|
||||||
|
@ -12,6 +12,6 @@ func BindToInterface(interfaceName string) Func {
|
||||||
err := conn.Control(func(fd uintptr) {
|
err := conn.Control(func(fd uintptr) {
|
||||||
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
innerErr = syscall.BindToDevice(int(fd), interfaceName)
|
||||||
})
|
})
|
||||||
return common.AnyError(innerErr, err)
|
return E.Errors(innerErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package control
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/sagernet/sing/common"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RoutingMark(mark int) Func {
|
func RoutingMark(mark int) Func {
|
||||||
|
@ -12,6 +12,6 @@ func RoutingMark(mark int) Func {
|
||||||
err := conn.Control(func(fd uintptr) {
|
err := conn.Control(func(fd uintptr) {
|
||||||
innerErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK, mark)
|
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 (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/sagernet/sing/common"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReuseAddr() Func {
|
func ReuseAddr() Func {
|
||||||
|
@ -11,11 +11,11 @@ func ReuseAddr() Func {
|
||||||
var innerErr error
|
var innerErr error
|
||||||
err := conn.Control(func(fd uintptr) {
|
err := conn.Control(func(fd uintptr) {
|
||||||
const SO_REUSEPORT = 0xf
|
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, syscall.SO_REUSEADDR, 1),
|
||||||
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, SO_REUSEPORT, 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
|
metadata.Destination = request.Destination
|
||||||
return handler.NewConnection(ctx, conn, metadata)
|
return handler.NewConnection(ctx, conn, metadata)
|
||||||
case socks5.CommandUDPAssociate:
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -224,7 +225,7 @@ func HandleConnection0(ctx context.Context, conn net.Conn, version byte, authent
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
err = common.Error(io.Copy(io.Discard, conn))
|
err = common.Error(io.Copy(io.Discard, conn))
|
||||||
return E.New(innerError, err)
|
return E.Errors(innerError, err)
|
||||||
default:
|
default:
|
||||||
err = socks5.WriteResponse(conn, socks5.Response{
|
err = socks5.WriteResponse(conn, socks5.Response{
|
||||||
ReplyCode: socks5.ReplyCodeUnsupported,
|
ReplyCode: socks5.ReplyCodeUnsupported,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue