github.com/kelleygo/clashcore@v1.0.2/context/packetconn.go (about)

     1  package context
     2  
     3  import (
     4  	"net"
     5  
     6  	"github.com/kelleygo/clashcore/common/utils"
     7  	C "github.com/kelleygo/clashcore/constant"
     8  
     9  	"github.com/gofrs/uuid/v5"
    10  )
    11  
    12  type PacketConnContext struct {
    13  	id         uuid.UUID
    14  	metadata   *C.Metadata
    15  	packetConn net.PacketConn
    16  }
    17  
    18  func NewPacketConnContext(metadata *C.Metadata) *PacketConnContext {
    19  	return &PacketConnContext{
    20  		id:       utils.NewUUIDV4(),
    21  		metadata: metadata,
    22  	}
    23  }
    24  
    25  // ID implement C.PacketConnContext ID
    26  func (pc *PacketConnContext) ID() uuid.UUID {
    27  	return pc.id
    28  }
    29  
    30  // Metadata implement C.PacketConnContext Metadata
    31  func (pc *PacketConnContext) Metadata() *C.Metadata {
    32  	return pc.metadata
    33  }
    34  
    35  // PacketConn implement C.PacketConnContext PacketConn
    36  func (pc *PacketConnContext) PacketConn() net.PacketConn {
    37  	return pc.packetConn
    38  }
    39  
    40  // InjectPacketConn injectPacketConn manually
    41  func (pc *PacketConnContext) InjectPacketConn(pconn C.PacketConn) {
    42  	pc.packetConn = pconn
    43  }