2019-02-07 16:57:59 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""Simple plugin to test the connected_hook.
|
|
|
|
|
|
|
|
It can mark some node_ids as rejects and it'll check for each
|
|
|
|
connection if it should be disconnected immediately or if it can
|
|
|
|
continue.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2020-02-11 23:04:21 +01:00
|
|
|
from pyln.client import Plugin
|
2019-02-07 16:57:59 +01:00
|
|
|
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.hook('peer_connected')
|
2019-08-05 02:19:48 +02:00
|
|
|
def on_connected(peer, plugin, **kwargs):
|
2019-02-07 16:57:59 +01:00
|
|
|
if peer['id'] in plugin.reject_ids:
|
|
|
|
print("{} is in reject list, disconnecting".format(peer['id']))
|
2019-04-16 02:11:48 +02:00
|
|
|
return {'result': 'disconnect', 'error_message': 'You are in reject list'}
|
2019-02-07 16:57:59 +01:00
|
|
|
|
|
|
|
print("{} is allowed".format(peer['id']))
|
|
|
|
return {'result': 'continue'}
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.init()
|
|
|
|
def init(configuration, options, plugin):
|
|
|
|
plugin.reject_ids = []
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.method('reject')
|
|
|
|
def reject(node_id, plugin):
|
|
|
|
"""Mark a given node_id as reject for future connections.
|
|
|
|
"""
|
|
|
|
print("Rejecting connections from {}".format(node_id))
|
|
|
|
plugin.reject_ids.append(node_id)
|
|
|
|
|
|
|
|
|
|
|
|
plugin.run()
|