Skip to content

Commit

Permalink
Merge pull request #248 from synonymdev/android-timeout-fix
Browse files Browse the repository at this point in the history
fix: increase android connect timeout to 3s
  • Loading branch information
Jasonvdb authored Jun 6, 2024
2 parents 564684d + 9c08fbc commit 58713d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/android/src/main/java/com/reactnativeldk/LdkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
override fun run() {
handleDroppedPeers()
}
}, 1000, 1000)
}, 1000, 3000)
timerTaskScheduled = true
}

Expand Down Expand Up @@ -638,7 +638,7 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod

try {
currentlyConnectingPeers.add(pubKey)
peerHandler!!.connect(pubKey.hexa(), InetSocketAddress(address, port.toInt()), 10)
peerHandler!!.connect(pubKey.hexa(), InetSocketAddress(address, port.toInt()), 3000)
LdkEventEmitter.send(EventTypes.native_log, "Connection to peer $pubKey re-established by handleDroppedPeers().")
} catch (e: Exception) {
LdkEventEmitter.send(EventTypes.native_log, "Error connecting peer $pubKey. Error: $e")
Expand Down Expand Up @@ -667,19 +667,20 @@ class LdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
currentlyConnectingPeers.add(pubKey)
peerHandler!!.connect(pubKey.hexa(), InetSocketAddress(address, port.toInt()), timeout.toInt())

handleResolve(promise, LdkCallbackResponses.add_peer_success)
} catch (e: Exception) {
handleReject(promise, LdkErrors.add_peer_fail, Error(e))
} finally {
currentlyConnectingPeers.remove(pubKey)

//Should retry if success or fail
if (!addedPeers.map { it["pubKey"] as String }.contains(pubKey)) {
addedPeers.add(hashMapOf(
"address" to address,
"port" to port,
"pubKey" to pubKey
))
}

handleResolve(promise, LdkCallbackResponses.add_peer_success)
} catch (e: Exception) {
handleReject(promise, LdkErrors.add_peer_fail, Error(e))
} finally {
currentlyConnectingPeers.remove(pubKey)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@synonymdev/react-native-ldk",
"title": "React Native LDK",
"version": "0.0.141",
"version": "0.0.143",
"description": "React Native wrapper for LDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down

0 comments on commit 58713d9

Please sign in to comment.