chia-agent 14.0.0-beta.0 → 14.0.0-beta.1
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/CHANGELOG.md +19 -0
- package/package.json +1 -1
- package/rpc/index.d.ts +20 -0
- package/rpc/index.js +30 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
## [14.0.0]
|
|
4
4
|
### Breaking change
|
|
5
5
|
- When RPC API responds with `success: false`, its `Promise` now does `reject`. (Previously it does `resolve`)
|
|
6
|
+
### Added
|
|
7
|
+
- Added connectivity options for `RPCAgent`.
|
|
8
|
+
- `keepAlive` (default: `true`)
|
|
9
|
+
- `keepAliveMsecs` (default: `1000`)
|
|
10
|
+
- `maxSockets` (default: `Infinity`)
|
|
11
|
+
- `timeout` (default: `undefined`)
|
|
12
|
+
```typescript
|
|
13
|
+
// Usage
|
|
14
|
+
const {RPCAgent, setLogLevel} = require("chia-agent");
|
|
15
|
+
const {get_plots} = require("chia-agent/api/rpc");
|
|
16
|
+
|
|
17
|
+
const agent = new RPCAgent({
|
|
18
|
+
service: "harvester",
|
|
19
|
+
keepAlive: true,
|
|
20
|
+
keepAliveMsecs: 3000,
|
|
21
|
+
maxSockets: 1, // Avoid to set `1` if your requests may be sent in parallel.
|
|
22
|
+
timeout: 5000,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
6
25
|
|
|
7
26
|
## [13.2.0]
|
|
8
27
|
### Added
|
package/package.json
CHANGED
package/rpc/index.d.ts
CHANGED
|
@@ -15,22 +15,38 @@ export declare type TRPCAgentProps = {
|
|
|
15
15
|
client_cert?: string | Buffer;
|
|
16
16
|
client_key?: string | Buffer;
|
|
17
17
|
skip_hostname_verification?: boolean;
|
|
18
|
+
keepAlive?: boolean;
|
|
19
|
+
keepAliveMsecs?: number;
|
|
20
|
+
maxSockets?: number;
|
|
21
|
+
timeout?: number;
|
|
18
22
|
} | {
|
|
19
23
|
protocol: "https";
|
|
20
24
|
host: string;
|
|
21
25
|
port: number;
|
|
22
26
|
configPath: string;
|
|
23
27
|
skip_hostname_verification?: boolean;
|
|
28
|
+
keepAlive?: boolean;
|
|
29
|
+
keepAliveMsecs?: number;
|
|
30
|
+
maxSockets?: number;
|
|
31
|
+
timeout?: number;
|
|
24
32
|
} | {
|
|
25
33
|
protocol: "http";
|
|
26
34
|
host: string;
|
|
27
35
|
port: number;
|
|
36
|
+
keepAlive?: boolean;
|
|
37
|
+
keepAliveMsecs?: number;
|
|
38
|
+
maxSockets?: number;
|
|
39
|
+
timeout?: number;
|
|
28
40
|
} | {
|
|
29
41
|
service: TDestination;
|
|
30
42
|
host?: string;
|
|
31
43
|
port?: number;
|
|
32
44
|
configPath?: string;
|
|
33
45
|
skip_hostname_verification?: boolean;
|
|
46
|
+
keepAlive?: boolean;
|
|
47
|
+
keepAliveMsecs?: number;
|
|
48
|
+
maxSockets?: number;
|
|
49
|
+
timeout?: number;
|
|
34
50
|
};
|
|
35
51
|
export declare class RPCAgent {
|
|
36
52
|
protected _protocol: "http" | "https";
|
|
@@ -41,6 +57,10 @@ export declare class RPCAgent {
|
|
|
41
57
|
protected _clientKey?: string | Buffer;
|
|
42
58
|
protected _agent: HttpsAgent | HttpAgent;
|
|
43
59
|
protected _skip_hostname_verification: boolean;
|
|
60
|
+
protected _keepAlive: boolean;
|
|
61
|
+
protected _keepAliveMsecs: number;
|
|
62
|
+
protected _maxSockets: number;
|
|
63
|
+
protected _timeout?: number;
|
|
44
64
|
constructor(props: TRPCAgentProps);
|
|
45
65
|
protected _getConfig(configPath?: string): TConfig;
|
|
46
66
|
protected _loadCertFilesFromConfig(config: TConfig): {
|
package/rpc/index.js
CHANGED
|
@@ -67,10 +67,21 @@ class RPCAgent {
|
|
|
67
67
|
this._clientCert = "";
|
|
68
68
|
this._clientKey = "";
|
|
69
69
|
this._skip_hostname_verification = false;
|
|
70
|
+
this._keepAlive = true;
|
|
71
|
+
this._keepAliveMsecs = 1000;
|
|
72
|
+
this._maxSockets = Infinity;
|
|
73
|
+
this._timeout = undefined;
|
|
70
74
|
if ("protocol" in props) {
|
|
71
75
|
this._protocol = props.protocol;
|
|
72
76
|
this._hostname = props.host;
|
|
73
77
|
this._port = props.port;
|
|
78
|
+
this._keepAlive = props.keepAlive !== false;
|
|
79
|
+
this._keepAliveMsecs = typeof props.keepAliveMsecs === "number" && props.keepAliveMsecs > 0 ?
|
|
80
|
+
props.keepAliveMsecs : this._keepAliveMsecs;
|
|
81
|
+
this._maxSockets = typeof props.maxSockets === "number" && props.maxSockets > 0 ?
|
|
82
|
+
props.maxSockets : this._maxSockets;
|
|
83
|
+
this._timeout = typeof props.timeout === "number" && props.timeout > 0 ?
|
|
84
|
+
props.timeout : this._timeout;
|
|
74
85
|
if (props.protocol === "https") {
|
|
75
86
|
if ("configPath" in props) {
|
|
76
87
|
const config = this._getConfig(props.configPath);
|
|
@@ -93,14 +104,28 @@ class RPCAgent {
|
|
|
93
104
|
cert: this._clientCert,
|
|
94
105
|
key: this._clientKey,
|
|
95
106
|
rejectUnauthorized: Boolean(this._caCert) && this._hostname !== "localhost",
|
|
107
|
+
keepAlive: this._keepAlive,
|
|
108
|
+
keepAliveMsecs: this._keepAliveMsecs,
|
|
109
|
+
maxSockets: this._maxSockets,
|
|
110
|
+
timeout: this._timeout,
|
|
96
111
|
});
|
|
97
112
|
}
|
|
98
113
|
else {
|
|
99
|
-
this._agent = new http_1.Agent(
|
|
114
|
+
this._agent = new http_1.Agent({
|
|
115
|
+
keepAlive: this._keepAlive,
|
|
116
|
+
keepAliveMsecs: this._keepAliveMsecs,
|
|
117
|
+
maxSockets: this._maxSockets,
|
|
118
|
+
timeout: this._timeout,
|
|
119
|
+
});
|
|
100
120
|
}
|
|
101
121
|
}
|
|
102
122
|
else {
|
|
103
123
|
this._protocol = "https";
|
|
124
|
+
this._keepAlive = props.keepAlive !== false;
|
|
125
|
+
this._keepAliveMsecs = typeof props.keepAliveMsecs === "number" ? props.keepAliveMsecs : this._keepAliveMsecs;
|
|
126
|
+
this._maxSockets = typeof props.maxSockets === "number" && props.maxSockets > 0 ?
|
|
127
|
+
props.maxSockets : this._maxSockets;
|
|
128
|
+
this._timeout = typeof props.timeout === "number" && props.timeout > 0 ? props.timeout : this._timeout;
|
|
104
129
|
const config = this._getConfig("configPath" in props ? props.configPath : undefined);
|
|
105
130
|
if (props.host && typeof props.port === "number") {
|
|
106
131
|
this._hostname = props.host;
|
|
@@ -124,6 +149,10 @@ class RPCAgent {
|
|
|
124
149
|
cert: this._clientCert,
|
|
125
150
|
key: this._clientKey,
|
|
126
151
|
rejectUnauthorized: Boolean(this._caCert) && this._hostname !== "localhost",
|
|
152
|
+
keepAlive: this._keepAlive,
|
|
153
|
+
keepAliveMsecs: this._keepAliveMsecs,
|
|
154
|
+
maxSockets: this._maxSockets,
|
|
155
|
+
timeout: this._timeout,
|
|
127
156
|
});
|
|
128
157
|
}
|
|
129
158
|
}
|