-
Notifications
You must be signed in to change notification settings - Fork 268
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
Peer reconnection address from node announcements #1009
Conversation
Use addresses from networkDb if Peer.Connect command doesn't have an address
… none was specified by the caller
What would be nice is also implement a |
We should also probably make the exponential backoff delay go all the way to 1 hour every reconnect attempt. |
# Conflicts: # eclair-core/src/main/scala/fr/acinq/eclair/api/FormParamExtractors.scala # eclair-core/src/test/scala/fr/acinq/eclair/api/ApiServiceSpec.scala
Codecov Report
@@ Coverage Diff @@
## master #1009 +/- ##
==========================================
+ Coverage 80.2% 81.01% +0.81%
==========================================
Files 98 98
Lines 7554 8124 +570
Branches 296 312 +16
==========================================
+ Hits 6059 6582 +523
- Misses 1495 1542 +47
|
Co-Authored-By: Pierre-Marie Padiou <pm47@users.noreply.github.com>
…DISCONNECTED(Reconnect) event, remove line breaks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
How about this refactoring: diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala b/eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala
index d7c1f4422..8560a4622 100644
--- a/eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala
+++ b/eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala
@@ -59,9 +59,9 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
when(DISCONNECTED) {
case Event(Peer.Connect(_, address_opt), d: DisconnectedData) =>
- address_opt.map(hAndp => new InetSocketAddress(hAndp.getHost, hAndp.getPort)).orElse {
- getPeerAddressFromNodeAnnouncement()
- } match {
+ address_opt
+ .map(hostAndPort2InetSocketAddress)
+ .orElse(getPeerAddressFromNodeAnnouncement) match {
case None =>
sender ! "no address found"
stay
@@ -78,7 +78,7 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
}
case Event(Reconnect, d: DisconnectedData) =>
- d.address_opt.orElse(getPeerAddressFromNodeAnnouncement()) match {
+ d.address_opt.orElse(getPeerAddressFromNodeAnnouncement) match {
case _ if d.channels.isEmpty => stay // no-op, no more channels with this peer
case None => stay // no-op, we don't know any address to this peer and we won't try reconnecting again
case Some(address) =>
@@ -518,7 +518,7 @@ class Peer(nodeParams: NodeParams, remoteNodeId: PublicKey, authenticator: Actor
}
// TODO gets the first of the list, improve selection?
- def getPeerAddressFromNodeAnnouncement(): Option[InetSocketAddress] = {
+ def getPeerAddressFromNodeAnnouncement: Option[InetSocketAddress] = {
nodeParams.db.network.getNode(remoteNodeId).flatMap(_.addresses.headOption.map(_.socketAddress))
}
@@ -643,4 +643,6 @@ object Peer {
case _ => true // if there is a filter and message doesn't have a timestamp (e.g. channel_announcement), then we send it
}
}
+
+ def hostAndPort2InetSocketAddress(hostAndPort: HostAndPort): InetSocketAddress = new InetSocketAddress(hostAndPort.getHost, hostAndPort.getPort)
} NB: for methods without side effect parentheses should be omitted |
Currently the node address information in
node_announcement
messages is not used when establishing a connection. Peer's addresses are known only when the user initiated the connection providing a destination address, in case of incoming connection the peer's address is blanked out and we can't reconnect. According to the spec theaddresses
field ofnode_announcement
should contain the network addresses where a peer expects an incoming connection, this PR leverages this information to provide the following enhancements:node_announcements
)node_announcements
address as fallback in case we don't know the addressFixes #1003