-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1411 from AntelopeIO/p2p-multiple-listen-addresses
Listen on multiple addresses for net_plugin p2p.
- Loading branch information
Showing
8 changed files
with
315 additions
and
70 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,103 @@ | ||
#!/usr/bin/env python3 | ||
|
||
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) |
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,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) |