Skip to content

Commit 7f44044

Browse files
authored
Expose node public port correctly (#2035)
1 parent 942f1d1 commit 7f44044

17 files changed

Lines changed: 44 additions & 30 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Changed
1111

1212
- Snapshots are generated by default on the current primary node, every `10,000` committed transaction (#2029).
13+
- Node information exposed in the API now correctly reports the public port when it differs from the local one. (#2001)
1314
- All `/gov` endpoints accept signature authentication again. Read-only `/gov` endpoints had been incorrectly changed in [0.16.1] to accept session certification authentication only (#2033).
1415

1516
## [0.16.1]

src/host/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ int main(int argc, char** argv)
624624
fmt::format("{}\n{}", rpc_address.hostname, rpc_address.port),
625625
rpc_address_file);
626626
}
627+
if (public_rpc_address.port == "0")
628+
{
629+
public_rpc_address.port = rpc_address.port;
630+
}
627631

628632
// Initialise the enclave and create a CCF node in it
629633
const size_t certificate_size = 4096;
@@ -655,7 +659,8 @@ int main(int argc, char** argv)
655659
public_rpc_address.hostname,
656660
node_address.hostname,
657661
node_address.port,
658-
rpc_address.port};
662+
rpc_address.port,
663+
public_rpc_address.port};
659664
ccf_config.domain = domain;
660665
ccf_config.snapshot_tx_interval = snapshot_tx_interval;
661666

src/node/node_info_network.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ namespace ccf
1717
std::string nodehost;
1818
std::string nodeport;
1919
std::string rpcport;
20+
std::string pubport;
2021

21-
MSGPACK_DEFINE(rpchost, pubhost, nodehost, nodeport, rpcport);
22+
MSGPACK_DEFINE(rpchost, pubhost, nodehost, nodeport, rpcport, pubport);
2223
};
2324
DECLARE_JSON_TYPE(NodeInfoNetwork);
2425
DECLARE_JSON_REQUIRED_FIELDS(
25-
NodeInfoNetwork, rpchost, pubhost, nodehost, nodeport, rpcport);
26+
NodeInfoNetwork, rpchost, pubhost, nodehost, nodeport, rpcport, pubport);
2627
}

src/node/rpc/common_endpoint_registry.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace ccf
173173
GetPrimaryInfo::Out out;
174174
out.primary_id = primary_id;
175175
out.primary_host = info->pubhost;
176-
out.primary_port = info->rpcport;
176+
out.primary_port = info->pubport;
177177
out.current_view = current_view;
178178
return make_success(out);
179179
}
@@ -202,7 +202,7 @@ namespace ccf
202202
nodes_view->foreach([&out](const NodeId& nid, const NodeInfo& ni) {
203203
if (ni.status == ccf::NodeStatus::TRUSTED)
204204
{
205-
out.nodes.push_back({nid, ni.pubhost, ni.rpcport});
205+
out.nodes.push_back({nid, ni.pubhost, ni.pubport});
206206
}
207207
return true;
208208
});
@@ -242,7 +242,7 @@ namespace ccf
242242
auto nodes_view =
243243
args.tx.template get_read_only_view<Nodes>(Tables::NODES);
244244
nodes_view->foreach([&in, &out](const NodeId& nid, const NodeInfo& ni) {
245-
if (ni.rpchost == in.host && ni.rpcport == in.port)
245+
if (ni.pubhost == in.host && ni.pubport == in.port)
246246
{
247247
if (ni.status != ccf::NodeStatus::RETIRED || in.retired)
248248
{

src/node/rpc/frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace ccf
135135
{
136136
ctx->set_response_header(
137137
http::headers::LOCATION,
138-
fmt::format("{}:{}", info->pubhost, info->rpcport));
138+
fmt::format("{}:{}", info->pubhost, info->pubport));
139139
}
140140
}
141141

src/node/rpc/node_frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ namespace ccf
367367
args.rpc_ctx->set_response_header(
368368
"Location",
369369
fmt::format(
370-
"https://{}:{}/node/primary", info->pubhost, info->rpcport));
370+
"https://{}:{}/node/primary", info->pubhost, info->pubport));
371371
}
372372
}
373373
}

tests/code_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_verify_quotes(network, args):
4040
assert (
4141
infra.proc.ccall(
4242
"verify_quote.sh",
43-
f"https://{node.pubhost}:{node.rpc_port}",
43+
f"https://{node.pubhost}:{node.pubport}",
4444
"--cacert",
4545
f"{cafile}",
4646
log_output=True,

tests/e2e_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_illegal(network, args, verify=True):
5858
)
5959
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6060
conn = context.wrap_socket(sock, server_side=False, server_hostname=primary.host)
61-
conn.connect((primary.host, primary.rpc_port))
61+
conn.connect((primary.host, primary.pubport))
6262
conn.sendall(b"NOTAVERB ")
6363
rv = conn.recv(1024)
6464
assert rv == b"", rv
@@ -593,7 +593,7 @@ def test_primary(network, args):
593593
assert r.status_code == http.HTTPStatus.PERMANENT_REDIRECT.value
594594
assert (
595595
r.headers["location"]
596-
== f"https://{primary.pubhost}:{primary.rpc_port}/node/primary"
596+
== f"https://{primary.pubhost}:{primary.pubport}/node/primary"
597597
)
598598
return network
599599

tests/e2e_scenarios.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def run(args):
7676

7777
if args.network_only:
7878
LOG.info("Keeping network alive with the following nodes:")
79-
LOG.info(" Primary = {}:{}".format(primary.pubhost, primary.rpc_port))
79+
LOG.info(" Primary = {}:{}".format(primary.pubhost, primary.pubport))
8080
for i, f in enumerate(backups):
81-
LOG.info(" Backup[{}] = {}:{}".format(i, f.pubhost, f.rpc_port))
81+
LOG.info(" Backup[{}] = {}:{}".format(i, f.pubhost, f.pubport))
8282

8383
input("Press Enter to shutdown...")
8484

tests/governance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_quote(network, args, verify=True):
8383
assert "Evidence verification succeeded (0)." in out
8484

8585
node = network.nodes[quote["node_id"]]
86-
node_cert = ssl.get_server_certificate((node.pubhost, node.rpc_port))
86+
node_cert = ssl.get_server_certificate((node.pubhost, node.pubport))
8787
public_key = x509.load_pem_x509_certificate(
8888
node_cert.encode(), default_backend()
8989
).public_key()
@@ -198,7 +198,7 @@ def test_node_ids(network, args):
198198
nodes = network.find_nodes()
199199
for node in nodes:
200200
with node.client() as c:
201-
r = c.get(f'/node/node/ids?host="{node.pubhost}"&port="{node.rpc_port}"')
201+
r = c.get(f'/node/node/ids?host="{node.pubhost}"&port="{node.pubport}"')
202202
assert r.status_code == 200
203203
assert r.body.json()["nodes"] == [
204204
{"node_id": node.node_id, "status": "TRUSTED"}

0 commit comments

Comments
 (0)