This commit is contained in:
crusader 2018-09-03 23:26:43 +09:00
parent c527a84bb2
commit 4c5ca04b8e

View File

@ -97,20 +97,21 @@ func hadlePrePacket(matchCtx *osm.MatchCtx, _connector connector, conn net.Conn,
var discoveredMatcher osm.Matcher var discoveredMatcher osm.Matcher
LOOP: LOOP:
for _, matcher := range matchers { for _, _matcher := range matchers {
if err := matcher.Match(matchCtx, 0, packet); err != nil { matchCtx.InitAttribute()
if err := _matcher.Match(matchCtx, 0, packet); err != nil {
continue LOOP continue LOOP
} }
packetCount := matcher.PacketCount(matchCtx) packetCount := _matcher.PacketCount(matchCtx)
if 0 == packetCount { if 0 == packetCount {
return matcher return _matcher
} }
INNER_LOOP: INNER_LOOP:
for j := 0; j < packetCount; j++ { for j := 0; j < packetCount; j++ {
_packet := matcher.Packet(matchCtx, j) _packet := _matcher.Packet(matchCtx, j)
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err { if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
return nil return nil
@ -128,8 +129,8 @@ LOOP:
return nil return nil
} }
if err := matcher.Match(matchCtx, j+1, osm.NewPacket(buf, n)); nil == err { if err := _matcher.Match(matchCtx, j+1, osm.NewPacket(buf, n)); nil == err {
discoveredMatcher = matcher discoveredMatcher = _matcher
} else { } else {
discoveredMatcher = nil discoveredMatcher = nil
break INNER_LOOP break INNER_LOOP
@ -160,8 +161,9 @@ func hadlePostPacket(matchCtx *osm.MatchCtx, _connector connector, targetPort *o
var discoveredMatcher osm.Matcher var discoveredMatcher osm.Matcher
LOOP: LOOP:
for _, matcher := range matchers { for _, _matcher := range matchers {
packetCount := matcher.PacketCount(matchCtx) matchCtx.InitAttribute()
packetCount := _matcher.PacketCount(matchCtx)
if 0 == packetCount { if 0 == packetCount {
continue LOOP continue LOOP
} }
@ -173,7 +175,7 @@ LOOP:
INNER_LOOP: INNER_LOOP:
for j := 0; j < packetCount; j++ { for j := 0; j < packetCount; j++ {
_packet := matcher.Packet(matchCtx, j) _packet := _matcher.Packet(matchCtx, j)
if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err { if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); nil != err {
break INNER_LOOP break INNER_LOOP
@ -188,8 +190,8 @@ LOOP:
} }
n, err := conn.Read(buf) n, err := conn.Read(buf)
if nil != err { if nil != err {
if !matcher.HasResponse(matchCtx, j) { if !_matcher.HasResponse(matchCtx, j) {
discoveredMatcher = matcher discoveredMatcher = _matcher
} }
break INNER_LOOP break INNER_LOOP
@ -197,9 +199,9 @@ LOOP:
// log.Printf("res: %s", string(buf[:n])) // log.Printf("res: %s", string(buf[:n]))
if err := matcher.Match(matchCtx, j+1, osm.NewPacket(buf, n)); err == nil { if err := _matcher.Match(matchCtx, j+1, osm.NewPacket(buf, n)); err == nil {
if packetCount-1 == j { if packetCount-1 == j {
discoveredMatcher = matcher discoveredMatcher = _matcher
break INNER_LOOP break INNER_LOOP
} }