-
Notifications
You must be signed in to change notification settings - Fork 0
/
uid.go
64 lines (53 loc) · 1.15 KB
/
uid.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
60
61
62
63
64
package common
import (
"fmt"
"runtime"
"github.com/devsolux/clash-meta/common/utils"
C "github.com/devsolux/clash-meta/constant"
"github.com/devsolux/clash-meta/log"
)
type Uid struct {
*Base
uids utils.IntRanges[uint32]
oUid string
adapter string
}
func NewUid(oUid, adapter string) (*Uid, error) {
if !(runtime.GOOS == "linux" || runtime.GOOS == "android") {
return nil, fmt.Errorf("uid rule not support this platform")
}
uidRange, err := utils.NewIntRanges[uint32](oUid)
if err != nil {
return nil, fmt.Errorf("%w, %w", errPayload, err)
}
if len(uidRange) == 0 {
return nil, errPayload
}
return &Uid{
Base: &Base{},
adapter: adapter,
oUid: oUid,
uids: uidRange,
}, nil
}
func (u *Uid) RuleType() C.RuleType {
return C.Uid
}
func (u *Uid) Match(metadata *C.Metadata) (bool, string) {
if metadata.Uid != 0 {
if u.uids.Check(metadata.Uid) {
return true, u.adapter
}
}
log.Warnln("[UID] could not get uid from %s", metadata.String())
return false, ""
}
func (u *Uid) Adapter() string {
return u.adapter
}
func (u *Uid) Payload() string {
return u.oUid
}
func (u *Uid) ShouldFindProcess() bool {
return true
}