mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-23 09:01:30 +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"
|
|
}
|