From 55efac7236ca63f7d16620190643a83c7d4ec4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 17 Mar 2023 13:17:01 +0800 Subject: [PATCH] Reformat code --- common/protocol/headers.go | 3 +-- infra/conf/transport_internet.go | 4 ++-- proxy/vless/encoding/encoding.go | 2 +- proxy/vless/outbound/outbound.go | 2 +- transport/internet/headers/dns/dns.go | 1 - transport/internet/kcp/listener.go | 16 ++++++++-------- transport/internet/reality/reality.go | 6 ++++-- transport/internet/sockopt_linux.go | 22 +++++++++++----------- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/common/protocol/headers.go b/common/protocol/headers.go index 8806ee80..0058d1c5 100644 --- a/common/protocol/headers.go +++ b/common/protocol/headers.go @@ -3,11 +3,10 @@ package protocol import ( "runtime" - "golang.org/x/sys/cpu" - "github.com/xtls/xray-core/common/bitmask" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/uuid" + "golang.org/x/sys/cpu" ) // RequestCommand is a custom command in a proxy request. diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 63c8fbed..7424c548 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -616,7 +616,7 @@ type SocketConfig struct { TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"` TCPKeepAliveIdle int32 `json:"tcpKeepAliveIdle"` TCPCongestion string `json:"tcpCongestion"` - TCPWindowClamp int32 `json:"tcpWindowClamp"` + TCPWindowClamp int32 `json:"tcpWindowClamp"` V6only bool `json:"v6only"` Interface string `json:"interface"` } @@ -668,7 +668,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) { TcpKeepAliveInterval: c.TCPKeepAliveInterval, TcpKeepAliveIdle: c.TCPKeepAliveIdle, TcpCongestion: c.TCPCongestion, - TcpWindowClamp: c.TCPWindowClamp, + TcpWindowClamp: c.TCPWindowClamp, V6Only: c.V6only, Interface: c.Interface, }, nil diff --git a/proxy/vless/encoding/encoding.go b/proxy/vless/encoding/encoding.go index b96acee9..27d1fb01 100644 --- a/proxy/vless/encoding/encoding.go +++ b/proxy/vless/encoding/encoding.go @@ -485,7 +485,7 @@ func XtlsPadding(b *buf.Buffer, command byte, userUUID *[]byte, longPadding bool } paddingLen = int32(l.Int64()) } - if paddingLen > buf.Size - 21 - contentLen { + if paddingLen > buf.Size-21-contentLen { paddingLen = buf.Size - 21 - contentLen } newbuffer := buf.New() diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index cde09bad..b7bc6964 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -287,7 +287,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte counter = statConn.ReadCounter } err = encoding.XtlsRead(serverReader, clientWriter, timer, netConn, rawConn, input, rawInput, counter, ctx, account.ID.Bytes(), - &numberOfPacketToFilter, &enableXtls, &isTLS12orAbove, &isTLS, &cipher, &remainingServerHello) + &numberOfPacketToFilter, &enableXtls, &isTLS12orAbove, &isTLS, &cipher, &remainingServerHello) } else { // from serverReader.ReadMultiBuffer to clientWriter.WriteMultiBufer err = buf.Copy(serverReader, clientWriter, buf.UpdateActivity(timer)) diff --git a/transport/internet/headers/dns/dns.go b/transport/internet/headers/dns/dns.go index 5839bc81..a7366d1a 100644 --- a/transport/internet/headers/dns/dns.go +++ b/transport/internet/headers/dns/dns.go @@ -37,7 +37,6 @@ func NewDNS(ctx context.Context, config interface{}) (interface{}, error) { buf := make([]byte, 0x100) off1, err := dns.PackDomainName(dns.Fqdn(config.(*Config).Domain), buf, 0, nil, false) - if err != nil { return nil, err } diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index baf38e6d..82b5a3bc 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -24,14 +24,14 @@ type ConnectionID struct { // Listener defines a server listening for connections type Listener struct { sync.Mutex - sessions map[ConnectionID]*Connection - hub *udp.Hub - tlsConfig *gotls.Config - config *Config - reader PacketReader - header internet.PacketHeader - security cipher.AEAD - addConn internet.ConnHandler + sessions map[ConnectionID]*Connection + hub *udp.Hub + tlsConfig *gotls.Config + config *Config + reader PacketReader + header internet.PacketHeader + security cipher.AEAD + addConn internet.ConnHandler } func NewListener(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, addConn internet.ConnHandler) (*Listener, error) { diff --git a/transport/internet/reality/reality.go b/transport/internet/reality/reality.go index 835c075a..3bdf1f43 100644 --- a/transport/internet/reality/reality.go +++ b/transport/internet/reality/reality.go @@ -240,8 +240,10 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati return uConn, nil } -var href = regexp.MustCompile(`href="([/h].*?)"`) -var dot = []byte(".") +var ( + href = regexp.MustCompile(`href="([/h].*?)"`) + dot = []byte(".") +) var maps struct { sync.Mutex diff --git a/transport/internet/sockopt_linux.go b/transport/internet/sockopt_linux.go index eda5de15..ea023f53 100644 --- a/transport/internet/sockopt_linux.go +++ b/transport/internet/sockopt_linux.go @@ -47,11 +47,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf } } - if config.Interface != "" { - if err := syscall.BindToDevice(int(fd), config.Interface); err != nil { - return newError("failed to set Interface").Base(err) - } - } + if config.Interface != "" { + if err := syscall.BindToDevice(int(fd), config.Interface); err != nil { + return newError("failed to set Interface").Base(err) + } + } if isTCPSocket(network) { tfo := config.ParseTFOValue() @@ -91,10 +91,10 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf } if config.TcpWindowClamp > 0 { - if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_WINDOW_CLAMP, int(config.TcpWindowClamp)); err != nil { - return newError("failed to set TCP_WINDOW_CLAMP", err) - } - } + if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_WINDOW_CLAMP, int(config.TcpWindowClamp)); err != nil { + return newError("failed to set TCP_WINDOW_CLAMP", err) + } + } } if config.Tproxy.IsEnabled() { @@ -148,8 +148,8 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) if config.TcpWindowClamp > 0 { if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_WINDOW_CLAMP, int(config.TcpWindowClamp)); err != nil { - return newError("failed to set TCP_WINDOW_CLAMP", err) - } + return newError("failed to set TCP_WINDOW_CLAMP", err) + } } }