diff --git a/src/connection/connection.js b/src/connection/connection.js index 2dd2d4d..f802e1f 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -260,6 +260,14 @@ class Connection extends EventEmitter { await this.sendToRadioFrame(data.toBytes()); } + async sendCommandSetFloodScope(transportKey) { + const data = new BufferWriter(); + data.writeByte(Constants.CommandCodes.SetFloodScope); + data.writeByte(0); // not documented, protocol version 8 checks if it's zero, else returns ERR_CODE_UNSUPPORTED_CMD + data.writeBytes(transportKey); + await this.sendToRadioFrame(data.toBytes()); + } + async sendCommandGetChannel(channelIdx) { const data = new BufferWriter(); data.writeByte(Constants.CommandCodes.GetChannel); @@ -1761,6 +1769,41 @@ class Connection extends EventEmitter { }); } + setFloodScope(transportKey) { + return new Promise(async (resolve, reject) => { + try { + + // resolve promise when we receive ok + const onOk = (response) => { + this.off(Constants.ResponseCodes.Ok, onOk); + this.off(Constants.ResponseCodes.Err, onErr); + resolve(response); + } + + // reject promise when we receive err + const onErr = () => { + this.off(Constants.ResponseCodes.Ok, onOk); + this.off(Constants.ResponseCodes.Err, onErr); + reject(); + } + + // listen for events + this.once(Constants.ResponseCodes.Ok, onOk); + this.once(Constants.ResponseCodes.Err, onErr); + + // send set flood scope + await this.sendCommandSetFloodScope(transportKey); + + } catch(e) { + reject(e); + } + }); + } + + clearFloodScope() { + return this.setFloodScope([]); + } + // @deprecated migrate to using tracePath instead. pingRepeaterZeroHop will be removed in a future update pingRepeaterZeroHop(contactPublicKey, timeoutMillis) { return new Promise(async (resolve, reject) => { diff --git a/src/constants.js b/src/constants.js index 2eb2706..9d62074 100644 --- a/src/constants.js +++ b/src/constants.js @@ -52,6 +52,8 @@ class Constants { SendTelemetryReq: 39, SendBinaryReq: 50, + + SetFloodScope: 54, } static ResponseCodes = {