mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
connected_hook: allow hook to specify an error message.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
a314bc62fc
commit
7f7ad4f89f
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Config: Adds parameter `min-capacity-sat` to reject tiny channels.
|
||||
- JSON API: `listforwards` now includes the time an HTLC was received and when it was resolved. Both are expressed as UNIX timestamps to facilitate parsing (Issue [#2491](https://github.com/ElementsProject/lightning/issues/2491), PR [#2528](https://github.com/ElementsProject/lightning/pull/2528))
|
||||
- JSON API: new plugin `invoice_payment` hook for intercepting invoices before they're paid.
|
||||
- plugin: the `connected` hook can now send an `error_message` to the rejected peer.
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -268,6 +268,12 @@ gossiped list of known addresses. In particular this means that the port for
|
||||
incoming connections is an ephemeral port, that may not be available for
|
||||
reconnections.
|
||||
|
||||
The returned result must contain a `result` member which is either
|
||||
the string `disconnect` or `continue`. If `disconnect` and
|
||||
there's a member `error_message`, that member is sent to the peer
|
||||
before disconnection.
|
||||
|
||||
|
||||
#### `db_write`
|
||||
|
||||
This hook is called whenever a change is about to be committed to the database.
|
||||
|
||||
@@ -706,6 +706,15 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
|
||||
}
|
||||
|
||||
if (json_tok_streq(buffer, resulttok, "disconnect")) {
|
||||
const jsmntok_t *m = json_get_member(buffer, toks,
|
||||
"error_message");
|
||||
if (m) {
|
||||
error = towire_errorfmt(tmpctx, NULL,
|
||||
"%.*s",
|
||||
m->end - m->start,
|
||||
buffer + m->start);
|
||||
goto send_error;
|
||||
}
|
||||
close(peer_fd);
|
||||
tal_free(payload);
|
||||
return;
|
||||
|
||||
@@ -16,7 +16,7 @@ plugin = Plugin()
|
||||
def on_connected(peer, plugin):
|
||||
if peer['id'] in plugin.reject_ids:
|
||||
print("{} is in reject list, disconnecting".format(peer['id']))
|
||||
return {'result': 'disconnect'}
|
||||
return {'result': 'disconnect', 'error_message': 'You are in reject list'}
|
||||
|
||||
print("{} is allowed".format(peer['id']))
|
||||
return {'result': 'continue'}
|
||||
|
||||
@@ -164,6 +164,11 @@ def test_plugin_connected_hook(node_factory):
|
||||
l3.connect(l1)
|
||||
l1.daemon.wait_for_log(r"{} is in reject list".format(l3.info['id']))
|
||||
|
||||
# FIXME: this error occurs *after* connection, so we connect then drop.
|
||||
l3.daemon.wait_for_log(r"lightning_openingd-{} chan #1: peer_in WIRE_ERROR"
|
||||
.format(l1.info['id']))
|
||||
l3.daemon.wait_for_log(r"You are in reject list")
|
||||
|
||||
peer = l1.rpc.listpeers(l3.info['id'])['peers']
|
||||
assert(peer == [] or not peer[0]['connected'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user