This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified main loop. Split out PingRecord and PingState code. Beginn…
…ing of geoip support.
- Loading branch information
Showing
7 changed files
with
129 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package pingbeat | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type PingRecord struct { | ||
Target string | ||
Sent time.Time | ||
} | ||
|
||
func NewPingRecord(target string) *PingRecord { | ||
return &PingRecord{ | ||
Target: target, | ||
Sent: time.Now().UTC(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pingbeat | ||
|
||
import ( | ||
"github.com/elastic/beats/libbeat/logp" | ||
"sync" | ||
) | ||
|
||
type PingState struct { | ||
MU sync.RWMutex | ||
Pings map[int]*PingRecord | ||
SeqNo int | ||
} | ||
|
||
func NewPingState() *PingState { | ||
return &PingState{SeqNo: 0, Pings: make(map[int]*PingRecord)} | ||
} | ||
|
||
func (p *PingState) GetSeqNo() int { | ||
s := p.SeqNo | ||
p.SeqNo++ | ||
// reset sequence no if we go above a 32-bit value | ||
if p.SeqNo > 65535 { | ||
logp.Debug("pingbeat", "Resetting sequence number") | ||
p.SeqNo = 0 | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.