Skip to content

Commit 2862b42

Browse files
committed
lint fixup for wireguard
1 parent 462eb77 commit 2862b42

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

common/dualStack/happyEyeball/racingDialer.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313

1414
type Dialer func(ctx context.Context, domainDestination net.Destination, ips net.IP) (internet.Connection, error)
1515

16-
func RacingDialer(ctx context.Context,
17-
domainDestination net.Destination, ips []net.IP, dialer Dialer,
18-
preferIPv6 bool, preferredHeadStart time.Duration) (internet.Connection, error) {
16+
func RacingDialer(ctx context.Context, domainDestination net.Destination, ips []net.IP, dialer Dialer, preferIPv6 bool, preferredHeadStart time.Duration) (internet.Connection, error) {
1917
// check if they are of a single family, if so no one have head start
2018
hasIPv4 := false
2119
hasIPv6 := false
@@ -32,7 +30,7 @@ func RacingDialer(ctx context.Context,
3230
}
3331

3432
// If there is only one family present, there is no head start
35-
if !(hasIPv4 && hasIPv6) {
33+
if !hasIPv4 || !hasIPv6 {
3634
preferredHeadStart = 0
3735
}
3836
if preferredHeadStart < 0 {
@@ -93,7 +91,7 @@ func RacingDialer(ctx context.Context,
9391
// channel already has a conn, close this extra one
9492
_ = c.Close()
9593
}
96-
finished.Close()
94+
_ = finished.Close()
9795
return nil
9896
})
9997
}

common/packetswitch/gvisorstack/adapter.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"context"
55
"sync"
66

7-
"github.com/v2fly/v2ray-core/v5/common"
8-
"github.com/v2fly/v2ray-core/v5/common/packetswitch"
97
"gvisor.dev/gvisor/pkg/buffer"
108
"gvisor.dev/gvisor/pkg/tcpip"
119
"gvisor.dev/gvisor/pkg/tcpip/header"
1210
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
1311
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
1412
"gvisor.dev/gvisor/pkg/tcpip/stack"
13+
14+
"github.com/v2fly/v2ray-core/v5/common"
15+
"github.com/v2fly/v2ray-core/v5/common/packetswitch"
1516
)
1617

17-
func NewNetworkLayerDeviceToGvisorLinkEndpointAdaptor(ctx context.Context, mtu int, networkLayerSwitch packetswitch.NetworkLayerDevice) *NetworkLayerDeviceToGvisorLinkEndpointAdaptor {
18+
func NewNetworkLayerDeviceToGvisorLinkEndpointAdaptor(_ context.Context, mtu int, networkLayerSwitch packetswitch.NetworkLayerDevice) *NetworkLayerDeviceToGvisorLinkEndpointAdaptor {
1819
return &NetworkLayerDeviceToGvisorLinkEndpointAdaptor{
1920
mtu: mtu,
2021
networkLayerSwitch: networkLayerSwitch,
@@ -57,7 +58,7 @@ func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) LinkAddress() tcpip.Link
5758
return ""
5859
}
5960

60-
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) SetLinkAddress(addr tcpip.LinkAddress) {
61+
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) SetLinkAddress(_ tcpip.LinkAddress) {
6162
// no-op
6263
}
6364

@@ -154,11 +155,11 @@ func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) ARPHardwareType() header
154155
return header.ARPHardwareNone
155156
}
156157

157-
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) AddHeader(buffer *stack.PacketBuffer) {
158+
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) AddHeader(_ *stack.PacketBuffer) {
158159
// No link-layer header to add.
159160
}
160161

161-
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) ParseHeader(buffer *stack.PacketBuffer) bool {
162+
func (n *NetworkLayerDeviceToGvisorLinkEndpointAdaptor) ParseHeader(_ *stack.PacketBuffer) bool {
162163
// Nothing to parse; packet is a bare network packet.
163164
return true
164165
}

proxy/wireguard/wgcommon/setup.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ func (w *WrappedWireguardDevice) SetupDeviceWithoutPeers() error {
4545

4646
var sb strings.Builder
4747
if len(w.config.PrivateKey) > 0 {
48-
sb.WriteString(fmt.Sprintf("private_key=%x\n", w.config.PrivateKey))
48+
_, _ = fmt.Fprintf(&sb, "private_key=%x\n", w.config.PrivateKey)
4949
}
5050
if w.config.ListenPort != 0 {
51-
sb.WriteString(fmt.Sprintf("listen_port=%d\n", w.config.ListenPort))
51+
_, _ = fmt.Fprintf(&sb, "listen_port=%d\n", w.config.ListenPort)
5252
}
5353

5454
// Terminate operation with a blank line.
@@ -75,23 +75,23 @@ func (w *WrappedWireguardDevice) AddOrReplacePeers(peers []*PeerConfig) error {
7575
continue
7676
}
7777
// start peer block
78-
sb.WriteString(fmt.Sprintf("public_key=%x\n", p.PublicKey))
78+
_, _ = fmt.Fprintf(&sb, "public_key=%x\n", p.PublicKey)
7979
if len(p.PresharedKey) > 0 {
80-
sb.WriteString(fmt.Sprintf("preshared_key=%x\n", p.PresharedKey))
80+
_, _ = fmt.Fprintf(&sb, "preshared_key=%x\n", p.PresharedKey)
8181
}
8282
if p.Endpoint != "" {
83-
sb.WriteString(fmt.Sprintf("endpoint=%s\n", p.Endpoint))
83+
_, _ = fmt.Fprintf(&sb, "endpoint=%s\n", p.Endpoint)
8484
}
8585
if p.PersistentKeepaliveInterval != 0 {
86-
sb.WriteString(fmt.Sprintf("persistent_keepalive_interval=%d\n", p.PersistentKeepaliveInterval))
86+
_, _ = fmt.Fprintf(&sb, "persistent_keepalive_interval=%d\n", p.PersistentKeepaliveInterval)
8787
}
8888
// replace allowed IPs for this peer
8989
sb.WriteString("replace_allowed_ips=true\n")
9090
for _, aip := range p.AllowedIps {
9191
if aip == "" {
9292
continue
9393
}
94-
sb.WriteString(fmt.Sprintf("allowed_ip=%s\n", aip))
94+
_, _ = fmt.Fprintf(&sb, "allowed_ip=%s\n", aip)
9595
}
9696
}
9797

@@ -113,7 +113,7 @@ func (w *WrappedWireguardDevice) RemovePeer(publicKey []byte) error {
113113
}
114114

115115
var sb strings.Builder
116-
sb.WriteString(fmt.Sprintf("public_key=%x\n", publicKey))
116+
_, _ = fmt.Fprintf(&sb, "public_key=%x\n", publicKey)
117117
sb.WriteString("remove=true\n")
118118
sb.WriteString("\n")
119119

proxy/wireguard/wgcommon/wgConnAdaptor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestNetPacketConnToWg_OpenReceive_Send(t *testing.T) {
3636
if port == 0 {
3737
// LocalAddr should have set actualPort, otherwise use svConn
3838
if la := svConn.LocalAddr(); la != nil {
39-
if ua, ok := la.(*net.UDPAddr); ok {
39+
if ua, ok := la.(*net.UDPAddr); ok && ua.Port != 0 {
4040
port = uint16(ua.Port)
4141
}
4242
}

0 commit comments

Comments
 (0)