mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 07:22:21 +08:00
30 lines
698 B
Go
30 lines
698 B
Go
package rule
|
|
|
|
import (
|
|
"github.com/sagernet/sing-box/adapter"
|
|
)
|
|
|
|
var _ RuleItem = (*NetworkIsConstrainedItem)(nil)
|
|
|
|
type NetworkIsConstrainedItem struct {
|
|
networkManager adapter.NetworkManager
|
|
}
|
|
|
|
func NewNetworkIsConstrainedItem(networkManager adapter.NetworkManager) *NetworkIsConstrainedItem {
|
|
return &NetworkIsConstrainedItem{
|
|
networkManager: networkManager,
|
|
}
|
|
}
|
|
|
|
func (r *NetworkIsConstrainedItem) Match(metadata *adapter.InboundContext) bool {
|
|
networkInterface := r.networkManager.DefaultNetworkInterface()
|
|
if networkInterface == nil {
|
|
return false
|
|
}
|
|
return networkInterface.Constrained
|
|
}
|
|
|
|
func (r *NetworkIsConstrainedItem) String() string {
|
|
return "network_is_expensive=true"
|
|
}
|