chore: using uint16 for ports in Metadata

This commit is contained in:
wwqgtxx
2023-08-09 13:51:02 +08:00
parent bad9f2e6dc
commit e2e0fd4eba
16 changed files with 84 additions and 79 deletions

View File

@ -2,7 +2,6 @@ package common
import (
"fmt"
"strconv"
"github.com/Dreamacro/clash/common/utils"
C "github.com/Dreamacro/clash/constant"
@ -28,7 +27,7 @@ func (p *Port) Match(metadata *C.Metadata) (bool, string) {
case C.SrcPort:
targetPort = metadata.SrcPort
}
return p.matchPortReal(targetPort), p.adapter
return p.portRanges.Check(targetPort), p.adapter
}
func (p *Port) Adapter() string {
@ -39,12 +38,6 @@ func (p *Port) Payload() string {
return p.port
}
func (p *Port) matchPortReal(portRef string) bool {
port, _ := strconv.Atoi(portRef)
return p.portRanges.Check(uint16(port))
}
func NewPort(port string, adapter string, ruleType C.RuleType) (*Port, error) {
portRanges, err := utils.NewIntRanges[uint16](port)
if err != nil {