github.com/igoogolx/clash@v1.19.8/context/packetconn.go (about)

     1  package context
     2  
     3  import (
     4  	"net"
     5  
     6  	C "github.com/igoogolx/clash/constant"
     7  
     8  	"github.com/gofrs/uuid/v5"
     9  )
    10  
    11  type PacketConnContext struct {
    12  	id         uuid.UUID
    13  	metadata   *C.Metadata
    14  	packetConn net.PacketConn
    15  }
    16  
    17  func NewPacketConnContext(metadata *C.Metadata) *PacketConnContext {
    18  	id, _ := uuid.NewV4()
    19  	return &PacketConnContext{
    20  		id:       id,
    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  }