Skip to content

Commit

Permalink
Merge branch 'main' into Mqtt5TopicAliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
bretambrose committed Nov 17, 2023
2 parents 6303bd2 + b294263 commit ead2982
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/stale_issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
cleanup:
runs-on: ubuntu-latest
name: Stale issue job
permissions:
issues: write
pull-requests: write
steps:
- uses: aws-actions/stale-issue-cleanup@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions lib/native/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function native_memory_dump(): void;
export function error_code_to_string(error_code: number): string;
/** @internal */
export function error_code_to_name(error_code: number): string;
/** @internal */
export function disable_threadsafe_function(): number;

/* IO */
/** @internal */
Expand Down
14 changes: 12 additions & 2 deletions lib/native/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CRuntimeType = Object.freeze({
});

function getCRuntime() {
if(platform() !== "linux") {
if (platform() !== "linux") {
return CRuntimeType.NON_LINUX;
}

Expand Down Expand Up @@ -74,5 +74,15 @@ if (binding == undefined) {
throw new Error("AWS CRT binary not present in any of the following locations:\n\t" + search_paths.join('\n\t'));
}

import crt_native from "./binding"
/** Electron will shutdown the node process on exit, which causes the threadsafe function to segfault. To prevent
* the segfault we disable the threadsafe function on node process exit. */
if (process.versions.hasOwnProperty('electron')) {
process.on('exit', function () {
crt_native.disable_threadsafe_function();
});
}


export default binding;
export { CRuntimeType , cRuntime };
export { CRuntimeType, cRuntime };
114 changes: 114 additions & 0 deletions lib/native/mqtt5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,111 @@ export * from '../common/mqtt5_packet';
*/
export type WebsocketHandshakeTransform = (request: http.HttpRequest, done: (error_code?: number) => void) => void;

/**
* An enumeration that controls how the client applies topic aliasing to outbound publish packets.
*
* Topic alias behavior is described in https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113
*/
export enum OutboundTopicAliasBehaviorType {

/**
* Maps to Disabled. This keeps the client from being broken (by default) if the broker
* topic aliasing implementation has a problem.
*/
Default = 0,

/**
* Outbound aliasing is the user's responsibility. Client will cache and use
* previously-established aliases if they fall within the negotiated limits of the connection.
*
* The user must still always submit a full topic in their publishes because disconnections disrupt
* topic alias mappings unpredictably. The client will properly use a requested alias when the most-recently-seen
* binding for a topic alias value matches the alias and topic in the publish packet.
*/
Manual = 1,

/**
* (Recommended) The client will ignore any user-specified topic aliasing and instead use an LRU cache to drive
* alias usage.
*/
LRU = 2,

/**
* Completely disable outbound topic aliasing.
*/
Disabled = 3,
}

/**
* An enumeration that controls whether or not the client allows the broker to send publishes that use topic
* aliasing.
*
* Topic alias behavior is described in https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113
*/
export enum InboundTopicAliasBehaviorType {

/**
* Maps to Disabled. This keeps the client from being broken (by default) if the broker
* topic aliasing implementation has a problem.
*/
Default = 0,

/**
* Allow the server to send PUBLISH packets to the client that use topic aliasing
*/
Enabled = 1,

/**
* Forbid the server from sending PUBLISH packets to the client that use topic aliasing
*/
Disabled = 2,
}

/**
* Configuration for all client topic aliasing behavior.
*/
export interface TopicAliasingOptions {

/**
* Controls what kind of outbound topic aliasing behavior the client should attempt to use.
*
* If topic aliasing is not supported by the server, this setting has no effect and any attempts to directly
* manipulate the topic alias id in outbound publishes will be ignored.
*
* If left undefined, then outbound topic aliasing is disabled.
*/
outboundBehavior?: OutboundTopicAliasBehaviorType,

/**
* If outbound topic aliasing is set to LRU, this controls the maximum size of the cache. If outbound topic
* aliasing is set to LRU and this is zero or undefined, a sensible default is used (25). If outbound topic
* aliasing is not set to LRU, then this setting has no effect.
*
* The final size of the cache is determined by the minimum of this setting and the value of the
* topic_alias_maximum property of the received CONNACK. If the received CONNACK does not have an explicit
* positive value for that field, outbound topic aliasing is disabled for the duration of that connection.
*/
outboundCacheMaxSize?: number,

/**
* Controls whether or not the client allows the broker to use topic aliasing when sending publishes. Even if
* inbound topic aliasing is enabled, it is up to the server to choose whether or not to use it.
*
* If left undefined, then inbound topic aliasing is disabled.
*/
inboundBehavior?: InboundTopicAliasBehaviorType,

/**
* If inbound topic aliasing is enabled, this will control the size of the inbound alias cache. If inbound
* aliases are enabled and this is zero or undefined, then a sensible default will be used (25). If inbound
* aliases are disabled, this setting has no effect.
*
* Behaviorally, this value overrides anything present in the topic_alias_maximum field of
* the CONNECT packet options.
*/
inboundCacheMaxSize?: number,
}

/**
* Information about the client's queue of operations
*/
Expand Down Expand Up @@ -263,6 +368,15 @@ export interface Mqtt5ClientConfig {
* @group Node-only
*/
extendedValidationAndFlowControlOptions? : ClientExtendedValidationAndFlowControl;

/**
* Additional controls for client behavior with respect to topic alias usage.
*
* If this setting is left undefined, then topic aliasing behavior will be disabled.
*
* @group Node-only
*/
topicAliasingOptions? : TopicAliasingOptions
}

/**
Expand Down
2 changes: 1 addition & 1 deletion source/http_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void s_on_body_call(napi_env env, napi_value on_body, void *context, void

AWS_NAPI_ENSURE(
env,
napi_create_external_arraybuffer(
aws_napi_create_external_arraybuffer(
env, args->chunk.buffer, args->chunk.len, s_external_arraybuffer_finalizer, args, &params[0]));

AWS_NAPI_ENSURE(
Expand Down
Loading

0 comments on commit ead2982

Please sign in to comment.