plugins: remove now-unused single-hook infrastructure.

Should have really let @mschmook do this, as he did all the work to
make it possible!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-04-07 11:58:05 +09:30
parent 9c3cf5aff9
commit c4dfac5c4b
2 changed files with 10 additions and 69 deletions

View File

@@ -86,11 +86,6 @@ struct plugin_hook *plugin_hook_register(struct plugin *plugin, const char *meth
if (hook->hooks == NULL) if (hook->hooks == NULL)
hook->hooks = notleak(tal_arr(NULL, struct hook_instance *, 0)); hook->hooks = notleak(tal_arr(NULL, struct hook_instance *, 0));
/* If this is a single type hook and we have a plugin registered we
* must fail this attempt to add the plugin to the hook. */
if (hook->type == PLUGIN_HOOK_SINGLE && tal_count(hook->hooks) > 0)
return NULL;
/* Ensure we don't register the same plugin multple times. */ /* Ensure we don't register the same plugin multple times. */
for (size_t i=0; i<tal_count(hook->hooks); i++) for (size_t i=0; i<tal_count(hook->hooks); i++)
if (hook->hooks[i]->plugin == plugin) if (hook->hooks[i]->plugin == plugin)
@@ -187,16 +182,14 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
r->hook->name, toks->end - toks->start, r->hook->name, toks->end - toks->start,
buffer + toks->start); buffer + toks->start);
if (r->hook->type == PLUGIN_HOOK_CHAIN) { db_begin_transaction(db);
db_begin_transaction(db); if (!r->hook->deserialize_cb(r->cb_arg, buffer,
if (!r->hook->deserialize_cb(r->cb_arg, buffer, resulttok)) {
resulttok)) { tal_free(r->cb_arg);
tal_free(r->cb_arg); db_commit_transaction(db);
db_commit_transaction(db); goto cleanup;
goto cleanup;
}
in_transaction = true;
} }
in_transaction = true;
} else { } else {
/* plugin died */ /* plugin died */
resulttok = NULL; resulttok = NULL;
@@ -212,10 +205,7 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks,
/* We optimize for the case where we already called deserialize_cb */ /* We optimize for the case where we already called deserialize_cb */
if (!in_transaction) if (!in_transaction)
db_begin_transaction(db); db_begin_transaction(db);
if (r->hook->type == PLUGIN_HOOK_CHAIN) r->hook->final_cb(r->cb_arg);
r->hook->final_cb(r->cb_arg);
else
r->hook->single_response_cb(r->cb_arg, buffer, resulttok);
db_commit_transaction(db); db_commit_transaction(db);
cleanup: cleanup:
@@ -282,10 +272,7 @@ bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
* roundtrip to the serializer and deserializer. If we * roundtrip to the serializer and deserializer. If we
* were expecting a default response it should have * were expecting a default response it should have
* been part of the `cb_arg`. */ * been part of the `cb_arg`. */
if (hook->type == PLUGIN_HOOK_CHAIN) hook->final_cb(cb_arg);
hook->final_cb(cb_arg);
else
hook->single_response_cb(cb_arg, NULL, NULL);
return true; return true;
} }
} }
@@ -294,8 +281,7 @@ bool plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook,
* annoying, and to make it clear that it's totally synchronous. */ * annoying, and to make it clear that it's totally synchronous. */
/* Special synchronous hook for db */ /* Special synchronous hook for db */
static struct plugin_hook db_write_hook = {"db_write", PLUGIN_HOOK_CHAIN, NULL, static struct plugin_hook db_write_hook = {"db_write", NULL, NULL};
NULL, NULL};
AUTODATA(hooks, &db_write_hook); AUTODATA(hooks, &db_write_hook);
/* A `db_write` for one particular plugin hook. */ /* A `db_write` for one particular plugin hook. */

View File

