mihomo/context/conn.go

41 lines
786 B
Go
Raw Permalink Normal View History

package context
import (
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/common/utils"
"net"
2023-11-03 21:01:45 +08:00
N "github.com/metacubex/mihomo/common/net"
C "github.com/metacubex/mihomo/constant"
2023-04-09 15:40:17 +08:00
"github.com/gofrs/uuid/v5"
)
type ConnContext struct {
id uuid.UUID
metadata *C.Metadata
conn *N.BufferedConn
}
func NewConnContext(conn net.Conn, metadata *C.Metadata) *ConnContext {
return &ConnContext{
2023-03-15 10:10:03 +08:00
id: utils.NewUUIDV4(),
metadata: metadata,
conn: N.NewBufferedConn(conn),
}
}
// 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() *N.BufferedConn {
return c.conn
}