bdy 1.9.6-stage → 1.9.7-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distTs/package.json +1 -1
- package/distTs/src/agent/manager.js +1 -0
- package/distTs/src/agent.js +34 -27
- package/distTs/src/api/socket.js +2 -1
- package/package.json +1 -1
package/distTs/package.json
CHANGED
package/distTs/src/agent.js
CHANGED
|
@@ -52,24 +52,29 @@ class Agent extends events_1.default {
|
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
54
|
logger_js_1.default.debug('Socket fetch tunnel after sync push');
|
|
55
|
-
this.socket.fetch(this.started, null, false, []);
|
|
55
|
+
this.socket.fetch(this.started, null, null, false, []);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
async _onSocketAgent(data, action) {
|
|
59
59
|
if (action === 'DEL') {
|
|
60
|
-
if (this.manager)
|
|
60
|
+
if (this.manager) {
|
|
61
61
|
return this.manager.disableAgentAndExit(texts_js_1.ERR_AGENT_REMOVED);
|
|
62
|
+
}
|
|
62
63
|
output_js_1.default.exitError(texts_js_1.ERR_AGENT_REMOVED);
|
|
63
|
-
return;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
else {
|
|
66
|
+
this.target = !!data.target;
|
|
67
|
+
if (data.action) {
|
|
68
|
+
try {
|
|
69
|
+
await this.makeAction(data.action);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
logger_js_1.default.error('Agent sync error');
|
|
73
|
+
logger_js_1.default.error(err);
|
|
74
|
+
}
|
|
69
75
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
logger_js_1.default.error(err);
|
|
76
|
+
else if (data.disabled === this.started) {
|
|
77
|
+
await this.makeAction(data.disabled ? this.AGENT_ACTION_STOP : this.AGENT_ACTION_START);
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
}
|
|
@@ -94,8 +99,9 @@ class Agent extends events_1.default {
|
|
|
94
99
|
}
|
|
95
100
|
_onSocketFetchFailed(err) {
|
|
96
101
|
if (err instanceof utils_js_1.ApiErrorAgentNotFound) {
|
|
97
|
-
if (this.manager)
|
|
102
|
+
if (this.manager) {
|
|
98
103
|
return this.manager.disableAgentAndExit(texts_js_1.ERR_AGENT_REMOVED);
|
|
104
|
+
}
|
|
99
105
|
output_js_1.default.exitError(texts_js_1.ERR_AGENT_REMOVED);
|
|
100
106
|
}
|
|
101
107
|
else {
|
|
@@ -114,17 +120,18 @@ class Agent extends events_1.default {
|
|
|
114
120
|
this.tunnels.forEach((t) => {
|
|
115
121
|
t.start();
|
|
116
122
|
});
|
|
117
|
-
this.socket.fetch(this.started, '', true, this.getTunnelsUpdate());
|
|
123
|
+
this.socket.fetch(this.started, '', false, true, this.getTunnelsUpdate());
|
|
118
124
|
}
|
|
119
125
|
async stop(clearAction = true) {
|
|
120
126
|
this.started = false;
|
|
121
127
|
this.tunnels.forEach((t) => {
|
|
122
128
|
t.stop();
|
|
123
129
|
});
|
|
124
|
-
this.socket.fetch(this.started, clearAction ? '' : null, false, this.getTunnelsUpdate());
|
|
130
|
+
this.socket.fetch(this.started, clearAction ? '' : null, true, false, this.getTunnelsUpdate());
|
|
125
131
|
}
|
|
126
132
|
async restart() {
|
|
127
133
|
await this.stop(false);
|
|
134
|
+
await (0, utils_js_1.sleep)(100);
|
|
128
135
|
await this.start();
|
|
129
136
|
}
|
|
130
137
|
async delete() {
|
|
@@ -139,9 +146,9 @@ class Agent extends events_1.default {
|
|
|
139
146
|
refreshIn15(fetch = true, counter = 1) {
|
|
140
147
|
setTimeout(async () => {
|
|
141
148
|
try {
|
|
142
|
-
if (fetch || counter >=
|
|
149
|
+
if (fetch || counter >= 3) {
|
|
143
150
|
counter = 0;
|
|
144
|
-
this.socket.fetch(this.started, null, false, this.getTunnelsUpdate());
|
|
151
|
+
this.socket.fetch(this.started, null, null, false, this.getTunnelsUpdate());
|
|
145
152
|
}
|
|
146
153
|
else {
|
|
147
154
|
this.update();
|
|
@@ -161,28 +168,28 @@ class Agent extends events_1.default {
|
|
|
161
168
|
}
|
|
162
169
|
async makeAction(action) {
|
|
163
170
|
if (action === utils_js_1.AGENT_ACTION_STOP) {
|
|
164
|
-
if (this.manager)
|
|
171
|
+
if (this.manager) {
|
|
165
172
|
return this.manager.agentStop();
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
}
|
|
174
|
+
return this.stop();
|
|
168
175
|
}
|
|
169
176
|
if (action === utils_js_1.AGENT_ACTION_START) {
|
|
170
|
-
if (this.manager)
|
|
177
|
+
if (this.manager) {
|
|
171
178
|
return this.manager.agentStart();
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
}
|
|
180
|
+
return this.start();
|
|
174
181
|
}
|
|
175
182
|
if (action === utils_js_1.AGENT_ACTION_RESTART) {
|
|
176
|
-
if (this.manager)
|
|
183
|
+
if (this.manager) {
|
|
177
184
|
return this.manager.agentRestart();
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
}
|
|
186
|
+
return this.restart();
|
|
180
187
|
}
|
|
181
188
|
if (action === utils_js_1.AGENT_ACTION_DELETE) {
|
|
182
|
-
if (this.manager)
|
|
189
|
+
if (this.manager) {
|
|
183
190
|
return this.manager.disableAgentAndExit(texts_js_1.ERR_AGENT_REMOVED);
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
}
|
|
192
|
+
return this.delete();
|
|
186
193
|
}
|
|
187
194
|
}
|
|
188
195
|
refreshTunnels(tunnels) {
|
package/distTs/src/api/socket.js
CHANGED
|
@@ -12,7 +12,7 @@ const socket_io_client_1 = require("socket.io-client");
|
|
|
12
12
|
const MAX_REQUESTS_SYNC_WINDOW = 30000;
|
|
13
13
|
const MAX_REQUESTS_SYNC_IN_WINDOW = 100;
|
|
14
14
|
class ApiSocketClass extends events_1.default {
|
|
15
|
-
fetch(activate = true, action = null, resetFirstHeard = false, tunnels) {
|
|
15
|
+
fetch(activate = true, action = null, disabled = null, resetFirstHeard = false, tunnels) {
|
|
16
16
|
this.socket.emit('fetchTunnelAgent', {
|
|
17
17
|
id: this.id,
|
|
18
18
|
token: this.token,
|
|
@@ -21,6 +21,7 @@ class ApiSocketClass extends events_1.default {
|
|
|
21
21
|
version: this.version,
|
|
22
22
|
activate,
|
|
23
23
|
action,
|
|
24
|
+
disabled,
|
|
24
25
|
resetFirstHeard,
|
|
25
26
|
tunnels,
|
|
26
27
|
});
|