mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 01:51:29 +00:00
30 lines
682 B
Go
30 lines
682 B
Go
package rule
|
|
|
|
import (
|
|
"github.com/sagernet/sing-box/adapter"
|
|
)
|
|
|
|
var _ RuleItem = (*NetworkIsExpensiveItem)(nil)
|
|
|
|
type NetworkIsExpensiveItem struct {
|
|
networkManager adapter.NetworkManager
|
|
}
|
|
|
|
func NewNetworkIsExpensiveItem(networkManager adapter.NetworkManager) *NetworkIsExpensiveItem {
|
|
return &NetworkIsExpensiveItem{
|
|
networkManager: networkManager,
|
|
}
|
|
}
|
|
|
|
func (r *NetworkIsExpensiveItem) Match(metadata *adapter.InboundContext) bool {
|
|
networkInterface := r.networkManager.DefaultNetworkInterface()
|
|
if networkInterface == nil {
|
|
return false
|
|
}
|
|
return networkInterface.Expensive
|
|
}
|
|
|
|
func (r *NetworkIsExpensiveItem) String() string {
|
|
return "network_is_expensive=true"
|
|
}
|