From 8d29338fe315ce27a0b1c1aeac6d35e8180b6806 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 3 Dec 2019 15:48:18 +0100 Subject: [PATCH] subd: Add a helper to get the current owning subd for a given peer This is currently in opening_control since that's the only part that has access to the uncommitted_channel internals. Otherwise it's independent from the specific daemon. --- lightningd/opening_control.c | 14 +++++++++++++- lightningd/opening_control.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 27919a75a..66eaed5f8 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -1338,3 +1337,16 @@ void opening_dev_memleak(struct command *cmd) opening_memleak_req_next(cmd, NULL); } #endif /* DEVELOPER */ + +struct subd *peer_get_owning_subd(struct peer *peer) +{ + struct channel *channel; + channel = peer_active_channel(peer); + + if (channel != NULL) { + return channel->owner; + } else if (peer->uncommitted_channel != NULL) { + return peer->uncommitted_channel->openingd; + } + return NULL; +} diff --git a/lightningd/opening_control.h b/lightningd/opening_control.h index 23df19eb3..fbf8ce715 100644 --- a/lightningd/opening_control.h +++ b/lightningd/opening_control.h @@ -2,6 +2,7 @@ #define LIGHTNING_LIGHTNINGD_OPENING_CONTROL_H #include "config.h" #include +#include struct channel_id; struct crypto_state; @@ -26,4 +27,6 @@ struct command; void opening_dev_memleak(struct command *cmd); #endif +struct subd *peer_get_owning_subd(struct peer *peer); + #endif /* LIGHTNING_LIGHTNINGD_OPENING_CONTROL_H */