github.com/yaling888/clash@v1.53.0/context/packetconn.go (about)

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