mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
45 lines
948 B
Go
45 lines
948 B
Go
package context
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/Dreamacro/clash/common/utils"
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
type PacketConnContext struct {
|
|
id uuid.UUID
|
|
metadata *C.Metadata
|
|
packetConn net.PacketConn
|
|
}
|
|
|
|
func NewPacketConnContext(metadata *C.Metadata) *PacketConnContext {
|
|
id, _ := utils.UnsafeUUIDGenerator.NewV4()
|
|
return &PacketConnContext{
|
|
id: id,
|
|
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
|
|
}
|