forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreject.py
executable file
·38 lines (25 loc) · 937 Bytes
/
reject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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.
"""
from pyln.client import Plugin
plugin = Plugin()
@plugin.hook('peer_connected')
def on_connected(peer, plugin, **kwargs):
if peer['id'] in plugin.reject_ids:
print("{} is in reject list, disconnecting".format(peer['id']))
return {'result': 'disconnect', 'error_message': 'You are in reject list'}
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()