Skip to content
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

fix: remove the insecure port of mirror nodes #1535

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/proto/src/proto
18 changes: 0 additions & 18 deletions src/ManagedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,6 @@ export default class ManagedNode {
throw new Error("not implemented");
}

/**
* @abstract
* @returns {ManagedNode<ChannelT>}
*/
// eslint-disable-next-line jsdoc/require-returns-check
toInsecure() {
throw new Error("not implemented");
}

/**
* @abstract
* @returns {ManagedNode<ChannelT>}
*/
// eslint-disable-next-line jsdoc/require-returns-check
toSecure() {
throw new Error("not implemented");
}

/**
* @param {string} ledgerId
* @returns {this}
Expand Down
22 changes: 2 additions & 20 deletions src/ManagedNodeAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,12 @@ export default class ManagedNodeAddress {
}

toInsecure() {
let port = this.port;

switch (this.port) {
case 50212:
port = 50211;
break;
case 443:
port = 5600;
}

let port = this.port === 50212 ? 50211 : this.port;
return new ManagedNodeAddress({ host: this.address, port });
}

toSecure() {
let port = this.port;

switch (this.port) {
case 50211:
port = 50212;
break;
case 5600:
port = 443;
}

let port = this.port === 50211 ? 50212 : this.port;
return new ManagedNodeAddress({ host: this.address, port });
}

Expand Down
18 changes: 0 additions & 18 deletions src/MirrorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,4 @@ export default class MirrorNode extends ManagedNode {
getKey() {
return this._address.toString();
}

/**
* @returns {MirrorNode}
*/
toInsecure() {
return new MirrorNode({
cloneNode: { node: this, address: this._address.toInsecure() },
});
}

/**
* @returns {MirrorNode}
*/
toSecure() {
return new MirrorNode({
cloneNode: { node: this, address: this._address.toSecure() },
});
}
}
1 change: 0 additions & 1 deletion src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ export default class Client {
*/
setTransportSecurity(transportSecurity) {
this._network.setTransportSecurity(transportSecurity);
this._mirrorNetwork.setTransportSecurity(transportSecurity);
return this;
}

Expand Down
54 changes: 0 additions & 54 deletions src/client/ManagedNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,66 +90,12 @@ export default class ManagedNetwork {
/** @type {number} */
this._maxNodeAttempts = -1;

this._transportSecurity = false;

this._nodeMinReadmitPeriod = this._minBackoff;
this._nodeMaxReadmitPeriod = this._maxBackoff;

this._earliestReadmitTime = Date.now() + this._nodeMinReadmitPeriod;
}

/**
* @returns {boolean}
*/
isTransportSecurity() {
return this._transportSecurity;
}

/**
* @param {boolean} transportSecurity
* @returns {this}
*/
setTransportSecurity(transportSecurity) {
if (this._transportSecurity == transportSecurity) {
return this;
}

this._network.clear();

for (let i = 0; i < this._nodes.length; i++) {
let node = this._nodes[i];
node.close();

node = /** @type {NetworkNodeT} */ (
transportSecurity
? node
.toSecure()
.setCert(
this._ledgerId != null
? this._ledgerId.toString()
: ""
)
: node.toInsecure()
);
this._nodes[i] = node;

const nodes =
this._network.get(node.getKey()) != null
? /** @type {NetworkNodeT[]} */ (
this._network.get(node.getKey())
)
: [];
nodes.push(node);
this._network.set(node.getKey(), nodes);
}

// Overwrite healthy node list since new ports might make the node work again
this._healthyNodes = [...this._nodes];

this._transportSecurity = transportSecurity;
return this;
}

/**
* @deprecated
* @param {string} networkName
Expand Down
53 changes: 53 additions & 0 deletions src/client/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export default class Network extends ManagedNetwork {

/** @type {NodeAddressBook | null} */
this._addressBook = null;

/** @type {boolean} */
this._transportSecurity = false;
}

/**
Expand Down Expand Up @@ -241,6 +244,56 @@ export default class Network extends ManagedNetwork {
return this;
}

/**
* @returns {boolean}
*/
isTransportSecurity() {
return this._transportSecurity;
}

/**
* @param {boolean} transportSecurity
* @returns {this}
*/
setTransportSecurity(transportSecurity) {
if (this._transportSecurity == transportSecurity) {
return this;
}

this._network.clear();

for (let i = 0; i < this._nodes.length; i++) {
let node = this._nodes[i];
node.close();

node = /** @type {Node} */ (
transportSecurity
? node
.toSecure()
.setCert(
this._ledgerId != null
? this._ledgerId.toString()
: ""
)
: node.toInsecure()
);
this._nodes[i] = node;

const nodes =
this._network.get(node.getKey()) != null
? /** @type {Node[]} */ (this._network.get(node.getKey()))
: [];
nodes.push(node);
this._network.set(node.getKey(), nodes);
}

// Overwrite healthy node list since new ports might make the node work again
this._healthyNodes = [...this._nodes];

this._transportSecurity = transportSecurity;
return this;
}

/**
* @internal
* @returns {number}
Expand Down
9 changes: 0 additions & 9 deletions test/unit/ManagedNodeAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ describe("ManagedNodeAddress", function () {
"testnet.mirrornode.hedera.com:443"
);

const mirrorNodeAddressInsecure = mirrorNodeAddressSecure.toInsecure();
expect(mirrorNodeAddressInsecure.address).to.be.equal(
"testnet.mirrornode.hedera.com"
);
expect(mirrorNodeAddressInsecure.port).to.be.equal(5600);
expect(mirrorNodeAddressInsecure.toString()).to.be.equal(
"testnet.mirrornode.hedera.com:5600"
);

let err = false;
try {
ManagedNodeAddress.fromString(
Expand Down
10 changes: 0 additions & 10 deletions test/unit/NodeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,5 @@ describe("Client", function () {
expect(client.mirrorNetwork).to.deep.equal([
"mainnet-public.mirrornode.hedera.com:443",
]);

client.setTransportSecurity(false);
expect(client.mirrorNetwork).to.deep.equal([
"mainnet-public.mirrornode.hedera.com:5600",
]);

client.setTransportSecurity(true);
expect(client.mirrorNetwork).to.deep.equal([
"mainnet-public.mirrornode.hedera.com:443",
]);
});
});