int app_rhizome_direct_sync(const struct cli_parsed *parsed, void *context) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); /* Attempt to connect with a remote Rhizome Direct instance, and negotiate which BARs to synchronise. */ const char *modeName = (parsed->argc >= 3 ? parsed->args[2] : "sync"); int mode=3; /* two-way sync */ if (!strcasecmp(modeName,"push")) mode=1; /* push only */ if (!strcasecmp(modeName,"pull")) mode=2; /* pull only */ DEBUGF("sync direction = %d",mode); if (parsed->args[3]) { struct config_rhizome_peer peer; const struct config_rhizome_peer *peers[1] = { &peer }; int result = cf_opt_rhizome_peer_from_uri(&peer, parsed->args[3]); if (result == CFOK) return rhizome_sync_with_peers(mode, 1, peers); else { strbuf b = strbuf_alloca(128); strbuf_cf_flag_reason(b, result); return WHYF("Invalid peer URI %s -- %s", alloca_str_toprint(parsed->args[3]), strbuf_str(b)); } } else if (config.rhizome.direct.peer.ac == 0) { DEBUG("No rhizome direct peers were configured or supplied"); return -1; } else { const struct config_rhizome_peer *peers[config.rhizome.direct.peer.ac]; int i; for (i = 0; i < config.rhizome.direct.peer.ac; ++i) peers[i] = &config.rhizome.direct.peer.av[i].value; return rhizome_sync_with_peers(mode, config.rhizome.direct.peer.ac, peers); } }
int cf_opt_rhizome_peer(struct config_rhizome_peer *rpeer, const struct cf_om_node *node) { if (!node->text) return cf_opt_config_rhizome_peer(rpeer, node); if (node->nodc) { cf_warn_incompatible_children(node); return CFINCOMPATIBLE; } return cf_opt_rhizome_peer_from_uri(rpeer, node->text); }