1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 01:27:03 -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()
}
}
var enablePacketAddrCapture = true
enablePacketAddrCapture := true
if h.senderSettings != nil && h.senderSettings.ProxySettings != nil && h.senderSettings.ProxySettings.HasTag() && h.senderSettings.ProxySettings.TransportLayerProxy {
tag := h.senderSettings.ProxySettings.Tag
newError("transport layer proxying to ", tag, " for dest ", dest).AtDebug().WriteToLog(session.ExportIDToError(ctx))

View File

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

View File

@ -2,10 +2,11 @@ package packetaddr
import (
"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"
"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(
@ -44,7 +45,7 @@ func ExtractAddressFromPacket(data *buf.Buffer) (*buf.Buffer, gonet.Addr, error)
if err != nil {
return nil, nil, err
}
var addr = &gonet.UDPAddr{
addr := &gonet.UDPAddr{
IP: address.IP(),
Port: int(port.Value()),
Zone: "",

View File

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

View File

@ -2,9 +2,10 @@ package socks
import (
"context"
"time"
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v4/transport/internet/udp"
"time"
core "github.com/v2fly/v2ray-core/v5"
"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
}
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()
_, err = buffer.ReadFrom(v.reader)
_, err = buffer.ReadFrom(r.reader)
if err != nil {
buffer.Release()
return 0, nil, err

View File

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

View File

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

View File

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

View File

@ -2,11 +2,12 @@ package udp
import (
"context"
"github.com/v2fly/v2ray-core/v4/common/buf"
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/common/net/packetaddr"
"github.com/v2fly/v2ray-core/v4/common/protocol/udp"
"github.com/v2fly/v2ray-core/v4/features/routing"
"github.com/v2fly/v2ray-core/v5/common/buf"
"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/udp"
"github.com/v2fly/v2ray-core/v5/features/routing"
)
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())})
}
func (p PacketAddrDispatcher) readWorker() {
for {
readBuf := buf.New()