mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-07 11:08:36 +00:00
Add simple meshmb find command
This commit is contained in:
parent
6a0b7a1da6
commit
67b9aeeb4e
41
meshmb.c
41
meshmb.c
@ -139,29 +139,56 @@ static int app_meshmb_read(const struct cli_parsed *parsed, struct cli_context *
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
DEFINE_CMD(app_meshmb_find, 0,
|
||||
"Browse available broadcast message feeds",
|
||||
"meshmb", "find", "[<search>]");
|
||||
static int app_meshmb_find(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
{
|
||||
|
||||
const char *search=NULL;
|
||||
cli_arg(parsed, "search", &search, NULL, "");
|
||||
// Ensure the Rhizome database exists and is open
|
||||
if (create_serval_instance_dir() == -1)
|
||||
return -1;
|
||||
if (rhizome_opendb() == -1)
|
||||
return -1;
|
||||
|
||||
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
|
||||
sqlite3_stmt *statement = sqlite_prepare(&retry,
|
||||
"SELECT ROWID, MANIFEST FROM MANIFESTS WHERE SERVICE = '"RHIZOME_SERVICE_MESHMB"' ORDER BY ROWID DESC;");
|
||||
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
|
||||
}
|
||||
struct rhizome_list_cursor cursor;
|
||||
bzero(&cursor, sizeof cursor);
|
||||
cursor.service = RHIZOME_SERVICE_MESHMB;
|
||||
cursor.name = search && search[0] ? search : NULL;
|
||||
|
||||
//TODO hide feeds that have been blocked
|
||||
|
||||
if (rhizome_list_open(&cursor) == -1)
|
||||
return -1;
|
||||
|
||||
const char *names[]={
|
||||
"_id",
|
||||
"id",
|
||||
"version",
|
||||
"date",
|
||||
"name"
|
||||
};
|
||||
cli_columns(context, 5, names);
|
||||
|
||||
unsigned rowcount=0;
|
||||
int n;
|
||||
|
||||
while ((n = rhizome_list_next(&cursor)) == 1) {
|
||||
rowcount++;
|
||||
rhizome_manifest *m = cursor.manifest;
|
||||
cli_put_long(context, m->rowid, ":");
|
||||
cli_put_hexvalue(context, m->cryptoSignPublic.binary, sizeof m->cryptoSignPublic.binary, ":");
|
||||
cli_put_long(context, m->version, ":");
|
||||
cli_put_long(context, m->has_date ? m->date : 0, ":");
|
||||
cli_put_string(context, m->name, "\n");
|
||||
}
|
||||
rhizome_list_release(&cursor);
|
||||
cli_row_count(context, rowcount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
DEFINE_CMD(app_meshmb_follow, 0,
|
||||
"",
|
||||
"meshmb", "follow|ignore|block" KEYRING_PIN_OPTIONS, "<id>", "<peer>");
|
||||
|
25
tests/meshmb
25
tests/meshmb
@ -8,6 +8,7 @@ rexp_age='[0-9]*'
|
||||
|
||||
setup_identities() {
|
||||
setup_servald
|
||||
set_instance +A
|
||||
executeOk_servald config \
|
||||
set debug.meshms on \
|
||||
set debug.rhizome on \
|
||||
@ -15,7 +16,6 @@ setup_identities() {
|
||||
set debug.rhizome_store on \
|
||||
set log.console.level debug \
|
||||
set log.console.show_time on
|
||||
set_instance +A
|
||||
create_identities $1
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ teardown() {
|
||||
report_all_servald_servers
|
||||
}
|
||||
|
||||
doc_meshmbSend="Send broadcast message"
|
||||
doc_meshmbSend="Send broadcast meshmb message"
|
||||
setup_meshmbSend() {
|
||||
setup_identities 1
|
||||
}
|
||||
@ -44,7 +44,7 @@ test_meshmbSend() {
|
||||
}
|
||||
|
||||
|
||||
doc_meshmbRead="Read messages"
|
||||
doc_meshmbRead="Read meshmb messages"
|
||||
setup_meshmbRead() {
|
||||
setup_identities 1
|
||||
executeOk_servald meshmb send $IDA1 "Message 1"
|
||||
@ -57,4 +57,23 @@ test_meshmbRead() {
|
||||
assertStdoutGrep --matches=1 "^1:12:${rexp_age}:Message 1$"
|
||||
assertStdoutLineCount '==' 4
|
||||
}
|
||||
|
||||
doc_meshmbListFeeds="List meshmb feeds"
|
||||
setup_meshmbListFeeds() {
|
||||
setup_identities 3
|
||||
executeOk_servald meshmb send $IDA1 "Message 1"
|
||||
executeOk_servald meshmb send $IDA2 "Message 2"
|
||||
executeOk_servald meshmb send $IDA3 "Message 3"
|
||||
}
|
||||
test_meshmbListFeeds() {
|
||||
executeOk_servald meshmb find
|
||||
tfw_cat --stdout
|
||||
assertStdoutGrep --matches=1 "^_id:id:version:date:name$"
|
||||
assertStdoutGrep --matches=1 ":${IDA1}:"
|
||||
assertStdoutGrep --matches=1 ":${IDA2}:"
|
||||
assertStdoutGrep --matches=1 ":${IDA3}:"
|
||||
assertStdoutLineCount '==' 5
|
||||
}
|
||||
|
||||
|
||||
runTests "$@"
|
||||
|
Loading…
x
Reference in New Issue
Block a user