Skip to content

Commit

Permalink
Test case fix and added inbound check
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Sep 29, 2021
1 parent 8c7f3e5 commit 3f98444
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
17 changes: 11 additions & 6 deletions dot/network/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/protocol"
ma "github.com/multiformats/go-multiaddr"

"github.com/ChainSafe/gossamer/dot/peerset"
"github.com/ChainSafe/gossamer/dot/state"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/utils"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/protocol"
ma "github.com/multiformats/go-multiaddr"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -437,7 +438,7 @@ func Test_AddReservedPeers(t *testing.T) {
err := nodeA.host.addReservedPeers(nodeBPeerAddr)
require.NoError(t, err)
time.Sleep(200 * time.Millisecond)

require.Equal(t, 1, nodeA.host.peerCount())
isProtected := nodeA.host.h.ConnManager().IsProtected(nodeB.host.addrInfo().ID, "")
require.True(t, isProtected)
}
Expand Down Expand Up @@ -470,12 +471,13 @@ func Test_RemoveReservedPeers(t *testing.T) {
require.NoError(t, err)

time.Sleep(200 * time.Millisecond)
require.Equal(t, 1, nodeA.host.peerCount())
pID := nodeB.host.addrInfo().ID.String()

err = nodeA.host.removeReservedPeers(pID)
require.NoError(t, err)
time.Sleep(200 * time.Millisecond)

require.Equal(t, 1, nodeA.host.peerCount())
isProtected := nodeA.host.h.ConnManager().IsProtected(nodeB.host.addrInfo().ID, "")
require.False(t, isProtected)

Expand Down Expand Up @@ -613,9 +615,12 @@ func TestPsmBannedPeer(t *testing.T) {
})

time.Sleep(200 * time.Millisecond)

require.Equal(t, 0, nodeA.host.peerCount())
require.Equal(t, 0, nodeB.host.peerCount())

time.Sleep(2000 * time.Millisecond)
require.Equal(t, 1, nodeA.host.peerCount())
require.Equal(t, 1, nodeB.host.peerCount())
}

// Test to check reputation updated by peer set manager
Expand Down
14 changes: 8 additions & 6 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,15 @@ func (s *Service) sentBlockIntervalTelemetry() {

func (s *Service) handleConn(conn libp2pnetwork.Conn) {
// TODO: setID currently is 0 change when we have multiple set.
m, err := s.host.cm.peerSetHandler.Incoming(0, conn.RemotePeer(), 0)
if err != nil {
logger.Error("failed to handle incoming connection request from", "peerID", conn.RemotePeer())
}
if conn.Stat().Direction.String() == "Inbound" {
m, err := s.host.cm.peerSetHandler.Incoming(0, conn.RemotePeer(), 0)
if err != nil {
logger.Error("failed to handle incoming connection request from", "peerID", conn.RemotePeer())
}

if m.GetStatus() == peerset.Reject {
_ = conn.Close()
if m.GetStatus() == peerset.Reject {
_ = conn.Close()
}
}

// TODO: remove the old peer scoring.
Expand Down

0 comments on commit 3f98444

Please sign in to comment.