2021-01-23 14:49:46 +08:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2023-03-05 11:00:14 +08:00
|
|
|
"github.com/Dreamacro/clash/common/utils"
|
2021-01-23 14:49:46 +08:00
|
|
|
"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
|
|
|
|
2023-04-09 15:40:17 +08:00
|
|
|
"github.com/gofrs/uuid/v5"
|
2021-01-23 14:49:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return &ConnContext{
|
2023-03-15 10:10:03 +08:00
|
|
|
id: utils.NewUUIDV4(),
|
2021-01-23 14:49:46 +08:00
|
|
|
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
|
|
|
|
}
|