*Update dist
This commit is contained in:
parent
bd4ac1584b
commit
2baf7a1eec
|
@ -0,0 +1,2 @@
|
||||||
|
export declare const ERR_NOT_READY = "NOT_READY";
|
||||||
|
//# sourceMappingURL=error.d.ts.map
|
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,cAAc,CAAC"}
|
|
@ -0,0 +1 @@
|
||||||
|
export const ERR_NOT_READY = "NOT_READY";
|
|
@ -1,22 +1,25 @@
|
||||||
import RpcQuery from "./rpcQuery.js";
|
import RpcQuery from "./rpcQuery.js";
|
||||||
export default class RpcNetwork {
|
export default class RpcNetwork {
|
||||||
private _dht;
|
|
||||||
private _majorityThreshold;
|
|
||||||
private _maxTtl;
|
|
||||||
private _queryTimeout;
|
|
||||||
private _relays;
|
|
||||||
private _ready;
|
|
||||||
private _force;
|
|
||||||
constructor(dht?: any);
|
constructor(dht?: any);
|
||||||
get ready(): Promise<void>;
|
private _dht;
|
||||||
get relays(): string[];
|
|
||||||
get dht(): any;
|
get dht(): any;
|
||||||
get maxTtl(): number;
|
private _majorityThreshold;
|
||||||
set maxTtl(value: number);
|
|
||||||
get queryTimeout(): number;
|
|
||||||
set queryTimeout(value: number);
|
|
||||||
get majorityThreshold(): number;
|
get majorityThreshold(): number;
|
||||||
set majorityThreshold(value: number);
|
set majorityThreshold(value: number);
|
||||||
|
private _maxTtl;
|
||||||
|
get maxTtl(): number;
|
||||||
|
set maxTtl(value: number);
|
||||||
|
private _queryTimeout;
|
||||||
|
get queryTimeout(): number;
|
||||||
|
set queryTimeout(value: number);
|
||||||
|
private _relayTimeout;
|
||||||
|
get relayTimeout(): number;
|
||||||
|
set relayTimeout(value: number);
|
||||||
|
private _relays;
|
||||||
|
get relays(): string[];
|
||||||
|
private _ready;
|
||||||
|
get ready(): Promise<void>;
|
||||||
|
private _force;
|
||||||
get force(): boolean;
|
get force(): boolean;
|
||||||
set force(value: boolean);
|
set force(value: boolean);
|
||||||
addRelay(pubkey: string): void;
|
addRelay(pubkey: string): void;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"rpcNetwork.d.ts","sourceRoot":"","sources":["../src/rpcNetwork.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAIrC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,aAAa,CAAM;IAC3B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAkB;gBAEpB,GAAG,MAAY;IAK3B,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAEzB;IAED,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,IAAI,GAAG,QAEN;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAEvB;IAED,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAElC;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,EAEvB;IAEM,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK9B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAWpC,WAAW,IAAI,IAAI;IAInB,KAAK,CACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,MAAM,GAAG,GAAG,EAAO,EACzB,KAAK,GAAE,OAAe,GACrB,QAAQ;CAQZ"}
|
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AQZ"}
|
|
@ -2,44 +2,51 @@ import RpcQuery from "./rpcQuery.js";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import DHT from "@hyperswarm/dht";
|
import DHT from "@hyperswarm/dht";
|
||||||
export default class RpcNetwork {
|
export default class RpcNetwork {
|
||||||
_dht;
|
|
||||||
_majorityThreshold = 0.75;
|
|
||||||
_maxTtl = 12 * 60 * 60;
|
|
||||||
_queryTimeout = 30;
|
|
||||||
_relays = [];
|
|
||||||
_ready;
|
|
||||||
_force = false;
|
|
||||||
constructor(dht = new DHT()) {
|
constructor(dht = new DHT()) {
|
||||||
this._dht = dht;
|
this._dht = dht;
|
||||||
this._ready = this._dht.ready();
|
this._ready = this._dht.ready();
|
||||||
}
|
}
|
||||||
get ready() {
|
_dht;
|
||||||
return this._ready;
|
|
||||||
}
|
|
||||||
get relays() {
|
|
||||||
return this._relays;
|
|
||||||
}
|
|
||||||
get dht() {
|
get dht() {
|
||||||
return this._dht;
|
return this._dht;
|
||||||
}
|
}
|
||||||
get maxTtl() {
|
_majorityThreshold = 0.75;
|
||||||
return this._maxTtl;
|
|
||||||
}
|
|
||||||
set maxTtl(value) {
|
|
||||||
this._maxTtl = value;
|
|
||||||
}
|
|
||||||
get queryTimeout() {
|
|
||||||
return this._queryTimeout;
|
|
||||||
}
|
|
||||||
set queryTimeout(value) {
|
|
||||||
this._queryTimeout = value;
|
|
||||||
}
|
|
||||||
get majorityThreshold() {
|
get majorityThreshold() {
|
||||||
return this._majorityThreshold;
|
return this._majorityThreshold;
|
||||||
}
|
}
|
||||||
set majorityThreshold(value) {
|
set majorityThreshold(value) {
|
||||||
this._majorityThreshold = value;
|
this._majorityThreshold = value;
|
||||||
}
|
}
|
||||||
|
_maxTtl = 12 * 60 * 60;
|
||||||
|
get maxTtl() {
|
||||||
|
return this._maxTtl;
|
||||||
|
}
|
||||||
|
set maxTtl(value) {
|
||||||
|
this._maxTtl = value;
|
||||||
|
}
|
||||||
|
_queryTimeout = 30;
|
||||||
|
get queryTimeout() {
|
||||||
|
return this._queryTimeout;
|
||||||
|
}
|
||||||
|
set queryTimeout(value) {
|
||||||
|
this._queryTimeout = value;
|
||||||
|
}
|
||||||
|
_relayTimeout = 2;
|
||||||
|
get relayTimeout() {
|
||||||
|
return this._relayTimeout;
|
||||||
|
}
|
||||||
|
set relayTimeout(value) {
|
||||||
|
this._relayTimeout = value;
|
||||||
|
}
|
||||||
|
_relays = [];
|
||||||
|
get relays() {
|
||||||
|
return this._relays;
|
||||||
|
}
|
||||||
|
_ready;
|
||||||
|
get ready() {
|
||||||
|
return this._ready;
|
||||||
|
}
|
||||||
|
_force = false;
|
||||||
get force() {
|
get force() {
|
||||||
return this._force;
|
return this._force;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"rpcQuery.d.ts","sourceRoot":"","sources":["../src/rpcQuery.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAe,MAAM,SAAS,CAAC;AAIlD,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAe;IAChC,OAAO,CAAC,aAAa,CAAC,CAAM;IAC5B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,UAAU,CAAwC;IAC1D,OAAO,CAAC,eAAe,CAAC,CAAsB;gBAElC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAMlD,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAEzB;IAED,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,OAAO;YAQD,IAAI;YA2BJ,UAAU;IA0BxB,OAAO,CAAC,cAAc;IA0CtB,OAAO,CAAC,KAAK;CASd"}
|
{"version":3,"file":"rpcQuery.d.ts","sourceRoot":"","sources":["../src/rpcQuery.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAe,MAAM,SAAS,CAAC;AAIlD,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAe;IAChC,OAAO,CAAC,aAAa,CAAC,CAAM;IAC5B,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,UAAU,CAAwC;IAC1D,OAAO,CAAC,eAAe,CAAC,CAAsB;gBAElC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAMlD,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAEzB;IAED,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,OAAO;YAQD,IAAI;YA2BJ,UAAU;IAgCxB,OAAO,CAAC,cAAc;IA8CtB,OAAO,CAAC,KAAK;CASd"}
|
|
@ -59,7 +59,9 @@ export default class RpcQuery {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
let timer;
|
||||||
socket.on("data", (res) => {
|
socket.on("data", (res) => {
|
||||||
|
clearTimeout(timer);
|
||||||
socket.end();
|
socket.end();
|
||||||
const response = unpack(res);
|
const response = unpack(res);
|
||||||
if (response && response.error) {
|
if (response && response.error) {
|
||||||
|
@ -69,7 +71,11 @@ export default class RpcQuery {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
socket.on("error", (error) => reject({ error }));
|
socket.on("error", (error) => reject({ error }));
|
||||||
|
socket.write("rpc");
|
||||||
socket.write(pack(this._query));
|
socket.write(pack(this._query));
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
reject("timeout");
|
||||||
|
}, this._network.relayTimeout * 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checkResponses() {
|
checkResponses() {
|
||||||
|
|
Loading…
Reference in New Issue