64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package matcher
|
|
|
|
type Matcher interface {
|
|
ServiceName() string
|
|
|
|
IsPrePacket() bool
|
|
PacketCount() int
|
|
Packet(index int) *Packet
|
|
HasResponse(index int) bool
|
|
|
|
IsError(info MatchInfo, index int, packet *Packet) bool
|
|
Match(info MatchInfo, index int, packet *Packet) bool
|
|
}
|
|
|
|
type UDPMatcher interface {
|
|
Matcher
|
|
IsSend(port int) bool
|
|
}
|
|
|
|
type Matchers struct {
|
|
packets []*Packet
|
|
}
|
|
|
|
func (m *Matchers) PacketCount() int {
|
|
return len(m.packets)
|
|
}
|
|
|
|
func (m *Matchers) Packet(index int) *Packet {
|
|
return m.packets[index]
|
|
}
|
|
|
|
func (m *Matchers) HasResponse(index int) bool {
|
|
return len(m.packets)-1 > index
|
|
}
|
|
|
|
func (m *Matchers) AddPacket(packet *Packet) {
|
|
m.packets = append(m.packets, packet)
|
|
}
|
|
|
|
type MatchInfo interface {
|
|
IP() string
|
|
Port() int
|
|
}
|
|
|
|
type simpleMatchInfo struct {
|
|
ip string
|
|
port int
|
|
}
|
|
|
|
func (mi *simpleMatchInfo) IP() string {
|
|
return mi.ip
|
|
}
|
|
|
|
func (mi *simpleMatchInfo) Port() int {
|
|
return mi.port
|
|
}
|
|
|
|
func NewMatchInfo(ip string, port int) MatchInfo {
|
|
return &simpleMatchInfo{
|
|
ip: ip,
|
|
port: port,
|
|
}
|
|
}
|