Skip to content

Commit 10322dd

Browse files
committed
v0.5.4: Node disconnection Auto Switch should start after successful disconnection
2 parents 6649d57 + 84fec6e commit 10322dd

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/blockchain/blocks-auditor.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,30 @@
6464
*/
6565
this.autoSwitchSocketNode = function() {
6666
var self = this;
67-
var currentHost = self.blockchain_.node_.host;
68-
69-
// iterate nodes and connect to first
70-
var nodesList = self.blockchain_.conf_.nem["nodes" + self.blockchain_.confSuffix];
71-
var nextHost = null;
72-
var nextPort = null;
73-
do {
74-
var cntNodes = nodesList.length;
75-
var randomIdx = Math.floor(Math.random() * (cntNodes - 1));
76-
77-
nextHost = nodesList[randomIdx].host;
78-
nextPort = nodesList[randomIdx].port;
79-
}
80-
while (nextHost == currentHost);
67+
// unsubscribe & disconnect, then re-issue connection
68+
self.module_.disconnectBlockchainSocket(function() {
69+
var currentHost = self.blockchain_.node_.host;
8170

82-
self.logger().warn("[NEM] [" + self.module_.logLabel + "] [AUDIT]", __line, "Socket now switching to Node: " + nextHost + ":" + nextPort + ".");
71+
// iterate nodes and connect to first
72+
var nodesList = self.blockchain_.conf_.nem["nodes" + self.blockchain_.confSuffix];
73+
var nextHost = null;
74+
var nextPort = null;
75+
do {
76+
var cntNodes = nodesList.length;
77+
var randomIdx = Math.floor(Math.random() * (cntNodes - 1));
8378

84-
// connect to node
85-
self.blockchain_.node_ = self.blockchain_.nem_.model.objects.create("endpoint")(nextHost, nextPort);
86-
self.blockchain_.nemHost = nextHost;
87-
self.blockchain_.nemPort = nextPort;
79+
nextHost = nodesList[randomIdx].host;
80+
nextPort = nodesList[randomIdx].port;
81+
}
82+
while (nextHost == currentHost);
83+
84+
self.logger().warn("[NEM] [" + self.module_.logLabel + "] [AUDIT]", __line, "Socket now switching to Node: " + nextHost + ":" + nextPort + ".");
85+
86+
// connect to node
87+
self.blockchain_.node_ = self.blockchain_.nem_.model.objects.create("endpoint")(nextHost, nextPort);
88+
self.blockchain_.nemHost = nextHost;
89+
self.blockchain_.nemPort = nextPort;
8890

89-
// now reconnect sockets
90-
self.module_.disconnectBlockchainSocket(function() {
9191
self.module_.connectBlockchainSocket();
9292
});
9393

0 commit comments

Comments
 (0)