fix: let quic-go works on outbound's packetConn
This commit is contained in:
parent
5d0efb5472
commit
516c219580
4 changed files with 48 additions and 25 deletions
|
@ -210,6 +210,8 @@ func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn {
|
||||||
type packetConn struct {
|
type packetConn struct {
|
||||||
net.PacketConn
|
net.PacketConn
|
||||||
chain C.Chain
|
chain C.Chain
|
||||||
|
adapterName string
|
||||||
|
connID string
|
||||||
actualRemoteDestination string
|
actualRemoteDestination string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +229,14 @@ func (c *packetConn) AppendToChains(a C.ProxyAdapter) {
|
||||||
c.chain = append(c.chain, a.Name())
|
c.chain = append(c.chain, a.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *packetConn) LocalAddr() net.Addr {
|
||||||
|
lAddr := c.PacketConn.LocalAddr()
|
||||||
|
return N.NewCustomAddr(c.adapterName, c.connID, lAddr) // make quic-go's connMultiplexer happy
|
||||||
|
}
|
||||||
|
|
||||||
func newPacketConn(pc net.PacketConn, a C.ProxyAdapter) C.PacketConn {
|
func newPacketConn(pc net.PacketConn, a C.ProxyAdapter) C.PacketConn {
|
||||||
return &packetConn{pc, []string{a.Name()}, parseRemoteDestination(a.Addr())}
|
id, _ := utils.UnsafeUUIDGenerator.NewV4()
|
||||||
|
return &packetConn{pc, []string{a.Name()}, a.Name(), id.String(), parseRemoteDestination(a.Addr())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRemoteDestination(addr string) string {
|
func parseRemoteDestination(addr string) string {
|
||||||
|
|
36
common/net/addr.go
Normal file
36
common/net/addr.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package net
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CustomAddr interface {
|
||||||
|
net.Addr
|
||||||
|
RawAddr() net.Addr
|
||||||
|
}
|
||||||
|
|
||||||
|
type customAddr struct {
|
||||||
|
networkStr string
|
||||||
|
addrStr string
|
||||||
|
rawAddr net.Addr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a customAddr) Network() string {
|
||||||
|
return a.networkStr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a customAddr) String() string {
|
||||||
|
return a.addrStr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a customAddr) RawAddr() net.Addr {
|
||||||
|
return a.rawAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCustomAddr(networkStr string, addrStr string, rawAddr net.Addr) CustomAddr {
|
||||||
|
return customAddr{
|
||||||
|
networkStr: networkStr,
|
||||||
|
addrStr: addrStr,
|
||||||
|
rawAddr: rawAddr,
|
||||||
|
}
|
||||||
|
}
|
|
@ -250,29 +250,7 @@ func (q *quicStreamPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *quicStreamPacketConn) LocalAddr() net.Addr {
|
func (q *quicStreamPacketConn) LocalAddr() net.Addr {
|
||||||
addr := q.quicConn.LocalAddr()
|
return q.quicConn.LocalAddr()
|
||||||
if q.inputConn != nil { // client
|
|
||||||
return &packetAddr{addrStr: q.quicConn.LocalAddr().String(), connId: q.connId, rawAddr: addr}
|
|
||||||
}
|
|
||||||
return addr // server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ net.PacketConn = &quicStreamPacketConn{}
|
var _ net.PacketConn = &quicStreamPacketConn{}
|
||||||
|
|
||||||
type packetAddr struct {
|
|
||||||
addrStr string
|
|
||||||
connId uint32
|
|
||||||
rawAddr net.Addr
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a packetAddr) Network() string {
|
|
||||||
return "tuic"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a packetAddr) String() string {
|
|
||||||
return fmt.Sprintf("%s-%d", a.addrStr, a.connId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a packetAddr) RawAddr() net.Addr {
|
|
||||||
return a.rawAddr
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -153,7 +154,7 @@ func (s *serverHandler) parsePacket(packet Packet, udpRelayMode string) (err err
|
||||||
return s.HandleUdpFn(packet.ADDR.SocksAddr(), &serverUDPPacket{
|
return s.HandleUdpFn(packet.ADDR.SocksAddr(), &serverUDPPacket{
|
||||||
pc: pc,
|
pc: pc,
|
||||||
packet: &packet,
|
packet: &packet,
|
||||||
rAddr: &packetAddr{addrStr: "tuic-" + s.uuid.String(), connId: assocId, rawAddr: s.quicConn.RemoteAddr()},
|
rAddr: N.NewCustomAddr("tuic", fmt.Sprintf("tuic-%s-%d", s.uuid, assocId), s.quicConn.RemoteAddr()), // for tunnel's handleUDPConn
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue