mihomo/context/packetconn.go

44 lines
924 B
Go
Raw Permalink Normal View History

package context
import (
"net"
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/common/utils"
C "github.com/metacubex/mihomo/constant"
2023-04-09 15:40:17 +08:00
"github.com/gofrs/uuid/v5"
)
type PacketConnContext struct {
id uuid.UUID
metadata *C.Metadata
packetConn net.PacketConn
}
func NewPacketConnContext(metadata *C.Metadata) *PacketConnContext {
return &PacketConnContext{
2023-03-15 10:10:03 +08:00
id: utils.NewUUIDV4(),
metadata: metadata,
}
}
// ID implement C.PacketConnContext ID
func (pc *PacketConnContext) ID() uuid.UUID {
return pc.id
}
// Metadata implement C.PacketConnContext Metadata
func (pc *PacketConnContext) Metadata() *C.Metadata {
return pc.metadata
}
// PacketConn implement C.PacketConnContext PacketConn
func (pc *PacketConnContext) PacketConn() net.PacketConn {
return pc.packetConn
}
// InjectPacketConn injectPacketConn manually
func (pc *PacketConnContext) InjectPacketConn(pconn C.PacketConn) {
pc.packetConn = pconn
}