mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Improve rhizome direct push/pull/sync command line parsing and
use of configuration. Not yet finished, but allows multiple rhizome direct peers and non-http URLs. #9
This commit is contained in:
parent
e015f0670b
commit
d11109bca5
@ -1782,13 +1782,13 @@ command_line_option command_line_options[]={
|
||||
"Extract a manifest from Rhizome and write it to the given path"},
|
||||
{app_rhizome_extract_file,{"rhizome","extract","file","<fileid>","[<filepath>]","[<key>]",NULL},CLIFLAG_STANDALONE,
|
||||
"Extract a file from Rhizome and write it to the given path"},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","sync","<ip:port>",NULL},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","sync","[peer url]",NULL},
|
||||
CLIFLAG_STANDALONE,
|
||||
"Synchronise with the specified Rhizome Direct server. Return when done."},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","push","<ip:port>",NULL},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","push","[peer url]",NULL},
|
||||
CLIFLAG_STANDALONE,
|
||||
"Deliver all new content to the specified Rhizome Direct server. Return when done."},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","pull","<ip:port>",NULL},
|
||||
{app_rhizome_direct_sync,{"rhizome","direct","pull","[peer url]",NULL},
|
||||
CLIFLAG_STANDALONE,
|
||||
"Fetch all new content from the specified Rhizome Direct server. Return when done."},
|
||||
{app_keyring_create,{"keyring","create",NULL},0,
|
||||
|
@ -498,25 +498,71 @@ int app_rhizome_direct_sync(int argc, const char *const *argv,
|
||||
transport and allowable traffic volumes. */
|
||||
rhizome_direct_transport_state_http
|
||||
*state=calloc(sizeof(rhizome_direct_transport_state_http),1);
|
||||
if (strlen(argv[3])>1020)
|
||||
const char *sync_url=confValueGet("rhizome.direct.peer", NULL);
|
||||
int peer_count=0;
|
||||
int peer_number=0;
|
||||
char peer_var[128];
|
||||
|
||||
if (argv[3]) {
|
||||
peer_count=1;
|
||||
sync_url=argv[3];
|
||||
}
|
||||
|
||||
if (peer_count<1) {
|
||||
DEBUG("No rhizome direct peers were configured or supplied.");
|
||||
}
|
||||
|
||||
/* XXX This code runs each sync in series, when we can probably do them in
|
||||
parallel. But we can't really do them in parallel until we make the
|
||||
synchronisation process fully asynchronous, which probably won't happen
|
||||
for a while yet.
|
||||
Also, we don't currently parse the URI protocol field fully. */
|
||||
next_peer:
|
||||
if (!sync_url) {
|
||||
snprintf(peer_var,128,"rhizome.direct.peer.%d",peer_number);
|
||||
sync_url=confValueGet(peer_var, NULL);
|
||||
}
|
||||
|
||||
if (strlen(sync_url)>1020)
|
||||
{
|
||||
DEBUG("rhizome direct URI too long");
|
||||
return -1;
|
||||
}
|
||||
if (sscanf(argv[3],"%[^:]:%d",state->host,&state->port)!=2)
|
||||
|
||||
char protocol[1024];
|
||||
state->port=RHIZOME_HTTP_PORT;
|
||||
int ok=0;
|
||||
if (sscanf(sync_url,"%[^:]://%[^:]:%d",protocol,state->host,&state->port)>=2)
|
||||
ok=1;
|
||||
if (!ok) sprintf(protocol,"http");
|
||||
if ((!ok)&&(sscanf(sync_url,"%[^:]:%d",state->host,&state->port)>=1))
|
||||
ok=2;
|
||||
if (!ok)
|
||||
{
|
||||
DEBUG("could not parse rhizome direct URI");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
DEBUGF("Rhizome direct peer is %s://%s:%d (parse route %d)",
|
||||
protocol,state->host,state->port,ok);
|
||||
|
||||
if (strcasecmp(protocol,"http")) {
|
||||
DEBUG("Unsupport Rhizome Direct synchronisation protocol."
|
||||
" Only HTTP is supported at present.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rhizome_direct_sync_request
|
||||
*s = rhizome_direct_new_sync_request(rhizome_direct_http_dispatch,
|
||||
65536,0,mode,state);
|
||||
|
||||
|
||||
rhizome_direct_start_sync_request(s);
|
||||
|
||||
|
||||
if (rd_sync_handle_count>0)
|
||||
while(fd_poll()&&(rd_sync_handle_count>0)) continue;
|
||||
|
||||
sync_url=NULL;
|
||||
peer_number++;
|
||||
if (peer_number<peer_count) goto next_peer;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -667,7 +713,6 @@ int rhizome_direct_bundle_iterator_fill(rhizome_direct_bundle_cursor *c,int max_
|
||||
c->buffer_used+=RHIZOME_BAR_BYTES*stuffed_now;
|
||||
if (!stuffed_now) {
|
||||
/* no more matches in this size bin, so move up a size bin */
|
||||
DEBUGF("Continue from next size bin");
|
||||
c->size_low=c->size_high+1;
|
||||
c->size_high*=2;
|
||||
/* Record that we covered to the end of that size bin */
|
||||
@ -678,7 +723,6 @@ int rhizome_direct_bundle_iterator_fill(rhizome_direct_bundle_cursor *c,int max_
|
||||
memset(c->bid_low,0x00,RHIZOME_MANIFEST_ID_BYTES);
|
||||
} else {
|
||||
/* Continue from next BID */
|
||||
DEBUGF("Continue from next BID");
|
||||
bcopy(c->bid_high,c->bid_low,RHIZOME_MANIFEST_ID_BYTES);
|
||||
int i;
|
||||
for(i=RHIZOME_BAR_BYTES-1;i>=0;i--)
|
||||
|
@ -274,6 +274,9 @@ setup_sync() {
|
||||
add_file file2
|
||||
BID2=$BID
|
||||
VERSION2=$VERSION
|
||||
executeOk_servald config set rhizome.direct.peer.count "1"
|
||||
executeOk_servald config set rhizome.direct.peer.0 "http://${addr_localhost}:${PORTA}"
|
||||
start_servald_instances dummy2 +B
|
||||
}
|
||||
|
||||
doc_Push="One way push bundle to unconnected node"
|
||||
@ -282,7 +285,7 @@ setup_Push() {
|
||||
setup_sync
|
||||
}
|
||||
test_Push() {
|
||||
executeOk_servald rhizome direct push "$addr_localhost:$PORTA"
|
||||
executeOk_servald rhizome direct push
|
||||
tfw_cat --stderr
|
||||
wait_until bundle_received_by $BID2 $VERSION2 +A
|
||||
assert ! bundle_received_by $BID1 $VERSION1 +B
|
||||
@ -296,7 +299,7 @@ setup_Pull() {
|
||||
setup_sync
|
||||
}
|
||||
test_Pull() {
|
||||
executeOk_servald rhizome direct pull "$addr_localhost:$PORTA"
|
||||
executeOk_servald rhizome direct pull
|
||||
tfw_cat --stderr
|
||||
assert bundle_received_by $BID1 $VERSION1 +B
|
||||
assert ! bundle_received_by $BID2 $VERSION2 +A
|
||||
@ -310,7 +313,7 @@ setup_Sync() {
|
||||
setup_sync
|
||||
}
|
||||
test_Sync() {
|
||||
executeOk_servald rhizome direct sync "$addr_localhost:$PORTA"
|
||||
executeOk_servald rhizome direct sync
|
||||
tfw_cat --stderr
|
||||
assert bundle_received_by $BID2 $VERSION2 +A
|
||||
assert bundle_received_by $BID1 $VERSION1 +B
|
||||
|
Loading…
Reference in New Issue
Block a user