Skip to content

Commit

Permalink
Merge pull request #364 from negbie/master
Browse files Browse the repository at this point in the history
Use absolute time for dedup
  • Loading branch information
negbie committed May 8, 2020
2 parents 6a2f3a1 + ebf9746 commit 0af21d0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ func (h *HEP) parse(packet []byte) error {
}

t := time.Now()
h.normPayload(t)
if h.ProtoType == 0 {
return nil
}

h.Timestamp = time.Unix(int64(h.Tsec), int64(h.Tmsec*1000))
d := t.Sub(h.Timestamp)
if d < 0 || (h.Tsec == 0 && h.Tmsec == 0) {
logp.Debug("hep", "got timestamp in the future with delta: %d from nodeID %d", d, h.NodeID)
h.Timestamp = t
}

h.normPayload()
if h.ProtoType == 0 {
return nil
}

if h.ProtoType == 1 && len(h.Payload) > 32 {
err = h.parseSIP()
if err != nil {
Expand Down Expand Up @@ -157,17 +157,20 @@ var fixUTF8 = func(r rune) rune {
return r
}

func (h *HEP) normPayload(t time.Time) {
func (h *HEP) normPayload() {
if config.Setting.Dedup {
ts := uint64(t.UnixNano())
ts := uint64(h.Timestamp.UnixNano())
kh := make([]byte, 8)
ks := xxhash.Sum64String(h.Payload)
binary.BigEndian.PutUint64(kh, ks)

if buf := dedup.Get(nil, kh); buf != nil {
i := binary.BigEndian.Uint64(buf)
d := ts - i
if d < 400e6 || d > 1e18 {
if i > ts {
d = i - ts
}
if d < 500e6 {
h.ProtoType = 0
return
}
Expand Down

0 comments on commit 0af21d0

Please sign in to comment.