-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: (handshake) missing domain type check (#1400)
* fix: domain type check * network id log
- Loading branch information
1 parent
a64d23d
commit 26a7672
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package connections | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/ssvlabs/ssv/network/records" | ||
) | ||
|
||
var AllowedDifference = 30 * time.Second | ||
|
||
// NetworkIDFilter determines whether we will connect to the given node by the network ID | ||
func NetworkIDFilter(networkID string) HandshakeFilter { | ||
return func(sender peer.ID, ni *records.NodeInfo) error { | ||
nid := ni.GetNodeInfo().NetworkID | ||
if networkID != nid { | ||
return errors.Errorf("mismatching domain type (want %s, got %s)", networkID, nid) | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package connections | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ssvlabs/ssv/network/records" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNetworkIDFilter(t *testing.T) { | ||
f := NetworkIDFilter("xxx") | ||
|
||
err := f("", &records.NodeInfo{ | ||
NetworkID: "xxx", | ||
}) | ||
require.NoError(t, err) | ||
|
||
err = f("", &records.NodeInfo{ | ||
NetworkID: "bbb", | ||
}) | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters