feat!: return `REMOTE_PEER_REJECTED` if remote peer rejected the message

This commit is contained in:
fryorcraken.eth 2023-09-21 11:32:34 +10:00
parent 6807185f3b
commit 053b6545ad
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 19 additions and 8 deletions

View File

@ -146,14 +146,19 @@ class LightPush extends BaseProtocol implements ILightPush {
return { recipients, error: SendError.DECODE_FAILED }; return { recipients, error: SendError.DECODE_FAILED };
} }
if (response?.isSuccess) { if (!response) {
recipients.some((recipient) => recipient.equals(peer.id)) ||
recipients.push(peer.id);
} else {
log("Remote peer fault: No response in PushRPC"); log("Remote peer fault: No response in PushRPC");
return { recipients, error: SendError.REMOTE_PEER_FAULT }; return { recipients, error: SendError.REMOTE_PEER_FAULT };
} }
if (!response.isSuccess) {
log("Remote peer rejected the message: ", response.info);
return { recipients, error: SendError.REMOTE_PEER_REJECTED };
}
recipients.some((recipient) => recipient.equals(peer.id)) ||
recipients.push(peer.id);
return { recipients }; return { recipients };
}); });

View File

@ -79,10 +79,16 @@ export enum SendError {
*/ */
NO_PEER_AVAILABLE = "No peer available", NO_PEER_AVAILABLE = "No peer available",
/** /**
* The remote peer did not behave as expected. Mitigation from `NO_PEER_AVAILABLE` * The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
* or `DECODE_FAILED` can be used. * or `DECODE_FAILED` can be used.
*/ */
REMOTE_PEER_FAULT = "Remote peer fault" REMOTE_PEER_FAULT = "Remote peer fault",
/**
* The remote peer rejected the message. Information provided by the remote peer
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
* or `DECODE_FAILED` can be used.
*/
REMOTE_PEER_REJECTED = "Remote peer rejected"
} }
export interface SendResult { export interface SendResult {

View File

@ -86,7 +86,7 @@ describe("Waku Light Push [node only]", function () {
}); });
} else { } else {
expect(pushResponse.recipients.length).to.eq(0); expect(pushResponse.recipients.length).to.eq(0);
expect(pushResponse.errors).to.include(SendError.NO_RPC_RESPONSE); expect(pushResponse.errors).to.include(SendError.REMOTE_PEER_REJECTED);
expect(await messageCollector.waitForMessages(1)).to.eq(false); expect(await messageCollector.waitForMessages(1)).to.eq(false);
} }
}); });
@ -158,7 +158,7 @@ describe("Waku Light Push [node only]", function () {
}); });
} else { } else {
expect(pushResponse.recipients.length).to.eq(0); expect(pushResponse.recipients.length).to.eq(0);
expect(pushResponse.errors).to.include(SendError.NO_RPC_RESPONSE); expect(pushResponse.errors).to.include(SendError.REMOTE_PEER_REJECTED);
expect(await messageCollector.waitForMessages(1)).to.eq(false); expect(await messageCollector.waitForMessages(1)).to.eq(false);
} }
}); });