2017-11-21 12:47:55 +00:00
|
|
|
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
|
2017-11-22 05:55:40 +00:00
|
|
|
IsSend(port int) bool
|
2017-11-21 12:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|