2021-01-23 14:49:46 +08:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2022-04-09 22:30:36 +08:00
|
|
|
CN "github.com/Dreamacro/clash/common/net"
|
2021-01-23 14:49:46 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConnContext struct {
|
|
|
|
id uuid.UUID
|
|
|
|
metadata *C.Metadata
|
|
|
|
conn net.Conn
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewConnContext(conn net.Conn, metadata *C.Metadata) *ConnContext {
|
|
|
|
id, _ := uuid.NewV4()
|
2022-07-05 21:00:41 +08:00
|
|
|
|
|
|
|
if _, ok := conn.(*CN.BufferedConn); !ok {
|
|
|
|
conn = CN.NewBufferedConn(conn)
|
|
|
|
}
|
|
|
|
|
2021-01-23 14:49:46 +08:00
|
|
|
return &ConnContext{
|
|
|
|
id: id,
|
|
|
|
metadata: metadata,
|
2022-07-05 21:00:41 +08:00
|
|
|
conn: 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
|
|
|
|
func (c *ConnContext) Conn() net.Conn {
|
|
|
|
return c.conn
|
|
|
|
}
|