This commit is contained in:
crusader 2018-10-23 15:02:07 +09:00
parent 59add71a72
commit c72e7b5a0a

View File

@ -138,16 +138,23 @@ func hadlePrePacket(matchCtx *osm.MatchCtx, _connector connector, conn net.Conn,
}
buf := make([]byte, 1024)
var discoveredMatcher osm.Matcher
var (
discoveredMatcher osm.Matcher
packetCount int
_packet *osm.Packet
err error
nRead int
)
LOOP:
for _, _matcher := range matchers {
matchCtx.InitAttribute()
if err := _matcher.Match(matchCtx, 0, packet); nil != err {
err = _matcher.Match(matchCtx, 0, packet)
if nil != err {
continue LOOP
}
packetCount := _matcher.PacketCount(matchCtx)
packetCount = _matcher.PacketCount(matchCtx)
if 0 == packetCount {
return _matcher
@ -155,25 +162,28 @@ LOOP:
INNER_LOOP:
for j := 0; j < packetCount; j++ {
_packet := _matcher.Packet(matchCtx, j)
_packet = _matcher.Packet(matchCtx, j)
if err := conn.SetWriteDeadline(time.Now().Add(deadline)); nil != err {
err = conn.SetWriteDeadline(time.Now().Add(deadline))
if nil != err {
return nil
}
_, err := conn.Write(_packet.Buffer)
_, err = conn.Write(_packet.Buffer)
if nil != err {
return nil
}
if err := conn.SetReadDeadline(time.Now().Add(deadline)); nil != err {
err = conn.SetReadDeadline(time.Now().Add(deadline))
if nil != err {
return nil
}
n, err := conn.Read(buf)
nRead, err = conn.Read(buf)
if nil != err {
return nil
}
if err := _matcher.Match(matchCtx, j+1, osm.NewPacket(buf, n)); nil == err {
err = _matcher.Match(matchCtx, j+1, osm.NewPacket(buf, nRead))
if nil == err {
discoveredMatcher = _matcher
} else {
discoveredMatcher = nil
@ -202,49 +212,57 @@ func hadlePostPacket(matchCtx *osm.MatchCtx, _connector connector, targetPort *o
}
buf := make([]byte, 1024)
var discoveredMatcher osm.Matcher
var (
discoveredMatcher osm.Matcher
packetCount int
_packet *osm.Packet
err error
conn net.Conn
nRead int
)
LOOP:
for _, _matcher := range matchers {
matchCtx.InitAttribute()
packetCount := _matcher.PacketCount(matchCtx)
packetCount = _matcher.PacketCount(matchCtx)
if 0 == packetCount {
continue LOOP
}
conn, err := _connector.dial(targetPort)
conn, err = _connector.dial(targetPort)
if nil != err {
return nil
}
INNER_LOOP:
for j := 0; j < packetCount; j++ {
_packet := _matcher.Packet(matchCtx, j)
_packet = _matcher.Packet(matchCtx, j)
if err := conn.SetWriteDeadline(time.Now().Add(deadline)); nil != err {
break INNER_LOOP
}
_, err := conn.Write(_packet.Buffer)
err = conn.SetWriteDeadline(time.Now().Add(deadline))
if nil != err {
break INNER_LOOP
}
_, err = conn.Write(_packet.Buffer)
if nil != err {
log.Print(err)
break INNER_LOOP
}
if err := conn.SetReadDeadline(time.Now().Add(deadline)); nil != err {
err = conn.SetReadDeadline(time.Now().Add(deadline))
if nil != err {
break INNER_LOOP
}
n, err := conn.Read(buf)
nRead, err = conn.Read(buf)
if nil != err {
// if !_matcher.HasResponse(matchCtx, j) {
// discoveredMatcher = _matcher
// }
break INNER_LOOP
}
// log.Printf("res: %s", string(buf[:n]))
if err := _matcher.Match(matchCtx, j, osm.NewPacket(buf, n)); err == nil {
err = _matcher.Match(matchCtx, j, osm.NewPacket(buf, nRead))
if err == nil {
if packetCount-1 == j {
discoveredMatcher = _matcher