github.com/sagernet/sing-box@v1.9.0-rc.20/route/rule_item_wifi_bssid.go (about)

     1  package route
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/sagernet/sing-box/adapter"
     7  	F "github.com/sagernet/sing/common/format"
     8  )
     9  
    10  var _ RuleItem = (*WIFIBSSIDItem)(nil)
    11  
    12  type WIFIBSSIDItem struct {
    13  	bssidList []string
    14  	bssidMap  map[string]bool
    15  	router    adapter.Router
    16  }
    17  
    18  func NewWIFIBSSIDItem(router adapter.Router, bssidList []string) *WIFIBSSIDItem {
    19  	bssidMap := make(map[string]bool)
    20  	for _, bssid := range bssidList {
    21  		bssidMap[bssid] = true
    22  	}
    23  	return &WIFIBSSIDItem{
    24  		bssidList,
    25  		bssidMap,
    26  		router,
    27  	}
    28  }
    29  
    30  func (r *WIFIBSSIDItem) Match(metadata *adapter.InboundContext) bool {
    31  	return r.bssidMap[r.router.WIFIState().BSSID]
    32  }
    33  
    34  func (r *WIFIBSSIDItem) String() string {
    35  	if len(r.bssidList) == 1 {
    36  		return F.ToString("wifi_bssid=", r.bssidList[0])
    37  	}
    38  	return F.ToString("wifi_bssid=[", strings.Join(r.bssidList, " "), "]")
    39  }