@@ -30,15 +30,6 @@
* *
* - `serialize_payload` which takes a payload of type `cb_arg_type` * - `serialize_payload` which takes a payload of type `cb_arg_type`
* and serializes it into the given `json_stream`. ` * and serializes it into the given `json_stream`. `
*
* For single-plugin hooks:
* - `single_response_cb` is called once the plugin has responded (or with
* buffer == NULL if there's no plugin). In addition an arbitrary
* additional argument of type `cb_arg_type` can be passed along
* that may contain any additional context necessary. It must free
* or otherwise take ownership of the cb_arg_type argument.
*
* For chained-plugin hooks:
* - `deserialize_cb` is called for each plugin, if it returns true the * - `deserialize_cb` is called for each plugin, if it returns true the
* next one is called, otherwise the cb_arg_type argument is free. * next one is called, otherwise the cb_arg_type argument is free.
* - If all `deserialize_cb` return true, `final_cb` is called. It must free * - If all `deserialize_cb` return true, `final_cb` is called. It must free
@@ -49,24 +40,9 @@
* that all the provided functions for serialization, deserialization * that all the provided functions for serialization, deserialization
* and callback have the correct type. * and callback have the correct type.
*/ */
enum plugin_hook_type {
PLUGIN_HOOK_SINGLE,
PLUGIN_HOOK_CHAIN,
};
struct plugin_hook { struct plugin_hook {
const char *name; const char *name;
/* Which type of plugin is this? It'll determine how many plugins can
* register this hook, and how the hooks are called. */
enum plugin_hook_type type;
/* For PLUGIN_HOOK_SINGLE hooks */
void (*single_response_cb)(void *arg,
const char *buffer, const jsmntok_t *toks);
/* For PLUGIN_HOOK_CHAIN hooks: */
/* Returns false if we should stop iterating (and free arg). */ /* Returns false if we should stop iterating (and free arg). */
bool (*deserialize_cb)(void *arg, bool (*deserialize_cb)(void *arg,
const char *buffer, const jsmntok_t *toks); const char *buffer, const jsmntok_t *toks);
@@ -114,31 +90,10 @@ bool plugin_hook_continue(void *arg, const char *buffer, const jsmntok_t *toks);
* response_cb function accepts the deserialized response format and * response_cb function accepts the deserialized response format and
* an arbitrary extra argument used to maintain context. * an arbitrary extra argument used to maintain context.
*/ */
#define REGISTER_SINGLE_PLUGIN_HOOK(name, response_cb, \
serialize_payload, cb_arg_type) \
struct plugin_hook name##_hook_gen = { \
stringify(name), \
PLUGIN_HOOK_SINGLE, \
typesafe_cb_cast( \
void (*)(void *STEALS, const char *, const jsmntok_t *), \
void (*)(cb_arg_type STEALS, const char *, const jsmntok_t *), \
response_cb), \
NULL, NULL, \
typesafe_cb_cast(void (*)(void *, struct json_stream *), \
void (*)(cb_arg_type, struct json_stream *), \
serialize_payload), \
NULL, /* .plugins */ \
}; \
AUTODATA(hooks, &name##_hook_gen); \
PLUGIN_HOOK_CALL_DEF(name, cb_arg_type)
#define REGISTER_PLUGIN_HOOK(name, deserialize_cb, final_cb, \ #define REGISTER_PLUGIN_HOOK(name, deserialize_cb, final_cb, \
serialize_payload, cb_arg_type) \ serialize_payload, cb_arg_type) \
struct plugin_hook name##_hook_gen = { \ struct plugin_hook name##_hook_gen = { \
stringify(name), \ stringify(name), \
PLUGIN_HOOK_CHAIN, \
NULL, \
typesafe_cb_cast( \ typesafe_cb_cast( \
bool (*)(void *, const char *, const jsmntok_t *), \ bool (*)(void *, const char *, const jsmntok_t *), \
bool (*)(cb_arg_type, const char *, const jsmntok_t *), \ bool (*)(cb_arg_type, const char *, const jsmntok_t *), \