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
import "errors"
var (
ErrNotRunning = errors.New("manager not running")
ErrNotANeighbor = errors.New("peer is not a neighbor")
ErrLoopback = errors.New("loopback connection not allowed")
ErrDuplicateNeighbor = errors.New("peer already connected")
ErrInvalidPacket = errors.New("invalid packet")
// ErrNotRunning is returned when a neighbor is added to a stopped or not yet started gossip manager.
ErrNotRunning = errors.New("manager not running")
// ErrUnknownNeighbor is returned when the specified neighbor is not known to the gossip manager.
ErrUnknownNeighbor = errors.New("unknown neighbor")
// 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 {
defer m.mu.Unlock()
if p.ID() == m.local.ID() {
return ErrLoopback
return ErrLoopbackNeighbor
}
if m.srv == nil {
return ErrNotRunning
......@@ -111,7 +111,7 @@ func (m *Manager) AddInbound(p *peer.Peer) error {
defer m.mu.Unlock()
if p.ID() == m.local.ID() {
return ErrLoopback
return ErrLoopbackNeighbor
}
if m.srv == nil {
return ErrNotRunning
......@@ -125,7 +125,7 @@ func (m *Manager) DropNeighbor(id identity.ID) error {
defer m.mu.Unlock()
if _, ok := m.neighbors[id]; !ok {
return ErrNotANeighbor
return ErrUnknownNeighbor
}
n := m.neighbors[id]
delete(m.neighbors, id)
......@@ -161,12 +161,12 @@ func (m *Manager) AllNeighbors() []*Neighbor {
func (m *Manager) getNeighbors(ids ...identity.ID) []*Neighbor {
if len(ids) > 0 {
return m.getNeighborsById(ids)
return m.getNeighborsByID(ids)
}
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))
m.mu.Lock()
......
......@@ -336,12 +336,12 @@ func TestMessageRequest(t *testing.T) {
// wait for the connections to establish
wg.Wait()
messageId := message.Id{}
id := message.Id{}
// mgrA should eventually receive the message
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)
mgrA.RequestMessage(b)
time.Sleep(graceTime)
......
package gossip
import (
"errors"
"io"
"net"
"strings"
......@@ -15,17 +14,13 @@ import (
"go.uber.org/atomic"
)
var (
// ErrNeighborQueueFull is returned when the send queue is already full.
ErrNeighborQueueFull = errors.New("send queue is full")
)
const (
neighborQueueSize = 5000
maxNumReadErrors = 10
droppedMessagesThreshold = 1000
)
// Neighbor describes the established gossip connection to another peer.
type Neighbor struct {
*peer.Peer
*buffconn.BufferedConnection
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment