Skip to content

Commit 2700b55

Browse files
committed
req_neighbours
1 parent e790e19 commit 2700b55

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "meshcore-cli"
7-
version = "1.2.11"
7+
version = "1.2.12"
88
authors = [
99
{ name="Florent de Lamotte", email="[email protected]" },
1010
]
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818
license = "MIT"
1919
license-files = ["LICEN[CS]E*"]
20-
dependencies = [ "meshcore >= 2.1.23", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
20+
dependencies = [ "meshcore >= 2.1.24", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
2121

2222
[project.urls]
2323
Homepage = "https://github.com/fdlamotte/meshcore-cli"

src/meshcore_cli/meshcore_cli.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from meshcore import MeshCore, EventType, logger
3333

3434
# Version
35-
VERSION = "v1.2.11"
35+
VERSION = "v1.2.12"
3636

3737
# default ble address is stored in a config file
3838
MCCLI_CONFIG_DIR = str(Path.home()) + "/.config/meshcore/"
@@ -578,6 +578,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
578578
"logout" : None,
579579
"req_status" : None,
580580
"req_bstatus" : None,
581+
"req_neighbours": None,
581582
"cmd" : None,
582583
"ver" : None,
583584
"advert" : None,
@@ -1083,6 +1084,7 @@ async def process_contact_chat_line(mc, contact, line):
10831084
line == "dp" or line == "disc_path" or\
10841085
line == "contact_info" or line == "ci" or\
10851086
line == "req_status" or line == "rs" or\
1087+
line == "req_neighbours" or line == "rn" or\
10861088
line == "req_bstatus" or line == "rbs" or\
10871089
line == "req_telemetry" or line == "rt" or\
10881090
line == "req_acl" or\
@@ -2634,6 +2636,31 @@ async def next_cmd(mc, cmds, json_output=False):
26342636
name = f"{ct['adv_name']:<20} [{e['key']}]"
26352637
print(f"{name:{' '}<35}: {e['perm']:02x}")
26362638

2639+
case "req_neighbours"|"rn" :
2640+
argnum = 1
2641+
await mc.ensure_contacts()
2642+
contact = mc.get_contact_by_name(cmds[1])
2643+
timeout = 0 if not "timeout" in contact else contact["timeout"]
2644+
res = await mc.commands.fetch_all_neighbours(contact, timeout=timeout)
2645+
if res is None :
2646+
if json_output :
2647+
print(json.dumps({"error" : "Getting data"}))
2648+
else:
2649+
print("Error getting data")
2650+
else :
2651+
if json_output:
2652+
print(json.dumps(res, indent=4))
2653+
else:
2654+
print(f"Got {res['results_count']} neighbours out of {res['neighbours_count']} from {contact['adv_name']}:")
2655+
for n in res['neighbours']:
2656+
ct = mc.get_contact_by_key_prefix(n["pubkey"])
2657+
if ct :
2658+
name = f"[{n['pubkey'][0:8]}] {ct['adv_name']}"
2659+
else:
2660+
name = f"[{n['pubkey']}]"
2661+
2662+
print(f" {name:30} last viewed {n['secs_ago']} sec ago at {n['snr']} ")
2663+
26372664
case "req_binary" :
26382665
argnum = 2
26392666
await mc.ensure_contacts()
@@ -3131,6 +3158,7 @@ def command_help():
31313158
cmd <name> <cmd> : sends a command to a repeater (no ack) c [
31323159
wmt8 : wait for a msg (reply) with a timeout ]
31333160
req_status <name> : requests status from a node rs
3161+
req_neighbours <name> : requests for neighbours in binary form rn
31343162
trace <path> : run a trace, path is comma separated""")
31353163

31363164
def usage () :

0 commit comments

Comments
 (0)