Skip to content

Commit

Permalink
Remove send restriction
Browse files Browse the repository at this point in the history
The valid peer list should only be applied when receiving new messages.
Sending to any node should always be allowed, as this is something that
comes from the inside, and we suppose that the protocols are correct.

Will need to bump the tag to v3.2.6 for inclusion in cothority
  • Loading branch information
ineiti committed Nov 5, 2020
1 parent c2ba2e8 commit bdb9e74
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 40 deletions.
5 changes: 0 additions & 5 deletions network/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@ func (r *Router) Stop() error {
// the messages are sent through the same connection and thus are correctly
// ordered.
func (r *Router) Send(e *ServerIdentity, msgs ...Message) (uint64, error) {
if !r.isPeerValid(e) {
return 0, xerrors.Errorf("%v rejecting send to %v: invalid peer",
r.ServerIdentity.ID, e.ID)
}

for _, msg := range msgs {
if msg == nil {
return 0, xerrors.New("cannot send nil-packets")
Expand Down
35 changes: 0 additions & 35 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,6 @@ func TestServer_Database(t *testing.T) {
c.Close()
}

func TestServer_FilterConnectionsOutgoing(t *testing.T) {
local := NewTCPTest(tSuite)
defer local.CloseAll()

srv := local.GenServers(3)
msg := &SimpleMessage{42}

testPeersID := network.NewPeerSetID([]byte{})

// Initially, messages can be sent freely as there is no restriction
_, err := srv[0].Send(srv[1].ServerIdentity, msg)
require.NoError(t, err)
_, err = srv[1].Send(srv[2].ServerIdentity, msg)
require.NoError(t, err)
_, err = srv[2].Send(srv[0].ServerIdentity, msg)
require.NoError(t, err)

// Set the valid peers of Srv0 to Srv1 only
validPeers := []*network.ServerIdentity{srv[1].ServerIdentity}
srv[0].SetValidPeers(testPeersID, validPeers)
// Now Srv0 can send to Srv1, but not to Srv2
_, err = srv[0].Send(srv[1].ServerIdentity, msg)
require.NoError(t, err)
_, err = srv[0].Send(srv[2].ServerIdentity, msg)
require.Regexp(t, "rejecting.*invalid peer", err.Error())

// Add Srv2 to the valid peers of Srv0
srv[0].SetValidPeers(testPeersID, append(validPeers, srv[2].ServerIdentity))
// Now Srv0 can send to both Srv1 and Srv2
_, err = srv[0].Send(srv[1].ServerIdentity, msg)
require.NoError(t, err)
_, err = srv[0].Send(srv[2].ServerIdentity, msg)
require.NoError(t, err)
}

func TestServer_FilterConnectionsIncomingInvalid(t *testing.T) {
local := NewTCPTest(tSuite)
defer local.CloseAll()
Expand Down

0 comments on commit bdb9e74

Please sign in to comment.