Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-meetings): reachability- add detection of symmetric NAT #4156

Merged

Conversation

k-wasniowski
Copy link
Contributor

@k-wasniowski k-wasniowski commented Mar 18, 2025

COMPLETES #SPARK-637849

This pull request addresses

This PR introduces possibility of finding out if customer is behind a symmetric NAT during the reachability.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

Sorry, something went wrong.

@k-wasniowski k-wasniowski requested review from a team as code owners March 18, 2025 19:12
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

📝 Walkthrough

Walkthrough

The update enhances the reachability modules by integrating NAT type detection. A new enumeration, NatType, is introduced with values such as Unknown and SymmetricNat, which are incorporated into the reachability metrics. The ClusterReachability class is modified to include a private property for storing server reflexive ICE candidates, and its constructor initializes the NAT type to NatType.Unknown. A new method, determineNatType, analyzes the ICE candidates to detect symmetric NAT conditions, emitting a natTypeUpdated event when necessary. The Reachability class is updated to include the natType property in its metrics and to listen for updates from the ClusterReachability class. Unit tests are also revised to validate the new NAT type data and event emissions, ensuring the updated functionality is properly tested.

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
warning [email protected]: Glob versions prior to v9 are no longer supported
warning intern > [email protected]: Glob versions prior to v9 are no longer supported
warning intern > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/transform > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning [email protected]: 16.1.1
warning sinon > @sinonjs/samsam > [email protected]: This package is deprecated. Use the optional chaining (?.) operator instead.
warning wd > [email protected]: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > archiver > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > [email protected]: request has been deprecated, see request/request#3142
warning wd > request > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning wd > archiver > archiver-utils > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > request > [email protected]: this library is no longer supported
warning @babel/cli > [email protected]: Glob versions prior to v9 are no longer supported
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > [email protected]: 16.1.1
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-18010b8a-c74f-40c3-9d6a-2d0c94717adf > @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

@k-wasniowski k-wasniowski added the validated If the pull request is validated for automation. label Mar 18, 2025
@k-wasniowski k-wasniowski self-assigned this Mar 18, 2025
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4156.d3m3l2kee0btzx.amplifyapp.com

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/@webex/plugin-meetings/test/unit/spec/reachability/index.ts (1)

2193-2194: Consider additional NAT type detection tests

While the basic structure testing is comprehensive, consider adding specific tests that verify the NAT type detection logic and the handling of natTypeUpdated events. This would improve test coverage for this new feature.

packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (2)

300-338: Consider preventing duplicate event emissions

The NAT type detection logic is well-implemented, but the current code might emit the natTypeUpdated event multiple times with the same value if multiple candidates confirm the symmetric NAT condition.

Consider checking if the NAT type has changed before emitting the event:

  private determineNatType(candidate: RTCIceCandidate) {
    this.srflxIceCandidates.push(candidate);

    if (this.srflxIceCandidates.length > 1) {
      const portsFound: {[key: string]: Set<number>} = {};

      this.srflxIceCandidates.forEach((c) => {
        const key = `${c.address}:${c.relatedPort}`;
        if (!portsFound[key]) {
          portsFound[key] = new Set();
        }
        portsFound[key].add(c.port);
      });

      Object.entries(portsFound).forEach(([, ports]) => {
        if (ports.size > 1) {
          // Found candidates with the same address and relatedPort, but different ports
+         const previousNatType = this.result.natType;
          this.result.natType = NatType.SymmetricNat;

+         if (previousNatType !== NatType.SymmetricNat) {
            this.emit(
              {
                file: 'clusterReachability',
                function: 'determineNatType',
              },
              Events.natTypeUpdated,
              {
                natType: NatType.SymmetricNat,
              }
            );
+         }
        }
      });
    }
  }

306-338: Add clarifying comment about relatedPort

The code correctly uses the relatedPort property for NAT detection, but this terminology might not be immediately clear to all developers.

