From 2baf7a1eec8aaf90887fff76c583469bfcd49c6e Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 23 Jul 2022 11:43:05 -0400 Subject: [PATCH] *Update dist --- dist/error.d.ts | 2 ++ dist/error.d.ts.map | 1 + dist/error.js | 1 + dist/rpcNetwork.d.ts | 29 +++++++++++--------- dist/rpcNetwork.d.ts.map | 2 +- dist/rpcNetwork.js | 57 ++++++++++++++++++++++------------------ dist/rpcQuery.d.ts.map | 2 +- dist/rpcQuery.js | 6 +++++ 8 files changed, 60 insertions(+), 40 deletions(-) create mode 100644 dist/error.d.ts create mode 100644 dist/error.d.ts.map create mode 100644 dist/error.js diff --git a/dist/error.d.ts b/dist/error.d.ts new file mode 100644 index 0000000..09f03e6 --- /dev/null +++ b/dist/error.d.ts @@ -0,0 +1,2 @@ +export declare const ERR_NOT_READY = "NOT_READY"; +//# sourceMappingURL=error.d.ts.map \ No newline at end of file diff --git a/dist/error.d.ts.map b/dist/error.d.ts.map new file mode 100644 index 0000000..63f7520 --- /dev/null +++ b/dist/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"} \ No newline at end of file diff --git a/dist/error.js b/dist/error.js new file mode 100644 index 0000000..74282fc --- /dev/null +++ b/dist/error.js @@ -0,0 +1 @@ +export const ERR_NOT_READY = "NOT_READY"; diff --git a/dist/rpcNetwork.d.ts b/dist/rpcNetwork.d.ts index d0c5579..32bbf8f 100644 --- a/dist/rpcNetwork.d.ts +++ b/dist/rpcNetwork.d.ts @@ -1,22 +1,25 @@ import RpcQuery from "./rpcQuery.js"; export default class RpcNetwork { - private _dht; - private _majorityThreshold; - private _maxTtl; - private _queryTimeout; - private _relays; - private _ready; - private _force; constructor(dht?: any); - get ready(): Promise; - get relays(): string[]; + private _dht; get dht(): any; - get maxTtl(): number; - set maxTtl(value: number); - get queryTimeout(): number; - set queryTimeout(value: number); + private _majorityThreshold; get majorityThreshold(): 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; + private _force; get force(): boolean; set force(value: boolean); addRelay(pubkey: string): void; diff --git a/dist/rpcNetwork.d.ts.map b/dist/rpcNetwork.d.ts.map index 0146ea1..d208c37 100644 --- a/dist/rpcNetwork.d.ts.map +++ b/dist/rpcNetwork.d.ts.map @@ -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,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,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"} \ No newline at end of file diff --git a/dist/rpcNetwork.js b/dist/rpcNetwork.js index 65f968e..9c3146a 100644 --- a/dist/rpcNetwork.js +++ b/dist/rpcNetwork.js @@ -2,44 +2,51 @@ import RpcQuery from "./rpcQuery.js"; // @ts-ignore import DHT from "@hyperswarm/dht"; export default class RpcNetwork { - _dht; - _majorityThreshold = 0.75; - _maxTtl = 12 * 60 * 60; - _queryTimeout = 30; - _relays = []; - _ready; - _force = false; constructor(dht = new DHT()) { this._dht = dht; this._ready = this._dht.ready(); } - get ready() { - return this._ready; - } - get relays() { - return this._relays; - } + _dht; get dht() { return this._dht; } - get maxTtl() { - return this._maxTtl; - } - set maxTtl(value) { - this._maxTtl = value; - } - get queryTimeout() { - return this._queryTimeout; - } - set queryTimeout(value) { - this._queryTimeout = value; - } + _majorityThreshold = 0.75; get majorityThreshold() { return this._majorityThreshold; } set 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() { return this._force; } diff --git a/dist/rpcQuery.d.ts.map b/dist/rpcQuery.d.ts.map index 2ef03bb..9f1cf32 100644 --- a/dist/rpcQuery.d.ts.map +++ b/dist/rpcQuery.d.ts.map @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/dist/rpcQuery.js b/dist/rpcQuery.js index 5b4f88f..4d1b221 100644 --- a/dist/rpcQuery.js +++ b/dist/rpcQuery.js @@ -59,7 +59,9 @@ export default class RpcQuery { return; } return new Promise((resolve, reject) => { + let timer; socket.on("data", (res) => { + clearTimeout(timer); socket.end(); const response = unpack(res); if (response && response.error) { @@ -69,7 +71,11 @@ export default class RpcQuery { resolve(null); }); socket.on("error", (error) => reject({ error })); + socket.write("rpc"); socket.write(pack(this._query)); + timer = setTimeout(() => { + reject("timeout"); + }, this._network.relayTimeout * 1000); }); } checkResponses() {