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
Branches
Tags
No related merge requests found
...@@ -6,6 +6,7 @@ var ( ...@@ -6,6 +6,7 @@ var (
ErrNotStarted = errors.New("manager not started") ErrNotStarted = errors.New("manager not started")
ErrClosed = errors.New("manager closed") ErrClosed = errors.New("manager closed")
ErrNotANeighbor = errors.New("peer is not a neighbor") ErrNotANeighbor = errors.New("peer is not a neighbor")
ErrLoopback = errors.New("loopback connection not allowed")
ErrDuplicateNeighbor = errors.New("peer already connected") ErrDuplicateNeighbor = errors.New("peer already connected")
ErrInvalidPacket = errors.New("invalid packet") ErrInvalidPacket = errors.New("invalid packet")
) )
...@@ -78,6 +78,9 @@ func (m *Manager) LocalAddr() net.Addr { ...@@ -78,6 +78,9 @@ func (m *Manager) LocalAddr() net.Addr {
// AddOutbound tries to add a neighbor by connecting to that peer. // AddOutbound tries to add a neighbor by connecting to that peer.
func (m *Manager) AddOutbound(p *peer.Peer) error { func (m *Manager) AddOutbound(p *peer.Peer) error {
if p.ID() == m.local.ID() {
return ErrLoopback
}
var srv *server.TCP var srv *server.TCP
m.mu.RLock() m.mu.RLock()
if m.srv == nil { if m.srv == nil {
...@@ -91,6 +94,9 @@ func (m *Manager) AddOutbound(p *peer.Peer) error { ...@@ -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. // AddInbound tries to add a neighbor by accepting an incoming connection from that peer.
func (m *Manager) AddInbound(p *peer.Peer) error { func (m *Manager) AddInbound(p *peer.Peer) error {
if p.ID() == m.local.ID() {
return ErrLoopback
}
var srv *server.TCP var srv *server.TCP
m.mu.RLock() m.mu.RLock()
if m.srv == nil { if m.srv == nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment