Skip to content

enhancement/node_localhost_setup #352

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

Merged

Conversation

rodvar
Copy link
Collaborator

@rodvar rodvar commented May 25, 2025

notes

DO NOT MERGE UNTIL BISQ2 PR HAS BEEN MERGED

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • The app now automatically detects if it is running on an Android emulator and adjusts its configuration accordingly.
    • Added debug logging to indicate whether the app is running on an emulator or a physical device.
  • Bug Fixes
    • Improved stability by handling exceptions in network connection counting and settings retrieval.
  • Improvements
    • Updated the selected market setting to use a new source for better configuration accuracy.

@rodvar rodvar self-assigned this May 25, 2025
Copy link
Contributor

coderabbitai bot commented May 25, 2025

Walkthrough

The MainApplication class is updated to implement the Logging interface and now includes logic to detect if the app is running on an Android emulator by examining device build properties. Emulator detection results are communicated to FacadeProvider, and a debug log statement reflects the configuration status. Additionally, exception handling is added to methods in NodeConnectivityService and NodeSettingsServiceFacade to safely handle errors. The market selection mapping in SettingsMapping is changed to use selectedMuSigMarket instead of selectedMarket.

Changes

File(s) Change Summary
.../MainApplication.kt Implements Logging, adds emulator detection via isEmulator(), updates FacadeProvider setup, logs configuration status, replaces AndroidEmulatorLocalhostFacade with conditional facade assignment.
.../NodeConnectivityService.kt Adds try-catch in currentConnections() to log exceptions and return 0 on failure.
.../NodeSettingsServiceFacade.kt Wraps getSettings() mapping in try-catch to return failure Result on exceptions.
.../Mappings.kt Changes market mapping in SettingsMapping.from from selectedMarket to selectedMuSigMarket.

Sequence Diagram(s)

sequenceDiagram
    participant MainApplication
    participant FacadeProvider
    participant Device (Android/Emulator)
    participant Logger

    MainApplication->>Device: Check build properties (FINGERPRINT, MODEL, MANUFACTURER, BRAND, DEVICE, PRODUCT)
    MainApplication->>MainApplication: Determine isEmulator (true/false)
    MainApplication->>FacadeProvider: setLocalhostFacade(ClearNetAndroidEmulatorLocalAddressFacade or ClearNetLANLocalAddressFacade)
    MainApplication->>Logger: Log configuration status (emulator or real device)
Loading

Suggested labels

AndroidConnect

Suggested reviewers

  • HenrikJannsen

Poem

In the Android fields where emulators play,
MainApplication hops and checks the way.
With logs and flags, it now can see—
Is this real, or just a sim for me?
FacadeProvider knows, thanks to our code,
Whether it’s carrot roads or emulator mode! 🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99790f7 and fb9f6e5.

📒 Files selected for processing (3)
  • androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/mapping/Mappings.kt (1 hunks)
  • androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/service/network/NodeConnectivityService.kt (1 hunks)
  • androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/service/settings/NodeSettingsServiceFacade.kt (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Project Build & Test (ubuntu-latest)
🔇 Additional comments (3)
androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/mapping/Mappings.kt (1)

1226-1226:

❓ Verification inconclusive

Verify the property change and check for consistency across the codebase.

The change from selectedMarket to selectedMuSigMarket aligns with the MuSig functionality mentioned in the PR objectives. However, please ensure this change is consistent throughout the codebase.


🏁 Script executed:

#!/bin/bash
# Description: Verify selectedMuSigMarket property exists and check for any remaining references to selectedMarket

# Check if selectedMuSigMarket property exists in SettingsService
echo "=== Searching for selectedMuSigMarket in SettingsService ==="
ast-grep --pattern 'selectedMuSigMarket'

echo -e "\n=== Searching for any remaining selectedMarket references ==="
rg -A 2 'selectedMarket' --type kotlin

echo -e "\n=== Checking SettingsService class for market-related properties ==="
ast-grep --pattern 'class SettingsService {
  $$$
}' | head -50

Length of output: 10944


🏁 Script executed:

#!/bin/bash
# Locate all Kotlin files defining SettingsService and inspect their top sections

echo "=== Locating SettingsService definitions ==="
rg -l --type kotlin "class SettingsService"

echo -e "\n=== Printing first 200 lines of each SettingsService file ==="
rg -l --type kotlin "class SettingsService" | uniq | xargs -I{} head -n 200 {}

Length of output: 368


#!/bin/bash
# 1. List all Kotlin files referencing SettingsService
echo "=== Files referencing SettingsService ==="
rg -l --type kotlin "SettingsService"

# 2. Show imports in Mappings.kt to see where SettingsService comes from
echo -e "\n=== Imports in Mappings.kt ==="
rg -n "^import" androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/mapping/Mappings.kt

# 3. Search for interface or class definitions of SettingsService
echo -e "\n=== Searching for interface SettingsService ==="
rg -n "interface SettingsService" --type kotlin

echo -e "\n=== Searching for class SettingsService ==="
rg -n "class SettingsService" --type kotlin

# 4. Search for selectedMuSigMarket declaration
echo -e "\n=== Searching for selectedMuSigMarket declaration ==="
rg -n "selectedMuSigMarket" --type kotlin

🏁 Script executed:

#!/bin/bash
# 1. Check imports in Mappings.kt for SettingsService
echo "=== Imports in Mappings.kt referencing SettingsService ==="
rg -n "^import.*SettingsService" androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/mapping/Mappings.kt || echo "No imports found"

# 2. Locate any Kotlin files named *SettingsService*.kt
echo -e "\n=== Files named *SettingsService*.kt ==="
find . -type f -iname "*settingsservice*.kt" -print || echo "No SettingsService files found"

# 3. Search for class or interface definitions of SettingsService
echo -e "\n=== class SettingsService definitions ==="
grep -R "class SettingsService" -n .

echo -e "\n=== interface SettingsService definitions ==="
grep -R "interface SettingsService" -n .

Length of output: 1224


#!/bin/bash
# Inspect NodeSettingsServiceFacade for selectedMuSigMarket and related properties

FILE="androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/service/settings/NodeSettingsServiceFacade.kt"

echo "=== Searching for selectedMuSigMarket in NodeSettingsServiceFacade ==="
rg -n "selectedMuSigMarket" "$FILE" || echo "No selectedMuSigMarket references"

echo -e "\n=== Searching for selectedMarket in NodeSettingsServiceFacade ==="
rg -n "selectedMarket" "$FILE"

echo -e "\n=== Displaying first 200 lines of NodeSettingsServiceFacade ==="
head -n 200 "$FILE"

Verify selectedMuSigMarket on SettingsService and audit remaining selectedMarket uses

The mapping change at line 1226 now calls

settingsService.selectedMuSigMarket.get()

– please ensure:

  • bisq.settings.SettingsService (external module) declares a selectedMuSigMarket property.
  • The old selectedMarket property is removed or deprecated in SettingsService if it’s fully replaced.
  • No leftover references to selectedMarket remain that could cause inconsistencies, for example in:
    • shared/domain/src/commonMain/kotlin/.../SettingsChangeRequest.kt
    • shared/domain/src/commonMain/kotlin/.../SettingsVO.kt
    • Client or Node service facades (ClientOffersServiceFacade, ClientMarketPriceServiceFacade, NodeOffersServiceFacade, etc.)
androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/service/network/NodeConnectivityService.kt (1)

34-41: LGTM: Excellent defensive programming.

The exception handling around the connection counting logic is well-implemented:

  • Prevents runtime crashes when network state is unavailable or unstable
  • Provides clear error logging for debugging purposes
  • Returns a sensible fallback value (0 connections)
  • Maintains the existing API contract

This change significantly improves the robustness of the connectivity service.

androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/service/settings/NodeSettingsServiceFacade.kt (1)

153-157: LGTM: Proper exception handling with Result pattern.

The addition of exception handling around the settings mapping operation is excellent defensive programming:

  • Converts potential runtime exceptions into a proper Result.failure()
  • Maintains the suspend function contract and Result pattern
  • Protects against mapping failures that could occur from the property changes in SettingsMapping.from()
  • Follows Kotlin best practices for error handling

This change works well in conjunction with the selectedMuSigMarket update in the mapping layer.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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

🧹 Nitpick comments (2)
androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/MainApplication.kt (2)

41-44: Good refactoring, but remove commented code.

The new explicit approach for configuring FacadeProvider is cleaner and more direct than the previous facade pattern. However, consider removing the commented code rather than leaving it in the codebase.

Note: Ensure the related bisq2 PR (bisq-network/bisq2#3524) is merged before this change, as mentioned in the PR description.

Apply this diff to remove the commented code:

-//        FacadeProvider.setLocalhostFacade(AndroidEmulatorLocalhostFacade())

55-64: Comprehensive emulator detection with minor style fix needed.

The emulator detection logic is thorough and covers various emulator types including standard Android emulators, Genymotion, and SDK emulators. However, there's a style inconsistency on line 63.

Apply this diff to fix the Kotlin style:

-                || "google_sdk".equals(android.os.Build.PRODUCT);
+                || "google_sdk".equals(android.os.Build.PRODUCT)

The method covers most common emulator detection patterns. Consider adding checks for newer emulator signatures if they become prevalent in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18c3238 and 76bf7b2.

📒 Files selected for processing (1)
  • androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/MainApplication.kt (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Project Build & Test (ubuntu-latest)
🔇 Additional comments (3)
androidNode/src/androidMain/kotlin/network/bisq/mobile/android/node/MainApplication.kt (3)

12-12: LGTM: Clean import addition.

The Logging interface import is correctly added to support the new interface implementation.


20-20: LGTM: Proper interface implementation.

Adding the Logging interface implementation enables structured logging throughout the class, which improves debugging capabilities.


52-52: LGTM: Informative debug logging.

The debug log provides useful configuration status information and will help with troubleshooting environment-specific issues.

@rodvar rodvar force-pushed the enhancement/node_setup_localhost_facade branch from 76bf7b2 to df9760d Compare May 28, 2025 01:03
rodvar added 2 commits May 29, 2025 10:42
 - crash prevention on connected nodes checkup
 - improved error handling on node getSettings api
@rodvar rodvar merged commit 0897620 into bisq-network:main May 29, 2025
2 checks passed
@rodvar rodvar deleted the enhancement/node_setup_localhost_facade branch May 29, 2025 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant