|
64 | 64 | */
|
65 | 65 | this.autoSwitchSocketNode = function() {
|
66 | 66 | 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; |
81 | 70 |
|
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)); |
83 | 78 |
|
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; |
88 | 90 |
|
89 |
| - // now reconnect sockets |
90 |
| - self.module_.disconnectBlockchainSocket(function() { |
91 | 91 | self.module_.connectBlockchainSocket();
|
92 | 92 | });
|
93 | 93 |
|
|
0 commit comments