1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

fix lint warnings in packetaddr

This commit is contained in:
Shelikhoo 2021-12-31 21:22:16 +00:00 committed by Xiaokang Wang (Shelikhoo)
parent dc5cffc8b0
commit 0f2da63f0c
10 changed files with 39 additions and 27 deletions

View File

@ -202,7 +202,7 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (internet.Conn
outbound.Gateway = h.senderSettings.Via.AsAddress() outbound.Gateway = h.senderSettings.Via.AsAddress()
} }
} }
var enablePacketAddrCapture = true enablePacketAddrCapture := true
if h.senderSettings != nil && h.senderSettings.ProxySettings != nil && h.senderSettings.ProxySettings.HasTag() && h.senderSettings.ProxySettings.TransportLayerProxy { if h.senderSettings != nil && h.senderSettings.ProxySettings != nil && h.senderSettings.ProxySettings.HasTag() && h.senderSettings.ProxySettings.TransportLayerProxy {
tag := h.senderSettings.ProxySettings.Tag tag := h.senderSettings.ProxySettings.Tag
newError("transport layer proxying to ", tag, " for dest ", dest).AtDebug().WriteToLog(session.ExportIDToError(ctx)) newError("transport layer proxying to ", tag, " for dest ", dest).AtDebug().WriteToLog(session.ExportIDToError(ctx))

View File

@ -6,16 +6,18 @@ import (
"sync" "sync"
"time" "time"
"github.com/v2fly/v2ray-core/v4/common" "github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v4/common/buf" "github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v4/common/errors" "github.com/v2fly/v2ray-core/v5/common/errors"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v4/features/routing" "github.com/v2fly/v2ray-core/v5/features/routing"
"github.com/v2fly/v2ray-core/v4/transport" "github.com/v2fly/v2ray-core/v5/transport"
) )
var errNotPacketConn = errors.New("not a packet connection") var (
var errUnsupported = errors.New("unsupported action") errNotPacketConn = errors.New("not a packet connection")
errUnsupported = errors.New("unsupported action")
)
func ToPacketAddrConn(link *transport.Link, dest net.Destination) (net.PacketConn, error) { func ToPacketAddrConn(link *transport.Link, dest net.Destination) (net.PacketConn, error) {
if !dest.Address.Family().IsDomain() { if !dest.Address.Family().IsDomain() {
@ -80,6 +82,9 @@ func (c *packetConnectionAdaptor) WriteTo(p []byte, addr gonet.Addr) (n int, err
payloadLen := len(p) payloadLen := len(p)
var buffer *buf.Buffer var buffer *buf.Buffer
buffer, err = AttachAddressToPacket(buf.FromBytes(p), addr) buffer, err = AttachAddressToPacket(buf.FromBytes(p), addr)
if err != nil {
return 0, err
}
mb := buf.MultiBuffer{buffer} mb := buf.MultiBuffer{buffer}
err = c.link.Writer.WriteMultiBuffer(mb) err = c.link.Writer.WriteMultiBuffer(mb)
if err != nil { if err != nil {

View File

@ -2,10 +2,11 @@ package packetaddr
import ( import (
"bytes" "bytes"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/protocol"
gonet "net" gonet "net"
"github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/protocol"
) )
var addrParser = protocol.NewAddressParser( var addrParser = protocol.NewAddressParser(
@ -44,7 +45,7 @@ func ExtractAddressFromPacket(data *buf.Buffer) (*buf.Buffer, gonet.Addr, error)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
var addr = &gonet.UDPAddr{ addr := &gonet.UDPAddr{
IP: address.IP(), IP: address.IP(),
Port: int(port.Value()), Port: int(port.Value()),
Zone: "", Zone: "",

View File

@ -1,10 +1,12 @@
package packetaddr package packetaddr
import ( import (
"github.com/stretchr/testify/assert"
"github.com/v2fly/v2ray-core/v4/common/buf"
sysnet "net" sysnet "net"
"testing" "testing"
"github.com/stretchr/testify/assert"
"github.com/v2fly/v2ray-core/v4/common/buf"
) )
func TestPacketEncodingIPv4(t *testing.T) { func TestPacketEncodingIPv4(t *testing.T) {

View File

@ -2,9 +2,10 @@ package socks
import ( import (
"context" "context"
"time"
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr" "github.com/v2fly/v2ray-core/v4/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v4/transport/internet/udp" "github.com/v2fly/v2ray-core/v4/transport/internet/udp"
"time"
core "github.com/v2fly/v2ray-core/v5" core "github.com/v2fly/v2ray-core/v5"
"github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common"

View File

@ -390,9 +390,9 @@ func (r *UDPReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
return buf.MultiBuffer{b}, nil return buf.MultiBuffer{b}, nil
} }
func (v *UDPReader) ReadFrom(p []byte) (n int, addr gonet.Addr, err error) { func (r *UDPReader) ReadFrom(p []byte) (n int, addr gonet.Addr, err error) {
buffer := buf.New() buffer := buf.New()
_, err = buffer.ReadFrom(v.reader) _, err = buffer.ReadFrom(r.reader)
if err != nil { if err != nil {
buffer.Release() buffer.Release()
return 0, nil, err return 0, nil, err

View File

@ -2,7 +2,6 @@ package socks
import ( import (
"context" "context"
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr"
"io" "io"
"time" "time"
@ -11,6 +10,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common/buf" "github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/log" "github.com/v2fly/v2ray-core/v5/common/log"
"github.com/v2fly/v2ray-core/v5/common/net" "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v5/common/protocol" "github.com/v2fly/v2ray-core/v5/common/protocol"
udp_proto "github.com/v2fly/v2ray-core/v5/common/protocol/udp" udp_proto "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
"github.com/v2fly/v2ray-core/v5/common/session" "github.com/v2fly/v2ray-core/v5/common/session"

View File

@ -3,8 +3,8 @@ package udp
import ( import (
gonet "net" gonet "net"
"github.com/v2fly/v2ray-core/v4/common/signal" "github.com/v2fly/v2ray-core/v5/common/signal"
"github.com/v2fly/v2ray-core/v4/transport/internet" "github.com/v2fly/v2ray-core/v5/transport/internet"
) )
type dataHandler func(content []byte, address gonet.Addr) type dataHandler func(content []byte, address gonet.Addr)
@ -31,7 +31,7 @@ func CopyPacketConn(dst internet.AbstractPacketConnWriter, src internet.Abstract
handler(buffer[:n], addr) handler(buffer[:n], addr)
} }
n, err = dst.WriteTo(buffer[:n], addr) _, err = dst.WriteTo(buffer[:n], addr)
if err != nil { if err != nil {
return err return err
} }

View File

@ -2,6 +2,7 @@ package udp
import ( import (
"context" "context"
"github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf" "github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v5/common/net" "github.com/v2fly/v2ray-core/v5/common/net"

View File

@ -2,11 +2,12 @@ package udp
import ( import (
"context" "context"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/net" "github.com/v2fly/v2ray-core/v5/common/buf"
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr" "github.com/v2fly/v2ray-core/v5/common/net"
"github.com/v2fly/v2ray-core/v4/common/protocol/udp" "github.com/v2fly/v2ray-core/v5/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v4/features/routing" "github.com/v2fly/v2ray-core/v5/common/protocol/udp"
"github.com/v2fly/v2ray-core/v5/features/routing"
) )
type PacketAddrDispatcher struct { type PacketAddrDispatcher struct {
@ -25,6 +26,7 @@ func (p PacketAddrDispatcher) Dispatch(ctx context.Context, destination net.Dest
} }
p.conn.WriteTo(payload.Bytes(), &net.UDPAddr{IP: destination.Address.IP(), Port: int(destination.Port.Value())}) p.conn.WriteTo(payload.Bytes(), &net.UDPAddr{IP: destination.Address.IP(), Port: int(destination.Port.Value())})
} }
func (p PacketAddrDispatcher) readWorker() { func (p PacketAddrDispatcher) readWorker() {
for { for {
readBuf := buf.New() readBuf := buf.New()