From d7ad10ff14c82a6ee6f76a85834fe10b99706a27 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Fri, 29 Apr 2022 21:36:26 +0100 Subject: [PATCH] fix coding style issue --- common/environment/envctx/env.go | 2 +- common/environment/rootcap_impl.go | 1 + .../transientstorageimpl/storage.go | 5 +- functions.go | 1 + proxy/vlite/inbound/connAdp.go | 5 +- proxy/vlite/inbound/inbound.go | 40 +++++++-------- proxy/vlite/outbound/outbound.go | 51 +++++++++---------- 7 files changed, 53 insertions(+), 52 deletions(-) diff --git a/common/environment/envctx/env.go b/common/environment/envctx/env.go index 66f34e905..2957735d4 100644 --- a/common/environment/envctx/env.go +++ b/common/environment/envctx/env.go @@ -7,7 +7,7 @@ const ( ) func ContextWithEnvironment(ctx context.Context, environment interface{}) context.Context { - return context.WithValue(ctx, environmentKey, environment) + return context.WithValue(ctx, environmentKey, environment) //nolint: revive } func EnvironmentFromContext(ctx context.Context) interface{} { diff --git a/common/environment/rootcap_impl.go b/common/environment/rootcap_impl.go index 5ad54ee9d..acea6a516 100644 --- a/common/environment/rootcap_impl.go +++ b/common/environment/rootcap_impl.go @@ -2,6 +2,7 @@ package environment import ( "context" + "github.com/v2fly/v2ray-core/v5/common/platform/filesystem/fsifce" "github.com/v2fly/v2ray-core/v5/features/extension/storage" "github.com/v2fly/v2ray-core/v5/transport/internet" diff --git a/common/environment/transientstorageimpl/storage.go b/common/environment/transientstorageimpl/storage.go index e97c0c56b..c349ef7ba 100644 --- a/common/environment/transientstorageimpl/storage.go +++ b/common/environment/transientstorageimpl/storage.go @@ -4,9 +4,10 @@ package transientstorageimpl import ( "context" - "github.com/v2fly/v2ray-core/v5/features/extension/storage" "strings" "sync" + + "github.com/v2fly/v2ray-core/v5/features/extension/storage" ) func NewScopedTransientStorageImpl() storage.ScopedTransientStorage { @@ -44,7 +45,7 @@ func (s *scopedTransientStorageImpl) List(ctx context.Context, keyPrefix string) s.access.Lock() defer s.access.Unlock() var ret []string - for key, _ := range s.values { + for key := range s.values { if strings.HasPrefix(key, keyPrefix) { ret = append(ret, key) } diff --git a/functions.go b/functions.go index 772606b78..831f513b5 100644 --- a/functions.go +++ b/functions.go @@ -3,6 +3,7 @@ package core import ( "bytes" "context" + "github.com/v2fly/v2ray-core/v5/common/environment/envctx" "github.com/v2fly/v2ray-core/v5/common" diff --git a/proxy/vlite/inbound/connAdp.go b/proxy/vlite/inbound/connAdp.go index d88c7edcb..c8d39eca9 100644 --- a/proxy/vlite/inbound/connAdp.go +++ b/proxy/vlite/inbound/connAdp.go @@ -1,10 +1,11 @@ package inbound import ( - "github.com/v2fly/v2ray-core/v5/common/buf" - "github.com/v2fly/v2ray-core/v5/common/signal/done" "io" "net" + + "github.com/v2fly/v2ray-core/v5/common/buf" + "github.com/v2fly/v2ray-core/v5/common/signal/done" ) func newUDPConnAdaptor(conn net.Conn, done *done.Instance) net.Conn { diff --git a/proxy/vlite/inbound/inbound.go b/proxy/vlite/inbound/inbound.go index 83e365636..ebc0ee6f4 100644 --- a/proxy/vlite/inbound/inbound.go +++ b/proxy/vlite/inbound/inbound.go @@ -2,7 +2,11 @@ package inbound import ( "context" - "github.com/mustafaturan/bus" + "io" + gonet "net" + "strconv" + "sync" + "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/environment" "github.com/v2fly/v2ray-core/v5/common/environment/envctx" @@ -11,6 +15,8 @@ import ( "github.com/v2fly/v2ray-core/v5/common/signal/done" "github.com/v2fly/v2ray-core/v5/features/routing" "github.com/v2fly/v2ray-core/v5/transport/internet" + + "github.com/mustafaturan/bus" "github.com/xiaokangwang/VLite/interfaces" "github.com/xiaokangwang/VLite/interfaces/ibus" "github.com/xiaokangwang/VLite/transport" @@ -20,10 +26,6 @@ import ( "github.com/xiaokangwang/VLite/transport/udp/udpuni/udpunis" "github.com/xiaokangwang/VLite/transport/uni/uniserver" "github.com/xiaokangwang/VLite/workers/server" - "io" - gonet "net" - "strconv" - "sync" ) //go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen @@ -60,17 +62,17 @@ type status struct { access sync.Mutex } -func (s *status) RelayStream(conn io.ReadWriteCloser, ctx context.Context) { +func (s *status) RelayStream(conn io.ReadWriteCloser, ctx context.Context) { //nolint:revive } -func (s *status) Connection(conn gonet.Conn, connctx context.Context) context.Context { - S_S2CTraffic := make(chan server.UDPServerTxToClientTraffic, 8) - S_S2CDataTraffic := make(chan server.UDPServerTxToClientDataTraffic, 8) - S_C2STraffic := make(chan server.UDPServerRxFromClientTraffic, 8) +func (s *status) Connection(conn gonet.Conn, connctx context.Context) context.Context { //nolint:revive + S_S2CTraffic := make(chan server.UDPServerTxToClientTraffic, 8) //nolint:revive + S_S2CDataTraffic := make(chan server.UDPServerTxToClientDataTraffic, 8) //nolint:revive + S_C2STraffic := make(chan server.UDPServerRxFromClientTraffic, 8) //nolint:revive - S_S2CTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) - S_S2CDataTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) - S_C2STraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) + S_S2CTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive + S_S2CDataTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive + S_C2STraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive go func(ctx context.Context) { for { @@ -92,7 +94,6 @@ func (s *status) Connection(conn gonet.Conn, connctx context.Context) context.Co return } } - }(connctx) go func(ctx context.Context) { @@ -104,7 +105,6 @@ func (s *status) Connection(conn gonet.Conn, connctx context.Context) context.Co return } } - }(connctx) if !s.config.EnableStabilization || !s.config.EnableRenegotiation { @@ -126,21 +126,21 @@ func createStatusFromConfig(config *UDPProtocolConfig) (*status, error) { s.password = []byte(config.Password) s.msgbus = ibus.NewMessageBus() - s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsMessageBus, s.msgbus) + s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsMessageBus, s.msgbus) //nolint:revive if config.ScramblePacket { - s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPShouldMask, true) + s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPShouldMask, true) //nolint:revive } if s.config.EnableFec { - s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPFECEnabled, true) + s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPFECEnabled, true) //nolint:revive } - s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPMask, string(s.password)) + s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUDPMask, string(s.password)) //nolint:revive if config.HandshakeMaskingPaddingSize != 0 { ctxv := &interfaces.ExtraOptionsUsePacketArmorValue{PacketArmorPaddingTo: int(config.HandshakeMaskingPaddingSize), UsePacketArmor: true} - s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUsePacketArmor, ctxv) + s.ctx = context.WithValue(s.ctx, interfaces.ExtraOptionsUsePacketArmor, ctxv) //nolint:revive } return s, nil diff --git a/proxy/vlite/outbound/outbound.go b/proxy/vlite/outbound/outbound.go index 01561604c..c86e081b6 100644 --- a/proxy/vlite/outbound/outbound.go +++ b/proxy/vlite/outbound/outbound.go @@ -3,7 +3,20 @@ package outbound import ( "context" "fmt" + "sync" + "time" + "github.com/mustafaturan/bus" + "github.com/xiaokangwang/VLite/ass/udpconn2tun" + "github.com/xiaokangwang/VLite/interfaces" + "github.com/xiaokangwang/VLite/interfaces/ibus" + vltransport "github.com/xiaokangwang/VLite/transport" + udpsctpserver "github.com/xiaokangwang/VLite/transport/packetsctp/sctprelay" + "github.com/xiaokangwang/VLite/transport/packetuni/puniClient" + "github.com/xiaokangwang/VLite/transport/udp/udpClient" + "github.com/xiaokangwang/VLite/transport/udp/udpuni/udpunic" + "github.com/xiaokangwang/VLite/transport/uni/uniclient" + "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/environment" "github.com/v2fly/v2ray-core/v5/common/environment/envctx" @@ -15,17 +28,6 @@ import ( "github.com/v2fly/v2ray-core/v5/transport" "github.com/v2fly/v2ray-core/v5/transport/internet" "github.com/v2fly/v2ray-core/v5/transport/internet/udp" - "github.com/xiaokangwang/VLite/ass/udpconn2tun" - "github.com/xiaokangwang/VLite/interfaces" - "github.com/xiaokangwang/VLite/interfaces/ibus" - vltransport "github.com/xiaokangwang/VLite/transport" - udpsctpserver "github.com/xiaokangwang/VLite/transport/packetsctp/sctprelay" - "github.com/xiaokangwang/VLite/transport/packetuni/puniClient" - "github.com/xiaokangwang/VLite/transport/udp/udpClient" - "github.com/xiaokangwang/VLite/transport/udp/udpuni/udpunic" - "github.com/xiaokangwang/VLite/transport/uni/uniclient" - "sync" - "time" client2 "github.com/xiaokangwang/VLite/workers/client" ) @@ -70,11 +72,9 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte if packetConn, err := packetaddr.ToPacketAddrConn(link, destination); err == nil { requestDone := func() error { - return udp.CopyPacketConn(packetConnOut, packetConn, udp.UpdateActivity(timer)) } responseDone := func() error { - return udp.CopyPacketConn(packetConn, packetConnOut, udp.UpdateActivity(timer)) } responseDoneAndCloseWriter := task.OnSuccess(responseDone, task.Close(link.Writer)) @@ -122,21 +122,21 @@ func createStatusFromConfig(config *UDPProtocolConfig) (*status, error) { ctx := context.Background() s.msgbus = ibus.NewMessageBus() - ctx = context.WithValue(ctx, interfaces.ExtraOptionsMessageBus, s.msgbus) + ctx = context.WithValue(ctx, interfaces.ExtraOptionsMessageBus, s.msgbus) //nolint:revive if config.EnableFec { - ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPFECEnabled, true) + ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPFECEnabled, true) //nolint:revive } if config.ScramblePacket { - ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPShouldMask, true) + ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPShouldMask, true) //nolint:revive } - ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPMask, string(s.password)) + ctx = context.WithValue(ctx, interfaces.ExtraOptionsUDPMask, string(s.password)) //nolint:revive if config.HandshakeMaskingPaddingSize != 0 { ctxv := &interfaces.ExtraOptionsUsePacketArmorValue{PacketArmorPaddingTo: int(config.HandshakeMaskingPaddingSize), UsePacketArmor: true} - ctx = context.WithValue(ctx, interfaces.ExtraOptionsUsePacketArmor, ctxv) + ctx = context.WithValue(ctx, interfaces.ExtraOptionsUsePacketArmor, ctxv) //nolint:revive } destinationString := fmt.Sprintf("%v:%v", config.Address.AsAddress().String(), config.Port) @@ -156,13 +156,13 @@ func enableInterface(s *status) error { return newError("unable to connect to remote").Base(err) } - C_C2STraffic := make(chan client2.UDPClientTxToServerTraffic, 8) - C_C2SDataTraffic := make(chan client2.UDPClientTxToServerDataTraffic, 8) - C_S2CTraffic := make(chan client2.UDPClientRxFromServerTraffic, 8) + C_C2STraffic := make(chan client2.UDPClientTxToServerTraffic, 8) //nolint:revive + C_C2SDataTraffic := make(chan client2.UDPClientTxToServerDataTraffic, 8) //nolint:revive + C_S2CTraffic := make(chan client2.UDPClientRxFromServerTraffic, 8) //nolint:revive - C_C2STraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) - C_C2SDataTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) - C_S2CTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) + C_C2STraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive + C_C2SDataTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive + C_S2CTraffic2 := make(chan interfaces.TrafficWithChannelTag, 8) //nolint:revive go func(ctx context.Context) { for { @@ -173,7 +173,6 @@ func enableInterface(s *status) error { return } } - }(connctx) go func(ctx context.Context) { @@ -185,7 +184,6 @@ func enableInterface(s *status) error { return } } - }(connctx) go func(ctx context.Context) { @@ -197,7 +195,6 @@ func enableInterface(s *status) error { return } } - }(connctx) TunnelTxToTun := make(chan interfaces.UDPPacket)