-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listen on multiple addresses for net_plugin p2p. #1411
Changes from all commits
3a7c072
d5fdd64
1c81166
db93c63
4d71d2a
3c10138
a4f9399
1bbb36a
374f8a3
2f55f15
4a4875e
31f3889
501056f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for adding the test. also, now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments added and text expanded to multiple ports and to test the |
||
|
||
import signal | ||
|
||
from TestHarness import Cluster, TestHelper, Utils, WalletMgr | ||
|
||
############################################################### | ||
# p2p_multiple_listen_test | ||
# | ||
# Test nodeos ability to listen on multiple ports for p2p | ||
# | ||
############################################################### | ||
|
||
Print=Utils.Print | ||
errorExit=Utils.errorExit | ||
|
||
args=TestHelper.parse_args({"-p","-n","-d","--keep-logs" | ||
,"--dump-error-details","-v" | ||
,"--leave-running","--unshared"}) | ||
pnodes=args.p | ||
delay=args.d | ||
debug=args.v | ||
total_nodes=5 | ||
dumpErrorDetails=args.dump_error_details | ||
|
||
Utils.Debug=debug | ||
testSuccessful=False | ||
|
||
cluster=Cluster(unshared=args.unshared, keepRunning=args.leave_running, keepLogs=args.keep_logs) | ||
walletMgr=WalletMgr(True) | ||
|
||
try: | ||
TestHelper.printSystemInfo("BEGIN") | ||
|
||
cluster.setWalletMgr(walletMgr) | ||
|
||
Print(f'producing nodes: {pnodes}, delay between nodes launch: {delay} second{"s" if delay != 1 else ""}') | ||
|
||
Print("Stand up cluster") | ||
specificArgs = { | ||
'0': '--agent-name node-00 --p2p-listen-endpoint 0.0.0.0:9876 --p2p-listen-endpoint 0.0.0.0:9779 --p2p-server-address ext-ip0:20000 --p2p-server-address ext-ip1:20001 --plugin eosio::net_api_plugin', | ||
'2': '--agent-name node-02 --p2p-peer-address localhost:9779 --plugin eosio::net_api_plugin', | ||
'4': '--agent-name node-04 --p2p-peer-address localhost:9876 --plugin eosio::net_api_plugin', | ||
} | ||
if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, topo='line', delay=delay, | ||
specificExtraNodeosArgs=specificArgs) is False: | ||
errorExit("Failed to stand up eos cluster.") | ||
|
||
# Be sure all nodes start out connected (bios node omitted from diagram for brevity) | ||
# node00 node01 node02 node03 node04 | ||
# localhost:9876 -> localhost:9877 -> localhost:9878 -> localhost:9879 -> localhost:9880 | ||
# localhost:9779 ^ | | | ||
# ^ +---------------------------+ | | ||
# +------------------------------------------------------------------------+ | ||
cluster.waitOnClusterSync(blockAdvancing=5) | ||
# Shut down bios node, which is connected to all other nodes in all topologies | ||
cluster.biosNode.kill(signal.SIGTERM) | ||
# Shut down second node, interrupting the default connections between it and nodes 00 and 02 | ||
cluster.getNode(1).kill(signal.SIGTERM) | ||
# Shut down the fourth node, interrupting the default connections between it and nodes 02 and 04 | ||
cluster.getNode(3).kill(signal.SIGTERM) | ||
# Be sure all remaining nodes continue to sync via the two listen ports on node 00 | ||
# node00 node01 node02 node03 node04 | ||
# localhost:9876 offline localhost:9878 offline localhost:9880 | ||
# localhost:9779 ^ | | | ||
# ^ +---------------------------+ | | ||
# +------------------------------------------------------------------------+ | ||
cluster.waitOnClusterSync(blockAdvancing=5) | ||
connections = cluster.nodes[0].processUrllibRequest('net', 'connections') | ||
open_socket_count = 0 | ||
for conn in connections['payload']: | ||
if conn['is_socket_open']: | ||
open_socket_count += 1 | ||
if conn['last_handshake']['agent'] == 'node-02': | ||
assert conn['last_handshake']['p2p_address'].split()[0] == 'localhost:9878', f"Connected node is listening on '{conn['last_handshake']['p2p_address'].split()[0]}' instead of port 9878" | ||
elif conn['last_handshake']['agent'] == 'node-04': | ||
assert conn['last_handshake']['p2p_address'].split()[0] == 'localhost:9880', f"Connected node is listening on '{conn['last_handshake']['p2p_address'].split()[0]}' instead of port 9880" | ||
assert open_socket_count == 2, 'Node 0 is expected to have only two open sockets' | ||
|
||
connections = cluster.nodes[2].processUrllibRequest('net', 'connections') | ||
open_socket_count = 0 | ||
for conn in connections['payload']: | ||
if conn['is_socket_open']: | ||
open_socket_count += 1 | ||
assert conn['last_handshake']['agent'] == 'node-00', f"Connected node identifed as '{conn['last_handshake']['agent']}' instead of node-00" | ||
assert conn['last_handshake']['p2p_address'].split()[0] == 'ext-ip0:20000', f"Connected node is advertising '{conn['last_handshake']['p2p_address'].split()[0]}' instead of ext-ip0:20000" | ||
assert open_socket_count == 1, 'Node 2 is expected to have only one open socket' | ||
|
||
connections = cluster.nodes[4].processUrllibRequest('net', 'connections') | ||
open_socket_count = 0 | ||
for conn in connections['payload']: | ||
if conn['is_socket_open']: | ||
open_socket_count += 1 | ||
assert conn['last_handshake']['agent'] == 'node-00', f"Connected node identifed as '{conn['last_handshake']['agent']}' instead of node-00" | ||
assert conn['last_handshake']['p2p_address'].split()[0] == 'ext-ip1:20001', f"Connected node is advertising '{conn['last_handshake']['p2p_address'].split()[0]} 'instead of ext-ip1:20001" | ||
assert open_socket_count == 1, 'Node 4 is expected to have only one open socket' | ||
|
||
testSuccessful=True | ||
finally: | ||
TestHelper.shutdown(cluster, walletMgr, testSuccessful=testSuccessful, dumpErrorDetails=dumpErrorDetails) | ||
|
||
exitCode = 0 if testSuccessful else 1 | ||
exit(exitCode) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import errno | ||
import pathlib | ||
import shutil | ||
import signal | ||
import socket | ||
import time | ||
|
||
from TestHarness import Node, TestHelper, Utils | ||
|
||
############################################################### | ||
# p2p_no_listen_test | ||
# | ||
# Test nodeos disabling p2p | ||
# | ||
############################################################### | ||
|
||
Print=Utils.Print | ||
errorExit=Utils.errorExit | ||
|
||
args=TestHelper.parse_args({"--keep-logs","-v","--leave-running","--unshared"}) | ||
debug=args.v | ||
|
||
Utils.Debug=debug | ||
testSuccessful=False | ||
|
||
try: | ||
TestHelper.printSystemInfo("BEGIN") | ||
|
||
cmd = [ | ||
Utils.EosServerPath, | ||
'-e', | ||
'-p', | ||
'eosio', | ||
'--p2p-listen-endpoint', | ||
'', | ||
'--plugin', | ||
'eosio::chain_api_plugin', | ||
'--config-dir', | ||
Utils.ConfigDir, | ||
'--data-dir', | ||
Utils.DataDir, | ||
'--http-server-address', | ||
'localhost:8888' | ||
] | ||
node = Node('localhost', '8888', '00', data_dir=pathlib.Path(Utils.DataDir), | ||
config_dir=pathlib.Path(Utils.ConfigDir), cmd=cmd) | ||
|
||
time.sleep(1) | ||
if not node.verifyAlive(): | ||
raise RuntimeError | ||
time.sleep(10) | ||
node.waitForBlock(5) | ||
|
||
s = socket.socket() | ||
err = s.connect_ex(('localhost',9876)) | ||
assert err == errno.ECONNREFUSED, 'Connection to port 9876 must be refused' | ||
|
||
testSuccessful=True | ||
finally: | ||
Utils.ShuttingDown=True | ||
|
||
if not args.leave_running: | ||
node.kill(signal.SIGTERM) | ||
|
||
if not (args.leave_running or args.keep_logs or not testSuccessful): | ||
shutil.rmtree(Utils.DataPath, ignore_errors=True) | ||
|
||
if testSuccessful: | ||
Utils.Print("Test succeeded.") | ||
else: | ||
Utils.Print("Test failed.") | ||
|
||
exitCode = 0 if testSuccessful else 1 | ||
exit(exitCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed please update help and PR description indicating that the first configured server_address is reported in the handshake message to peers. Also guard against
p2p_addresses
being empty here.