stats/udp: nop on nil DefaultStats
This commit is contained in:
parent
5af37be85c
commit
9b4999c0cf
2 changed files with 16 additions and 13 deletions
|
@ -271,15 +271,21 @@ func (s *Stats) handlePeerEvent(ps *PeerStats, event int) {
|
||||||
|
|
||||||
// RecordEvent broadcasts an event to the default stats queue.
|
// RecordEvent broadcasts an event to the default stats queue.
|
||||||
func RecordEvent(event int) {
|
func RecordEvent(event int) {
|
||||||
|
if DefaultStats != nil {
|
||||||
DefaultStats.RecordEvent(event)
|
DefaultStats.RecordEvent(event)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RecordPeerEvent broadcasts a peer event to the default stats queue.
|
// RecordPeerEvent broadcasts a peer event to the default stats queue.
|
||||||
func RecordPeerEvent(event int, ipv6 bool) {
|
func RecordPeerEvent(event int, ipv6 bool) {
|
||||||
|
if DefaultStats != nil {
|
||||||
DefaultStats.RecordPeerEvent(event, ipv6)
|
DefaultStats.RecordPeerEvent(event, ipv6)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RecordTiming broadcasts a timing event to the default stats queue.
|
// RecordTiming broadcasts a timing event to the default stats queue.
|
||||||
func RecordTiming(event int, duration time.Duration) {
|
func RecordTiming(event int, duration time.Duration) {
|
||||||
|
if DefaultStats != nil {
|
||||||
DefaultStats.RecordTiming(event, duration)
|
DefaultStats.RecordTiming(event, duration)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,21 +13,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
"github.com/chihaya/chihaya/stats"
|
|
||||||
"github.com/chihaya/chihaya/tracker"
|
"github.com/chihaya/chihaya/tracker"
|
||||||
|
|
||||||
_ "github.com/chihaya/chihaya/backend/noop"
|
_ "github.com/chihaya/chihaya/backend/noop"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testPort = "34137"
|
var (
|
||||||
var connectAction = []byte{0, 0, 0, byte(connectActionID)}
|
testPort = "34137"
|
||||||
var announceAction = []byte{0, 0, 0, byte(announceActionID)}
|
connectAction = []byte{0, 0, 0, byte(connectActionID)}
|
||||||
var scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)}
|
announceAction = []byte{0, 0, 0, byte(announceActionID)}
|
||||||
var errorAction = []byte{0, 0, 0, byte(errorActionID)}
|
scrapeAction = []byte{0, 0, 0, byte(scrapeActionID)}
|
||||||
|
errorAction = []byte{0, 0, 0, byte(errorActionID)}
|
||||||
func init() {
|
)
|
||||||
stats.DefaultStats = stats.New(config.StatsConfig{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupTracker(cfg *config.Config) (*Server, chan struct{}, error) {
|
func setupTracker(cfg *config.Config) (*Server, chan struct{}, error) {
|
||||||
tkr, err := tracker.New(cfg)
|
tkr, err := tracker.New(cfg)
|
||||||
|
|
Loading…
Reference in a new issue