mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-24 17:41:29 +00: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"
|
||
|
}
|