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