@tdxvolt/volt-client-grpc 0.11.8 → 0.14.60
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/lib/index.cjs +116 -107
- package/package.json +1 -1
- package/protobuf/tdx/volt_api/data/v1/sqlite_database_api.proto +5 -1
- package/protobuf/tdx/volt_api/relay/v1/relay_api.proto +1 -1
- package/protobuf/tdx/volt_api/volt/v1/file_api.proto +1 -1
- package/protobuf/tdx/volt_api/volt/v1/remote.proto +0 -1
- package/protobuf/tdx/volt_api/volt/v1/volt.proto +70 -44
- package/protobuf/tdx/volt_api/volt/v1/volt_api.proto +183 -75
- package/protobuf/tdx/volt_api/volt/v1/wire_api.proto +1 -1
- package/src/volt-client-internal.js +5 -5
- package/src/volt-client.js +4 -4
- package/src/volt-connection.js +106 -98
- package/src/volt-credential.js +1 -0
package/src/volt-connection.js
CHANGED
|
@@ -7,50 +7,55 @@ import GRPCCall from "./grpc-call.js";
|
|
|
7
7
|
const log = debug("volt-client-grpc:volt-connection");
|
|
8
8
|
|
|
9
9
|
function _cleanUp(immediateReconnect) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
10
|
+
this._connectionId = "";
|
|
11
|
+
|
|
12
|
+
if (this._pingTimer) {
|
|
13
|
+
clearTimeout(this._pingTimer);
|
|
14
|
+
this._pingTimer = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (this._pingTimeoutTimer) {
|
|
18
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
19
|
+
this._pingTimeoutTimer = 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
!this._dying &&
|
|
24
|
+
(immediateReconnect || (this._autoRetry && !this._reconnectTimer))
|
|
25
|
+
) {
|
|
26
|
+
this._reconnectTimer = setTimeout(
|
|
27
|
+
() => {
|
|
28
|
+
this._reconnectTimer = 0;
|
|
29
|
+
_doConnect.call(this, this._helloPayload);
|
|
30
|
+
},
|
|
31
|
+
immediateReconnect ? 0 : this._reconnectInterval,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (this.call?.writable) {
|
|
36
|
+
this.call.end();
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function _connectionTimeoutHandler() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
log("server timed out");
|
|
42
|
+
this.emit("connected", false);
|
|
43
|
+
_cleanUp.call(this);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function _doConnect() {
|
|
47
|
-
|
|
46
|
+
function _doConnect(connectHello) {
|
|
47
|
+
this.call = new GRPCCall(this._voltClient, "Connect", "METHOD_TYPE_BIDI");
|
|
48
|
+
|
|
49
|
+
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
50
|
+
|
|
51
|
+
let helloPayload = connectHello;
|
|
52
|
+
if (!connectHello) {
|
|
53
|
+
log("defaulting hello payload");
|
|
54
|
+
helloPayload = {
|
|
55
|
+
hello: {},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
48
58
|
|
|
49
|
-
const grpcClient = this._voltClient.getVoltAPIClient();
|
|
50
|
-
const helloPayload = {
|
|
51
|
-
hello: {},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
59
|
this.call.on("error", (err) => {
|
|
55
60
|
log("error on connection stream [%s]", err.message);
|
|
56
61
|
_cleanUp.call(this);
|
|
@@ -71,10 +76,11 @@ function _doConnect() {
|
|
|
71
76
|
_startPingTimer.call(this);
|
|
72
77
|
break;
|
|
73
78
|
}
|
|
74
|
-
case "
|
|
75
|
-
if (!this.
|
|
76
|
-
this.
|
|
77
|
-
|
|
79
|
+
case "acknowledge": {
|
|
80
|
+
if (!this._connectionId) {
|
|
81
|
+
this._connectionId = response.acknowledge.connection_id;
|
|
82
|
+
log("connection id is %s", this._connectionId);
|
|
83
|
+
this.emit("connected", this._connectionId);
|
|
78
84
|
}
|
|
79
85
|
break;
|
|
80
86
|
}
|
|
@@ -90,72 +96,74 @@ function _doConnect() {
|
|
|
90
96
|
});
|
|
91
97
|
|
|
92
98
|
this.call.on("end", () => {
|
|
93
|
-
if (this.
|
|
99
|
+
if (this._connectionId) {
|
|
94
100
|
this.emit("connected", false);
|
|
95
101
|
}
|
|
96
102
|
_cleanUp.call(this);
|
|
97
103
|
});
|
|
98
104
|
|
|
99
|
-
|
|
105
|
+
this.call.start(grpcClient, helloPayload);
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
_startPingTimer.call(this);
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
function _startPingTimer() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
111
|
+
if (this._pingTimer) {
|
|
112
|
+
log("ping timer running");
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this._pingTimer = setTimeout(() => {
|
|
117
|
+
// Send next ping to server.
|
|
118
|
+
const request = { ping: { timestamp: Date.now() } };
|
|
119
|
+
|
|
120
|
+
log("pinging Volt");
|
|
121
|
+
this.call.write(request);
|
|
122
|
+
|
|
123
|
+
this._pingTimer = 0;
|
|
124
|
+
|
|
125
|
+
// Schedule a timeout if we don't hear back from the server.
|
|
126
|
+
if (this._pingTimeoutTimer) {
|
|
127
|
+
clearTimeout(this._pingTimeoutTimer);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this._pingTimeoutTimer = setTimeout(
|
|
131
|
+
_connectionTimeoutHandler.bind(this),
|
|
132
|
+
this._timeoutInterval,
|
|
133
|
+
);
|
|
134
|
+
}, this._pingInterval);
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
export default class VoltConnection extends EventEmitter {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
138
|
+
constructor(voltClient, grpc) {
|
|
139
|
+
super();
|
|
140
|
+
|
|
141
|
+
const config = voltClient.config;
|
|
142
|
+
this._grpc = grpc;
|
|
143
|
+
this._autoRetry =
|
|
144
|
+
config.autoReconnect === undefined ? true : !!config.autoReconnect;
|
|
145
|
+
this._dying = false;
|
|
146
|
+
this._voltClient = voltClient;
|
|
147
|
+
this._pingTimer = 0;
|
|
148
|
+
this._pingTimeoutTimer = 0;
|
|
149
|
+
this._connectionId = "";
|
|
150
|
+
this._pingInterval = config.pingInterval || 10000;
|
|
151
|
+
this._reconnectInterval = config.reconnectInterval || 5000;
|
|
152
|
+
this._timeoutInterval = config.timeoutInterval || 60000;
|
|
153
|
+
this._helloPayload = undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
connect(helloPayload, throwOnFail) {
|
|
157
|
+
this._helloPayload = helloPayload;
|
|
158
|
+
if (throwOnFail) {
|
|
159
|
+
return _doConnect.call(this, this._helloPayload);
|
|
160
|
+
} else {
|
|
161
|
+
return Promise.resolve(_cleanUp.call(this, true));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
disconnect() {
|
|
166
|
+
this._dying = true;
|
|
167
|
+
_cleanUp.call(this);
|
|
168
|
+
}
|
|
161
169
|
}
|