github.com/chwjbn/xclash@v0.2.0/context/conn.go (about)

     1  package context
     2  
     3  import (
     4  	"github.com/chwjbn/xclash/component/auth"
     5  	"net"
     6  
     7  	C "github.com/chwjbn/xclash/constant"
     8  
     9  	"github.com/gofrs/uuid"
    10  )
    11  
    12  type ConnContext struct {
    13  	id       uuid.UUID
    14  	metadata *C.Metadata
    15  	conn     net.Conn
    16  	authUser *auth.AuthUser
    17  }
    18  
    19  func NewConnContext(conn net.Conn, metadata *C.Metadata) *ConnContext {
    20  	id, _ := uuid.NewV4()
    21  	return &ConnContext{
    22  		id:       id,
    23  		metadata: metadata,
    24  		conn:     conn,
    25  	}
    26  }
    27  
    28  func NewConnContextWithAuth(conn net.Conn, metadata *C.Metadata, authUser *auth.AuthUser) *ConnContext {
    29  	id, _ := uuid.NewV4()
    30  	return &ConnContext{
    31  		id:       id,
    32  		metadata: metadata,
    33  		conn:     conn,
    34  		authUser: authUser,
    35  	}
    36  }
    37  
    38  // ID implement C.ConnContext ID
    39  func (c *ConnContext) ID() uuid.UUID {
    40  	return c.id
    41  }
    42  
    43  // Metadata implement C.ConnContext Metadata
    44  func (c *ConnContext) Metadata() *C.Metadata {
    45  	return c.metadata
    46  }
    47  
    48  // Conn implement C.ConnContext Conn
    49  func (c *ConnContext) Conn() net.Conn {
    50  	return c.conn
    51  }
    52  
    53  func (c *ConnContext) AuthUser() *auth.AuthUser {
    54  	return c.authUser
    55  }
    56  
    57  func (c *ConnContext) SetAuthUser(authUser *auth.AuthUser) {
    58  	c.authUser = authUser
    59  }