mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Add power report service
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/common/dialer"
|
||||
"github.com/sagernet/sing-box/service/powerreport"
|
||||
"github.com/sagernet/sing-tun"
|
||||
"github.com/sagernet/sing/common"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -152,6 +153,18 @@ func (e *Endpoint) Start(postStart bool) error {
|
||||
e.egressPool = tun.NewUDPEgressPool(egressPoolOptions)
|
||||
standardBind.SetEgressProvider(e.egressPool)
|
||||
}
|
||||
powerManager := service.FromContext[*powerreport.Manager](e.options.Context)
|
||||
if powerManager != nil {
|
||||
recorder := powerManager.Recorder()
|
||||
if recorder != nil {
|
||||
attribution := &powerreport.Attribution{Endpoint: e.options.Tag}
|
||||
standardBind.SetIOActivityFuncs(func(size int) {
|
||||
recorder.Touch(powerreport.DirectionInbound, size, attribution)
|
||||
}, func(size int) {
|
||||
recorder.Touch(powerreport.DirectionOutbound, size, attribution)
|
||||
})
|
||||
}
|
||||
}
|
||||
bind = standardBind
|
||||
} else {
|
||||
var (
|
||||
|
||||
@@ -27,6 +27,7 @@ type EndpointOptions struct {
|
||||
EgressPoolOptions tun.UDPEgressPoolOptions
|
||||
Dialer N.Dialer
|
||||
CreateDialer func(interfaceName string) N.Dialer
|
||||
Tag string
|
||||
Name string
|
||||
MTU uint32
|
||||
Address []netip.Prefix
|
||||
|
||||
Reference in New Issue
Block a user