This commit is contained in:
jackdaw@loafle.com 2017-04-11 12:20:05 +09:00
parent 031ba9e162
commit 74b626cd9d

View File

@ -9,6 +9,11 @@ import (
type SocketHeahthCrawler struct {
CrawlerImpl
m matcher.Matcher
}
func (s *SocketHeahthCrawler) SetMatcher(m matcher.Matcher) {
s.m = m
}
func (s *SocketHeahthCrawler) getConnection(params map[string]interface{}) (net.Conn, error) {
@ -44,7 +49,7 @@ func (s *SocketHeahthCrawler) getConnection(params map[string]interface{}) (net.
}
}
func (s *SocketHeahthCrawler) CheckHeahth(params map[string]interface{}, mat matcher.Matcher) (bool, error) {
func (s *SocketHeahthCrawler) CheckHeahth(params map[string]interface{}) (bool, error) {
conn, err := s.getConnection(params)
if err != nil {
@ -52,28 +57,47 @@ func (s *SocketHeahthCrawler) CheckHeahth(params map[string]interface{}, mat mat
}
defer conn.Close()
if mat.IsPrePacket() == true {
if s.m.IsPrePacket() == true {
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := packet.NewPacket(bytes, n)
if mat.Match(0, p, nil) == false {
if s.m.Match(0, p, nil) == false {
return false, nil
}
}
} else {
for i := 0; i < mat.PacketCount(); i++ {
pack := mat.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
for i := 1 ; i < s.m.PacketCount(); i++ {
pack := s.m.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
if s.m.IsNoResponse(i) == true { // empty last response
break
}
p := packet.NewPacket(bytes, n)
if s.m.Match(i, p, nil) == false {
return false, nil
}
}
if mat.IsNoResponse(i) == true { // empty last response
break
}
p := packet.NewPacket(bytes, n)
if mat.Match(i, p, nil) == false {
return false, nil
} else {
for i := 0 ; i < s.m.PacketCount(); i++ {
pack := s.m.Packet(i)
conn.Write(pack.Buffer)
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
if s.m.IsNoResponse(i) == true { // empty last response
break
}
p := packet.NewPacket(bytes, n)
if s.m.Match(i, p, nil) == false {
return false, nil
}
}
}