Skip to content
Snippets Groups Projects
Unverified Commit efcefdcc authored by Wolfgang Welz's avatar Wolfgang Welz Committed by GitHub
Browse files

Fix linter warnings in gossip package (#572)

parent 82fc88d1
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,16 @@ package gossip ...@@ -3,9 +3,16 @@ package gossip
import "errors" import "errors"
var ( var (
ErrNotRunning = errors.New("manager not running") // ErrNotRunning is returned when a neighbor is added to a stopped or not yet started gossip manager.
ErrNotANeighbor = errors.New("peer is not a neighbor") ErrNotRunning = errors.New("manager not running")
ErrLoopback = errors.New("loopback connection not allowed") // ErrUnknownNeighbor is returned when the specified neighbor is not known to the gossip manager.
ErrDuplicateNeighbor = errors.New("peer already connected") ErrUnknownNeighbor = errors.New("unknown neighbor")
ErrInvalidPacket = errors.New("invalid packet") // ErrLoopbackNeighbor is returned when the own peer is specified as a neighbor.
ErrLoopbackNeighbor = errors.New("loopback connection not allowed")
// ErrDuplicateNeighbor is returned when the same peer is added more than once as a neighbor.
ErrDuplicateNeighbor = errors.New("already connected")
// ErrInvalidPacket is returned when the gossip manager receives an invalid packet.
ErrInvalidPacket = errors.New("invalid packet")
// ErrNeighborQueueFull is returned when the send queue is already full.
ErrNeighborQueueFull = errors.New("send queue is full")
) )
...@@ -97,7 +97,7 @@ func (m *Manager) AddOutbound(p *peer.Peer) error { ...@@ -97,7 +97,7 @@ func (m *Manager) AddOutbound(p *peer.Peer) error {
defer m.mu.Unlock() defer m.mu.Unlock()
if p.ID() == m.local.ID() { if p.ID() == m.local.ID() {
return ErrLoopback return ErrLoopbackNeighbor
} }
if m.srv == nil { if m.srv == nil {
return ErrNotRunning return ErrNotRunning
...@@ -111,7 +111,7 @@ func (m *Manager) AddInbound(p *peer.Peer) error { ...@@ -111,7 +111,7 @@ func (m *Manager) AddInbound(p *peer.Peer) error {
defer m.mu.Unlock() defer m.mu.Unlock()
if p.ID() == m.local.ID() { if p.ID() == m.local.ID() {
return ErrLoopback return ErrLoopbackNeighbor
} }
if m.srv == nil { if m.srv == nil {
return ErrNotRunning return ErrNotRunning
...@@ -125,7 +125,7 @@ func (m *Manager) DropNeighbor(id identity.ID) error { ...@@ -125,7 +125,7 @@ func (m *Manager) DropNeighbor(id identity.ID) error {
defer m.mu.Unlock() defer m.mu.Unlock()
if _, ok := m.neighbors[id]; !ok { if _, ok := m.neighbors[id]; !ok {
return ErrNotANeighbor return ErrUnknownNeighbor
} }
n := m.neighbors[id] n := m.neighbors[id]
delete(m.neighbors, id) delete(m.neighbors, id)
...@@ -161,12 +161,12 @@ func (m *Manager) AllNeighbors() []*Neighbor { ...@@ -161,12 +161,12 @@ func (m *Manager) AllNeighbors() []*Neighbor {
func (m *Manager) getNeighbors(ids ...identity.ID) []*Neighbor { func (m *Manager) getNeighbors(ids ...identity.ID) []*Neighbor {
if len(ids) > 0 { if len(ids) > 0 {
return m.getNeighborsById(ids) return m.getNeighborsByID(ids)
} }
return m.AllNeighbors() return m.AllNeighbors()
} }
func (m *Manager) getNeighborsById(ids []identity.ID) []*Neighbor { func (m *Manager) getNeighborsByID(ids []identity.ID) []*Neighbor {
result := make([]*Neighbor, 0, len(ids)) result := make([]*Neighbor, 0, len(ids))
m.mu.Lock() m.mu.Lock()
......
...@@ -336,12 +336,12 @@ func TestMessageRequest(t *testing.T) { ...@@ -336,12 +336,12 @@ func TestMessageRequest(t *testing.T) {
// wait for the connections to establish // wait for the connections to establish
wg.Wait() wg.Wait()
messageId := message.Id{} id := message.Id{}
// mgrA should eventually receive the message // mgrA should eventually receive the message
mgrA.On("messageReceived", &MessageReceivedEvent{Data: testMessageData, Peer: peerB}).Once() mgrA.On("messageReceived", &MessageReceivedEvent{Data: testMessageData, Peer: peerB}).Once()
b, err := proto.Marshal(&pb.MessageRequest{Id: messageId[:]}) b, err := proto.Marshal(&pb.MessageRequest{Id: id[:]})
require.NoError(t, err) require.NoError(t, err)
mgrA.RequestMessage(b) mgrA.RequestMessage(b)
time.Sleep(graceTime) time.Sleep(graceTime)
......
package gossip package gossip
import ( import (
"errors"
"io" "io"
"net" "net"
"strings" "strings"
...@@ -15,17 +14,13 @@ import ( ...@@ -15,17 +14,13 @@ import (
"go.uber.org/atomic" "go.uber.org/atomic"
) )
var (
// ErrNeighborQueueFull is returned when the send queue is already full.
ErrNeighborQueueFull = errors.New("send queue is full")
)
const ( const (
neighborQueueSize = 5000 neighborQueueSize = 5000
maxNumReadErrors = 10 maxNumReadErrors = 10
droppedMessagesThreshold = 1000 droppedMessagesThreshold = 1000
) )
// Neighbor describes the established gossip connection to another peer.
type Neighbor struct { type Neighbor struct {
*peer.Peer *peer.Peer
*buffconn.BufferedConnection *buffconn.BufferedConnection
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment