mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
52 lines
806 B
Go
52 lines
806 B
Go
package rules
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
type Port struct {
|
|
adapter string
|
|
port string
|
|
isSource bool
|
|
}
|
|
|
|
func (p *Port) RuleType() C.RuleType {
|
|
if p.isSource {
|
|
return C.SrcPort
|
|
}
|
|
return C.DstPort
|
|
}
|
|
|
|
func (p *Port) Match(metadata *C.Metadata) bool {
|
|
if p.isSource {
|
|
return metadata.SrcPort == p.port
|
|
}
|
|
return metadata.DstPort == p.port
|
|
}
|
|
|
|
func (p *Port) Adapter() string {
|
|
return p.adapter
|
|
}
|
|
|
|
func (p *Port) Payload() string {
|
|
return p.port
|
|
}
|
|
|
|
func (p *Port) ShouldResolveIP() bool {
|
|
return false
|
|
}
|
|
|
|
func NewPort(port string, adapter string, isSource bool) (*Port, error) {
|
|
_, err := strconv.ParseUint(port, 10, 16)
|
|
if err != nil {
|
|
return nil, errPayload
|
|
}
|
|
return &Port{
|
|
adapter: adapter,
|
|
port: port,
|
|
isSource: isSource,
|
|
}, nil
|
|
}
|