Skip to content

Commit 2e3083a

Browse files
committed
Gossip golint fixes under gossip/util
Fixed all golint warnings under gossip/gossip/util Change-Id: Ia68cdb4eee9e0737168b7e4a76b84e16c81f6602 Signed-off-by: Yacov Manevich <[email protected]>
1 parent 2be1717 commit 2e3083a

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

gossip/comm/comm_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewCommInstanceWithServer(port int, idMapper identity.Mapper, peerIdentity
8787
selfCertHash: certHash,
8888
PKIID: idMapper.GetPKIidOfCert(peerIdentity),
8989
idMapper: idMapper,
90-
logger: util.GetLogger(util.LOGGING_COMM_MODULE, fmt.Sprintf("%d", port)),
90+
logger: util.GetLogger(util.LoggingCommModule, fmt.Sprintf("%d", port)),
9191
peerIdentity: peerIdentity,
9292
opts: dialOpts,
9393
port: port,

gossip/discovery/discovery_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func NewDiscoveryService(bootstrapPeers []string, self NetworkMember, comm CommS
115115
lock: &sync.RWMutex{},
116116
toDieChan: make(chan struct{}, 1),
117117
toDieFlag: int32(0),
118-
logger: util.GetLogger(util.LOGGING_DISCOVERY_MODULE, self.Endpoint),
118+
logger: util.GetLogger(util.LoggingDiscoveryModule, self.Endpoint),
119119
}
120120

121121
d.logger.SetLevel(logging.WARNING)

gossip/gossip/gossip_impl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewGossipService(conf *Config, s *grpc.Server, secAdvisor api.SecurityAdvis
7777
var c comm.Comm
7878
var err error
7979
idMapper := identity.NewIdentityMapper(mcs)
80-
lgr := util.GetLogger(util.LOGGING_GOSSIP_MODULE, conf.ID)
80+
lgr := util.GetLogger(util.LoggingGossipModule, conf.ID)
8181
if s == nil {
8282
c, err = createCommWithServer(conf.BindPort, idMapper, selfIdentity)
8383
} else {

gossip/util/logging.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import (
2828
)
2929

3030
const (
31-
LOGGING_MESSAGE_BUFF_MODULE = "mbuff"
32-
LOGGING_EMITTER_MODULE = "emitter"
33-
LOGGING_GOSSIP_MODULE = "gossip"
34-
LOGGING_DISCOVERY_MODULE = "discovery"
35-
LOGGING_COMM_MODULE = "comm"
31+
// LoggingMessageBuffModule defines the module for logging message buffer
32+
LoggingMessageBuffModule = "mbuff"
33+
// LoggingEmitterModule defines the module for logging emitter
34+
LoggingEmitterModule = "emitter"
35+
// LoggingGossipModule defines the module for logging gossip
36+
LoggingGossipModule = "gossip"
37+
// LoggingDiscoveryModule defines the module for logging discovery
38+
LoggingDiscoveryModule = "discovery"
39+
// LoggingCommModule defines the module for logging communication
40+
LoggingCommModule = "comm"
3641
)
3742

3843
var loggersByModules = make(map[string]*Logger)
@@ -48,25 +53,30 @@ func init() {
4853
grpclog.SetLogger(log.New(ioutil.Discard, "", 0))
4954
}
5055

56+
// Logger defines a logger for gossip
5157
type Logger struct {
5258
logging.Logger
5359
module string
5460
}
5561

62+
// SetDefaultFormat sets the formatter for the gossip logger
5663
func SetDefaultFormat(formatStr string) {
5764
format = logging.MustStringFormatter(formatStr)
5865
}
5966

67+
// SetDefaultLoggingLevel sets the default logging level for the gossip logger
6068
func SetDefaultLoggingLevel(level logging.Level) {
6169
defaultLevel = level
6270
}
6371

72+
// SetLevel sets the level for the logger
6473
func (l *Logger) SetLevel(lvl logging.Level) {
6574
logging.SetLevel(lvl, l.module)
6675
}
6776

68-
func GetLogger(module string, peerId string) *Logger {
69-
module = module + "-" + peerId
77+
// GetLogger returns a logger for given gossip module and peerID
78+
func GetLogger(module string, peerID string) *Logger {
79+
module = module + "-" + peerID
7080
lock.Lock()
7181
defer lock.Unlock()
7282

gossip/util/misc.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import (
2424
"sync"
2525
)
2626

27+
// Equals returns whether a and b are the same
2728
type Equals func(a interface{}, b interface{}) bool
2829

2930
func init() {
3031
rand.Seed(42)
3132
}
3233

34+
// IndexInSlice returns the index of given object o in array
3335
func IndexInSlice(array interface{}, o interface{}, equals Equals) int {
3436
arr := reflect.ValueOf(array)
3537
for i := 0; i < arr.Len(); i++ {
@@ -44,6 +46,8 @@ func numbericEqual(a interface{}, b interface{}) bool {
4446
return a.(int) == b.(int)
4547
}
4648

49+
// GetRandomIndices returns a slice of random indices
50+
// from 0 to given highestIndex
4751
func GetRandomIndices(indiceCount, highestIndex int) []int {
4852
if highestIndex+1 < indiceCount {
4953
return nil
@@ -67,36 +71,43 @@ func GetRandomIndices(indiceCount, highestIndex int) []int {
6771
return indices
6872
}
6973

74+
// Abs returns abs(a-b)
7075
func Abs(a, b uint64) uint64 {
7176
if a > b {
7277
return a - b
73-
} else {
74-
return b - a
7578
}
79+
return b - a
7680
}
7781

82+
// Set is a generic and thread-safe
83+
// set container
7884
type Set struct {
7985
items map[interface{}]struct{}
8086
lock *sync.RWMutex
8187
}
8288

89+
// NewSet returns a new set
8390
func NewSet() *Set {
8491
return &Set{lock: &sync.RWMutex{}, items: make(map[interface{}]struct{})}
8592
}
8693

94+
// Add adds given item to the set
8795
func (s *Set) Add(item interface{}) {
8896
s.lock.Lock()
8997
defer s.lock.Unlock()
9098
s.items[item] = struct{}{}
9199
}
92100

101+
// Exists returns true whether given item is in the set
93102
func (s *Set) Exists(item interface{}) bool {
94103
s.lock.RLock()
95104
defer s.lock.RUnlock()
96105
_, exists := s.items[item]
97106
return exists
98107
}
99108

109+
// ToArray returns a slice with items
110+
// at the point in time the method was invoked
100111
func (s *Set) ToArray() []interface{} {
101112
s.lock.RLock()
102113
defer s.lock.RUnlock()
@@ -109,12 +120,14 @@ func (s *Set) ToArray() []interface{} {
109120
return a
110121
}
111122

123+
// Clear removes all elements from set
112124
func (s *Set) Clear() {
113125
s.lock.Lock()
114126
defer s.lock.Unlock()
115127
s.items = make(map[interface{}]struct{})
116128
}
117129

130+
// Remove removes a given item from the set
118131
func (s *Set) Remove(item interface{}) {
119132
s.lock.Lock()
120133
defer s.lock.Unlock()
@@ -126,6 +139,8 @@ type goroutine struct {
126139
Stack []string
127140
}
128141

142+
// PrintStackTrace prints to stdout
143+
// all goroutines
129144
func PrintStackTrace() {
130145
buf := make([]byte, 1<<16)
131146
runtime.Stack(buf, true)

0 commit comments

Comments
 (0)