2022-07-23 19:01:41 +08:00
|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/netip"
|
|
|
|
|
2022-08-15 11:40:49 +08:00
|
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
"github.com/sagernet/sing-tun"
|
2022-07-23 19:01:41 +08:00
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Searcher interface {
|
2022-08-20 10:38:12 +08:00
|
|
|
FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error)
|
2022-07-23 19:01:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var ErrNotFound = E.New("process not found")
|
|
|
|
|
2022-08-15 11:40:49 +08:00
|
|
|
type Config struct {
|
|
|
|
Logger log.ContextLogger
|
|
|
|
PackageManager tun.PackageManager
|
|
|
|
}
|
|
|
|
|
2022-07-23 19:01:41 +08:00
|
|
|
type Info struct {
|
|
|
|
ProcessPath string
|
|
|
|
PackageName string
|
|
|
|
User string
|
|
|
|
UserId int32
|
|
|
|
}
|
2022-08-20 10:38:12 +08:00
|
|
|
|
|
|
|
func FindProcessInfo(searcher Searcher, ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
|
2022-09-25 22:16:24 +08:00
|
|
|
return findProcessInfo(searcher, ctx, network, source, destination)
|
2022-08-20 10:38:12 +08:00
|
|
|
}
|