Consider adding a clarifying comment about what relatedPort represents:

  private determineNatType(candidate: RTCIceCandidate) {
    this.srflxIceCandidates.push(candidate);

    if (this.srflxIceCandidates.length > 1) {
      const portsFound: {[key: string]: Set<number>} = {};

+     // Group candidates by address and relatedPort (the local/private interface port)
+     // In symmetric NAT, the same private endpoint maps to different public ports
      this.srflxIceCandidates.forEach((c) => {
        const key = `${c.address}:${c.relatedPort}`;
        if (!portsFound[key]) {
          portsFound[key] = new Set();
        }
        portsFound[key].add(c.port);
      });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3695649 and 957bb88.

📒 Files selected for processing (5)
  • packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (6 hunks)
  • packages/@webex/plugin-meetings/src/reachability/index.ts (5 hunks)
  • packages/@webex/plugin-meetings/src/reachability/reachability.types.ts (2 hunks)
  • packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (12 hunks)
  • packages/@webex/plugin-meetings/test/unit/spec/reachability/index.ts (24 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/@webex/plugin-meetings/src/reachability/index.ts (1)
packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (3) (3)
  • Events (29:33)
  • Events (35:35)
  • NatTypeUpdatedEventData (25:27)
packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (1)
packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (5) (5)
  • Events (29:33)
  • Events (35:35)
  • ResultEventData (12:17)
  • ClientMediaIpsUpdatedEventData (20:23)
  • NatTypeUpdatedEventData (25:27)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test - Integration
🔇 Additional comments (22)
packages/@webex/plugin-meetings/src/reachability/reachability.types.ts (3)

10-13: Well-structured NAT type enumeration

The addition of the NatType enum with Unknown and SymmetricNat values provides a clear, type-safe way to represent the NAT detection states. This is a clean implementation that allows for future expansion if additional NAT types need to be supported.


20-20: Appropriate addition of NAT type to cluster result type

Adding the natType property to the ClusterReachabilityResult type ensures that NAT type information is properly tracked per cluster, which aligns well with the PR objective of detecting symmetric NAT.


36-36: Consistent inclusion of NAT type in metrics

Adding the natType property to the ReachabilityMetrics type ensures that NAT information is available for analytics and reporting, which is important for monitoring network conditions across the user base.

packages/@webex/plugin-meetings/src/reachability/index.ts (6)

26-26: Proper import of NatType enum

The import of the NatType enum is correctly added to utilize the new type definition.


32-33: Import for new event data type

The import of NatTypeUpdatedEventData is appropriately added to support handling the new NAT type update events.


310-310: Appropriate initialization of NAT type in metrics

The natType property is correctly initialized to NatType.Unknown in the metrics object, providing a sensible default value.


326-328: Well-implemented NAT type update logic

The implementation only updates the natType when a non-unknown value is detected, which is a good approach to ensure that more specific information takes precedence. This handles the case where different clusters might detect different NAT types.


873-873: Proper initialization of NAT type in cluster results

The natType property is correctly initialized to NatType.Unknown when setting up the initial cluster results. This ensures consistency with the type definition and provides a clear default state.


973-980: Well-implemented event listener for NAT type updates

The event listener for natTypeUpdated follows the same pattern as the existing event listeners, ensuring consistency in the codebase. It correctly updates the NAT type in the results object and persists the changes to storage.

packages/@webex/plugin-meetings/test/unit/spec/reachability/index.ts (2)

552-553: Updated mock data with NAT type

The addition of natType: 'unknown' to mock cluster data ensures the tests remain compatible with the updated data structures.


588-589: Consistent NAT type in expected results

The expected results in assertions are properly updated to include the natType field, ensuring the tests verify the complete result structure.

packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (5)

12-14: Correct imports for new NAT-related types

The necessary imports for NatTypeUpdatedEventData and NatType are properly added to support the updated testing code.


22-26: Updated event tracking for NAT type events

The emittedEvents record is appropriately updated to track NatTypeUpdatedEventData events, ensuring the test infrastructure can verify the emission of NAT type updates.


32-32: Updated event reset function

The resetEmittedEvents function is correctly updated to clear the natTypeUpdated event array, ensuring a clean state between tests.


64-66: Added event listener for NAT type updates

The event listener for natTypeUpdated events is properly implemented, following the same pattern as the existing event listeners and storing the events for later verification.


462-498: Comprehensive test for symmetric NAT detection

This new test case effectively verifies the core functionality of detecting symmetric NAT:

  1. It confirms no event is emitted with just one server reflexive candidate
  2. It verifies a natTypeUpdated event is emitted when a second candidate with the same IP but different port is received
  3. It checks that the final result correctly includes the detected NAT type

This is a well-constructed test that covers the key aspects of the new functionality.

packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (6)

9-9: LGTM: Import of NatType enum

The import is correctly added to include the new NatType enum alongside the existing ClusterReachabilityResult type.


25-27: LGTM: Well-designed event data type

The NatTypeUpdatedEventData type follows the established pattern of other event data types in the file, with clear and concise structure.


32-32: LGTM: Event declaration

The new natTypeUpdated event is properly added to the Events constant with a descriptive comment.


49-49: LGTM: Storage for server reflexive candidates

Good choice to store server reflexive candidates for later analysis in the NAT type determination.


79-79: LGTM: Initializing natType property

Correctly initializing the natType to Unknown in the constructor as a good default state.


359-359: LGTM: Appropriate integration point

Calling determineNatType when server reflexive candidates are received is the perfect integration point for this feature.

Object.entries(portsFound).forEach(([, ports]) => {
if (ports.size > 1) {
// Found candidates with the same address and relatedPort, but different ports
this.result.natType = NatType.SymmetricNat;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also add support for other types of nat like full cone, right? (if we get multiple srflx candidates from different servers all with same port) It could be added in another PR...

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c7e0440 and 9b61bde.

📒 Files selected for processing (1)
  • packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (1)
packages/@webex/plugin-meetings/src/reachability/clusterReachability.ts (5)
  • Events (29-33)
  • Events (35-35)
  • ResultEventData (12-17)
  • ClientMediaIpsUpdatedEventData (20-23)
  • NatTypeUpdatedEventData (25-27)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Packages
  • GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (2)
packages/@webex/plugin-meetings/test/unit/spec/reachability/clusterReachability.ts (2)

22-25: LGTM! Event handling implementation for natTypeUpdated.

The event handling for natTypeUpdated is well implemented, following the established pattern in the codebase with consistent typing, reset handling, and event listener setup.

Also applies to: 32-32, 64-66


452-488: LGTM! Comprehensive test case for symmetric NAT detection.

The test case correctly verifies the NAT detection logic by:

  1. Confirming no event is emitted with a single candidate
  2. Verifying the event is emitted when a second candidate with the same IP but different port is received
  3. Validating the correct NAT type value ('symmetric-nat') in the emitted event
  4. Ensuring the reachability results remain accurate after detection

This thoroughly tests the intended functionality of detecting symmetric NAT conditions.

@k-wasniowski k-wasniowski merged commit dc8ca61 into webex:next Mar 28, 2025
13 checks passed
@k-wasniowski k-wasniowski deleted the feat-add-detection-of-symmetric-nat branch March 28, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants