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(dashmate): validate external IP #2183

Merged
merged 2 commits into from
Sep 29, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Sep 28, 2024

Issue being fixed or feature implemented

Partially implements #1272

What was done?

  • The dashmate status commands should indicate wrong external IP configuration
  • The dashmate doctor command suggests to fix wrong external IP

How Has This Been Tested?

Running locally

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Enhanced error messages for unavailable ports, providing clearer guidance on checking public IP and firewall settings.
    • Updated port status checks to include external IP address for improved validation across multiple services.
  • Bug Fixes

    • Adjusted port status checking logic to ensure accurate validation with external IP configuration.

@shumkov shumkov self-assigned this Sep 28, 2024
Copy link
Contributor

coderabbitai bot commented Sep 28, 2024

Walkthrough

The changes involve updates to the handling of port status checks across multiple files in the Dashmate project. Key modifications include enhancing error messages related to unavailable ports, incorporating external IP addresses into port status checks, and adjusting method signatures to support these changes. The overall aim is to improve user guidance and the accuracy of port status validation.

Changes

File Path Change Summary
packages/dashmate/src/doctor/analyse/analyseConfigFactory.js Expanded error messages for unavailable ports to include guidance on public IP and firewall settings.
packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js Updated checkPortStatus method calls to include externalIp for Core P2P, Gateway HTTP, and Tenderdash P2P ports.
packages/dashmate/src/status/providers.js Modified checkPortStatus method to accept an optional ip parameter for IP validation in requests.
packages/dashmate/src/status/scopes/core.js Updated checkPortStatus calls to include externalIp parameter in the getCoreScopeFactory function.
packages/dashmate/src/status/scopes/platform.js Altered checkPortStatus calls to include externalIp in the getPlatformScopeFactory function.

Possibly related PRs

Suggested reviewers

  • QuantumExplorer

Poem

🐇 In the land of code where rabbits play,
We’ve fixed the ports in a clever way.
With IPs checked and messages clear,
No more confusion, let’s all cheer!
Hopping through changes, we’ll find our way,
Dashmate’s better, hip-hip-hooray! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a64f0e2 and 9fe2779.

📒 Files selected for processing (2)
  • packages/dashmate/src/doctor/analyse/analyseConfigFactory.js (3 hunks)
  • packages/dashmate/src/status/providers.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/dashmate/src/doctor/analyse/analyseConfigFactory.js
  • packages/dashmate/src/status/providers.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

🧹 Outside diff range and nitpick comments (9)
packages/dashmate/src/status/providers.js (2)

66-66: LGTM: IP validation support added successfully.

The changes to include an optional ip parameter and conditionally construct the request path are well-implemented. This modification aligns with the PR objectives to validate external IP configuration.

Consider adding a comment explaining the ip parameter.

To improve code readability and maintainability, consider adding a brief comment explaining the purpose of the new ip parameter and its role in external IP validation.

Here's a suggested comment to add above the method signature:

/**
 * Check the status of a port and optionally validate an IP address.
 * @param {number} port - The port number to check.
 * @param {string} [ip] - Optional. The IP address to validate.
 * @returns {Promise<string>} A promise that resolves to the port status.
 */

Also applies to: 75-75


Line range hint 66-127: Consider updating error handling as per previous feedback.

Based on the retrieved learning from a previous review, it's recommended to update the error handling in this method. Failures should resolve with PortStateEnum.ERROR instead of rejecting the promise.

While this isn't directly related to the current changes, it would improve the overall robustness of the method. Consider updating the error handling in the req.on('error', ...) callback:

req.on('error', (e) => {
  if (process.env.DEBUG) {
    // eslint-disable-next-line no-console
    console.warn(`Port check request failed: ${e}`);
  }

  resolve(PortStateEnum.ERROR);
});

This change ensures consistent behavior across different types of failures.

packages/dashmate/src/status/scopes/platform.js (1)

92-93: Approve changes with a minor suggestion for clarity.

The addition of config.get('externalIp') to the checkPortStatus calls enhances the validation process by verifying port accessibility from the configured external IP. This change aligns well with the PR objective of validating the external IP configuration.

Consider adding a brief comment explaining the purpose of including the external IP in these checks. This would improve code readability and make the intent clearer for future maintainers. For example:

// Check port status using the configured external IP to validate accessibility
providers.mnowatch.checkPortStatus(config.get('platform.gateway.listeners.dapiAndDrive.port'), config.get('externalIp')),
providers.mnowatch.checkPortStatus(config.get('platform.drive.tenderdash.p2p.port'), config.get('externalIp')),
packages/dashmate/src/doctor/analyse/analyseConfigFactory.js (3)

163-181: Improved error message for Core P2P port unavailability.

The changes enhance the clarity of the error message and provide more actionable instructions, which is in line with the PR objectives. The conditional logic for the external IP is a good addition, as it tailors the message to the user's specific configuration.

Consider adding a newline character (\n) before "Ensure that port ${port}..." in the conditional block to improve readability:

 solution = chalk`Please ensure your configured IP address ${externalIp} is your public IP.
 You can change it using {bold.cyanBright dashmate config set externalIp [IP]}.
-Ensure that port ${port} on your public IP address is open
+\nEnsure that port ${port} on your public IP address is open
 for incoming connections. You may need to configure your firewall to
 ensure this port is accessible from the public internet. If you are using
 Network Address Translation (NAT), please enable port forwarding for port 80
 and all Dash service ports listed above.`;

193-211: Improved error message for Gateway HTTP port unavailability.

The changes are consistent with the improvements made to the Core P2P port error message, maintaining a uniform structure across error messages. This enhancement aligns well with the PR objectives of improving the dashmate status commands.

For consistency with the suggested change in the Core P2P port message, consider adding a newline character (\n) before "Ensure that port ${port}..." in the conditional block:

 solution = chalk`Please ensure your configured IP address ${externalIp} is your public IP.
 You can change it using {bold.cyanBright dashmate config set externalIp [IP]}.
-Ensure that port ${port} on your public IP address is open
+\nEnsure that port ${port} on your public IP address is open
 for incoming connections. You may need to configure your firewall to
 ensure this port is accessible from the public internet. If you are using
 Network Address Translation (NAT), please enable port forwarding for port 80
 and all Dash service ports listed above.`;

223-241: Improved error message for Tenderdash P2P port unavailability.

The changes maintain consistency with the improvements made to the other port error messages, which is excellent for user experience. This enhancement aligns well with the PR objectives of improving the dashmate status commands.

For consistency with the suggested changes in the previous port messages, consider adding a newline character (\n) before "Ensure that port ${port}..." in the conditional block:

 solution = chalk`Please ensure your configured IP address ${externalIp} is your public IP.
 You can change it using {bold.cyanBright dashmate config set externalIp [IP]}.
-Ensure that port ${port} on your public IP address is open
+\nEnsure that port ${port} on your public IP address is open
 for incoming connections. You may need to configure your firewall to
 ensure this port is accessible from the public internet. If you are using
 Network Address Translation (NAT), please enable port forwarding for port 80
 and all Dash service ports listed above.`;

Consider refactoring the port availability check logic into a separate function to reduce code duplication. This would make the code more maintainable and easier to update in the future. Here's a suggested approach:

function createPortAvailabilityProblem(portType, port, externalIp) {
  let solution = chalk`Please ensure that port ${port} on your public IP address ${externalIp} is open
for incoming connections. You may need to configure your firewall to
ensure this port is accessible from the public internet. If you are using
Network Address Translation (NAT), please enable port forwarding for port 80
and all Dash service ports listed above.`;

  if (externalIp) {
    solution = chalk`Please ensure your configured IP address ${externalIp} is your public IP.
You can change it using {bold.cyanBright dashmate config set externalIp [IP]}.

Ensure that port ${port} on your public IP address is open
for incoming connections. You may need to configure your firewall to
ensure this port is accessible from the public internet. If you are using
Network Address Translation (NAT), please enable port forwarding for port 80
and all Dash service ports listed above.`;
  }

  return new Problem(
    `${portType} port is unavailable for incoming connections.`,
    solution,
    SEVERITY.HIGH,
  );
}

// Usage:
problems.push(createPortAvailabilityProblem('Core P2P', config.get('core.p2p.port'), config.get('externalIp')));
problems.push(createPortAvailabilityProblem('Gateway HTTP', config.get('platform.gateway.listeners.dapiAndDrive.port'), config.get('externalIp')));
problems.push(createPortAvailabilityProblem('Tenderdash P2P', config.get('platform.drive.tenderdash.p2p.port'), config.get('externalIp')));

This refactoring would significantly reduce code duplication and make it easier to maintain consistent messages across all port availability checks.

packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (3)

168-172: LGTM! Consider adding a comment for clarity.

The addition of config.get('externalIp') to the checkPortStatus function call aligns well with the PR objective of validating the external IP configuration. This change enhances the port status check by incorporating the external IP.

Consider adding a brief comment explaining the purpose of including the external IP in the port status check. This would improve code readability and make the intent clearer for future maintainers. For example:

// Check port status using both port and external IP for comprehensive validation
const response = await providers.mnowatch.checkPortStatus(port, config.get('externalIp'));

178-182: LGTM! Consider adding a comment for consistency.

The addition of config.get('externalIp') to the checkPortStatus function call for the Gateway HTTP port is consistent with the previous change and aligns with the PR objectives.

For consistency with the previous suggestion, consider adding a brief comment here as well:

// Check Gateway HTTP port status using both port and external IP
const response = await providers.mnowatch.checkPortStatus(port, config.get('externalIp'));

187-191: LGTM! Consider adding a comment for consistency and completeness.

The addition of config.get('externalIp') to the checkPortStatus function call for the Tenderdash P2P port completes the set of changes, ensuring all relevant port checks now include external IP validation.

For consistency, consider adding a brief comment here as well:

// Check Tenderdash P2P port status using both port and external IP
const response = await providers.mnowatch.checkPortStatus(port, config.get('externalIp'));

Overall, these changes effectively implement the PR objective of validating the external IP configuration across all relevant port checks. The modifications are consistent, non-breaking, and improve the functionality of the dashmate doctor command as intended.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4ae1efd and a64f0e2.

📒 Files selected for processing (5)
  • packages/dashmate/src/doctor/analyse/analyseConfigFactory.js (3 hunks)
  • packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (3 hunks)
  • packages/dashmate/src/status/providers.js (2 hunks)
  • packages/dashmate/src/status/scopes/core.js (1 hunks)
  • packages/dashmate/src/status/scopes/platform.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/dashmate/src/status/providers.js (1)
Learnt from: shumkov
PR: dashpay/platform#2162
File: packages/dashmate/src/status/providers.js:121-127
Timestamp: 2024-09-26T14:28:54.892Z
Learning: In the `mnowatch.checkPortStatus` function, failures should resolve with `PortStateEnum.ERROR` instead of rejecting the promise.
🔇 Additional comments (5)
packages/dashmate/src/status/providers.js (1)

Line range hint 1-127: Overall assessment: Changes look good with minor suggestions for improvement.

The modifications to the checkPortStatus method successfully implement the ability to validate external IP configurations, which aligns with the PR objectives. The code changes are well-integrated and maintain the existing structure of the file. The suggestions provided are for minor improvements in documentation and error handling, which would enhance the overall quality of the code but don't impact the core functionality introduced by this PR.

packages/dashmate/src/status/scopes/core.js (1)

119-119: LGTM! Verify checkPortStatus method implementation.

The addition of the external IP as a parameter to checkPortStatus aligns well with the PR objective of validating the external IP configuration. This change enhances the port status check by considering both the port and the external IP.

To ensure consistency, please run the following script to verify the checkPortStatus method implementation:

This script will help ensure that the checkPortStatus method is properly updated to handle the new parameter and that all calls to this method across the codebase are consistent with this change.

packages/dashmate/src/status/scopes/platform.js (1)

Line range hint 1-324: Summary of changes and their impact

The modifications in this file successfully implement the validation of the external IP configuration for both DAPI/Drive and P2P ports. This change enhances the dashmate status commands by providing more accurate information about port accessibility from the configured external IP.

The implementation is minimal and non-breaking, aligning well with the PR objectives and contributing to the partial implementation of issue #1272. The changes improve the overall functionality of the platform status checks without affecting other parts of the file or introducing any potential issues.

packages/dashmate/src/doctor/analyse/analyseConfigFactory.js (1)

Line range hint 1-258: Overall assessment of changes in analyseConfigFactory.js

The modifications in this file effectively enhance the dashmate status commands by improving the error messages for port availability across different services (Core P2P, Gateway HTTP, and Tenderdash P2P). These changes align well with the PR objectives and provide more actionable information to users.

Key points:

  1. The error messages now include more detailed instructions about firewall configuration and port forwarding.
  2. Conditional logic has been added to tailor messages based on whether an external IP is configured.
  3. The changes maintain consistency across different port availability checks, which is good for user experience.

Suggestions for improvement:

  1. Minor formatting changes have been suggested to improve readability.
  2. A refactoring suggestion has been made to reduce code duplication and improve maintainability.

Overall, these changes represent a significant improvement in the functionality and user-friendliness of the dashmate tool.

packages/dashmate/src/listr/tasks/doctor/collectSamplesTaskFactory.js (1)

Line range hint 1-391: Overall assessment: Changes look good and align with PR objectives.

The modifications made to the collectSamplesTaskFactory.js file successfully implement the validation of external IP configuration for the Core P2P, Gateway HTTP, and Tenderdash P2P ports. These changes are consistent, non-breaking, and improve the functionality of the dashmate doctor command as intended.

Key points:

  1. All relevant port checks now include external IP validation.
  2. The changes are consistent across different port check tasks.
  3. The modifications align well with the PR objectives and summary.

The only suggestion is to add brief comments for each port check to improve code readability and maintainability. Otherwise, the implementation looks solid and ready for merging.

@shumkov shumkov merged commit bc55acd into v1.4-dev Sep 29, 2024
23 checks passed
@shumkov shumkov deleted the feat/dashmate/validate-ip-and-port branch September 29, 2024 07:42
@thephez thephez added this to the v1.4.0 milestone Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants