1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-03-13 19:37:35 +01:00

Add support for FCM custom token (bit 35017)

When sending this message to a peer, the node expects the peer to
link the token with its own pubkey, and use fcm to wake him up
when needed.
This commit is contained in:
dpad85 2020-07-21 17:03:32 +02:00
parent 4280e28595
commit 4638578ce9
No known key found for this signature in database
GPG key ID: 574C8C6A1673E987
4 changed files with 24 additions and 6 deletions

View file

@ -146,6 +146,11 @@ class Peer(val nodeParams: NodeParams, remoteNodeId: PublicKey, watcher: ActorRe
context.system.eventStream.publish(swapOutResponse)
stay
case Event(f: SendFCMToken, d: ConnectedData) =>
log.info(s"peer forwarding $f to peerConnection")
d.peerConnection ! FCMToken(f.token)
stay
case Event(c: Peer.OpenChannel, d: ConnectedData) =>
if (c.fundingSatoshis >= Channel.MAX_FUNDING && !nodeParams.features.hasFeature(Wumbo)) {
sender ! Status.Failure(new RuntimeException(s"fundingSatoshis=${c.fundingSatoshis} is too big, you must enable large channels support in 'eclair.features' to use funding above ${Channel.MAX_FUNDING} (see eclair.conf)"))
@ -486,7 +491,7 @@ object Peer {
case class SendSwapOutRequest(nodeId: PublicKey, amountSatoshis: Satoshi, bitcoinAddress: String, feeratePerKw: Long)
case class SendSwapInRequest(nodeId: PublicKey)
case class SendFCMToken(nodeId: PublicKey, token: String)
// @formatter:on
def makeChannelParams(nodeParams: NodeParams, defaultFinalScriptPubkey: ByteVector, localPaymentBasepoint: Option[PublicKey], isFunder: Boolean, fundingAmount: Satoshi): LocalParams = {

View file

@ -81,6 +81,12 @@ class Switchboard(nodeParams: NodeParams, watcher: ActorRef, relayer: ActorRef,
case None => sender ! Status.Failure(new RuntimeException("no connection to peer"))
}
case f: Peer.SendFCMToken =>
getPeer(f.nodeId) match {
case Some(peer) => peer forward f
case None => log.error(s"could not register fcm token=${f.token} with unknown peer=${f.nodeId}")
}
case authenticated: PeerConnection.Authenticated =>
// if this is an incoming connection, we might not yet have created the peer
val peer = createOrGetPeer(authenticated.remoteNodeId, offlineChannels = Set.empty)

View file

@ -63,7 +63,7 @@ object LightningMessageCodecs {
val magic: Codec[Boolean] = recover(constant(hex"fe 47010000"))
// we have limited space for backup, largest message is commit_sig with 30 htlcs in each direction: 65535B - (32B + 64B + 2*30*64B) = 61599B ~= 60000B
val channeldataoptional: Codec[Option[ByteVector]] = choice(optional(magic, limitedSizeBytes( 60000, variableSizeBytesLong(varintoverflow, bytes))), provide(Option.empty[ByteVector]))
val channeldataoptional: Codec[Option[ByteVector]] = choice(optional(magic, limitedSizeBytes(60000, variableSizeBytesLong(varintoverflow, bytes))), provide(Option.empty[ByteVector]))
val channelReestablishCodec: Codec[ChannelReestablish] = (
("channelId" | bytes32) ::
@ -347,6 +347,9 @@ object LightningMessageCodecs {
//
val fcmTokenCodec: Codec[FCMToken] =
("fcmToken" | variableSizeBytes(uint16, utf8)).as[FCMToken]
val lightningMessageCodec = discriminated[LightningMessage].by(uint16)
.typecase(16, initCodec)
.typecase(17, errorCodec)
@ -376,15 +379,15 @@ object LightningMessageCodecs {
.typecase(263, queryChannelRangeCodec)
.typecase(264, replyChannelRangeCodec)
.typecase(265, gossipTimestampFilterCodec)
// NB: blank lines to minimize merge conflicts
// NB: blank lines to minimize merge conflicts
.typecase(35001, payToOpenRequestCodec)
.typecase(35003, payToOpenResponseCodec)
//
//
.typecase(35005, swapInPendingCodec)
.typecase(35007, swapInRequestCodec)
.typecase(35009, swapInResponseCodec)
.typecase(35015, swapInConfirmedCodec)
//
//
.typecase(35011, swapOutRequestCodec)
.typecase(35013, swapOutResponseCodec)
//
@ -393,6 +396,8 @@ object LightningMessageCodecs {
//
.typecase(35017, fcmTokenCodec)
val meteredLightningMessageCodec = Codec[LightningMessage](
(msg: LightningMessage) => KamonExt.time(Metrics.EncodeDuration.withTag(Tags.MessageType, msg.getClass.getSimpleName))(lightningMessageCodec.encode(msg)),
(bits: BitVector) => {

View file

@ -375,3 +375,5 @@ case class SwapOutResponse(chainHash: ByteVector32,
//
//
case class FCMToken(token: String) extends LightningMessage