1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 10:39:19 +01:00

now sending network events (Node/Channel Lost not yet implemented)

This commit is contained in:
pm47 2017-02-02 15:01:41 +01:00
parent 7a8420c170
commit f7c558871c
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package fr.acinq.eclair.router
import fr.acinq.bitcoin.BinaryData
import fr.acinq.eclair.wire.{ChannelAnnouncement, NodeAnnouncement}
/**
* Created by PM on 02/02/2017.
*/
trait NetworkEvent
case class NodeDiscovered(ann: NodeAnnouncement) extends NetworkEvent
case class NodeLost(nodeId: BinaryData) extends NetworkEvent
case class ChannelDiscovered(ann: ChannelAnnouncement) extends NetworkEvent
case class ChannelLost(channelId: Long) extends NetworkEvent

View File

@ -39,6 +39,8 @@ class Router(watcher: ActorRef, announcement: NodeAnnouncement) extends Actor wi
context.system.eventStream.subscribe(self, classOf[ChannelChangedState])
context.system.scheduler.schedule(10 seconds, 60 seconds, self, 'tick_broadcast)
context.system.eventStream.publish(NodeDiscovered(announcement))
def receive: Receive = main(local = announcement, nodes = Map(announcement.nodeId -> announcement), channels = Map(), updates = Map(), rebroadcast = Nil)
def main(
@ -69,6 +71,7 @@ class Router(watcher: ActorRef, announcement: NodeAnnouncement) extends Actor wi
log.info(s"added channel channelId=${c.channelId} (nodes=${nodes.size} channels=${channels.size + 1})")
// let's trigger the broadcast immediately so that we don't wait for 60 seconds to announce our newly created channel
self ! 'tick_broadcast
context.system.eventStream.publish(ChannelDiscovered(c))
context become main(local, nodes, channels + (c.channelId -> c), updates, rebroadcast :+ c :+ local :+ u)
case s: ChannelChangedState =>
@ -85,6 +88,7 @@ class Router(watcher: ActorRef, announcement: NodeAnnouncement) extends Actor wi
// TODO: forget channel once funding tx spent (add watch)
//watcher ! WatchSpent(self, txId: BinaryData, outputIndex: Int, minDepth: Int, event: BitcoinEvent)
log.info(s"added channel channelId=${c.channelId} (nodes=${nodes.size} channels=${channels.size + 1})")
context.system.eventStream.publish(ChannelDiscovered(c))
context become main(local, nodes, channels + (c.channelId -> c), updates, rebroadcast :+ c)
case n: NodeAnnouncement if !checkSig(n) =>
@ -98,6 +102,7 @@ class Router(watcher: ActorRef, announcement: NodeAnnouncement) extends Actor wi
case n: NodeAnnouncement =>
log.info(s"added/replaced node nodeId=${n.nodeId} (nodes=${nodes.size + 1} channels=${channels.size})")
context.system.eventStream.publish(NodeDiscovered(n))
context become main(local, nodes + (n.nodeId -> n), channels, updates, rebroadcast :+ n)
case u: ChannelUpdate if !channels.contains(u.channelId) =>