plugin: Parse and react to the result of the peer_connected hook
Final step for the `peer_connected` hook, we parse the result and act accordingly. Currently we just close the underlying connection, but we may want to clean up peers that did not end up with a channel. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
ff0ddee56e
commit
2c443cc0fd
|
@ -632,7 +632,23 @@ static struct peer_connected_hook_response *
|
|||
peer_connected_deserialize(const tal_t *ctx, const char *buffer,
|
||||
const jsmntok_t *toks)
|
||||
{
|
||||
return NULL;
|
||||
const jsmntok_t *resulttok;
|
||||
struct peer_connected_hook_response *resp;
|
||||
resulttok = json_get_member(buffer, toks, "result");
|
||||
if (!resulttok) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
resp = tal(ctx, struct peer_connected_hook_response);
|
||||
if (json_tok_streq(buffer, resulttok, "continue"))
|
||||
resp->result = PEER_CONNECTED_CONTINUE;
|
||||
else if (json_tok_streq(buffer, resulttok, "disconnect"))
|
||||
resp->result = PEER_CONNECTED_DISCONNECT;
|
||||
else
|
||||
fatal("Plugin returned an invalid response to the connected "
|
||||
"hook: %s", buffer);
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -648,6 +664,12 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
|
|||
int peer_fd = payload->peer_fd;
|
||||
u8 *error;
|
||||
|
||||
if (response && response->result == PEER_CONNECTED_DISCONNECT) {
|
||||
close(peer_fd);
|
||||
tal_free(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
log_debug(channel->log, "Peer has reconnected, state %s",
|
||||
channel_state_name(channel));
|
||||
|
|
|
@ -257,6 +257,10 @@ void json_array_start(struct json_stream *js UNNEEDED, const char *fieldname UNN
|
|||
struct json_escaped *json_escaped_string_(const tal_t *ctx UNNEEDED,
|
||||
const void *bytes UNNEEDED, size_t len UNNEEDED)
|
||||
{ fprintf(stderr, "json_escaped_string_ called!\n"); abort(); }
|
||||
/* Generated stub for json_get_member */
|
||||
const jsmntok_t *json_get_member(const char *buffer UNNEEDED, const jsmntok_t tok[] UNNEEDED,
|
||||
const char *label UNNEEDED)
|
||||
{ fprintf(stderr, "json_get_member called!\n"); abort(); }
|
||||
/* Generated stub for json_object_end */
|
||||
void json_object_end(struct json_stream *js UNNEEDED)
|
||||
{ fprintf(stderr, "json_object_end called!\n"); abort(); }
|
||||
|
@ -276,6 +280,9 @@ const char *json_tok_full(const char *buffer UNNEEDED, const jsmntok_t *t UNNEED
|
|||
/* Generated stub for json_tok_full_len */
|
||||
int json_tok_full_len(const jsmntok_t *t UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_full_len called!\n"); abort(); }
|
||||
/* Generated stub for json_tok_streq */
|
||||
bool json_tok_streq(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, const char *str UNNEEDED)
|
||||
{ fprintf(stderr, "json_tok_streq called!\n"); abort(); }
|
||||
/* Generated stub for json_to_pubkey */
|
||||
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct pubkey *pubkey UNNEEDED)
|
||||
|
|
Loading…
Reference in New Issue