mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-07 22:04:03 -05:00
net: allow runtime modification of outbound connection count. adds a method to darkirc to set_outbound_connections, use the scripts ./script/node_get_info.py and ./script/node_set-connect.py to verify
This commit is contained in:
@@ -73,6 +73,12 @@ class JsonRpc:
|
||||
async def dnet_subscribe_events(self):
|
||||
return await self._subscribe("dnet.subscribe_events", [])
|
||||
|
||||
async def get_info(self):
|
||||
return await self._make_request("p2p.get_info", [])
|
||||
|
||||
async def set_outbound_connections(self, n):
|
||||
return await self._make_request("p2p.set_outbound_connections", [n])
|
||||
|
||||
async def main(argv):
|
||||
rpc = JsonRpc()
|
||||
while True:
|
||||
@@ -126,4 +132,6 @@ async def main(argv):
|
||||
|
||||
await rpc.stop()
|
||||
|
||||
asyncio.run(main(sys.argv))
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main(sys.argv))
|
||||
|
||||
55
script/node_set-conns.py
Executable file
55
script/node_set-conns.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# This file is part of DarkFi (https://dark.fi)
|
||||
#
|
||||
# Copyright (C) 2020-2025 Dyne.org foundation
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from node_get_info import JsonRpc
|
||||
|
||||
async def main(argv):
|
||||
if len(argv) != 2:
|
||||
print(f"Usage: {argv[0]} <num_connections>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
num_conns = int(argv[1])
|
||||
if num_conns <= 0:
|
||||
raise ValueError()
|
||||
except ValueError:
|
||||
print("Error: num_connections must be a positive integer", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
rpc = JsonRpc()
|
||||
while True:
|
||||
try:
|
||||
await rpc.start("localhost", 26660)
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
response = await rpc.set_outbound_connections(num_conns)
|
||||
|
||||
if "error" in response:
|
||||
print(f"Error: {response['error']}")
|
||||
await rpc.stop()
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Set outbound connections to {num_conns}: {response['result']}")
|
||||
await rpc.stop()
|
||||
|
||||
asyncio.run(main(sys.argv))
|
||||
Reference in New Issue
Block a user