2012-04-20 07:32:29 +00:00
|
|
|
/*
|
2012-02-16 14:05:28 +00:00
|
|
|
Serval Distributed Numbering Architecture (DNA)
|
2012-04-20 07:32:29 +00:00
|
|
|
Copyright (C) 2010-2012 Paul Gardner-Stephen
|
2012-02-16 14:05:28 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-04-02 08:12:40 +00:00
|
|
|
#include <sys/time.h>
|
2012-05-10 04:37:11 +00:00
|
|
|
#include <sys/wait.h>
|
2012-04-02 08:12:40 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2012-07-04 09:27:02 +00:00
|
|
|
#include <ctype.h>
|
2012-05-14 09:02:10 +00:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
2012-04-10 08:42:17 +00:00
|
|
|
#include <time.h>
|
2012-04-13 08:17:20 +00:00
|
|
|
#include <unistd.h>
|
2012-04-23 02:35:00 +00:00
|
|
|
#include <stdarg.h>
|
2012-04-19 08:33:04 +00:00
|
|
|
#include <stdlib.h>
|
2012-04-10 08:42:17 +00:00
|
|
|
#include <stdio.h>
|
2012-08-20 05:31:07 +00:00
|
|
|
#include <limits.h>
|
2012-04-20 07:51:03 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-04-20 07:32:29 +00:00
|
|
|
#include <jni.h>
|
2012-04-20 07:51:03 +00:00
|
|
|
#endif
|
2012-02-23 02:15:42 +00:00
|
|
|
#include "serval.h"
|
2012-04-02 08:12:40 +00:00
|
|
|
#include "rhizome.h"
|
2012-05-20 03:32:41 +00:00
|
|
|
#include "strbuf.h"
|
2012-09-14 02:17:48 +00:00
|
|
|
#include "mdp_client.h"
|
2012-09-25 04:01:34 +00:00
|
|
|
#include "cli.h"
|
2012-02-16 14:05:28 +00:00
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
extern struct command_line_option command_line_options[];
|
|
|
|
|
|
|
|
int commandline_usage(int argc, const char *const *argv, struct command_line_option *o, void *context){
|
2012-08-01 08:24:02 +00:00
|
|
|
printf("Serval Mesh version <version>.\n");
|
2012-09-25 04:01:34 +00:00
|
|
|
return cli_usage(command_line_options);
|
2012-02-16 14:05:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 07:42:10 +00:00
|
|
|
/* Data structures for accumulating output of a single JNI call.
|
|
|
|
*/
|
|
|
|
|
2012-04-24 08:33:52 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
|
|
|
|
2012-04-30 08:15:24 +00:00
|
|
|
#define OUTV_BUFFER_ALLOCSIZE (8192)
|
2012-04-23 07:42:10 +00:00
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
JNIEnv *jni_env = NULL;
|
|
|
|
int jni_exception = 0;
|
2012-04-23 07:42:10 +00:00
|
|
|
|
2012-04-30 08:15:24 +00:00
|
|
|
jobject outv_list = NULL;
|
|
|
|
jmethodID listAddMethodId = NULL;
|
2012-04-23 07:42:10 +00:00
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
char *outv_buffer = NULL;
|
2012-04-23 07:42:10 +00:00
|
|
|
char *outv_current = NULL;
|
|
|
|
char *outv_limit = NULL;
|
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
static int outv_growbuf(size_t needed)
|
2012-04-23 07:42:10 +00:00
|
|
|
{
|
2012-04-24 07:36:48 +00:00
|
|
|
size_t newsize = (outv_limit - outv_current < needed) ? (outv_limit - outv_buffer) + needed : 0;
|
|
|
|
if (newsize) {
|
2012-04-30 08:15:24 +00:00
|
|
|
// Round up to nearest multiple of OUTV_BUFFER_ALLOCSIZE.
|
|
|
|
newsize = newsize + OUTV_BUFFER_ALLOCSIZE - ((newsize - 1) % OUTV_BUFFER_ALLOCSIZE + 1);
|
2012-04-24 07:36:48 +00:00
|
|
|
size_t length = outv_current - outv_buffer;
|
|
|
|
outv_buffer = realloc(outv_buffer, newsize);
|
|
|
|
if (outv_buffer == NULL)
|
|
|
|
return WHYF("Out of memory allocating %lu bytes", (unsigned long) newsize);
|
|
|
|
outv_current = outv_buffer + length;
|
|
|
|
outv_limit = outv_buffer + newsize;
|
2012-04-23 07:42:10 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
static int outv_end_field()
|
2012-04-23 07:42:10 +00:00
|
|
|
{
|
2012-04-24 07:36:48 +00:00
|
|
|
outv_growbuf(1);
|
|
|
|
*outv_current++ = '\0';
|
2012-04-30 08:15:24 +00:00
|
|
|
jstring str = (jstring)(*jni_env)->NewStringUTF(jni_env, outv_buffer);
|
2012-04-24 07:36:48 +00:00
|
|
|
outv_current = outv_buffer;
|
2012-04-30 08:15:24 +00:00
|
|
|
if (str == NULL) {
|
2012-04-24 07:36:48 +00:00
|
|
|
jni_exception = 1;
|
|
|
|
return WHY("Exception thrown from NewStringUTF()");
|
|
|
|
}
|
2012-04-30 08:15:24 +00:00
|
|
|
(*jni_env)->CallBooleanMethod(jni_env, outv_list, listAddMethodId, str);
|
|
|
|
if ((*jni_env)->ExceptionOccurred(jni_env)) {
|
|
|
|
jni_exception = 1;
|
|
|
|
return WHY("Exception thrown from CallBooleanMethod()");
|
|
|
|
}
|
2012-05-27 05:34:37 +00:00
|
|
|
(*jni_env)->DeleteLocalRef(jni_env, str);
|
2012-04-23 07:42:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-04-20 07:32:29 +00:00
|
|
|
|
|
|
|
/* JNI entry point to command line. See org.servalproject.servald.ServalD class for the Java side.
|
2012-04-30 08:15:24 +00:00
|
|
|
JNI method descriptor: "(Ljava/util/List;[Ljava/lang/String;)I"
|
2012-04-20 07:32:29 +00:00
|
|
|
*/
|
2012-04-30 08:15:24 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_servalproject_servald_ServalD_rawCommand(JNIEnv *env, jobject this, jobject outv, jobjectArray args)
|
2012-04-20 07:32:29 +00:00
|
|
|
{
|
|
|
|
jclass stringClass = NULL;
|
2012-04-30 08:15:24 +00:00
|
|
|
jclass listClass = NULL;
|
2012-05-03 02:47:12 +00:00
|
|
|
unsigned char status = 0; // to match what the shell gets: 0..255
|
2012-04-23 07:42:10 +00:00
|
|
|
// Enforce non re-entrancy.
|
2012-04-24 07:36:48 +00:00
|
|
|
if (jni_env) {
|
2012-04-23 07:42:10 +00:00
|
|
|
jclass exceptionClass = NULL;
|
2012-04-30 08:15:24 +00:00
|
|
|
if ((exceptionClass = (*env)->FindClass(env, "java/lang/IllegalStateException")) == NULL)
|
|
|
|
return -1; // exception
|
2012-04-23 07:42:10 +00:00
|
|
|
(*env)->ThrowNew(env, exceptionClass, "re-entrancy not supported");
|
2012-04-30 08:15:24 +00:00
|
|
|
return -1;
|
2012-04-23 07:42:10 +00:00
|
|
|
}
|
2012-04-24 07:36:48 +00:00
|
|
|
// Get some handles to some classes and methods that we use later on.
|
2012-04-20 07:32:29 +00:00
|
|
|
if ((stringClass = (*env)->FindClass(env, "java/lang/String")) == NULL)
|
2012-04-30 08:15:24 +00:00
|
|
|
return -1; // exception
|
|
|
|
if ((listClass = (*env)->FindClass(env, "java/util/List")) == NULL)
|
|
|
|
return -1; // exception
|
|
|
|
if ((listAddMethodId = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z")) == NULL)
|
|
|
|
return -1; // exception
|
2012-04-24 07:36:48 +00:00
|
|
|
// Construct argv, argc from this method's arguments.
|
2012-04-20 07:32:29 +00:00
|
|
|
jsize len = (*env)->GetArrayLength(env, args);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char **argv = malloc(sizeof(char*) * (len + 1));
|
|
|
|
if (argv == NULL) {
|
|
|
|
jclass exceptionClass = NULL;
|
|
|
|
if ((exceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError")) == NULL)
|
2012-04-30 08:15:24 +00:00
|
|
|
return -1; // exception
|
2012-04-23 07:42:10 +00:00
|
|
|
(*env)->ThrowNew(env, exceptionClass, "malloc returned NULL");
|
2012-04-30 08:15:24 +00:00
|
|
|
return -1;
|
2012-04-23 07:42:10 +00:00
|
|
|
}
|
2012-04-20 07:32:29 +00:00
|
|
|
jsize i;
|
2012-04-24 07:36:48 +00:00
|
|
|
for (i = 0; i <= len; ++i)
|
|
|
|
argv[i] = NULL;
|
|
|
|
int argc = len;
|
|
|
|
// From now on, in case of an exception we have to free some resources before
|
|
|
|
// returning.
|
|
|
|
jni_exception = 0;
|
|
|
|
for (i = 0; !jni_exception && i != len; ++i) {
|
2012-04-20 07:32:29 +00:00
|
|
|
const jstring arg = (jstring)(*env)->GetObjectArrayElement(env, args, i);
|
2012-04-24 07:36:48 +00:00
|
|
|
if (arg == NULL)
|
|
|
|
jni_exception = 1;
|
|
|
|
else {
|
|
|
|
const char *str = (*env)->GetStringUTFChars(env, arg, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
jni_exception = 1;
|
|
|
|
else
|
|
|
|
argv[i] = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!jni_exception) {
|
|
|
|
// Set up the output buffer.
|
2012-04-30 08:15:24 +00:00
|
|
|
outv_list = outv;
|
2012-04-24 07:36:48 +00:00
|
|
|
outv_current = outv_buffer;
|
|
|
|
// Execute the command.
|
|
|
|
jni_env = env;
|
2012-07-24 06:09:36 +00:00
|
|
|
status = parseCommandLine(NULL, argc, argv);
|
2012-04-24 07:36:48 +00:00
|
|
|
jni_env = NULL;
|
|
|
|
}
|
|
|
|
// Release argv Java string buffers.
|
|
|
|
for (i = 0; i != len; ++i) {
|
|
|
|
if (argv[i]) {
|
|
|
|
const jstring arg = (jstring)(*env)->GetObjectArrayElement(env, args, i);
|
|
|
|
(*env)->ReleaseStringUTFChars(env, arg, argv[i]);
|
|
|
|
}
|
2012-04-23 07:42:10 +00:00
|
|
|
}
|
|
|
|
free(argv);
|
2012-04-24 07:36:48 +00:00
|
|
|
// Deal with Java exceptions: NewStringUTF out of memory in outv_end_field().
|
|
|
|
if (jni_exception || (outv_current != outv_buffer && outv_end_field() == -1))
|
2012-04-30 08:15:24 +00:00
|
|
|
return -1;
|
2012-05-03 02:47:12 +00:00
|
|
|
return (jint) status;
|
2012-04-20 07:32:29 +00:00
|
|
|
}
|
2012-04-23 02:35:00 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_JNI_H */
|
2012-04-20 07:32:29 +00:00
|
|
|
|
2012-07-24 06:09:36 +00:00
|
|
|
/* The argc and argv arguments must be passed verbatim from main(argc, argv), so argv[0] is path to
|
|
|
|
executable.
|
|
|
|
*/
|
|
|
|
int parseCommandLine(const char *argv0, int argc, const char *const *args)
|
2012-02-16 14:05:28 +00:00
|
|
|
{
|
2012-07-03 05:42:42 +00:00
|
|
|
fd_clearstats();
|
|
|
|
IN();
|
2012-05-14 09:02:10 +00:00
|
|
|
confSetDebugFlags();
|
2012-09-25 04:01:34 +00:00
|
|
|
|
|
|
|
int result = cli_execute(argv0, argc, args, command_line_options, NULL);
|
2012-04-30 10:34:07 +00:00
|
|
|
/* clean up after ourselves */
|
|
|
|
overlay_mdp_client_done();
|
2012-07-03 05:42:42 +00:00
|
|
|
OUT();
|
2012-07-25 02:44:53 +00:00
|
|
|
|
|
|
|
if (debug&DEBUG_TIMING)
|
2012-07-03 05:42:42 +00:00
|
|
|
fd_showstats();
|
2012-04-30 10:34:07 +00:00
|
|
|
return result;
|
2012-02-16 14:05:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-23 07:42:10 +00:00
|
|
|
/* Write a single character to output. If in a JNI call, then this appends the character to the
|
|
|
|
current output field. Returns the character written cast to an unsigned char then to int, or EOF
|
|
|
|
on error.
|
|
|
|
*/
|
|
|
|
int cli_putchar(char c)
|
|
|
|
{
|
2012-04-24 08:33:52 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-04-24 07:36:48 +00:00
|
|
|
if (jni_env) {
|
2012-04-23 07:42:10 +00:00
|
|
|
if (outv_current == outv_limit && outv_growbuf(1) == -1)
|
|
|
|
return EOF;
|
|
|
|
*outv_current++ = c;
|
|
|
|
return (unsigned char) c;
|
|
|
|
}
|
|
|
|
else
|
2012-04-24 08:33:52 +00:00
|
|
|
#endif
|
2012-04-23 07:42:10 +00:00
|
|
|
return putchar(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a null-terminated string to output. If in a JNI call, then this appends the string to the
|
|
|
|
current output field. The terminating null is not included. Returns a non-negative integer on
|
|
|
|
success, EOF on error.
|
|
|
|
*/
|
|
|
|
int cli_puts(const char *str)
|
|
|
|
{
|
2012-04-24 08:33:52 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-04-24 07:36:48 +00:00
|
|
|
if (jni_env) {
|
2012-04-23 07:42:10 +00:00
|
|
|
size_t len = strlen(str);
|
|
|
|
size_t avail = outv_limit - outv_current;
|
|
|
|
if (avail < len) {
|
|
|
|
strncpy(outv_current, str, avail);
|
|
|
|
outv_current = outv_limit;
|
|
|
|
if (outv_growbuf(len) == -1)
|
|
|
|
return EOF;
|
|
|
|
len -= avail;
|
|
|
|
str += avail;
|
|
|
|
}
|
|
|
|
strncpy(outv_current, str, len);
|
|
|
|
outv_current += len;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
2012-04-24 08:33:52 +00:00
|
|
|
#endif
|
2012-04-23 07:42:10 +00:00
|
|
|
return fputs(str, stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a formatted string to output. If in a JNI call, then this appends the string to the
|
|
|
|
current output field, excluding the terminating null. Returns the number of bytes
|
|
|
|
written/appended, or -1 on error.
|
|
|
|
*/
|
2012-04-23 02:35:00 +00:00
|
|
|
int cli_printf(const char *fmt, ...)
|
|
|
|
{
|
2012-04-23 07:42:10 +00:00
|
|
|
int ret = 0;
|
2012-05-23 06:37:52 +00:00
|
|
|
va_list ap;
|
2012-04-24 08:33:52 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-04-24 07:36:48 +00:00
|
|
|
if (jni_env) {
|
2012-04-23 07:42:10 +00:00
|
|
|
size_t avail = outv_limit - outv_current;
|
2012-05-23 06:37:52 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
int count = vsnprintf(outv_current, avail, fmt, ap);
|
|
|
|
va_end(ap);
|
2012-04-23 07:42:10 +00:00
|
|
|
if (count >= avail) {
|
|
|
|
if (outv_growbuf(count) == -1)
|
|
|
|
return -1;
|
2012-05-23 06:37:52 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vsprintf(outv_current, fmt, ap);
|
|
|
|
va_end(ap);
|
2012-04-23 07:42:10 +00:00
|
|
|
}
|
|
|
|
outv_current += count;
|
|
|
|
ret = count;
|
|
|
|
} else
|
2012-04-24 08:33:52 +00:00
|
|
|
#endif
|
2012-05-23 06:37:52 +00:00
|
|
|
{
|
|
|
|
va_start(ap, fmt);
|
|
|
|
ret = vfprintf(stdout, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2012-04-23 07:42:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delimit the current output field. This closes the current field, so that the next cli_ output
|
|
|
|
function will start appending to a new field. Returns 0 on success, -1 on error. If not in a
|
|
|
|
JNI call, then this simply writes a newline to standard output (or the value of the
|
|
|
|
SERVALD_OUTPUT_DELIMITER env var if set).
|
|
|
|
*/
|
2012-04-24 08:20:27 +00:00
|
|
|
int cli_delim(const char *opt)
|
2012-04-23 07:42:10 +00:00
|
|
|
{
|
2012-04-24 08:33:52 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-10-08 06:43:17 +00:00
|
|
|
if (jni_env)
|
2012-04-30 08:15:24 +00:00
|
|
|
return outv_end_field();
|
2012-04-24 08:33:52 +00:00
|
|
|
#endif
|
2012-10-08 06:43:17 +00:00
|
|
|
const char *delim = getenv("SERVALD_OUTPUT_DELIMITER");
|
|
|
|
if (delim == NULL)
|
|
|
|
delim = opt ? opt : "\n";
|
|
|
|
fputs(delim, stdout);
|
2012-04-23 02:35:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-08 06:43:17 +00:00
|
|
|
/* Flush the output fields if they are being written to standard output.
|
|
|
|
*/
|
|
|
|
void cli_flush()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_JNI_H
|
|
|
|
if (jni_env)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_echo(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-23 08:55:26 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 08:55:26 +00:00
|
|
|
int i;
|
|
|
|
for (i = 1; i < argc; ++i) {
|
2012-05-14 09:02:10 +00:00
|
|
|
if (debug & DEBUG_VERBOSE)
|
|
|
|
DEBUGF("echo:argv[%d]=%s", i, argv[i]);
|
2012-04-23 08:55:26 +00:00
|
|
|
cli_puts(argv[i]);
|
2012-04-24 08:20:27 +00:00
|
|
|
cli_delim(NULL);
|
2012-04-23 08:55:26 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-02 06:43:12 +00:00
|
|
|
void lookup_send_request(unsigned char *srcsid, int srcport, unsigned char *dstsid, const char *did){
|
|
|
|
int i;
|
|
|
|
overlay_mdp_frame mdp;
|
|
|
|
bzero(&mdp,sizeof(mdp));
|
|
|
|
|
|
|
|
|
|
|
|
/* set source address to a local address, and pick a random port */
|
|
|
|
mdp.out.src.port=srcport;
|
|
|
|
bcopy(srcsid,mdp.out.src.sid,SID_SIZE);
|
|
|
|
|
|
|
|
/* Send to destination address and DNA lookup port */
|
|
|
|
|
|
|
|
if (dstsid){
|
|
|
|
/* Send an encrypted unicast packet */
|
|
|
|
mdp.packetTypeAndFlags=MDP_TX;
|
|
|
|
bcopy(dstsid, mdp.out.dst.sid, SID_SIZE);
|
|
|
|
}else{
|
|
|
|
/* Send a broadcast packet, flooding across the local mesh network */
|
|
|
|
mdp.packetTypeAndFlags=MDP_TX|MDP_NOCRYPT;
|
|
|
|
for(i=0;i<SID_SIZE;i++)
|
|
|
|
mdp.out.dst.sid[i]=0xff;
|
|
|
|
}
|
|
|
|
mdp.out.dst.port=MDP_PORT_DNALOOKUP;
|
|
|
|
|
|
|
|
/* put DID into packet */
|
|
|
|
bcopy(did,&mdp.out.payload[0],strlen(did)+1);
|
|
|
|
mdp.out.payload_length=strlen(did)+1;
|
|
|
|
|
|
|
|
overlay_mdp_send(&mdp,0,0);
|
|
|
|
|
|
|
|
/* Also send an encrypted unicast request to a configured directory service */
|
|
|
|
if (!dstsid){
|
|
|
|
const char *directory_service = confValueGet("directory.service", NULL);
|
|
|
|
if (directory_service){
|
|
|
|
if (stowSid(mdp.out.dst.sid, 0, directory_service)==-1){
|
|
|
|
WHYF("Invalid directory server SID %s", directory_service);
|
|
|
|
}else{
|
|
|
|
mdp.packetTypeAndFlags=MDP_TX;
|
|
|
|
overlay_mdp_send(&mdp,0,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_dna_lookup(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-02-16 14:05:28 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-08-10 05:55:06 +00:00
|
|
|
|
2012-03-29 07:21:59 +00:00
|
|
|
/* Create the instance directory if it does not yet exist */
|
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-04-24 20:46:31 +00:00
|
|
|
|
2012-06-20 03:26:32 +00:00
|
|
|
int uri_count=0;
|
|
|
|
#define MAXREPLIES 256
|
|
|
|
#define MAXURILEN 256
|
|
|
|
char uris[MAXREPLIES][MAXURILEN];
|
2012-05-01 04:09:43 +00:00
|
|
|
|
2012-08-10 05:55:06 +00:00
|
|
|
const char *did, *delay;
|
2012-07-23 02:53:17 +00:00
|
|
|
if (cli_arg(argc, argv, o, "did", &did, cli_lookup_did, "*") == -1)
|
2012-04-25 05:54:21 +00:00
|
|
|
return -1;
|
2012-08-10 05:55:06 +00:00
|
|
|
if (cli_arg(argc, argv, o, "timeout", &delay, NULL, "3000") == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
int idelay=atoi(delay);
|
|
|
|
int one_reply=0;
|
|
|
|
|
|
|
|
// Ugly hack, if timeout is negative, stop after first reply
|
|
|
|
if (idelay<0){
|
|
|
|
one_reply=1;
|
|
|
|
idelay=-idelay;
|
|
|
|
}
|
|
|
|
|
2012-04-25 05:54:21 +00:00
|
|
|
/* Bind to MDP socket and await confirmation */
|
|
|
|
unsigned char srcsid[SID_SIZE];
|
|
|
|
int port=32768+(random()&32767);
|
|
|
|
if (overlay_mdp_getmyaddr(0,srcsid)) return WHY("Could not get local address");
|
|
|
|
if (overlay_mdp_bind(srcsid,port)) return WHY("Could not bind to MDP socket");
|
|
|
|
|
2012-04-24 20:46:31 +00:00
|
|
|
/* use MDP to send the lookup request to MDP_PORT_DNALOOKUP, and wait for
|
|
|
|
replies. */
|
|
|
|
|
2012-04-25 05:54:21 +00:00
|
|
|
/* Now repeatedly send resolution request and collect results until we reach
|
|
|
|
timeout. */
|
2012-08-10 05:55:06 +00:00
|
|
|
time_ms_t timeout = gettime_ms() + idelay;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t last_tx = 0;
|
|
|
|
time_ms_t now;
|
2012-09-07 03:37:59 +00:00
|
|
|
int interval=125;
|
|
|
|
|
2012-08-09 02:44:32 +00:00
|
|
|
while (timeout > (now = gettime_ms()))
|
2012-04-25 05:54:21 +00:00
|
|
|
{
|
2012-09-07 03:37:59 +00:00
|
|
|
if ((last_tx+interval)<now)
|
2012-10-02 06:43:12 +00:00
|
|
|
{
|
2012-04-25 10:44:56 +00:00
|
|
|
|
2012-10-02 06:43:12 +00:00
|
|
|
lookup_send_request(srcsid, port, NULL, did);
|
2012-09-14 05:12:15 +00:00
|
|
|
|
2012-04-25 05:54:21 +00:00
|
|
|
last_tx=now;
|
2012-09-19 04:46:40 +00:00
|
|
|
interval+=interval>>1;
|
2012-04-25 05:54:21 +00:00
|
|
|
}
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t short_timeout=125;
|
2012-04-25 05:54:21 +00:00
|
|
|
while(short_timeout>0) {
|
|
|
|
if (overlay_mdp_client_poll(short_timeout))
|
|
|
|
{
|
|
|
|
overlay_mdp_frame rx;
|
|
|
|
int ttl;
|
2012-10-02 06:43:12 +00:00
|
|
|
if (overlay_mdp_recv(&rx, port, &ttl)==0)
|
2012-04-25 05:54:21 +00:00
|
|
|
{
|
|
|
|
if (rx.packetTypeAndFlags==MDP_ERROR)
|
|
|
|
{
|
2012-09-28 01:58:01 +00:00
|
|
|
WHYF(" Error message: %s", rx.error.message);
|
2012-04-25 05:54:21 +00:00
|
|
|
}
|
2012-05-01 04:09:43 +00:00
|
|
|
else if ((rx.packetTypeAndFlags&MDP_TYPE_MASK)==MDP_TX) {
|
2012-06-20 03:26:32 +00:00
|
|
|
/* Extract DID, Name, URI from response. */
|
|
|
|
if (strlen((char *)rx.in.payload)<512) {
|
2012-07-23 08:59:57 +00:00
|
|
|
char sidhex[SID_STRLEN + 1];
|
2012-07-18 09:46:30 +00:00
|
|
|
char did[DID_MAXSIZE + 1];
|
|
|
|
char name[64];
|
2012-06-20 03:26:32 +00:00
|
|
|
char uri[512];
|
2012-07-23 08:59:57 +00:00
|
|
|
if ( !parseDnaReply((char *)rx.in.payload, rx.in.payload_length, sidhex, did, name, uri, NULL)
|
|
|
|
|| !str_is_subscriber_id(sidhex)
|
|
|
|
|| !str_is_did(did)
|
|
|
|
|| !str_is_uri(uri)
|
|
|
|
) {
|
|
|
|
WHYF("Received malformed DNA reply: %s", alloca_toprint(160, (const char *)rx.in.payload, rx.in.payload_length));
|
|
|
|
} else {
|
2012-07-18 09:46:30 +00:00
|
|
|
/* Have we seen this response before? */
|
|
|
|
int i;
|
|
|
|
for(i=0;i<uri_count;i++)
|
|
|
|
if (!strcmp(uri,uris[i])) break;
|
|
|
|
if (i==uri_count) {
|
|
|
|
/* Not previously seen, so report it */
|
|
|
|
cli_puts(uri); cli_delim(":");
|
|
|
|
cli_puts(did); cli_delim(":");
|
|
|
|
cli_puts(name); cli_delim("\n");
|
2012-08-10 05:55:06 +00:00
|
|
|
|
|
|
|
if (one_reply){
|
|
|
|
timeout=now;
|
|
|
|
short_timeout=0;
|
|
|
|
}
|
|
|
|
|
2012-07-18 09:46:30 +00:00
|
|
|
/* Remember that we have seen it */
|
|
|
|
if (uri_count<MAXREPLIES&&strlen(uri)<MAXURILEN) {
|
|
|
|
strcpy(uris[uri_count++],uri);
|
2012-06-20 03:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 09:46:30 +00:00
|
|
|
}
|
2012-05-01 04:09:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-25 11:03:25 +00:00
|
|
|
else WHYF("packettype=0x%x",rx.packetTypeAndFlags);
|
2012-04-25 05:54:21 +00:00
|
|
|
if (servalShutdown) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (servalShutdown) break;
|
2012-07-30 07:52:38 +00:00
|
|
|
short_timeout=125-(gettime_ms()-now);
|
2012-04-25 05:54:21 +00:00
|
|
|
}
|
|
|
|
if (servalShutdown) break;
|
|
|
|
}
|
|
|
|
|
2012-04-30 10:34:07 +00:00
|
|
|
overlay_mdp_client_done();
|
2012-04-25 05:54:21 +00:00
|
|
|
return 0;
|
2012-02-16 14:36:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_server_start(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-06-26 06:37:24 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-22 06:24:14 +00:00
|
|
|
/* Process optional arguments */
|
2012-06-26 06:37:24 +00:00
|
|
|
int pid=-1;
|
2012-10-08 06:43:17 +00:00
|
|
|
int cpid=-1;
|
2012-06-26 06:37:24 +00:00
|
|
|
#if 0
|
2012-10-08 06:43:17 +00:00
|
|
|
// It would have been nice if whoever disabled this code had left a comment as to why they didn't
|
|
|
|
// simply delete it altogether. In any event, this logic is largely redundant because the Android
|
|
|
|
// Batphone app automatically calls "servald stop" then "servald start" (via JNI) whenever its
|
|
|
|
// monitor interface socket is broken.
|
|
|
|
// -- Andrew Bettison <andrew@servalproject.com>
|
2012-06-26 06:37:24 +00:00
|
|
|
int status=server_probe(&pid);
|
|
|
|
switch(status) {
|
|
|
|
case SERVER_NOTRESPONDING:
|
|
|
|
/* server is not responding, and we have been asked to start,
|
|
|
|
so try to kill it?
|
|
|
|
*/
|
|
|
|
WHYF("Serval process already running (pid=%d), but no responding.", pid);
|
|
|
|
if (pid>-1) {
|
|
|
|
kill(pid,SIGHUP); sleep(1);
|
|
|
|
status=server_probe(&pid);
|
|
|
|
if (status!=SERVER_NOTRUNNING) {
|
|
|
|
WHY("Tried to stop stuck servald process, but attempt failed.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
WHY("Killed stuck servald process, so will try to start");
|
|
|
|
pid=-1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SERVER_NOTRUNNING:
|
|
|
|
/* all is well */
|
|
|
|
break;
|
|
|
|
case SERVER_RUNNING:
|
|
|
|
/* instance running */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* no idea what is going on, so try to start anyway */
|
|
|
|
break;
|
2012-06-22 06:24:14 +00:00
|
|
|
}
|
2012-06-26 06:37:24 +00:00
|
|
|
#endif
|
2012-07-29 09:28:41 +00:00
|
|
|
const char *execpath, *instancepath;
|
2012-08-20 05:31:07 +00:00
|
|
|
char *tmp;
|
2012-06-26 06:37:24 +00:00
|
|
|
int foregroundP = (argc >= 2 && !strcasecmp(argv[1], "foreground"));
|
2012-07-29 09:28:41 +00:00
|
|
|
if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1
|
2012-06-26 06:37:24 +00:00
|
|
|
|| cli_arg(argc, argv, o, "exec path", &execpath, cli_absolute_path, NULL) == -1)
|
|
|
|
return -1;
|
2012-07-29 09:28:41 +00:00
|
|
|
if (instancepath != NULL)
|
|
|
|
serval_setinstancepath(instancepath);
|
2012-07-24 06:09:36 +00:00
|
|
|
if (execpath == NULL) {
|
2012-08-10 07:24:42 +00:00
|
|
|
#ifdef HAVE_JNI_H
|
2012-07-24 06:09:36 +00:00
|
|
|
if (jni_env)
|
|
|
|
return WHY("Must supply <exec path> argument when invoked via JNI");
|
2012-08-10 07:24:42 +00:00
|
|
|
#endif
|
2012-08-20 05:31:07 +00:00
|
|
|
if ((tmp = malloc(PATH_MAX)) == NULL)
|
2012-10-08 06:43:17 +00:00
|
|
|
return WHY("Out of memory");
|
2012-08-20 05:31:07 +00:00
|
|
|
if (get_self_executable_path(tmp, PATH_MAX) == -1)
|
|
|
|
return WHY("unable to determine own executable name");
|
|
|
|
execpath = tmp;
|
2012-07-24 06:09:36 +00:00
|
|
|
}
|
2012-03-29 04:33:17 +00:00
|
|
|
/* Create the instance directory if it does not yet exist */
|
2012-06-26 06:37:24 +00:00
|
|
|
if (create_serval_instance_dir() == -1)
|
2012-03-29 04:33:17 +00:00
|
|
|
return -1;
|
2012-03-19 03:56:14 +00:00
|
|
|
/* Now that we know our instance path, we can ask for the default set of
|
|
|
|
network interfaces that we will take interest in. */
|
2012-06-26 06:37:24 +00:00
|
|
|
const char *interfaces = confValueGet("interfaces", "");
|
2012-05-07 04:19:38 +00:00
|
|
|
if (!interfaces[0])
|
|
|
|
WHY("No network interfaces configured (empty 'interfaces' config setting)");
|
|
|
|
overlay_interface_args(interfaces);
|
2012-06-26 06:37:24 +00:00
|
|
|
if (pid == -1)
|
|
|
|
pid = server_pid();
|
2012-05-07 04:19:38 +00:00
|
|
|
if (pid < 0)
|
2012-06-26 06:37:24 +00:00
|
|
|
return -1;
|
|
|
|
int ret = -1;
|
2012-07-24 06:09:36 +00:00
|
|
|
// If the pidfile identifies this process, it probably means we are re-spawning after a SEGV, so
|
|
|
|
// go ahead and do the fork/exec.
|
|
|
|
if (pid > 0 && pid != getpid()) {
|
2012-06-28 08:04:21 +00:00
|
|
|
INFOF("Server already running (pid=%d)", pid);
|
2012-06-26 06:37:24 +00:00
|
|
|
ret = 10;
|
|
|
|
} else {
|
2012-07-27 10:29:16 +00:00
|
|
|
if (foregroundP)
|
|
|
|
INFOF("Foreground server process %s", execpath ? execpath : "without exec");
|
|
|
|
else
|
|
|
|
INFOF("Starting background server %s", execpath ? execpath : "without exec");
|
2012-06-26 06:37:24 +00:00
|
|
|
/* Start the Serval process. All server settings will be read by the server process from the
|
|
|
|
instance directory when it starts up. */
|
|
|
|
if (server_remove_stopfile() == -1)
|
|
|
|
return -1;
|
2012-10-04 10:34:49 +00:00
|
|
|
if (rhizome_enabled() && rhizome_opendb() == -1)
|
2012-06-26 06:37:24 +00:00
|
|
|
return -1;
|
|
|
|
overlayMode = 1;
|
|
|
|
if (foregroundP)
|
|
|
|
return server(NULL);
|
2012-10-08 06:43:17 +00:00
|
|
|
const char *dir = getenv("SERVALD_SERVER_CHDIR");
|
|
|
|
if (!dir)
|
|
|
|
dir = confValueGet("server.chdir", "/");
|
|
|
|
switch (cpid = fork()) {
|
2012-06-26 06:37:24 +00:00
|
|
|
case -1:
|
2012-06-26 07:57:19 +00:00
|
|
|
/* Main process. Fork failed. There is no child process. */
|
2012-06-26 06:37:24 +00:00
|
|
|
return WHY_perror("fork");
|
|
|
|
case 0: {
|
2012-10-08 06:43:17 +00:00
|
|
|
/* Child process. Fork then exit, to disconnect daemon from parent process, so that
|
|
|
|
when daemon exits it does not live on as a zombie. N.B. Do not return from within this
|
|
|
|
process; that will unroll the JNI call stack and cause havoc. Use _exit(). */
|
|
|
|
switch (fork()) {
|
|
|
|
case -1:
|
|
|
|
exit(WHY_perror("fork"));
|
|
|
|
case 0: {
|
|
|
|
/* Grandchild process. Close logfile (so that it gets re-opened again on demand, with
|
|
|
|
our own file pointer), disconnect from current directory, disconnect standard I/O
|
|
|
|
streams, and start a new process session so that if we are being started by an adb
|
|
|
|
shell session, then we don't receive a SIGHUP when the adb shell process ends. */
|
|
|
|
close_logging();
|
|
|
|
int fd;
|
|
|
|
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
|
|
|
|
_exit(WHY_perror("open"));
|
|
|
|
if (setsid() == -1)
|
|
|
|
_exit(WHY_perror("setsid"));
|
|
|
|
(void)chdir(dir);
|
|
|
|
(void)dup2(fd, 0);
|
|
|
|
(void)dup2(fd, 1);
|
|
|
|
(void)dup2(fd, 2);
|
|
|
|
if (fd > 2)
|
|
|
|
(void)close(fd);
|
|
|
|
/* The execpath option is provided so that a JNI call to "start" can be made which
|
|
|
|
creates a new server daemon process with the correct argv[0]. Otherwise, the servald
|
|
|
|
process appears as a process with argv[0] = "org.servalproject". */
|
|
|
|
if (execpath) {
|
|
|
|
/* Need the cast on Solaris because it defines NULL as 0L and gcc doesn't see it as a
|
|
|
|
sentinal. */
|
|
|
|
execl(execpath, execpath, "start", "foreground", (void *)NULL);
|
|
|
|
_exit(-1);
|
|
|
|
}
|
|
|
|
_exit(server(NULL));
|
|
|
|
// NOT REACHED
|
|
|
|
}
|
2012-06-26 06:37:24 +00:00
|
|
|
}
|
2012-10-08 06:43:17 +00:00
|
|
|
_exit(0); // Main process is waitpid()-ing for this.
|
2012-06-26 06:37:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-08 06:43:17 +00:00
|
|
|
/* Main process. Wait for the child process to fork the grandchild and exit. */
|
|
|
|
waitpid(cpid, NULL, 0);
|
|
|
|
/* Allow a few seconds for the grandchild process to report for duty. */
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t timeout = gettime_ms() + 5000;
|
2012-06-26 06:37:24 +00:00
|
|
|
do {
|
2012-09-05 09:23:22 +00:00
|
|
|
sleep_ms(200); // 5 Hz
|
2012-06-26 06:37:24 +00:00
|
|
|
} while ((pid = server_pid()) == 0 && gettime_ms() < timeout);
|
|
|
|
if (pid == -1)
|
|
|
|
return -1;
|
|
|
|
if (pid == 0)
|
|
|
|
return WHY("Server process did not start");
|
|
|
|
ret = 0;
|
2012-03-19 03:56:14 +00:00
|
|
|
}
|
2012-05-07 09:21:05 +00:00
|
|
|
cli_puts("instancepath");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(serval_instancepath());
|
|
|
|
cli_delim("\n");
|
2012-06-26 06:37:24 +00:00
|
|
|
cli_puts("pid");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%d", pid);
|
|
|
|
cli_delim("\n");
|
2012-10-08 06:43:17 +00:00
|
|
|
cli_flush();
|
|
|
|
/* Sleep before returning if env var is set. This is used in testing, to simulate the situation
|
|
|
|
on Android phones where the "start" command is invoked via the JNI interface and the calling
|
|
|
|
process does not die.
|
|
|
|
*/
|
|
|
|
const char *post_sleep = getenv("SERVALD_START_POST_SLEEP");
|
|
|
|
if (post_sleep) {
|
|
|
|
time_ms_t milliseconds = atof(post_sleep) * 1000;
|
|
|
|
if (milliseconds > 0) {
|
|
|
|
INFOF("Sleeping for %lld milliseconds", (long long) milliseconds);
|
|
|
|
sleep_ms(milliseconds);
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 06:37:24 +00:00
|
|
|
return ret;
|
2012-02-16 14:36:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_server_stop(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-06-26 06:37:24 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-22 06:24:14 +00:00
|
|
|
int pid, tries, running;
|
|
|
|
const char *instancepath;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t timeout;
|
2012-07-29 09:28:41 +00:00
|
|
|
if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1)
|
2012-06-22 06:24:14 +00:00
|
|
|
return WHY("Unable to determine instance path");
|
2012-07-29 09:28:41 +00:00
|
|
|
if (instancepath != NULL)
|
|
|
|
serval_setinstancepath(instancepath);
|
2012-06-22 06:24:14 +00:00
|
|
|
instancepath = serval_instancepath();
|
2012-05-07 04:19:38 +00:00
|
|
|
cli_puts("instancepath");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(instancepath);
|
|
|
|
cli_delim("\n");
|
2012-06-22 06:24:14 +00:00
|
|
|
pid = server_pid();
|
|
|
|
/* Not running, nothing to stop */
|
2012-05-08 05:14:15 +00:00
|
|
|
if (pid <= 0)
|
|
|
|
return 1;
|
2012-06-28 08:04:21 +00:00
|
|
|
INFOF("Stopping server (pid=%d)", pid);
|
2012-06-22 06:24:14 +00:00
|
|
|
/* Set the stop file and signal the process */
|
2012-05-08 05:14:15 +00:00
|
|
|
cli_puts("pid");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%d", pid);
|
|
|
|
cli_delim("\n");
|
2012-06-22 06:24:14 +00:00
|
|
|
tries = 0;
|
|
|
|
running = pid;
|
2012-05-08 05:14:15 +00:00
|
|
|
while (running == pid) {
|
|
|
|
if (tries >= 5)
|
|
|
|
return WHYF(
|
2012-05-08 07:03:51 +00:00
|
|
|
"Servald pid=%d for instance '%s' did not stop after %d SIGHUP signals",
|
|
|
|
pid, instancepath, tries
|
2012-05-08 05:14:15 +00:00
|
|
|
);
|
|
|
|
++tries;
|
|
|
|
/* Create the stopfile, which causes the server process's signal handler to exit
|
2012-06-26 06:37:24 +00:00
|
|
|
instead of restarting. */
|
2012-05-08 05:14:15 +00:00
|
|
|
server_create_stopfile();
|
|
|
|
if (kill(pid, SIGHUP) == -1) {
|
|
|
|
// ESRCH means process is gone, possibly we are racing with another stop, or servald just
|
|
|
|
// died voluntarily.
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
serverCleanUp();
|
|
|
|
break;
|
2012-03-04 22:57:31 +00:00
|
|
|
}
|
2012-05-08 07:03:51 +00:00
|
|
|
WHY_perror("kill");
|
|
|
|
return WHYF("Error sending SIGHUP to Servald pid=%d for instance '%s'", pid, instancepath);
|
2012-03-04 22:57:31 +00:00
|
|
|
}
|
2012-05-08 05:14:15 +00:00
|
|
|
/* Allow a few seconds for the process to die. */
|
2012-06-22 06:24:14 +00:00
|
|
|
timeout = gettime_ms() + 2000;
|
2012-08-21 04:04:29 +00:00
|
|
|
do
|
|
|
|
sleep_ms(200); // 5 Hz
|
|
|
|
while ((running = server_pid()) == pid && gettime_ms() < timeout);
|
2012-05-07 04:19:38 +00:00
|
|
|
}
|
2012-05-08 05:14:15 +00:00
|
|
|
server_remove_stopfile();
|
|
|
|
cli_puts("tries");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%d", tries);
|
|
|
|
cli_delim("\n");
|
|
|
|
return 0;
|
2012-02-16 14:36:08 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_server_status(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-06-26 06:37:24 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-22 06:24:14 +00:00
|
|
|
int pid;
|
2012-07-29 09:28:41 +00:00
|
|
|
const char *instancepath;
|
|
|
|
if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1)
|
2012-06-22 06:24:14 +00:00
|
|
|
return WHY("Unable to determine instance path");
|
2012-07-29 09:28:41 +00:00
|
|
|
if (instancepath != NULL)
|
|
|
|
serval_setinstancepath(instancepath);
|
2012-06-22 06:24:14 +00:00
|
|
|
pid = server_pid();
|
2012-05-07 04:19:38 +00:00
|
|
|
cli_puts("instancepath");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(serval_instancepath());
|
|
|
|
cli_delim("\n");
|
2012-05-21 11:15:07 +00:00
|
|
|
cli_puts("status");
|
|
|
|
cli_delim(":");
|
2012-06-22 06:24:14 +00:00
|
|
|
cli_printf("%s", pid > 0 ? "running" : "stopped");
|
2012-05-21 11:15:07 +00:00
|
|
|
cli_delim("\n");
|
2012-06-22 06:24:14 +00:00
|
|
|
if (pid > 0) {
|
2012-05-07 04:19:38 +00:00
|
|
|
cli_puts("pid");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%d", pid);
|
|
|
|
cli_delim("\n");
|
2012-02-23 01:25:39 +00:00
|
|
|
}
|
2012-05-07 04:19:38 +00:00
|
|
|
return pid > 0 ? 0 : 1;
|
2012-02-16 14:05:28 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-03-18 22:57:06 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-09-19 00:18:12 +00:00
|
|
|
const char *sid, *count;
|
2012-07-12 06:44:25 +00:00
|
|
|
if (cli_arg(argc, argv, o, "SID|broadcast", &sid, str_is_subscriber_id, "broadcast") == -1)
|
2012-04-19 08:33:04 +00:00
|
|
|
return -1;
|
2012-09-19 00:18:12 +00:00
|
|
|
if (cli_arg(argc, argv, o, "count", &count, NULL, "0") == -1)
|
|
|
|
return -1;
|
|
|
|
|
2012-09-19 04:46:06 +00:00
|
|
|
// assume we wont hear any responses
|
|
|
|
int ret=-1;
|
2012-09-19 00:18:12 +00:00
|
|
|
int icount=atoi(count);
|
2012-03-18 22:57:06 +00:00
|
|
|
|
2012-03-19 05:36:34 +00:00
|
|
|
overlay_mdp_frame mdp;
|
2012-09-28 01:58:01 +00:00
|
|
|
bzero(&mdp, sizeof(overlay_mdp_frame));
|
2012-03-19 05:36:34 +00:00
|
|
|
/* Bind to MDP socket and await confirmation */
|
2012-03-27 09:15:52 +00:00
|
|
|
unsigned char srcsid[SID_SIZE];
|
2012-04-25 05:54:21 +00:00
|
|
|
int port=32768+(random()&32767);
|
|
|
|
if (overlay_mdp_getmyaddr(0,srcsid)) return WHY("Could not get local address");
|
|
|
|
if (overlay_mdp_bind(srcsid,port)) return WHY("Could not bind to MDP socket");
|
2012-03-18 22:57:06 +00:00
|
|
|
|
2012-03-20 16:57:47 +00:00
|
|
|
/* First sequence number in the echo frames */
|
|
|
|
unsigned int firstSeq=random();
|
|
|
|
unsigned int sequence_number=firstSeq;
|
|
|
|
|
2012-03-27 08:55:38 +00:00
|
|
|
/* Get SID that we want to ping.
|
2012-03-28 02:56:14 +00:00
|
|
|
XXX - allow lookup of SID prefixes and telephone numbers
|
|
|
|
(that would require MDP lookup of phone numbers, which doesn't yet occur) */
|
2012-03-20 17:25:13 +00:00
|
|
|
int i;
|
2012-04-13 17:07:50 +00:00
|
|
|
int broadcast=0;
|
2012-03-20 17:25:13 +00:00
|
|
|
unsigned char ping_sid[SID_SIZE];
|
|
|
|
if (strcasecmp(sid,"broadcast")) {
|
|
|
|
stowSid(ping_sid,0,sid);
|
|
|
|
} else {
|
|
|
|
for(i=0;i<SID_SIZE;i++) ping_sid[i]=0xff;
|
2012-04-13 17:07:50 +00:00
|
|
|
broadcast=1;
|
2012-03-20 17:25:13 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 02:56:14 +00:00
|
|
|
/* XXX Eventually we should try to resolve SID to phone number and vice versa */
|
2012-07-03 08:29:30 +00:00
|
|
|
printf("MDP PING %s (%s): 12 data bytes\n", alloca_tohex_sid(ping_sid), alloca_tohex_sid(ping_sid));
|
2012-03-28 02:56:14 +00:00
|
|
|
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t rx_mintime=-1;
|
|
|
|
time_ms_t rx_maxtime=-1;
|
|
|
|
time_ms_t rx_ms=0;
|
|
|
|
time_ms_t rx_times[1024];
|
2012-03-29 10:00:17 +00:00
|
|
|
long long rx_count=0,tx_count=0;
|
|
|
|
|
2012-04-15 21:36:22 +00:00
|
|
|
if (broadcast)
|
2012-05-03 05:08:30 +00:00
|
|
|
WHY("WARNING: broadcast ping packets will not be encryped.");
|
2012-09-19 00:18:12 +00:00
|
|
|
while(icount==0 || tx_count<icount) {
|
2012-03-20 16:57:47 +00:00
|
|
|
/* Now send the ping packets */
|
2012-04-13 17:07:50 +00:00
|
|
|
mdp.packetTypeAndFlags=MDP_TX;
|
2012-04-15 21:36:22 +00:00
|
|
|
if (broadcast) mdp.packetTypeAndFlags|=MDP_NOCRYPT;
|
2012-03-27 09:15:52 +00:00
|
|
|
mdp.out.src.port=port;
|
|
|
|
bcopy(srcsid,mdp.out.src.sid,SID_SIZE);
|
2012-10-09 06:33:17 +00:00
|
|
|
bcopy(ping_sid,mdp.out.dst.sid,SID_SIZE);
|
2012-10-09 05:39:33 +00:00
|
|
|
mdp.out.queue=OQ_MESH_MANAGEMENT;
|
2012-10-09 06:33:17 +00:00
|
|
|
/* Set port to well known echo port */
|
|
|
|
mdp.out.dst.port=MDP_PORT_ECHO;
|
2012-03-28 02:46:06 +00:00
|
|
|
mdp.out.payload_length=4+8;
|
2012-03-20 16:57:47 +00:00
|
|
|
int *seq=(int *)&mdp.out.payload;
|
|
|
|
*seq=sequence_number;
|
2012-03-28 02:46:06 +00:00
|
|
|
long long *txtime=(long long *)&mdp.out.payload[4];
|
2012-07-30 07:52:38 +00:00
|
|
|
*txtime=gettime_ms();
|
2012-03-20 16:57:47 +00:00
|
|
|
|
2012-03-28 02:40:55 +00:00
|
|
|
int res=overlay_mdp_send(&mdp,0,0);
|
2012-03-20 16:57:47 +00:00
|
|
|
if (res) {
|
2012-05-03 05:08:30 +00:00
|
|
|
WHYF("ERROR: Could not dispatch PING frame #%d (error %d)", sequence_number - firstSeq, res);
|
|
|
|
if (mdp.packetTypeAndFlags==MDP_ERROR)
|
|
|
|
WHYF(" Error message: %s", mdp.error.message);
|
2012-03-29 10:00:17 +00:00
|
|
|
} else tx_count++;
|
2012-03-20 16:57:47 +00:00
|
|
|
|
|
|
|
/* Now look for replies until one second has passed, and print any replies
|
|
|
|
with appropriate information as required */
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t now = gettime_ms();
|
|
|
|
time_ms_t timeout = now + 1000;
|
2012-03-20 16:57:47 +00:00
|
|
|
|
|
|
|
while(now<timeout) {
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t timeout_ms = timeout - gettime_ms();
|
2012-04-25 05:54:21 +00:00
|
|
|
int result = overlay_mdp_client_poll(timeout_ms);
|
2012-03-20 16:57:47 +00:00
|
|
|
|
|
|
|
if (result>0) {
|
2012-03-20 17:25:13 +00:00
|
|
|
int ttl=-1;
|
2012-10-02 06:43:12 +00:00
|
|
|
if (overlay_mdp_recv(&mdp, port, &ttl)==0) {
|
2012-03-20 17:25:13 +00:00
|
|
|
switch(mdp.packetTypeAndFlags&MDP_TYPE_MASK) {
|
|
|
|
case MDP_ERROR:
|
2012-05-03 05:08:30 +00:00
|
|
|
WHYF("mdpping: overlay_mdp_recv: %s (code %d)", mdp.error.message, mdp.error.error);
|
2012-03-20 17:25:13 +00:00
|
|
|
break;
|
2012-04-25 11:03:25 +00:00
|
|
|
case MDP_TX:
|
2012-03-28 02:46:06 +00:00
|
|
|
{
|
|
|
|
int *rxseq=(int *)&mdp.in.payload;
|
|
|
|
long long *txtime=(long long *)&mdp.in.payload[4];
|
2012-10-10 05:52:31 +00:00
|
|
|
int hop_count = 64 - mdp.in.ttl;
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t delay = gettime_ms() - *txtime;
|
2012-10-10 05:52:31 +00:00
|
|
|
printf("%s: seq=%d time=%lld hops=%d ms%s%s\n",
|
|
|
|
alloca_tohex_sid(mdp.in.src.sid),
|
|
|
|
(*rxseq)-firstSeq+1,
|
|
|
|
delay,
|
|
|
|
hop_count,
|
2012-04-14 13:48:18 +00:00
|
|
|
mdp.packetTypeAndFlags&MDP_NOCRYPT?"":" ENCRYPTED",
|
|
|
|
mdp.packetTypeAndFlags&MDP_NOSIGN?"":" SIGNED");
|
2012-06-25 05:36:35 +00:00
|
|
|
// TODO Put duplicate pong detection here so that stats work properly.
|
2012-03-29 10:00:17 +00:00
|
|
|
rx_count++;
|
2012-09-19 04:46:06 +00:00
|
|
|
ret=0;
|
2012-03-29 10:00:17 +00:00
|
|
|
rx_ms+=delay;
|
|
|
|
if (rx_mintime>delay||rx_mintime==-1) rx_mintime=delay;
|
|
|
|
if (delay>rx_maxtime) rx_maxtime=delay;
|
|
|
|
rx_times[rx_count%1024]=delay;
|
2012-03-28 02:46:06 +00:00
|
|
|
}
|
2012-03-20 17:25:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-05-03 05:08:30 +00:00
|
|
|
WHYF("mdpping: overlay_mdp_recv: Unexpected MDP frame type 0x%x", mdp.packetTypeAndFlags);
|
2012-03-20 17:25:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-20 16:57:47 +00:00
|
|
|
}
|
2012-07-30 07:52:38 +00:00
|
|
|
now=gettime_ms();
|
2012-09-19 04:46:06 +00:00
|
|
|
if (servalShutdown)
|
|
|
|
break;
|
2012-03-20 16:57:47 +00:00
|
|
|
}
|
2012-03-28 02:40:55 +00:00
|
|
|
sequence_number++;
|
2012-03-20 16:57:47 +00:00
|
|
|
timeout=now+1000;
|
|
|
|
}
|
|
|
|
|
2012-09-19 04:46:06 +00:00
|
|
|
{
|
|
|
|
float rx_stddev=0;
|
|
|
|
float rx_mean=rx_ms*1.0/rx_count;
|
|
|
|
int samples=rx_count;
|
|
|
|
if (samples>1024) samples=1024;
|
|
|
|
int i;
|
|
|
|
for(i=0;i<samples;i++)
|
|
|
|
rx_stddev+=(rx_mean-rx_times[i])*(rx_mean-rx_times[i]);
|
|
|
|
rx_stddev/=samples;
|
|
|
|
rx_stddev=sqrtf(rx_stddev);
|
|
|
|
|
|
|
|
/* XXX Report final statistics before going */
|
|
|
|
printf("--- %s ping statistics ---\n", alloca_tohex_sid(ping_sid));
|
|
|
|
printf("%lld packets transmitted, %lld packets received, %3.1f%% packet loss\n",
|
|
|
|
tx_count,rx_count,tx_count?(tx_count-rx_count)*100.0/tx_count:0);
|
|
|
|
printf("round-trip min/avg/max/stddev%s = %lld/%.3f/%lld/%.3f ms\n",
|
|
|
|
(samples<rx_count)?" (stddev calculated from last 1024 samples)":"",
|
|
|
|
rx_mintime,rx_mean,rx_maxtime,rx_stddev);
|
|
|
|
}
|
2012-04-30 10:34:07 +00:00
|
|
|
overlay_mdp_client_done();
|
2012-09-19 04:46:06 +00:00
|
|
|
return ret;
|
2012-03-18 22:57:06 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_config_set(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-03-29 04:51:30 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *var, *val;
|
2012-07-04 09:27:02 +00:00
|
|
|
if ( cli_arg(argc, argv, o, "variable", &var, is_configvarname, NULL)
|
2012-04-19 08:33:04 +00:00
|
|
|
|| cli_arg(argc, argv, o, "value", &val, NULL, ""))
|
|
|
|
return -1;
|
2012-03-29 04:51:30 +00:00
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-07-04 09:27:02 +00:00
|
|
|
return confValueSet(var, val) == -1 ? -1 : confWrite();
|
2012-03-29 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_config_del(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-03-29 04:51:30 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *var;
|
2012-07-04 09:27:02 +00:00
|
|
|
if (cli_arg(argc, argv, o, "variable", &var, is_configvarname, NULL))
|
2012-04-19 08:33:04 +00:00
|
|
|
return -1;
|
2012-04-12 08:10:00 +00:00
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-07-04 09:27:02 +00:00
|
|
|
return confValueSet(var, NULL) == -1 ? -1 : confWrite();
|
2012-03-29 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_config_get(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-03-29 04:51:30 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *var;
|
2012-07-04 09:27:02 +00:00
|
|
|
if (cli_arg(argc, argv, o, "variable", &var, is_configvarname, NULL) == -1)
|
2012-04-19 08:33:04 +00:00
|
|
|
return -1;
|
2012-04-12 08:10:00 +00:00
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-07-04 09:27:02 +00:00
|
|
|
if (var) {
|
|
|
|
const char *value = confValueGet(var, NULL);
|
|
|
|
if (value) {
|
|
|
|
cli_puts(var);
|
|
|
|
cli_delim("=");
|
|
|
|
cli_puts(value);
|
|
|
|
cli_delim("\n");
|
2012-03-29 07:21:59 +00:00
|
|
|
}
|
2012-07-04 09:27:02 +00:00
|
|
|
} else {
|
|
|
|
int n = confVarCount();
|
|
|
|
if (n == -1)
|
|
|
|
return -1;
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i != n; ++i) {
|
|
|
|
cli_puts(confVar(i));
|
|
|
|
cli_delim("=");
|
|
|
|
cli_puts(confValue(i));
|
|
|
|
cli_delim("\n");
|
2012-03-29 04:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_hash_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-05-21 03:46:44 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-05-25 15:20:48 +00:00
|
|
|
/* compute hash of file. We do this without a manifest, so it will necessarily
|
|
|
|
return the hash of the file unencrypted. */
|
2012-05-21 03:46:44 +00:00
|
|
|
const char *filepath;
|
|
|
|
cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
|
2012-05-23 06:34:00 +00:00
|
|
|
char hexhash[RHIZOME_FILEHASH_STRLEN + 1];
|
2012-05-25 15:20:48 +00:00
|
|
|
if (rhizome_hash_file(NULL,filepath, hexhash))
|
2012-05-21 03:46:44 +00:00
|
|
|
return -1;
|
|
|
|
cli_puts(hexhash);
|
|
|
|
cli_delim("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-03-29 07:21:59 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-08 05:57:15 +00:00
|
|
|
const char *filepath, *manifestpath, *authorSidHex, *pin, *bskhex;
|
2012-04-19 08:33:04 +00:00
|
|
|
cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
|
2012-06-08 05:57:15 +00:00
|
|
|
if (cli_arg(argc, argv, o, "author_sid", &authorSidHex, cli_optional_sid, "") == -1)
|
2012-06-05 04:28:59 +00:00
|
|
|
return -1;
|
2012-05-17 02:30:03 +00:00
|
|
|
cli_arg(argc, argv, o, "pin", &pin, NULL, "");
|
2012-04-19 08:33:04 +00:00
|
|
|
cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "");
|
2012-06-05 04:28:59 +00:00
|
|
|
if (cli_arg(argc, argv, o, "bsk", &bskhex, cli_optional_bundle_key, "") == -1)
|
|
|
|
return -1;
|
2012-06-08 05:57:15 +00:00
|
|
|
unsigned char authorSid[SID_SIZE];
|
|
|
|
if (authorSidHex[0] && fromhexstr(authorSid, authorSidHex, SID_SIZE) == -1)
|
|
|
|
return WHYF("invalid author_sid: %s", authorSidHex);
|
|
|
|
unsigned char bsk[RHIZOME_BUNDLE_KEY_BYTES];
|
|
|
|
if (bskhex[0] && fromhexstr(bsk, bskhex, RHIZOME_BUNDLE_KEY_BYTES) == -1)
|
|
|
|
return WHYF("invalid bsk: %s", bskhex);
|
2012-04-02 08:12:40 +00:00
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-05-20 05:55:19 +00:00
|
|
|
if (!(keyring = keyring_open_with_pins((char *)pin)))
|
2012-05-19 04:39:50 +00:00
|
|
|
return -1;
|
2012-05-18 09:23:27 +00:00
|
|
|
if (rhizome_opendb() == -1)
|
|
|
|
return -1;
|
2012-04-10 08:42:17 +00:00
|
|
|
/* Create a new manifest that will represent the file. If a manifest file was supplied, then read
|
|
|
|
* it, otherwise create a blank manifest. */
|
2012-05-25 06:08:13 +00:00
|
|
|
rhizome_manifest *m = rhizome_new_manifest();
|
|
|
|
if (!m)
|
|
|
|
return WHY("Manifest struct could not be allocated -- not added to rhizome");
|
2012-05-19 04:39:50 +00:00
|
|
|
if (manifestpath[0] && access(manifestpath, R_OK) == 0) {
|
2012-05-20 14:39:14 +00:00
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("reading manifest from %s", manifestpath);
|
2012-05-25 23:54:47 +00:00
|
|
|
/* Don't verify the manifest, because it will fail if it is incomplete.
|
|
|
|
This is okay, because we fill in any missing bits and sanity check before
|
|
|
|
trying to write it out. */
|
|
|
|
if (rhizome_read_manifest_file(m, manifestpath, 0) == -1) {
|
2012-05-25 06:08:13 +00:00
|
|
|
rhizome_manifest_free(m);
|
2012-04-13 08:17:20 +00:00
|
|
|
return WHY("Manifest file could not be loaded -- not added to rhizome");
|
2012-05-25 06:08:13 +00:00
|
|
|
}
|
2012-04-10 08:42:17 +00:00
|
|
|
} else {
|
2012-05-25 06:08:13 +00:00
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("manifest file %s does not exist -- creating new manifest", manifestpath);
|
2012-04-10 08:42:17 +00:00
|
|
|
}
|
2012-04-13 08:17:20 +00:00
|
|
|
/* Fill in a few missing manifest fields, to make it easier to use when adding new files:
|
2012-05-20 06:37:22 +00:00
|
|
|
- the default service is FILE
|
|
|
|
- use the current time for "date"
|
|
|
|
- if service is file, then use the payload file's basename for "name"
|
2012-04-13 08:17:20 +00:00
|
|
|
*/
|
2012-05-17 06:39:57 +00:00
|
|
|
const char *service = rhizome_manifest_get(m, "service", NULL, 0);
|
|
|
|
if (service == NULL) {
|
2012-05-20 06:37:22 +00:00
|
|
|
rhizome_manifest_set(m, "service", (service = RHIZOME_SERVICE_FILE));
|
2012-05-20 14:39:14 +00:00
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'service', set default service=%s", service);
|
|
|
|
} else {
|
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains service=%s", service);
|
2012-05-17 06:39:57 +00:00
|
|
|
}
|
2012-05-16 04:16:42 +00:00
|
|
|
if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) {
|
2012-08-09 02:44:32 +00:00
|
|
|
rhizome_manifest_set_ll(m, "date", (long long) gettime_ms());
|
2012-05-20 14:39:14 +00:00
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0));
|
2012-05-16 04:16:42 +00:00
|
|
|
}
|
2012-05-20 06:37:22 +00:00
|
|
|
if (strcasecmp(RHIZOME_SERVICE_FILE, service) == 0) {
|
2012-05-20 14:39:14 +00:00
|
|
|
const char *name = rhizome_manifest_get(m, "name", NULL, 0);
|
|
|
|
if (name == NULL) {
|
|
|
|
name = strrchr(filepath, '/');
|
2012-05-17 06:39:57 +00:00
|
|
|
name = name ? name + 1 : filepath;
|
|
|
|
rhizome_manifest_set(m, "name", name);
|
2012-05-20 14:39:14 +00:00
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'name', set default name=\"%s\"", name);
|
|
|
|
} else {
|
|
|
|
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains name=\"%s\"", name);
|
2012-05-17 06:39:57 +00:00
|
|
|
}
|
2012-04-10 08:42:17 +00:00
|
|
|
}
|
2012-06-12 02:18:15 +00:00
|
|
|
/* If the author was not specified on the command-line, then the manifest's "sender"
|
|
|
|
field is used, if present. */
|
|
|
|
const char *sender = NULL;
|
|
|
|
if (!authorSidHex[0] && (sender = rhizome_manifest_get(m, "sender", NULL, 0)) != NULL) {
|
|
|
|
if (fromhexstr(authorSid, sender, SID_SIZE) == -1)
|
|
|
|
return WHYF("invalid sender: %s", sender);
|
|
|
|
authorSidHex = sender;
|
|
|
|
}
|
2012-06-05 04:28:59 +00:00
|
|
|
/* Bind an ID to the manifest, and also bind the file. Then finalise the manifest.
|
2012-05-25 23:01:23 +00:00
|
|
|
But if the manifest already contains an ID, don't override it. */
|
2012-10-09 07:13:34 +00:00
|
|
|
if (authorSidHex[0]) {
|
|
|
|
if (debug & DEBUG_RHIZOME)
|
|
|
|
DEBUGF("author=%s", authorSidHex);
|
|
|
|
memcpy(m->author, authorSid, SID_SIZE);
|
|
|
|
}
|
2012-06-08 05:57:15 +00:00
|
|
|
if (rhizome_manifest_get(m, "id", NULL, 0) == NULL) {
|
2012-10-09 07:13:34 +00:00
|
|
|
if (rhizome_manifest_bind_id(m) == -1) {
|
2012-06-05 04:28:59 +00:00
|
|
|
rhizome_manifest_free(m);
|
|
|
|
m = NULL;
|
2012-05-25 23:01:23 +00:00
|
|
|
return WHY("Could not bind manifest to an ID");
|
2012-05-26 02:25:56 +00:00
|
|
|
}
|
2012-06-05 04:28:59 +00:00
|
|
|
} else if (bskhex[0]) {
|
2012-06-12 02:18:15 +00:00
|
|
|
/* Modifying an existing bundle. If the caller provides the bundle secret key, then ensure that
|
|
|
|
it corresponds to the bundle's public key (its bundle ID), otherwise the caller cannot modify
|
|
|
|
the bundle. */
|
2012-06-05 04:28:59 +00:00
|
|
|
memcpy(m->cryptoSignSecret, bsk, RHIZOME_BUNDLE_KEY_BYTES);
|
|
|
|
if (rhizome_verify_bundle_privatekey(m) == -1) {
|
|
|
|
rhizome_manifest_free(m);
|
|
|
|
m = NULL;
|
|
|
|
return WHY("Incorrect BID secret key.");
|
|
|
|
}
|
2012-06-12 02:18:15 +00:00
|
|
|
} else if (!authorSidHex[0]) {
|
|
|
|
/* In order to modify an existing bundle, the author must be known. */
|
2012-06-08 05:57:15 +00:00
|
|
|
rhizome_manifest_free(m);
|
|
|
|
m = NULL;
|
|
|
|
return WHY("Author SID not specified");
|
2012-06-12 02:18:15 +00:00
|
|
|
} else if (rhizome_extract_privatekey(m, authorSid) == -1) {
|
|
|
|
/* Only the original author can modify an existing bundle. */
|
|
|
|
rhizome_manifest_free(m);
|
|
|
|
m = NULL;
|
|
|
|
return WHY("Could not extract BID secret key. Does the manifest have a BK?");
|
2012-05-26 02:25:56 +00:00
|
|
|
}
|
2012-06-25 05:36:35 +00:00
|
|
|
int encryptP = 0; // TODO Determine here whether payload is to be encrypted.
|
|
|
|
if (rhizome_manifest_bind_file(m, filepath, encryptP)) {
|
2012-05-26 02:25:56 +00:00
|
|
|
rhizome_manifest_free(m);
|
2012-05-25 15:20:48 +00:00
|
|
|
return WHYF("Could not bind manifest to file '%s'",filepath);
|
2012-05-26 02:25:56 +00:00
|
|
|
}
|
2012-10-02 23:25:04 +00:00
|
|
|
/* Add the manifest and its associated file to the Rhizome database,
|
|
|
|
generating an "id" in the process.
|
|
|
|
PGS @20121003 - Hang on, didn't we create the ID above? Presumably the
|
|
|
|
following does NOT in fact generate a bundle ID.
|
|
|
|
*/
|
2012-05-25 23:01:23 +00:00
|
|
|
int ret=0;
|
2012-10-09 07:13:34 +00:00
|
|
|
rhizome_manifest *mout = NULL;
|
|
|
|
if (rhizome_manifest_check_duplicate(m, &mout) == 2) {
|
|
|
|
/* duplicate found -- verify it so that we can write it out later */
|
|
|
|
rhizome_manifest_verify(mout);
|
|
|
|
ret=2;
|
|
|
|
} else {
|
2012-05-25 15:20:48 +00:00
|
|
|
/* not duplicate, so finalise and add to database */
|
|
|
|
if (rhizome_manifest_finalise(m)) {
|
|
|
|
rhizome_manifest_free(m);
|
|
|
|
return WHY("Could not finalise manifest");
|
|
|
|
}
|
2012-10-09 07:13:34 +00:00
|
|
|
if (rhizome_add_manifest(m, 255 /* TTL */)) {
|
2012-05-25 15:20:48 +00:00
|
|
|
rhizome_manifest_free(m);
|
|
|
|
return WHY("Manifest not added to Rhizome database");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 02:16:58 +00:00
|
|
|
/* If successfully added, overwrite the manifest file so that the Java component that is
|
|
|
|
invoking this command can read it to obtain feedback on the result. */
|
2012-10-09 07:13:34 +00:00
|
|
|
rhizome_manifest *mwritten = mout ? mout : m;
|
2012-05-25 15:20:48 +00:00
|
|
|
if (manifestpath[0]
|
|
|
|
&& rhizome_write_manifest_file(mwritten, manifestpath) == -1)
|
2012-04-16 02:16:58 +00:00
|
|
|
ret = WHY("Could not overwrite manifest file.");
|
2012-05-25 15:20:48 +00:00
|
|
|
service = rhizome_manifest_get(mwritten, "service", NULL, 0);
|
2012-05-17 06:39:57 +00:00
|
|
|
if (service) {
|
2012-07-16 09:01:00 +00:00
|
|
|
cli_puts("service");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(service);
|
|
|
|
cli_delim("\n");
|
2012-05-17 06:39:57 +00:00
|
|
|
}
|
2012-06-05 04:28:59 +00:00
|
|
|
{
|
|
|
|
char bid[RHIZOME_MANIFEST_ID_STRLEN + 1];
|
|
|
|
rhizome_bytes_to_hex_upper(mwritten->cryptoSignPublic, bid, RHIZOME_MANIFEST_ID_BYTES);
|
2012-07-16 09:01:00 +00:00
|
|
|
cli_puts("manifestid");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(bid);
|
|
|
|
cli_delim("\n");
|
2012-06-05 04:28:59 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
|
|
|
|
rhizome_bytes_to_hex_upper(mwritten->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
|
2012-07-16 09:01:00 +00:00
|
|
|
cli_puts("secret");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(secret);
|
|
|
|
cli_delim("\n");
|
|
|
|
}
|
|
|
|
cli_puts("filesize");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%lld", mwritten->fileLength);
|
|
|
|
cli_delim("\n");
|
|
|
|
if (mwritten->fileLength != 0) {
|
|
|
|
cli_puts("filehash");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(mwritten->fileHexHash);
|
|
|
|
cli_delim("\n");
|
2012-06-05 04:28:59 +00:00
|
|
|
}
|
2012-05-25 15:20:48 +00:00
|
|
|
const char *name = rhizome_manifest_get(mwritten, "name", NULL, 0);
|
2012-05-04 06:01:03 +00:00
|
|
|
if (name) {
|
2012-07-16 09:01:00 +00:00
|
|
|
cli_puts("name");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(name);
|
|
|
|
cli_delim("\n");
|
2012-05-04 06:01:03 +00:00
|
|
|
}
|
2012-04-02 08:12:40 +00:00
|
|
|
rhizome_manifest_free(m);
|
2012-04-13 08:17:20 +00:00
|
|
|
if (mout != m)
|
|
|
|
rhizome_manifest_free(mout);
|
2012-04-02 08:12:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_import_bundle(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-06-08 08:55:43 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-08 08:55:43 +00:00
|
|
|
const char *filepath, *manifestpath;
|
|
|
|
cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
|
|
|
|
cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "");
|
|
|
|
if (rhizome_opendb() == -1)
|
|
|
|
return -1;
|
2012-10-02 10:53:44 +00:00
|
|
|
int status=rhizome_import_from_files(manifestpath,filepath);
|
2012-06-08 08:55:43 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_extract_manifest(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-05-02 06:33:09 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-05-02 06:33:09 +00:00
|
|
|
const char *manifestid, *manifestpath;
|
2012-05-02 06:54:27 +00:00
|
|
|
if (cli_arg(argc, argv, o, "manifestid", &manifestid, cli_manifestid, NULL)
|
2012-05-25 02:22:49 +00:00
|
|
|
|| cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, NULL) == -1)
|
2012-05-02 06:54:27 +00:00
|
|
|
return -1;
|
2012-05-02 06:33:09 +00:00
|
|
|
/* Ensure the Rhizome database exists and is open */
|
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-05-18 09:23:27 +00:00
|
|
|
if (rhizome_opendb() == -1)
|
|
|
|
return -1;
|
2012-05-02 06:33:09 +00:00
|
|
|
/* Extract the manifest from the database */
|
|
|
|
rhizome_manifest *m = NULL;
|
2012-05-02 06:54:27 +00:00
|
|
|
int ret = rhizome_retrieve_manifest(manifestid, &m);
|
|
|
|
switch (ret) {
|
|
|
|
case 0: ret = 1; break;
|
|
|
|
case 1: ret = 0;
|
2012-05-25 02:22:49 +00:00
|
|
|
if (manifestpath) {
|
2012-05-16 06:25:03 +00:00
|
|
|
/* If the manifest has been read in from database, the blob is there,
|
|
|
|
and we can lie and say we are finalised and just want to write it
|
|
|
|
out. XXX really should have a dirty/clean flag, so that write
|
|
|
|
works is clean but not finalised. */
|
|
|
|
m->finalised=1;
|
|
|
|
if (rhizome_write_manifest_file(m, manifestpath) == -1)
|
2012-05-25 02:22:49 +00:00
|
|
|
ret = -1;
|
2012-05-02 06:33:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-05-02 06:54:27 +00:00
|
|
|
case -1: break;
|
|
|
|
default: ret = WHYF("Unsupported return value %d", ret); break;
|
2012-05-02 06:33:09 +00:00
|
|
|
}
|
|
|
|
if (m)
|
|
|
|
rhizome_manifest_free(m);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_extract_file(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-05-02 06:33:09 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-01 08:42:59 +00:00
|
|
|
const char *fileid, *filepath, *keyhex;
|
2012-05-02 08:27:35 +00:00
|
|
|
if (cli_arg(argc, argv, o, "fileid", &fileid, cli_fileid, NULL)
|
|
|
|
|| cli_arg(argc, argv, o, "filepath", &filepath, NULL, "") == -1)
|
|
|
|
return -1;
|
2012-06-05 04:28:59 +00:00
|
|
|
cli_arg(argc, argv, o, "key", &keyhex, cli_optional_bundle_crypt_key, "");
|
|
|
|
unsigned char key[RHIZOME_CRYPT_KEY_STRLEN + 1];
|
2012-06-08 05:57:15 +00:00
|
|
|
if (keyhex[0] && fromhexstr(key, keyhex, RHIZOME_CRYPT_KEY_BYTES) == -1)
|
2012-06-01 08:42:59 +00:00
|
|
|
return -1;
|
2012-05-02 08:27:35 +00:00
|
|
|
/* Ensure the Rhizome database exists and is open */
|
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-05-18 09:23:27 +00:00
|
|
|
if (rhizome_opendb() == -1)
|
|
|
|
return -1;
|
2012-05-26 04:12:33 +00:00
|
|
|
/* Extract the file from the database.
|
|
|
|
We don't provide a decryption key here, because we don't know it.
|
|
|
|
(We probably should allow the user to provide one).
|
|
|
|
*/
|
2012-06-05 04:28:59 +00:00
|
|
|
int ret = rhizome_retrieve_file(fileid, filepath, keyhex[0] ? key : NULL);
|
2012-05-02 08:27:35 +00:00
|
|
|
switch (ret) {
|
|
|
|
case 0: ret = 1; break;
|
|
|
|
case 1: ret = 0; break;
|
|
|
|
case -1: break;
|
|
|
|
default: ret = WHYF("Unsupported return value %d", ret); break;
|
|
|
|
}
|
|
|
|
return ret;
|
2012-05-02 06:33:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_rhizome_list(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-02 08:12:40 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-08 08:55:43 +00:00
|
|
|
const char *pin, *service, *sender_sid, *recipient_sid, *offset, *limit;
|
|
|
|
cli_arg(argc, argv, o, "pin,pin...", &pin, NULL, "");
|
2012-05-16 04:16:42 +00:00
|
|
|
cli_arg(argc, argv, o, "service", &service, NULL, "");
|
|
|
|
cli_arg(argc, argv, o, "sender_sid", &sender_sid, cli_optional_sid, "");
|
|
|
|
cli_arg(argc, argv, o, "recipient_sid", &recipient_sid, cli_optional_sid, "");
|
2012-04-19 08:33:04 +00:00
|
|
|
cli_arg(argc, argv, o, "offset", &offset, cli_uint, "0");
|
|
|
|
cli_arg(argc, argv, o, "limit", &limit, cli_uint, "0");
|
2012-04-02 08:12:40 +00:00
|
|
|
/* Create the instance directory if it does not yet exist */
|
|
|
|
if (create_serval_instance_dir() == -1)
|
|
|
|
return -1;
|
2012-06-08 08:55:43 +00:00
|
|
|
if (!(keyring = keyring_open_with_pins(pin)))
|
|
|
|
return -1;
|
2012-05-18 09:23:27 +00:00
|
|
|
if (rhizome_opendb() == -1)
|
|
|
|
return -1;
|
2012-05-16 04:16:42 +00:00
|
|
|
return rhizome_list_manifests(service, sender_sid, recipient_sid, atoi(offset), atoi(limit));
|
2012-03-29 07:21:59 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_keyring_create(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-12 04:30:51 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *pin;
|
2012-06-08 08:55:43 +00:00
|
|
|
cli_arg(argc, argv, o, "pin,pin...", &pin, NULL, "");
|
2012-05-19 01:08:29 +00:00
|
|
|
if (!keyring_open_with_pins(pin))
|
|
|
|
return -1;
|
2012-04-12 04:30:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_keyring_list(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-12 04:30:51 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *pin;
|
2012-06-08 08:55:43 +00:00
|
|
|
cli_arg(argc, argv, o, "pin,pin...", &pin, NULL, "");
|
2012-05-19 01:08:29 +00:00
|
|
|
keyring_file *k = keyring_open_with_pins(pin);
|
|
|
|
if (!k)
|
|
|
|
return -1;
|
2012-07-06 03:47:53 +00:00
|
|
|
int cn, in;
|
|
|
|
for (cn = 0; cn < k->context_count; ++cn)
|
|
|
|
for (in = 0; in < k->contexts[cn]->identity_count; ++in) {
|
|
|
|
const unsigned char *sid = NULL;
|
|
|
|
const char *did = NULL;
|
|
|
|
const char *name = NULL;
|
|
|
|
keyring_identity_extract(k->contexts[cn]->identities[in], &sid, &did, &name);
|
|
|
|
if (sid || did) {
|
|
|
|
if (sid) cli_printf("%s", alloca_tohex_sid(sid));
|
|
|
|
cli_delim(":");
|
|
|
|
if (did) cli_puts(did);
|
|
|
|
cli_delim(":");
|
|
|
|
if (name) cli_puts(name);
|
|
|
|
cli_delim("\n");
|
2012-04-12 04:30:51 +00:00
|
|
|
}
|
2012-07-06 03:47:53 +00:00
|
|
|
}
|
2012-04-12 04:30:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_keyring_add(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-12 04:30:51 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-23 07:42:10 +00:00
|
|
|
const char *pin;
|
2012-04-19 08:33:04 +00:00
|
|
|
cli_arg(argc, argv, o, "pin", &pin, NULL, "");
|
2012-05-19 01:08:29 +00:00
|
|
|
keyring_file *k = keyring_open_with_pins("");
|
|
|
|
if (!k)
|
|
|
|
return -1;
|
2012-07-06 03:47:53 +00:00
|
|
|
const keyring_identity *id = keyring_create_identity(k, k->contexts[0], pin);
|
|
|
|
if (id == NULL) {
|
|
|
|
keyring_free(k);
|
|
|
|
return WHY("Could not create new identity");
|
|
|
|
}
|
|
|
|
const unsigned char *sid = NULL;
|
|
|
|
const char *did = "";
|
|
|
|
const char *name = "";
|
|
|
|
keyring_identity_extract(id, &sid, &did, &name);
|
|
|
|
if (!sid) {
|
|
|
|
keyring_free(k);
|
|
|
|
return WHY("New identity has no SID");
|
|
|
|
}
|
|
|
|
if (keyring_commit(k) == -1) {
|
|
|
|
keyring_free(k);
|
|
|
|
return WHY("Could not write new identity");
|
|
|
|
}
|
|
|
|
cli_puts("sid");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%s", alloca_tohex_sid(sid));
|
|
|
|
cli_delim("\n");
|
|
|
|
if (did) {
|
|
|
|
cli_puts("did");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(did);
|
|
|
|
cli_delim("\n");
|
|
|
|
}
|
|
|
|
if (name) {
|
|
|
|
cli_puts("name");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_puts(name);
|
|
|
|
cli_delim("\n");
|
|
|
|
}
|
2012-04-12 04:30:51 +00:00
|
|
|
keyring_free(k);
|
|
|
|
return 0;
|
2012-04-12 13:45:21 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_keyring_set_did(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-12 13:45:21 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-05-01 05:08:09 +00:00
|
|
|
const char *sid, *did, *pin, *name;
|
2012-07-23 02:53:17 +00:00
|
|
|
cli_arg(argc, argv, o, "sid", &sid, str_is_subscriber_id, "");
|
2012-07-23 05:47:21 +00:00
|
|
|
cli_arg(argc, argv, o, "did", &did, cli_optional_did, "");
|
2012-05-01 05:08:09 +00:00
|
|
|
cli_arg(argc, argv, o, "name", &name, NULL, "");
|
2012-04-19 08:33:04 +00:00
|
|
|
cli_arg(argc, argv, o, "pin", &pin, NULL, "");
|
2012-04-12 13:45:21 +00:00
|
|
|
|
2012-05-01 05:08:09 +00:00
|
|
|
if (strlen(name)>63) return WHY("Name too long (31 char max)");
|
2012-04-12 04:30:51 +00:00
|
|
|
|
2012-06-08 08:55:43 +00:00
|
|
|
if (!(keyring = keyring_open_with_pins(pin)))
|
2012-05-19 01:08:29 +00:00
|
|
|
return -1;
|
2012-04-12 13:45:21 +00:00
|
|
|
|
|
|
|
unsigned char packedSid[SID_SIZE];
|
|
|
|
stowSid(packedSid,0,(char *)sid);
|
|
|
|
|
|
|
|
int cn=0,in=0,kp=0;
|
2012-04-27 04:47:41 +00:00
|
|
|
int r=keyring_find_sid(keyring,&cn,&in,&kp,packedSid);
|
2012-04-12 13:45:21 +00:00
|
|
|
if (!r) return WHY("No matching SID");
|
2012-05-01 05:08:09 +00:00
|
|
|
if (keyring_set_did(keyring->contexts[cn]->identities[in],
|
|
|
|
(char *)did,(char *)name))
|
2012-04-12 13:45:21 +00:00
|
|
|
return WHY("Could not set DID");
|
2012-04-27 04:47:41 +00:00
|
|
|
if (keyring_commit(keyring))
|
2012-04-12 13:45:21 +00:00
|
|
|
return WHY("Could not write updated keyring record");
|
|
|
|
|
|
|
|
return 0;
|
2012-04-12 04:30:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_id_self(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-25 20:18:06 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-25 20:18:06 +00:00
|
|
|
/* List my own identities */
|
|
|
|
overlay_mdp_frame a;
|
2012-09-28 01:58:01 +00:00
|
|
|
bzero(&a, sizeof(overlay_mdp_frame));
|
2012-04-25 20:24:54 +00:00
|
|
|
int result;
|
2012-04-26 20:28:31 +00:00
|
|
|
int count=0;
|
2012-04-25 20:18:06 +00:00
|
|
|
|
|
|
|
a.packetTypeAndFlags=MDP_GETADDRS;
|
2012-04-25 20:36:04 +00:00
|
|
|
if (!strcasecmp(argv[1],"self"))
|
2012-07-04 02:36:15 +00:00
|
|
|
a.addrlist.mode = MDP_ADDRLIST_MODE_SELF; /* get own identities */
|
|
|
|
else if (!strcasecmp(argv[1],"allpeers"))
|
|
|
|
a.addrlist.mode = MDP_ADDRLIST_MODE_ALL_PEERS; /* get all known peers */
|
|
|
|
else if (!strcasecmp(argv[1],"peers"))
|
|
|
|
a.addrlist.mode = MDP_ADDRLIST_MODE_ROUTABLE_PEERS; /* get routable (reachable) peers */
|
2012-04-25 20:36:04 +00:00
|
|
|
else
|
2012-07-04 02:36:15 +00:00
|
|
|
return WHYF("unsupported arg '%s'", argv[1]);
|
2012-08-22 00:51:38 +00:00
|
|
|
a.addrlist.first_sid=0;
|
2012-04-25 20:24:54 +00:00
|
|
|
|
2012-10-08 04:29:25 +00:00
|
|
|
do{
|
2012-04-25 20:24:54 +00:00
|
|
|
result=overlay_mdp_send(&a,MDP_AWAITREPLY,5000);
|
|
|
|
if (result) {
|
|
|
|
if (a.packetTypeAndFlags==MDP_ERROR)
|
|
|
|
{
|
|
|
|
WHYF(" MDP Server error #%d: '%s'",
|
|
|
|
a.error.error,a.error.message);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WHYF("Could not get list of local MDP addresses");
|
|
|
|
return WHY("Failed to get local address list");
|
|
|
|
}
|
|
|
|
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
|
|
|
|
return WHY("MDP Server returned something other than an address list");
|
|
|
|
int i;
|
|
|
|
for(i=0;i<a.addrlist.frame_sid_count;i++) {
|
2012-04-26 20:28:31 +00:00
|
|
|
count++;
|
2012-07-03 08:29:30 +00:00
|
|
|
cli_printf("%s", alloca_tohex_sid(a.addrlist.sids[i])); cli_delim("\n");
|
2012-04-25 20:24:54 +00:00
|
|
|
}
|
|
|
|
/* get ready to ask for next block of SIDs */
|
|
|
|
a.packetTypeAndFlags=MDP_GETADDRS;
|
|
|
|
a.addrlist.first_sid=a.addrlist.last_sid+1;
|
2012-10-08 04:29:25 +00:00
|
|
|
}while(a.addrlist.frame_sid_count==MDP_MAX_SID_REQUEST);
|
|
|
|
|
2012-04-25 20:18:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-03 06:51:47 +00:00
|
|
|
int app_count_peers(int argc, const char *const *argv, struct command_line_option *o, void *context){
|
|
|
|
overlay_mdp_frame a;
|
|
|
|
bzero(&a, sizeof(overlay_mdp_frame));
|
|
|
|
a.packetTypeAndFlags=MDP_GETADDRS;
|
|
|
|
a.addrlist.mode = MDP_ADDRLIST_MODE_ROUTABLE_PEERS;
|
|
|
|
a.addrlist.first_sid=0x7fffffff;
|
|
|
|
if (overlay_mdp_send(&a,MDP_AWAITREPLY,5000)){
|
|
|
|
if (a.packetTypeAndFlags==MDP_ERROR)
|
|
|
|
return WHYF(" MDP Server error #%d: '%s'",a.error.error,a.error.message);
|
|
|
|
return WHYF("Failed to send request");
|
|
|
|
}
|
|
|
|
cli_printf("%d",a.addrlist.server_sid_count);
|
|
|
|
cli_delim("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_test_rfs(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-05-07 07:20:49 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-08-01 08:24:02 +00:00
|
|
|
printf("Testing that RFS coder works properly.\n");
|
2012-05-07 07:20:49 +00:00
|
|
|
int i;
|
2012-08-01 08:24:02 +00:00
|
|
|
for(i=0;i<65536;i++) {
|
|
|
|
unsigned char bytes[8];
|
|
|
|
rfs_encode(i, &bytes[0]);
|
|
|
|
int zero=0;
|
|
|
|
int r=rfs_decode(&bytes[0],&zero);
|
|
|
|
if (i != r)
|
|
|
|
printf("RFS encoding of %d decodes to %d: %s\n", i, r, alloca_tohex(bytes, sizeof bytes));
|
|
|
|
}
|
2012-05-07 07:20:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_crypt_test(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-06-20 04:31:12 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-06-20 04:31:12 +00:00
|
|
|
unsigned char nonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES];
|
|
|
|
unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
|
|
|
|
|
|
|
|
unsigned char plain_block[65536];
|
|
|
|
|
|
|
|
urandombytes(nonce,sizeof(nonce));
|
|
|
|
urandombytes(k,sizeof(k));
|
|
|
|
|
|
|
|
int len,i;
|
|
|
|
|
|
|
|
for(len=16;len<=65536;len*=2) {
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t start = gettime_ms();
|
2012-06-20 04:31:12 +00:00
|
|
|
for (i=0;i<1000;i++) {
|
|
|
|
bzero(&plain_block[0],crypto_box_curve25519xsalsa20poly1305_ZEROBYTES);
|
|
|
|
crypto_box_curve25519xsalsa20poly1305_afternm
|
|
|
|
(plain_block,plain_block,len,nonce,k);
|
|
|
|
}
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t end = gettime_ms();
|
2012-06-20 04:31:12 +00:00
|
|
|
printf("%d bytes - 100 tests took %lldms - mean time = %.2fms\n",
|
2012-08-09 02:44:32 +00:00
|
|
|
len, (long long) end - start, (end - start) * 1.0 / i);
|
2012-06-20 04:31:12 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
int app_node_info(int argc, const char *const *argv, struct command_line_option *o, void *context)
|
2012-04-25 21:44:01 +00:00
|
|
|
{
|
2012-07-27 08:29:33 +00:00
|
|
|
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv);
|
2012-04-25 21:44:01 +00:00
|
|
|
const char *sid;
|
|
|
|
cli_arg(argc, argv, o, "sid", &sid, NULL, "");
|
|
|
|
|
|
|
|
overlay_mdp_frame mdp;
|
|
|
|
bzero(&mdp,sizeof(mdp));
|
2012-04-30 05:42:31 +00:00
|
|
|
int resolveDid=0;
|
2012-04-25 21:44:01 +00:00
|
|
|
|
|
|
|
mdp.packetTypeAndFlags=MDP_NODEINFO;
|
2012-05-07 05:58:15 +00:00
|
|
|
if (argc>3) resolveDid=1;
|
2012-06-20 08:15:40 +00:00
|
|
|
mdp.nodeinfo.resolve_did=1; // Request resolution of DID and Name by local server if it can.
|
2012-04-25 21:44:01 +00:00
|
|
|
|
2012-04-26 06:17:05 +00:00
|
|
|
/* get SID or SID prefix
|
|
|
|
XXX - Doesn't correctly handle odd-lengthed SID prefixes (ignores last digit).
|
|
|
|
The matching code in overlay_route.c also has a similar problem with the last
|
|
|
|
digit of an odd-length prefix being ignored. */
|
2012-04-25 21:44:01 +00:00
|
|
|
int i;
|
|
|
|
mdp.nodeinfo.sid_prefix_length=0;
|
2012-04-26 06:17:05 +00:00
|
|
|
for(i = 0; (i != SID_SIZE)&&sid[i<<1]&&sid[(i<<1)+1]; i++) {
|
|
|
|
mdp.nodeinfo.sid[mdp.nodeinfo.sid_prefix_length] = hexvalue(sid[i<<1]) << 4;
|
|
|
|
mdp.nodeinfo.sid[mdp.nodeinfo.sid_prefix_length++] |= hexvalue(sid[(i<<1)+1]);
|
2012-04-25 21:44:01 +00:00
|
|
|
}
|
2012-04-26 06:17:05 +00:00
|
|
|
mdp.nodeinfo.sid_prefix_length*=2;
|
2012-04-25 21:44:01 +00:00
|
|
|
|
|
|
|
int result=overlay_mdp_send(&mdp,MDP_AWAITREPLY,5000);
|
|
|
|
if (result) {
|
|
|
|
if (mdp.packetTypeAndFlags==MDP_ERROR)
|
|
|
|
{
|
2012-04-30 10:34:07 +00:00
|
|
|
overlay_mdp_client_done();
|
2012-04-25 21:44:01 +00:00
|
|
|
return WHYF(" MDP Server error #%d: '%s'",mdp.error.error,mdp.error.message);
|
|
|
|
}
|
2012-04-30 10:34:07 +00:00
|
|
|
else {
|
|
|
|
overlay_mdp_client_done();
|
2012-04-25 21:44:01 +00:00
|
|
|
return WHYF("Could not get information about node.");
|
2012-04-30 10:34:07 +00:00
|
|
|
}
|
2012-04-25 21:44:01 +00:00
|
|
|
}
|
|
|
|
|
2012-04-30 05:42:31 +00:00
|
|
|
if (resolveDid&&(!mdp.nodeinfo.resolve_did)) {
|
|
|
|
/* Asked for DID resolution, but did not get it, so do a DNA lookup
|
|
|
|
here. We do this on the client side, so that we don't block the
|
|
|
|
single-threaded server. */
|
2012-08-27 00:34:59 +00:00
|
|
|
overlay_mdp_frame mdp_reply;
|
2012-04-30 05:42:31 +00:00
|
|
|
int port=32768+(random()&0xffff);
|
2012-08-27 00:34:59 +00:00
|
|
|
|
2012-04-30 05:42:31 +00:00
|
|
|
unsigned char srcsid[SID_SIZE];
|
|
|
|
if (overlay_mdp_getmyaddr(0,srcsid)) port=0;
|
|
|
|
if (overlay_mdp_bind(srcsid,port)) port=0;
|
|
|
|
|
|
|
|
if (port) {
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t now = gettime_ms();
|
|
|
|
time_ms_t timeout = now + 3000;
|
|
|
|
time_ms_t next_send = now;
|
2012-06-26 01:47:33 +00:00
|
|
|
|
|
|
|
while(now < timeout){
|
2012-07-30 07:52:38 +00:00
|
|
|
now=gettime_ms();
|
2012-06-26 01:47:33 +00:00
|
|
|
|
|
|
|
if (now >= next_send){
|
2012-10-02 06:43:12 +00:00
|
|
|
/* Send a unicast packet to this node, asking for any did */
|
|
|
|
lookup_send_request(srcsid, port, mdp.nodeinfo.sid, "");
|
2012-06-26 01:47:33 +00:00
|
|
|
next_send+=125;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-09 02:44:32 +00:00
|
|
|
time_ms_t timeout_ms = (next_send>timeout?timeout:next_send) - now;
|
2012-06-26 01:47:33 +00:00
|
|
|
if (overlay_mdp_client_poll(timeout_ms)<=0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int ttl=-1;
|
2012-10-02 06:43:12 +00:00
|
|
|
if (overlay_mdp_recv(&mdp_reply, port, &ttl))
|
2012-06-26 01:47:33 +00:00
|
|
|
continue;
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
if ((mdp_reply.packetTypeAndFlags&MDP_TYPE_MASK)==MDP_ERROR){
|
2012-06-26 01:47:33 +00:00
|
|
|
// TODO log error?
|
2012-05-25 00:25:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
if (mdp_reply.packetTypeAndFlags!=MDP_TX) {
|
2012-05-25 00:25:56 +00:00
|
|
|
WHYF("MDP returned an unexpected message (type=0x%x)",
|
2012-08-27 00:34:59 +00:00
|
|
|
mdp_reply.packetTypeAndFlags);
|
2012-05-25 00:25:56 +00:00
|
|
|
|
2012-08-27 00:34:59 +00:00
|
|
|
if (mdp_reply.packetTypeAndFlags==MDP_ERROR)
|
2012-05-25 00:25:56 +00:00
|
|
|
WHYF("MDP message is return/error: %d:%s",
|
2012-08-27 00:34:59 +00:00
|
|
|
mdp_reply.error.error,mdp_reply.error.message);
|
2012-05-25 00:25:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-26 01:47:33 +00:00
|
|
|
// we might receive a late response from an ealier request, ignore it
|
2012-08-27 00:34:59 +00:00
|
|
|
if (memcmp(mdp_reply.in.src.sid, mdp.nodeinfo.sid, SID_SIZE)){
|
|
|
|
WHYF("Unexpected result from SID %s", alloca_tohex_sid(mdp_reply.in.src.sid));
|
2012-05-25 00:25:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-07-20 08:47:43 +00:00
|
|
|
{
|
2012-07-23 08:59:57 +00:00
|
|
|
char sidhex[SID_STRLEN + 1];
|
2012-07-18 09:46:30 +00:00
|
|
|
char did[DID_MAXSIZE + 1];
|
|
|
|
char name[64];
|
2012-06-20 05:32:58 +00:00
|
|
|
char uri[512];
|
2012-08-27 00:34:59 +00:00
|
|
|
if ( !parseDnaReply((char *)mdp_reply.in.payload, mdp_reply.in.payload_length, sidhex, did, name, uri, NULL)
|
2012-07-23 08:59:57 +00:00
|
|
|
|| !str_is_subscriber_id(sidhex)
|
|
|
|
|| !str_is_did(did)
|
|
|
|
|| !str_is_uri(uri)
|
|
|
|
) {
|
2012-08-27 00:34:59 +00:00
|
|
|
WHYF("Received malformed DNA reply: %s",
|
|
|
|
alloca_toprint(160, (const char *)mdp_reply.in.payload, mdp_reply.in.payload_length));
|
2012-07-23 08:59:57 +00:00
|
|
|
} else {
|
2012-10-02 06:43:12 +00:00
|
|
|
/* Got a good DNA reply, copy it into place and stop polling */
|
2012-06-26 01:47:33 +00:00
|
|
|
bcopy(did,mdp.nodeinfo.did,32);
|
|
|
|
bcopy(name,mdp.nodeinfo.name,64);
|
|
|
|
mdp.nodeinfo.resolve_did=1;
|
|
|
|
break;
|
|
|
|
}
|
2012-04-30 11:36:40 +00:00
|
|
|
}
|
2012-04-30 05:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-26 22:57:55 +00:00
|
|
|
cli_printf("record"); cli_delim(":");
|
2012-08-15 04:06:10 +00:00
|
|
|
// TODO remove these two unused output fields
|
|
|
|
cli_printf("%d",1); cli_delim(":");
|
|
|
|
cli_printf("%d",1); cli_delim(":");
|
2012-04-26 22:57:55 +00:00
|
|
|
cli_printf("%s",mdp.nodeinfo.foundP?"found":"noresult"); cli_delim(":");
|
2012-07-03 08:29:30 +00:00
|
|
|
cli_printf("%s", alloca_tohex_sid(mdp.nodeinfo.sid)); cli_delim(":");
|
2012-04-26 22:57:55 +00:00
|
|
|
cli_printf("%s",mdp.nodeinfo.resolve_did?mdp.nodeinfo.did:"did-not-resolved");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%s",mdp.nodeinfo.localP?"self":"peer"); cli_delim(":");
|
|
|
|
cli_printf("%s",mdp.nodeinfo.neighbourP?"direct":"indirect");
|
|
|
|
cli_delim(":");
|
|
|
|
cli_printf("%d",mdp.nodeinfo.score); cli_delim(":");
|
2012-05-01 05:08:09 +00:00
|
|
|
cli_printf("%d",mdp.nodeinfo.interface_number); cli_delim(":");
|
|
|
|
cli_printf("%s",mdp.nodeinfo.resolve_did?mdp.nodeinfo.name:"name-not-resolved");
|
2012-04-26 06:17:05 +00:00
|
|
|
cli_delim("\n");
|
2012-04-25 21:44:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 14:05:28 +00:00
|
|
|
/* NULL marks ends of command structure.
|
|
|
|
"<anystring>" marks an arg that can take any value.
|
2012-03-29 07:21:59 +00:00
|
|
|
"[<anystring>]" marks an optional arg that can take any value.
|
|
|
|
All args following the first optional arg are optional, whether marked or not.
|
2012-02-16 14:05:28 +00:00
|
|
|
Only exactly matching prototypes will be used.
|
|
|
|
Together with the description, this makes it easy for us to auto-generate the
|
|
|
|
list of valid command line formats for display to the user if they try an
|
|
|
|
invalid one. It also means we can do away with getopt() etc.
|
|
|
|
|
2012-04-25 20:18:06 +00:00
|
|
|
The CLIFLAG_STANDALONE means that they cannot be used with a running servald
|
|
|
|
instance, but act as an instance. In other words, don't call these from the
|
|
|
|
serval frontend, e.g, Java application on Android. There are various reasons,
|
|
|
|
such as some will try to fork() and exec() (bad for a Java thread to do), while
|
|
|
|
others manipulate files that the running instance may be using.
|
|
|
|
|
2012-02-16 14:05:28 +00:00
|
|
|
Keep this list alphabetically sorted for user convenience.
|
|
|
|
*/
|
2012-09-25 04:01:34 +00:00
|
|
|
struct command_line_option command_line_options[]={
|
2012-08-10 05:55:06 +00:00
|
|
|
{app_dna_lookup,{"dna","lookup","<did>","[<timeout>]",NULL},0,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Lookup the SIP/MDP address of the supplied telephone number (DID)."},
|
2012-09-25 04:01:34 +00:00
|
|
|
{commandline_usage,{"help",NULL},0,
|
2012-02-23 01:25:39 +00:00
|
|
|
"Display command usage."},
|
2012-04-23 08:55:26 +00:00
|
|
|
{app_echo,{"echo","...",NULL},CLIFLAG_STANDALONE,
|
2012-04-25 05:54:21 +00:00
|
|
|
"Output the supplied string."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_start,{"start",NULL},CLIFLAG_STANDALONE,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Start Serval Mesh node process with instance path taken from SERVALINSTANCE_PATH environment variable."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_start,{"start","in","<instance path>",NULL},CLIFLAG_STANDALONE,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Start Serval Mesh node process with given instance path."},
|
2012-05-07 09:21:05 +00:00
|
|
|
{app_server_start,{"start","exec","<exec path>",NULL},CLIFLAG_STANDALONE,
|
|
|
|
"Start Serval Mesh node process with instance path taken from SERVALINSTANCE_PATH environment variable."},
|
|
|
|
{app_server_start,{"start","exec","<exec path>","in","<instance path>",NULL},CLIFLAG_STANDALONE,
|
|
|
|
"Start Serval Mesh node process with given instance path."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_start,{"start","foreground",NULL},CLIFLAG_STANDALONE,
|
2012-03-04 22:57:31 +00:00
|
|
|
"Start Serval Mesh node process without detatching from foreground."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_start,{"start","foreground","in","<instance path>",NULL},CLIFLAG_STANDALONE,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Start Serval Mesh node process with given instance path, without detatching from foreground."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_stop,{"stop",NULL},0,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Stop a running Serval Mesh node process with instance path taken from SERVALINSTANCE_PATH environment variable."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_stop,{"stop","in","<instance path>",NULL},0,
|
2012-03-29 07:21:59 +00:00
|
|
|
"Stop a running Serval Mesh node process with given instance path."},
|
2012-04-25 21:44:01 +00:00
|
|
|
{app_server_status,{"status",NULL},0,
|
2012-02-23 01:25:39 +00:00
|
|
|
"Display information about any running Serval Mesh node."},
|
2012-09-19 00:18:12 +00:00
|
|
|
{app_mdp_ping,{"mdp","ping","<SID|broadcast>","[<count>]",NULL},CLIFLAG_STANDALONE,
|
2012-03-18 22:57:06 +00:00
|
|
|
"Attempts to ping specified node via Mesh Datagram Protocol (MDP)."},
|
2012-04-20 07:32:29 +00:00
|
|
|
{app_config_set,{"config","set","<variable>","<value>",NULL},CLIFLAG_STANDALONE,
|
2012-03-29 04:51:30 +00:00
|
|
|
"Set specified configuration variable."},
|
2012-04-20 07:32:29 +00:00
|
|
|
{app_config_del,{"config","del","<variable>",NULL},CLIFLAG_STANDALONE,
|
2012-03-19 03:56:14 +00:00
|
|
|
"Set specified configuration variable."},
|
2012-04-20 07:32:29 +00:00
|
|
|
{app_config_get,{"config","get","[<variable>]",NULL},CLIFLAG_STANDALONE,
|
2012-03-29 04:51:30 +00:00
|
|
|
"Get specified configuration variable."},
|
2012-09-27 06:57:37 +00:00
|
|
|
{app_vomp_console,{"console",NULL},0,
|
|
|
|
"Test phone call life-cycle from the console"},
|
2012-05-21 03:46:44 +00:00
|
|
|
{app_rhizome_hash_file,{"rhizome","hash","file","<filepath>",NULL},CLIFLAG_STANDALONE,
|
|
|
|
"Compute the Rhizome hash of a file"},
|
2012-06-05 04:28:59 +00:00
|
|
|
{app_rhizome_add_file,{"rhizome","add","file","<author_sid>","<pin>","<filepath>","[<manifestpath>]","[<bsk>]",NULL},CLIFLAG_STANDALONE,
|
2012-04-02 08:12:40 +00:00
|
|
|
"Add a file to Rhizome and optionally write its manifest to the given path"},
|
2012-06-08 08:55:43 +00:00
|
|
|
{app_rhizome_import_bundle,{"rhizome","import","bundle","<filepath>","<manifestpath>",NULL},CLIFLAG_STANDALONE,
|
|
|
|
"Import a payload/manifest pair into Rhizome"},
|
|
|
|
{app_rhizome_list,{"rhizome","list","<pin,pin...>","[<service>]","[<sender_sid>]","[<recipient_sid>]","[<offset>]","[<limit>]",NULL},CLIFLAG_STANDALONE,
|
2012-04-02 08:12:40 +00:00
|
|
|
"List all manifests and files in Rhizome"},
|
2012-05-02 06:54:27 +00:00
|
|
|
{app_rhizome_extract_manifest,{"rhizome","extract","manifest","<manifestid>","[<manifestpath>]",NULL},CLIFLAG_STANDALONE,
|
2012-05-02 06:33:09 +00:00
|
|
|
"Extract a manifest from Rhizome and write it to the given path"},
|
2012-06-01 08:42:59 +00:00
|
|
|
{app_rhizome_extract_file,{"rhizome","extract","file","<fileid>","[<filepath>]","[<key>]",NULL},CLIFLAG_STANDALONE,
|
2012-05-02 06:33:09 +00:00
|
|
|
"Extract a file from Rhizome and write it to the given path"},
|
2012-10-02 10:24:02 +00:00
|
|
|
{app_rhizome_direct_sync,{"rhizome","direct","sync","[peer url]",NULL},
|
2012-08-28 04:02:02 +00:00
|
|
|
CLIFLAG_STANDALONE,
|
|
|
|
"Synchronise with the specified Rhizome Direct server. Return when done."},
|
2012-10-02 10:24:02 +00:00
|
|
|
{app_rhizome_direct_sync,{"rhizome","direct","push","[peer url]",NULL},
|
2012-09-07 13:23:16 +00:00
|
|
|
CLIFLAG_STANDALONE,
|
|
|
|
"Deliver all new content to the specified Rhizome Direct server. Return when done."},
|
2012-10-02 10:24:02 +00:00
|
|
|
{app_rhizome_direct_sync,{"rhizome","direct","pull","[peer url]",NULL},
|
2012-09-07 13:23:16 +00:00
|
|
|
CLIFLAG_STANDALONE,
|
|
|
|
"Fetch all new content from the specified Rhizome Direct server. Return when done."},
|
2012-04-12 04:30:51 +00:00
|
|
|
{app_keyring_create,{"keyring","create",NULL},0,
|
|
|
|
"Create a new keyring file."},
|
2012-06-08 08:55:43 +00:00
|
|
|
{app_keyring_list,{"keyring","list","[<pin,pin...>]",NULL},CLIFLAG_STANDALONE,
|
2012-04-12 04:30:51 +00:00
|
|
|
"List identites in specified key ring that can be accessed using the specified PINs"},
|
2012-04-12 13:45:21 +00:00
|
|
|
{app_keyring_add,{"keyring","add","[<pin>]",NULL},CLIFLAG_STANDALONE,
|
2012-04-12 04:30:51 +00:00
|
|
|
"Create a new identity in the keyring protected by the provided PIN"},
|
2012-05-01 05:08:09 +00:00
|
|
|
{app_keyring_set_did,{"set","did","<sid>","<did>","<name>","[<pin>]",NULL},CLIFLAG_STANDALONE,
|
2012-04-12 13:45:21 +00:00
|
|
|
"Set the DID for the specified SID. Optionally supply PIN to unlock the SID record in the keyring."},
|
2012-04-25 20:18:06 +00:00
|
|
|
{app_id_self,{"id","self",NULL},0,
|
2012-07-04 02:36:15 +00:00
|
|
|
"Return my own identity(s) as URIs"},
|
2012-04-25 20:36:04 +00:00
|
|
|
{app_id_self,{"id","peers",NULL},0,
|
2012-07-04 02:36:15 +00:00
|
|
|
"Return identity of known routable peers as URIs"},
|
|
|
|
{app_id_self,{"id","allpeers",NULL},0,
|
|
|
|
"Return identity of all known peers as URIs"},
|
2012-04-27 04:47:41 +00:00
|
|
|
{app_node_info,{"node","info","<sid>","[getdid]",NULL},0,
|
2012-04-25 21:44:01 +00:00
|
|
|
"Return information about SID, and optionally ask for DID resolution via network"},
|
2012-10-03 06:51:47 +00:00
|
|
|
{app_count_peers,{"peer","count",NULL},0,
|
|
|
|
"Return a count of routable peers on the network"},
|
2012-05-07 07:20:49 +00:00
|
|
|
{app_test_rfs,{"test","rfs",NULL},0,
|
|
|
|
"Test RFS field calculation"},
|
2012-09-25 04:01:34 +00:00
|
|
|
{app_monitor_cli,{"monitor",NULL},0,
|
|
|
|
"Interactive servald monitor interface."},
|
2012-06-20 04:31:12 +00:00
|
|
|
{app_crypt_test,{"crypt","test",NULL},0,
|
|
|
|
"Run cryptography speed test"},
|
2012-04-23 11:28:28 +00:00
|
|
|
#ifdef HAVE_VOIPTEST
|
|
|
|
{app_pa_phone,{"phone",NULL},0,
|
|
|
|
"Run phone test application"},
|
|
|
|
#endif
|
2012-02-16 14:05:28 +00:00
|
|
|
{NULL,{NULL}}
|
|
|
|
};
|