Skip to content

Commit

Permalink
Filter out p2p addresses in wsNetwork phonebook
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Feb 6, 2024
1 parent dd5d2d9 commit c5d2a66
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
11 changes: 10 additions & 1 deletion network/wsNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/logging/telemetryspec"
"github.com/algorand/go-algorand/network/addr"
"github.com/algorand/go-algorand/network/limitcaller"
"github.com/algorand/go-algorand/network/limitlistener"
"github.com/algorand/go-algorand/network/p2p"
Expand Down Expand Up @@ -2271,7 +2272,15 @@ func (wn *WebsocketNetwork) SetPeerData(peer Peer, key string, value interface{}
func NewWebsocketNetwork(log logging.Logger, config config.Local, phonebookAddresses []string, genesisID string, networkID protocol.NetworkID, nodeInfo NodeInfo, peerID p2p.PeerID, idSigner identityChallengeSigner) (wn *WebsocketNetwork, err error) {
pb := phonebook.MakePhonebook(config.ConnectionsRateLimitingCount,
time.Duration(config.ConnectionsRateLimitingWindowSeconds)*time.Second)
pb.AddPersistentPeers(phonebookAddresses, string(networkID), phonebook.PhoneBookEntryRelayRole)

addresses := make([]string, 0, len(phonebookAddresses))
for _, a := range phonebookAddresses {
_, err := addr.ParseHostOrURL(a)
if err == nil {
addresses = append(addresses, a)
}
}
pb.AddPersistentPeers(addresses, string(networkID), phonebook.PhoneBookEntryRelayRole)
wn = &WebsocketNetwork{
log: log,
config: config,
Expand Down
20 changes: 20 additions & 0 deletions network/wsNetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4544,3 +4544,23 @@ func TestSendMessageCallbackDrain(t *testing.T) {
50*time.Millisecond,
)
}

// TestWsNetworkPhonebookMix ensures p2p addresses are not added into wsNetwork via phonebook
func TestWsNetworkPhonebookMix(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

net, err := NewWebsocketNetwork(
logging.TestingLog(t),
config.GetDefaultLocal(),
[]string{"127.0.0.1:1234", "/ip4/127.0.0.1/tcp/1234", "/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"},
"test",
"net",
nil,
"",
nil,
)
require.NoError(t, err)
addrs := net.phonebook.GetAddresses(10, phonebook.PhoneBookEntryRelayRole)
require.Len(t, addrs, 1)
}
2 changes: 1 addition & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ func TestMaxSizesCorrect(t *testing.T) {
// N -- R -- A and ensures N can discover A and download blocks from it.
//
// N is a non-part node that joins the network later
// R is a non-arhival relay node with block service disabled. It MUST NOT service blocks to force N to discover A.
// R is a non-archival relay node with block service disabled. It MUST NOT service blocks to force N to discover A.
// A is a archival node that can only provide blocks.
// Nodes N and A have only R in their initial phonebook, and all nodes are in hybrid mode.
func TestNodeHybridTopology(t *testing.T) {
Expand Down

0 comments on commit c5d2a66

Please sign in to comment.