Print successfully connected message every 100 times (#1118)

This commit is contained in:
Egon Elbre 2019-01-23 14:07:22 +02:00 committed by GitHub
parent 05b96f95a3
commit 8677c68b68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ package node
import (
"context"
"sync/atomic"
"go.uber.org/zap"
@ -16,6 +17,8 @@ import (
type Server struct {
dht dht.DHT
log *zap.Logger
connected int32
}
// NewServer returns a newly instantiated Node Server
@ -46,7 +49,12 @@ func (server *Server) Query(ctx context.Context, req *pb.QueryRequest) (*pb.Quer
if err != nil {
server.log.Error("could not respond to connection success", zap.Error(err))
} else {
server.log.Sugar().Debugf("Successfully connected with %s", req.Sender.Address.Address)
count := atomic.AddInt32(&server.connected, 1)
if count == 1 {
server.log.Sugar().Debugf("Successfully connected with %s", req.Sender.Address.Address)
} else if count%100 == 0 {
server.log.Sugar().Debugf("Successfully connected with %s %dx times", req.Sender.Address.Address, count)
}
}
}
}