2021-01-23 14:49:46 +08:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2022-10-14 07:46:33 +08:00
|
|
|
N "github.com/Dreamacro/clash/common/net"
|
2021-01-23 14:49:46 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
2022-10-14 07:46:33 +08:00
|
|
|
|
2021-01-23 14:49:46 +08:00
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConnContext struct {
|
|
|
|
id uuid.UUID
|
|
|
|
metadata *C.Metadata
|
2023-02-24 09:54:54 +08:00
|
|
|
conn *N.BufferedConn
|
2021-01-23 14:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConnContext(conn net.Conn, metadata *C.Metadata) *ConnContext {
|
|
|
|
id, _ := uuid.NewV4()
|
2022-07-05 21:00:41 +08:00
|
|
|
|
2021-01-23 14:49:46 +08:00
|
|
|
return &ConnContext{
|
|
|
|
id: id,
|
|
|
|
metadata: metadata,
|
2022-10-14 07:46:33 +08:00
|
|
|
conn: N.NewBufferedConn(conn),
|
2021-01-23 14:49:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID implement C.ConnContext ID
|
|
|
|
func (c *ConnContext) ID() uuid.UUID {
|
|
|
|
return c.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Metadata implement C.ConnContext Metadata
|
|
|
|
func (c *ConnContext) Metadata() *C.Metadata {
|
|
|
|
return c.metadata
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conn implement C.ConnContext Conn
|
2023-02-24 09:54:54 +08:00
|
|
|
func (c *ConnContext) Conn() *N.BufferedConn {
|
2021-01-23 14:49:46 +08:00
|
|
|
return c.conn
|
|
|
|
}
|