Skip to content
Snippets Groups Projects
Commit b5bc0d39 authored by Wolfgang Welz's avatar Wolfgang Welz
Browse files

Do not allow loopback connections

parent 29b53a5f
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ var (
ErrNotStarted = errors.New("manager not started")
ErrClosed = errors.New("manager closed")
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")
)
......@@ -78,6 +78,9 @@ func (m *Manager) LocalAddr() net.Addr {
// AddOutbound tries to add a neighbor by connecting to that peer.
func (m *Manager) AddOutbound(p *peer.Peer) error {
if p.ID() == m.local.ID() {
return ErrLoopback
}
var srv *server.TCP
m.mu.RLock()
if m.srv == nil {
......@@ -91,6 +94,9 @@ func (m *Manager) AddOutbound(p *peer.Peer) error {
// AddInbound tries to add a neighbor by accepting an incoming connection from that peer.
func (m *Manager) AddInbound(p *peer.Peer) error {
if p.ID() == m.local.ID() {
return ErrLoopback
}
var srv *server.TCP
m.mu.RLock()
if m.srv == nil {
......
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