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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ import android.os.Process
import bisq.common.facades.FacadeProvider
import bisq.common.facades.android.AndroidGuavaFacade
import bisq.common.facades.android.AndroidJdkFacade
import bisq.common.network.AndroidEmulatorLocalhostFacade
import bisq.common.network.ClearNetAndroidEmulatorLocalAddressFacade
import bisq.common.network.ClearNetLANLocalAddressFacade
import network.bisq.mobile.android.node.di.androidNodeModule
import network.bisq.mobile.domain.di.domainModule
import network.bisq.mobile.domain.di.serviceModule
import network.bisq.mobile.domain.utils.Logging
import network.bisq.mobile.presentation.di.presentationModule
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import java.security.Security

class MainApplication : Application() {
class MainApplication : Application(), Logging {
companion object {
private val nodeModules = listOf(domainModule, serviceModule, presentationModule, androidNodeModule)

Expand All @@ -38,13 +40,31 @@ class MainApplication : Application() {
}

private fun setupBisqCoreStatics() {
FacadeProvider.setLocalhostFacade(AndroidEmulatorLocalhostFacade())
val isEmulator = isEmulator()
val clearNetFacade = if (isEmulator) {
ClearNetAndroidEmulatorLocalAddressFacade()
} else {
ClearNetLANLocalAddressFacade()
}
FacadeProvider.setLocalhostFacade(clearNetFacade)
FacadeProvider.setJdkFacade(AndroidJdkFacade(Process.myPid()))
FacadeProvider.setGuavaFacade(AndroidGuavaFacade())

// Androids default BC version does not support all algorithms we need, thus we remove
// it and add our BC provider
Security.removeProvider("BC")
Security.addProvider(BouncyCastleProvider())
log.d { "Configured bisq2 for Android${if (isEmulator) " emulator" else ""}" }
}

private fun isEmulator(): Boolean {
return android.os.Build.FINGERPRINT.startsWith("generic")
|| android.os.Build.FINGERPRINT.startsWith("unknown")
|| android.os.Build.MODEL.contains("google_sdk")
|| android.os.Build.MODEL.contains("Emulator")
|| android.os.Build.MODEL.contains("Android SDK built for x86")
|| android.os.Build.MANUFACTURER.contains("Genymotion")
|| (android.os.Build.BRAND.startsWith("generic") && android.os.Build.DEVICE.startsWith("generic"))
|| "google_sdk".equals(android.os.Build.PRODUCT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ class Mappings {
settingsService.supportedLanguageCodes,
settingsService.maxTradePriceDeviation.get(),
settingsService.useAnimations.get(),
MarketMapping.fromBisq2Model(settingsService.selectedMarket.get()),
MarketMapping.fromBisq2Model(settingsService.selectedMuSigMarket.get()),
settingsService.numDaysAfterRedactingTradeData.get()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ class NodeConnectivityService(private val applicationService: AndroidApplication
}

private fun currentConnections(): Int {
return applicationService.networkService.get()
.serviceNodesByTransport.allServiceNodes
.sumOf { it.defaultNode?.numConnections ?: 0 }
try {
return applicationService.networkService.get()
.serviceNodesByTransport.allServiceNodes
.sumOf { it.defaultNode?.numConnections ?: 0 }
} catch (e: Exception) {
log.e(e) { "Failed to check current connections, assuming none: ${e.message}" }
return 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class NodeSettingsServiceFacade(applicationService: AndroidApplicationService.Pr

// API
override suspend fun getSettings(): Result<SettingsVO> {
return Result.success(Mappings.SettingsMapping.from(settingsService))
return try {
Result.success(Mappings.SettingsMapping.from(settingsService))
} catch (e: Exception) {
Result.failure(e)
}
}
}
Loading