mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
fix: fixed replay time computation using actual dates instead of the assumption of one frame per second
This commit is contained in:
parent
50d01429cd
commit
54116f7fbe
4 changed files with 45 additions and 2 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/session"
|
||||
|
||||
|
@ -146,6 +147,36 @@ func (e *RecordEntry) Next() []byte {
|
|||
return e.frames[cur]
|
||||
}
|
||||
|
||||
func (e *RecordEntry) TimeOf(idx int) time.Time {
|
||||
e.Lock()
|
||||
defer e.Unlock()
|
||||
|
||||
buf := e.frames[idx]
|
||||
frame := make(map[string]interface{})
|
||||
|
||||
if err := json.Unmarshal(buf, &frame); err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
return time.Time{}
|
||||
} else if tm, err := time.Parse(time.RFC3339, frame["polled_at"].(string)); err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
return time.Time{}
|
||||
} else {
|
||||
return tm
|
||||
}
|
||||
}
|
||||
|
||||
func (e *RecordEntry) StartedAt() time.Time {
|
||||
return e.TimeOf(0)
|
||||
}
|
||||
|
||||
func (e *RecordEntry) StoppedAt() time.Time {
|
||||
return e.TimeOf(e.NumStates)
|
||||
}
|
||||
|
||||
func (e *RecordEntry) Duration() time.Duration {
|
||||
return e.StoppedAt().Sub(e.StartedAt())
|
||||
}
|
||||
|
||||
// the Record object represents a recorded session
|
||||
type Record struct {
|
||||
sync.Mutex
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue