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

     1  package context
     2  
     3  import (
     4  	"github.com/kelleygo/clashcore/common/utils"
     5  	"net"
     6  
     7  	N "github.com/kelleygo/clashcore/common/net"
     8  	C "github.com/kelleygo/clashcore/constant"
     9  
    10  	"github.com/gofrs/uuid/v5"
    11  )
    12  
    13  type ConnContext struct {
    14  	id       uuid.UUID
    15  	metadata *C.Metadata
    16  	conn     *N.BufferedConn
    17  }
    18  
    19  func NewConnContext(conn net.Conn, metadata *C.Metadata) *ConnContext {
    20  	return &ConnContext{
    21  		id:       utils.NewUUIDV4(),
    22  		metadata: metadata,
    23  		conn:     N.NewBufferedConn(conn),
    24  	}
    25  }
    26  
    27  // ID implement C.ConnContext ID
    28  func (c *ConnContext) ID() uuid.UUID {
    29  	return c.id
    30  }
    31  
    32  // Metadata implement C.ConnContext Metadata
    33  func (c *ConnContext) Metadata() *C.Metadata {
    34  	return c.metadata
    35  }
    36  
    37  // Conn implement C.ConnContext Conn
    38  func (c *ConnContext) Conn() *N.BufferedConn {
    39  	return c.conn
    40  }