optimize ssh Feed function example

This commit is contained in:
PICKQUE 2024-06-12 17:55:32 +08:00
parent 1de95ed53e
commit 98113964ad

View File

@ -50,38 +50,48 @@ func newSSHStream(logger analyzer.Logger) *sshStream {
return s return s
} }
func (s *sshStream) Feed(rev, start, end bool, skip int, data []byte) (u *analyzer.PropUpdate, done bool) { func (s *sshStream) Feed(rev, start, end bool, skip int, data []byte) (u *analyzer.PropUpdate, _done bool) {
if skip != 0 { if skip != 0 {
return nil, true return nil, true
} }
if len(data) == 0 { if len(data) == 0 {
return nil, false return nil, false
} }
var update *analyzer.PropUpdate var update *analyzer.PropUpdate
var cancelled bool var cancelled bool
var buf *utils.ByteBuffer
var updated, done *bool
var m *analyzer.PropMap
var lsm *utils.LinearStateMachine
var key string
if rev { if rev {
s.serverBuf.Append(data) buf = s.serverBuf
s.serverUpdated = false updated = &s.serverUpdated
cancelled, s.serverDone = s.serverLSM.Run() lsm = s.serverLSM
if s.serverUpdated { m = &s.serverMap
update = &analyzer.PropUpdate{ done = &s.serverDone
Type: analyzer.PropUpdateMerge, key = "server"
M: analyzer.PropMap{"server": s.serverMap},
}
s.serverUpdated = false
}
} else { } else {
s.clientBuf.Append(data) buf = s.clientBuf
s.clientUpdated = false updated = &s.serverUpdated
cancelled, s.clientDone = s.clientLSM.Run() lsm = s.clientLSM
if s.clientUpdated { m = &s.serverMap
update = &analyzer.PropUpdate{ done = &s.clientDone
Type: analyzer.PropUpdateMerge, key = "client"
M: analyzer.PropMap{"client": s.clientMap},
}
s.clientUpdated = false
}
} }
buf.Append(data)
cancelled, *done = lsm.Run()
if *updated {
update = &analyzer.PropUpdate{
Type: analyzer.PropUpdateMerge,
M: analyzer.PropMap{key: *m},
}
*updated = false
}
return update, cancelled || (s.clientDone && s.serverDone) return update, cancelled || (s.clientDone && s.serverDone)
} }