mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Reduce coupling with console, dna_helper, monitor & directory_client features
This commit is contained in:
parent
331e0ae576
commit
d844b0f6bd
@ -88,19 +88,6 @@ int commandline_main(struct cli_context *context, const char *argv0, int argc, c
|
|||||||
// undefined reference to `__start_tr_cmd_cleanup'
|
// undefined reference to `__start_tr_cmd_cleanup'
|
||||||
// undefined reference to `__stop_tr_cmd_cleanup'
|
// undefined reference to `__stop_tr_cmd_cleanup'
|
||||||
|
|
||||||
static void __dummy_on_cmd_cleanup();
|
|
||||||
DEFINE_TRIGGER(cmd_cleanup, __dummy_on_cmd_cleanup);
|
|
||||||
static void __dummy_on_cmd_cleanup() {}
|
static void __dummy_on_cmd_cleanup() {}
|
||||||
|
DEFINE_TRIGGER(cmd_cleanup, __dummy_on_cmd_cleanup);
|
||||||
|
|
||||||
int commandline_main_stdio(FILE *output, const char *argv0, int argc, const char *const *args)
|
|
||||||
{
|
|
||||||
struct cli_context_stdio cli_context_stdio = {
|
|
||||||
.fp = output
|
|
||||||
};
|
|
||||||
struct cli_context cli_context = {
|
|
||||||
.vtable = &cli_vtable_stdio,
|
|
||||||
.context = &cli_context_stdio
|
|
||||||
};
|
|
||||||
|
|
||||||
return commandline_main(&cli_context, argv0, argc, args);
|
|
||||||
}
|
|
||||||
|
@ -41,6 +41,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "keyring.h"
|
#include "keyring.h"
|
||||||
#include "serval.h" // for overlay_send_frame()
|
#include "serval.h" // for overlay_send_frame()
|
||||||
#include "route_link.h"
|
#include "route_link.h"
|
||||||
|
#include "server.h"
|
||||||
|
#include "feature.h"
|
||||||
|
|
||||||
|
DEFINE_FEATURE(directory_client);
|
||||||
|
|
||||||
__thread struct subscriber *directory_service;
|
__thread struct subscriber *directory_service;
|
||||||
|
|
||||||
@ -112,7 +116,7 @@ static void directory_update(struct sched_ent *alarm){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int directory_service_init(){
|
static void directory_service_init(){
|
||||||
if (is_sid_t_any(config.directory.service)) {
|
if (is_sid_t_any(config.directory.service)) {
|
||||||
directory_service = NULL;
|
directory_service = NULL;
|
||||||
}else{
|
}else{
|
||||||
@ -126,8 +130,8 @@ int directory_service_init(){
|
|||||||
}
|
}
|
||||||
unschedule(&directory_alarm);
|
unschedule(&directory_alarm);
|
||||||
directory_update(&directory_alarm);
|
directory_update(&directory_alarm);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(conf_change, directory_service_init);
|
||||||
|
|
||||||
// called when we discover a route to the directory service SID
|
// called when we discover a route to the directory service SID
|
||||||
int directory_registration(){
|
int directory_registration(){
|
||||||
@ -140,10 +144,9 @@ int directory_registration(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void interface_change(struct overlay_interface *UNUSED(interface), unsigned count){
|
static void interface_change(struct overlay_interface *UNUSED(interface), unsigned count){
|
||||||
|
unschedule(&directory_alarm);
|
||||||
if (count)
|
if (count)
|
||||||
directory_registration();
|
directory_update(&directory_alarm);
|
||||||
else
|
|
||||||
unschedule(&directory_alarm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_TRIGGER(iupdown, interface_change);
|
DEFINE_TRIGGER(iupdown, interface_change);
|
||||||
|
84
dna_helper.c
84
dna_helper.c
@ -62,6 +62,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "mdp_services.h"
|
||||||
|
#include "feature.h"
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE_FEATURE(dna_helper);
|
||||||
|
|
||||||
static void dna_helper_shutdown();
|
static void dna_helper_shutdown();
|
||||||
|
|
||||||
@ -84,38 +89,6 @@ static void dna_helper_shutdown();
|
|||||||
main loop.
|
main loop.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
|
||||||
parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp)
|
|
||||||
{
|
|
||||||
/* Replies look like: TOKEN|URI|DID|NAME| where TOKEN is usually a hex SID */
|
|
||||||
const char *b = buf;
|
|
||||||
const char *e = buf + len;
|
|
||||||
char *p, *q;
|
|
||||||
for (p = token, q = token + SID_STRLEN; b != e && *b != '|' && p != q; ++p, ++b)
|
|
||||||
*p = *b;
|
|
||||||
*p = '\0';
|
|
||||||
if (b == e || *b++ != '|')
|
|
||||||
return 0;
|
|
||||||
for (p = uri, q = uri + 511; b != e && *b != '|' && p != q; ++p, ++b)
|
|
||||||
*p = *b;
|
|
||||||
*p = '\0';
|
|
||||||
if (b == e || *b++ != '|')
|
|
||||||
return 0;
|
|
||||||
for (p = did, q = did + DID_MAXSIZE; b != e && *b != '|' && p != q; ++p, ++b)
|
|
||||||
*p = *b;
|
|
||||||
*p = '\0';
|
|
||||||
if (b == e || *b++ != '|')
|
|
||||||
return 0;
|
|
||||||
for (p = name, q = name + ID_NAME_MAXSIZE; b != e && *b != '|' && p != q; ++p, ++b)
|
|
||||||
*p = *b;
|
|
||||||
*p = '\0';
|
|
||||||
if (b == e || *b++ != '|')
|
|
||||||
return 0;
|
|
||||||
if (bufp)
|
|
||||||
*bufp = b;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static pid_t dna_helper_pid = -1;
|
static pid_t dna_helper_pid = -1;
|
||||||
static int dna_helper_stdin = -1;
|
static int dna_helper_stdin = -1;
|
||||||
static int dna_helper_stdout = -1;
|
static int dna_helper_stdout = -1;
|
||||||
@ -179,25 +152,29 @@ dna_helper_close_pipes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void dna_helper_start()
|
||||||
dna_helper_start()
|
|
||||||
{
|
{
|
||||||
dna_helper_shutdown();
|
dna_helper_shutdown();
|
||||||
|
if (!serverMode)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!config.dna.helper.executable[0]) {
|
if (!config.dna.helper.executable[0]) {
|
||||||
INFO("DNAHELPER none configured");
|
INFO("DNAHELPER none configured");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *mysid = alloca_tohex_sid_t(get_my_subscriber(1)->sid);
|
const char *mysid = alloca_tohex_sid_t(get_my_subscriber(1)->sid);
|
||||||
|
|
||||||
int stdin_fds[2], stdout_fds[2], stderr_fds[2];
|
int stdin_fds[2], stdout_fds[2], stderr_fds[2];
|
||||||
if (pipe(stdin_fds) == -1)
|
if (pipe(stdin_fds) == -1){
|
||||||
return WHY_perror("pipe");
|
WHY_perror("pipe");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pipe(stdout_fds) == -1) {
|
if (pipe(stdout_fds) == -1) {
|
||||||
WHY_perror("pipe");
|
WHY_perror("pipe");
|
||||||
close(stdin_fds[0]);
|
close(stdin_fds[0]);
|
||||||
close(stdin_fds[1]);
|
close(stdin_fds[1]);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
if (pipe(stderr_fds) == -1) {
|
if (pipe(stderr_fds) == -1) {
|
||||||
WHY_perror("pipe");
|
WHY_perror("pipe");
|
||||||
@ -205,7 +182,7 @@ dna_helper_start()
|
|||||||
close(stdin_fds[1]);
|
close(stdin_fds[1]);
|
||||||
close(stdout_fds[0]);
|
close(stdout_fds[0]);
|
||||||
close(stdout_fds[1]);
|
close(stdout_fds[1]);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
// Construct argv[] for execv() and log messages.
|
// Construct argv[] for execv() and log messages.
|
||||||
const char *argv[config.dna.helper.argv.ac + 2];
|
const char *argv[config.dna.helper.argv.ac + 2];
|
||||||
@ -246,7 +223,8 @@ dna_helper_start()
|
|||||||
close(stdout_fds[1]);
|
close(stdout_fds[1]);
|
||||||
close(stderr_fds[0]);
|
close(stderr_fds[0]);
|
||||||
close(stderr_fds[1]);
|
close(stderr_fds[1]);
|
||||||
return -1;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Parent, should put file descriptors into place for use */
|
/* Parent, should put file descriptors into place for use */
|
||||||
close(stdin_fds[0]);
|
close(stdin_fds[0]);
|
||||||
@ -279,10 +257,9 @@ dna_helper_start()
|
|||||||
watch(&sched_replies);
|
watch(&sched_replies);
|
||||||
watch(&sched_errors);
|
watch(&sched_errors);
|
||||||
schedule(&sched_harvester);
|
schedule(&sched_harvester);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(conf_change, dna_helper_start);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dna_helper_kill()
|
dna_helper_kill()
|
||||||
@ -581,17 +558,21 @@ static void reply_timeout(struct sched_ent *alarm)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static void dna_helper_enqueue(struct internal_mdp_header *header, const char *did)
|
||||||
dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did)
|
|
||||||
{
|
{
|
||||||
|
struct subscriber *source = header->source;
|
||||||
|
mdp_port_t source_port = header->source_port;
|
||||||
|
|
||||||
DEBUGF(dnahelper, "DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid_t(source->sid));
|
DEBUGF(dnahelper, "DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid_t(source->sid));
|
||||||
if (dna_helper_pid == 0)
|
if (dna_helper_pid == 0)
|
||||||
return 0;
|
return;
|
||||||
// Only try to restart a DNA helper process if the previous one is well and truly gone.
|
// Only try to restart a DNA helper process if the previous one is well and truly gone.
|
||||||
if (dna_helper_pid == -1 && dna_helper_stdin == -1 && dna_helper_stdout == -1 && dna_helper_stderr == -1) {
|
if (dna_helper_pid == -1 && dna_helper_stdin == -1 && dna_helper_stdout == -1 && dna_helper_stderr == -1) {
|
||||||
if (dna_helper_start() == -1) {
|
dna_helper_start();
|
||||||
|
if (dna_helper_pid == -1 && dna_helper_stdin == -1 && dna_helper_stdout == -1 && dna_helper_stderr == -1) {
|
||||||
/* Something broke, bail out */
|
/* Something broke, bail out */
|
||||||
return WHY("DNAHELPER start failed");
|
WHY("DNAHELPER start failed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Write request to dna helper.
|
/* Write request to dna helper.
|
||||||
@ -601,14 +582,14 @@ dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char
|
|||||||
which will include the requestor's SID.
|
which will include the requestor's SID.
|
||||||
*/
|
*/
|
||||||
if (dna_helper_stdin == -1)
|
if (dna_helper_stdin == -1)
|
||||||
return 0;
|
return;
|
||||||
if (request_bufptr && request_bufptr != request_buffer) {
|
if (request_bufptr && request_bufptr != request_buffer) {
|
||||||
WARNF("DNAHELPER currently sending request %s -- dropping new request", request_buffer);
|
WARNF("DNAHELPER currently sending request %s -- dropping new request", request_buffer);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
if (awaiting_reply) {
|
if (awaiting_reply) {
|
||||||
WARN("DNAHELPER currently awaiting reply -- dropping new request");
|
WARN("DNAHELPER currently awaiting reply -- dropping new request");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
char buffer[sizeof request_buffer];
|
char buffer[sizeof request_buffer];
|
||||||
strbuf b = request_bufptr == request_buffer ? strbuf_local_buf(buffer) : strbuf_local_buf(request_buffer);
|
strbuf b = request_bufptr == request_buffer ? strbuf_local_buf(buffer) : strbuf_local_buf(request_buffer);
|
||||||
@ -636,5 +617,6 @@ dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char
|
|||||||
sched_requests.poll.fd = dna_helper_stdin;
|
sched_requests.poll.fd = dna_helper_stdin;
|
||||||
watch(&sched_requests);
|
watch(&sched_requests);
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(dna_lookup, dna_helper_enqueue);
|
||||||
|
|
||||||
|
27
mdp_services.h
Normal file
27
mdp_services.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2012-2015 Serval Project Inc.
|
||||||
|
Copyright (C) 2016 Flinders University
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__MDP_SERVICES_H
|
||||||
|
#define __SERVAL_DNA__MDP_SERVICES_H
|
||||||
|
|
||||||
|
#include "trigger.h"
|
||||||
|
|
||||||
|
DECLARE_TRIGGER(dna_lookup, struct internal_mdp_header *header, const char *did);
|
||||||
|
|
||||||
|
#endif
|
26
monitor.c
26
monitor.c
@ -72,6 +72,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "route_link.h"
|
#include "route_link.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "mdp_services.h"
|
||||||
|
|
||||||
#ifdef HAVE_UCRED_H
|
#ifdef HAVE_UCRED_H
|
||||||
#include <ucred.h>
|
#include <ucred.h>
|
||||||
@ -117,8 +118,11 @@ struct sched_ent named_socket;
|
|||||||
struct profile_total named_stats;
|
struct profile_total named_stats;
|
||||||
struct profile_total client_stats;
|
struct profile_total client_stats;
|
||||||
|
|
||||||
int monitor_setup_sockets()
|
static void monitor_setup_sockets()
|
||||||
{
|
{
|
||||||
|
if (serverMode==0)
|
||||||
|
return;
|
||||||
|
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
if ((sock = esocket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
if ((sock = esocket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
@ -139,13 +143,14 @@ int monitor_setup_sockets()
|
|||||||
named_socket.poll.events=POLLIN;
|
named_socket.poll.events=POLLIN;
|
||||||
watch(&named_socket);
|
watch(&named_socket);
|
||||||
INFOF("Monitor socket: fd=%d %s", sock, alloca_socket_address(&addr));
|
INFOF("Monitor socket: fd=%d %s", sock, alloca_socket_address(&addr));
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (sock != -1)
|
if (sock != -1)
|
||||||
close(sock);
|
close(sock);
|
||||||
return -1;
|
serverMode=0;
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(startup, monitor_setup_sockets);
|
||||||
|
|
||||||
#define monitor_write_error(C,E) _monitor_write_error(__WHENCE__, C, E)
|
#define monitor_write_error(C,E) _monitor_write_error(__WHENCE__, C, E)
|
||||||
static int _monitor_write_error(struct __sourceloc __whence, struct monitor_context *c, const char *error){
|
static int _monitor_write_error(struct __sourceloc __whence, struct monitor_context *c, const char *error){
|
||||||
@ -452,7 +457,11 @@ static int monitor_set(const struct cli_parsed *parsed, struct cli_context *cont
|
|||||||
c->flags|=MONITOR_QUIT_ON_DISCONNECT;
|
c->flags|=MONITOR_QUIT_ON_DISCONNECT;
|
||||||
}else if (strcase_startswith(parsed->args[1],"interface", NULL)){
|
}else if (strcase_startswith(parsed->args[1],"interface", NULL)){
|
||||||
c->flags|=MONITOR_INTERFACE;
|
c->flags|=MONITOR_INTERFACE;
|
||||||
overlay_interface_monitor_up();
|
unsigned i;
|
||||||
|
for (i=0;i<OVERLAY_MAX_INTERFACES;i++){
|
||||||
|
if (overlay_interfaces[i].state == INTERFACE_STATE_UP)
|
||||||
|
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%u:%s:UP\n", i, overlay_interfaces[i].name);
|
||||||
|
}
|
||||||
}else
|
}else
|
||||||
return monitor_write_error(c,"Unknown monitor type");
|
return monitor_write_error(c,"Unknown monitor type");
|
||||||
|
|
||||||
@ -694,6 +703,15 @@ int monitor_tell_formatted(int mask, char *fmt, ...){
|
|||||||
return monitor_tell_clients(msg, n, mask);
|
return monitor_tell_clients(msg, n, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void monitor_dna_helper(struct internal_mdp_header *header, const char *did)
|
||||||
|
{
|
||||||
|
monitor_tell_formatted(MONITOR_DNAHELPER, "LOOKUP:%s:%d:%s\n",
|
||||||
|
alloca_tohex_sid_t(header->source->sid), header->source_port,
|
||||||
|
did);
|
||||||
|
}
|
||||||
|
DEFINE_TRIGGER(dna_lookup, monitor_dna_helper);
|
||||||
|
|
||||||
|
|
||||||
static void monitor_interface_change(struct overlay_interface *interface, unsigned UNUSED(count)){
|
static void monitor_interface_change(struct overlay_interface *interface, unsigned UNUSED(count)){
|
||||||
unsigned i = interface - overlay_interfaces;
|
unsigned i = interface - overlay_interfaces;
|
||||||
if (interface->state==INTERFACE_STATE_UP)
|
if (interface->state==INTERFACE_STATE_UP)
|
||||||
|
@ -116,15 +116,6 @@ static void overlay_interface_close_all()
|
|||||||
}
|
}
|
||||||
DEFINE_TRIGGER(shutdown, overlay_interface_close_all);
|
DEFINE_TRIGGER(shutdown, overlay_interface_close_all);
|
||||||
|
|
||||||
void overlay_interface_monitor_up()
|
|
||||||
{
|
|
||||||
unsigned i;
|
|
||||||
for (i=0;i<OVERLAY_MAX_INTERFACES;i++){
|
|
||||||
if (overlay_interfaces[i].state == INTERFACE_STATE_UP)
|
|
||||||
monitor_tell_formatted(MONITOR_INTERFACE, "\nINTERFACE:%u:%s:UP\n", i, overlay_interfaces[i].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void interface_state_html(struct strbuf *b, struct overlay_interface *interface)
|
void interface_state_html(struct strbuf *b, struct overlay_interface *interface)
|
||||||
{
|
{
|
||||||
switch(interface->state){
|
switch(interface->state){
|
||||||
@ -307,7 +298,7 @@ overlay_interface * overlay_interface_find_name_addr(const char *name, struct so
|
|||||||
int i;
|
int i;
|
||||||
assert(name || addr);
|
assert(name || addr);
|
||||||
for(i = 0; i < OVERLAY_MAX_INTERFACES; i++){
|
for(i = 0; i < OVERLAY_MAX_INTERFACES; i++){
|
||||||
if (overlay_interfaces[i].state==INTERFACE_STATE_DOWN)
|
if (overlay_interfaces[i].state!=INTERFACE_STATE_UP)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((!addr || cmp_sockaddr(addr, &overlay_interfaces[i].address)==0)
|
if ((!addr || cmp_sockaddr(addr, &overlay_interfaces[i].address)==0)
|
||||||
@ -1475,8 +1466,11 @@ static void rescan_soon(time_ms_t run_at){
|
|||||||
RESCHEDULE(alarm, run_at, run_at, run_at);
|
RESCHEDULE(alarm, run_at, run_at, run_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
void overlay_interface_config_change()
|
static void overlay_interface_config_change()
|
||||||
{
|
{
|
||||||
|
if (!serverMode)
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
int real_interface = 0;
|
int real_interface = 0;
|
||||||
|
|
||||||
@ -1522,6 +1516,7 @@ void overlay_interface_config_change()
|
|||||||
if (real_interface)
|
if (real_interface)
|
||||||
rescan_soon(gettime_ms());
|
rescan_soon(gettime_ms());
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(conf_change, overlay_interface_config_change);
|
||||||
|
|
||||||
void logServalPacket(int level, struct __sourceloc __whence, const char *message, const unsigned char *packet, size_t len) {
|
void logServalPacket(int level, struct __sourceloc __whence, const char *message, const unsigned char *packet, size_t len) {
|
||||||
struct mallocbuf mb = STRUCT_MALLOCBUF_NULL;
|
struct mallocbuf mb = STRUCT_MALLOCBUF_NULL;
|
||||||
|
@ -108,7 +108,6 @@ struct network_destination * create_unicast_destination(struct socket_address *a
|
|||||||
struct network_destination * add_destination_ref(struct network_destination *ref);
|
struct network_destination * add_destination_ref(struct network_destination *ref);
|
||||||
void release_destination_ref(struct network_destination *ref);
|
void release_destination_ref(struct network_destination *ref);
|
||||||
int set_destination_ref(struct network_destination **ptr, struct network_destination *ref);
|
int set_destination_ref(struct network_destination **ptr, struct network_destination *ref);
|
||||||
void overlay_interface_config_change();
|
|
||||||
|
|
||||||
struct config_mdp_iftype;
|
struct config_mdp_iftype;
|
||||||
int overlay_destination_configure(struct network_destination *dest, const struct config_mdp_iftype *ifconfig);
|
int overlay_destination_configure(struct network_destination *dest, const struct config_mdp_iftype *ifconfig);
|
||||||
|
@ -113,6 +113,15 @@ struct network_destination *load_subscriber_address(struct subscriber *subscribe
|
|||||||
addr.inet.sin_addr = hostc->address;
|
addr.inet.sin_addr = hostc->address;
|
||||||
}
|
}
|
||||||
addr.inet.sin_port = htons(hostc->port);
|
addr.inet.sin_port = htons(hostc->port);
|
||||||
|
|
||||||
|
if (!interface && addr.addr.sa_family == AF_INET)
|
||||||
|
interface = overlay_interface_find(addr.inet.sin_addr, 1);
|
||||||
|
|
||||||
|
if (!interface){
|
||||||
|
WARNF("Can't find interface for %s", alloca_socket_address(&addr));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUGF(overlayrouting, "Loaded address %s for %s", alloca_socket_address(&addr), alloca_tohex_sid_t(subscriber->sid));
|
DEBUGF(overlayrouting, "Loaded address %s for %s", alloca_socket_address(&addr), alloca_tohex_sid_t(subscriber->sid));
|
||||||
return create_unicast_destination(&addr, interface);
|
return create_unicast_destination(&addr, interface);
|
||||||
}
|
}
|
||||||
|
@ -246,23 +246,30 @@ static void overlay_mdp_shutdown()
|
|||||||
}
|
}
|
||||||
DEFINE_TRIGGER(shutdown, overlay_mdp_shutdown);
|
DEFINE_TRIGGER(shutdown, overlay_mdp_shutdown);
|
||||||
|
|
||||||
int overlay_mdp_setup_sockets()
|
static void overlay_mdp_setup_sockets()
|
||||||
{
|
{
|
||||||
|
if (serverMode==0)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Delete stale socket files from instance directory. */
|
/* Delete stale socket files from instance directory. */
|
||||||
overlay_mdp_clean_socket_files();
|
overlay_mdp_clean_socket_files();
|
||||||
|
|
||||||
if (mdp_sock.poll.fd == -1) {
|
if (mdp_sock.poll.fd == -1) {
|
||||||
mdp_sock.poll.fd = mdp_bind_socket("mdp.socket");
|
mdp_sock.poll.fd = mdp_bind_socket("mdp.socket");
|
||||||
if (mdp_sock.poll.fd == -1)
|
if (mdp_sock.poll.fd == -1){
|
||||||
return -1;
|
serverMode=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
mdp_sock.poll.events = POLLIN;
|
mdp_sock.poll.events = POLLIN;
|
||||||
watch(&mdp_sock);
|
watch(&mdp_sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mdp_sock2.poll.fd == -1) {
|
if (mdp_sock2.poll.fd == -1) {
|
||||||
mdp_sock2.poll.fd = mdp_bind_socket("mdp.2.socket");
|
mdp_sock2.poll.fd = mdp_bind_socket("mdp.2.socket");
|
||||||
if (mdp_sock2.poll.fd == -1)
|
if (mdp_sock2.poll.fd == -1){
|
||||||
return -1;
|
serverMode=0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
mdp_sock2.poll.events = POLLIN;
|
mdp_sock2.poll.events = POLLIN;
|
||||||
watch(&mdp_sock2);
|
watch(&mdp_sock2);
|
||||||
}
|
}
|
||||||
@ -304,12 +311,13 @@ int overlay_mdp_setup_sockets()
|
|||||||
|
|
||||||
if (fd!=-1){
|
if (fd!=-1){
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
serverMode=0;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(startup, overlay_mdp_setup_sockets);
|
||||||
|
|
||||||
#define MDP_MAX_SOCKET_NAME_LEN 110
|
#define MDP_MAX_SOCKET_NAME_LEN 110
|
||||||
|
|
||||||
|
@ -24,6 +24,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "keyring.h"
|
#include "keyring.h"
|
||||||
#include "overlay_buffer.h"
|
#include "overlay_buffer.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "mdp_services.h"
|
||||||
|
|
||||||
|
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp)
|
||||||
|
{
|
||||||
|
/* Replies look like: TOKEN|URI|DID|NAME| where TOKEN is usually a hex SID */
|
||||||
|
const char *b = buf;
|
||||||
|
const char *e = buf + len;
|
||||||
|
char *p, *q;
|
||||||
|
for (p = token, q = token + SID_STRLEN; b != e && *b != '|' && p != q; ++p, ++b)
|
||||||
|
*p = *b;
|
||||||
|
*p = '\0';
|
||||||
|
if (b == e || *b++ != '|')
|
||||||
|
return 0;
|
||||||
|
for (p = uri, q = uri + 511; b != e && *b != '|' && p != q; ++p, ++b)
|
||||||
|
*p = *b;
|
||||||
|
*p = '\0';
|
||||||
|
if (b == e || *b++ != '|')
|
||||||
|
return 0;
|
||||||
|
for (p = did, q = did + DID_MAXSIZE; b != e && *b != '|' && p != q; ++p, ++b)
|
||||||
|
*p = *b;
|
||||||
|
*p = '\0';
|
||||||
|
if (b == e || *b++ != '|')
|
||||||
|
return 0;
|
||||||
|
for (p = name, q = name + ID_NAME_MAXSIZE; b != e && *b != '|' && p != q; ++p, ++b)
|
||||||
|
*p = *b;
|
||||||
|
*p = '\0';
|
||||||
|
if (b == e || *b++ != '|')
|
||||||
|
return 0;
|
||||||
|
if (bufp)
|
||||||
|
*bufp = b;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_BINDING(MDP_PORT_DNALOOKUP, overlay_mdp_service_dnalookup);
|
DEFINE_BINDING(MDP_PORT_DNALOOKUP, overlay_mdp_service_dnalookup);
|
||||||
static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
||||||
@ -77,10 +109,11 @@ static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, str
|
|||||||
when results become available, so this function will return
|
when results become available, so this function will return
|
||||||
immediately, so as not to cause blockages and delays in servald.
|
immediately, so as not to cause blockages and delays in servald.
|
||||||
*/
|
*/
|
||||||
dna_helper_enqueue(header->source, header->source_port, did);
|
CALL_TRIGGER(dna_lookup, header, did);
|
||||||
monitor_tell_formatted(MONITOR_DNAHELPER, "LOOKUP:%s:%d:%s\n",
|
|
||||||
alloca_tohex_sid_t(header->source->sid), header->source_port,
|
|
||||||
did);
|
|
||||||
}
|
}
|
||||||
RETURN(0);
|
RETURN(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put a dummy no-op trigger callback into the "cmd_cleanup" trigger section,
|
||||||
|
static void __dummy_dna_lookup(struct internal_mdp_header *UNUSED(header), const char *UNUSED(did)){}
|
||||||
|
DEFINE_TRIGGER(dna_lookup, __dummy_dna_lookup);
|
||||||
|
@ -83,15 +83,15 @@ static struct sched_ent read_watch={
|
|||||||
.poll={.fd=-1,.events=POLLIN},
|
.poll={.fd=-1,.events=POLLIN},
|
||||||
};
|
};
|
||||||
|
|
||||||
int olsr_init_socket(void){
|
static void olsr_init_socket(void){
|
||||||
int fd;
|
int fd;
|
||||||
int reuseP = 1;
|
int reuseP = 1;
|
||||||
|
|
||||||
if (read_watch.poll.fd>=0)
|
if (read_watch.poll.fd>=0)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (!config.olsr.enable)
|
if (!config.olsr.enable)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
INFOF("Initialising olsr broadcast forwarding via ports %d-%d", config.olsr.local_port, config.olsr.remote_port);
|
INFOF("Initialising olsr broadcast forwarding via ports %d-%d", config.olsr.local_port, config.olsr.remote_port);
|
||||||
struct sockaddr_in addr = {
|
struct sockaddr_in addr = {
|
||||||
@ -103,20 +103,21 @@ int olsr_init_socket(void){
|
|||||||
|
|
||||||
fd = socket(AF_INET,SOCK_DGRAM,0);
|
fd = socket(AF_INET,SOCK_DGRAM,0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
return WHY_perror("Error creating socket");
|
WHY_perror("Error creating socket");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseP, sizeof(reuseP)) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuseP, sizeof(reuseP)) < 0) {
|
||||||
WHY_perror("setsockopt(SO_REUSEADR)");
|
WHY_perror("setsockopt(SO_REUSEADR)");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SO_REUSEPORT
|
#ifdef SO_REUSEPORT
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &reuseP, sizeof(reuseP)) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &reuseP, sizeof(reuseP)) < 0) {
|
||||||
WHY_perror("setsockopt(SO_REUSEPORT)");
|
WHY_perror("setsockopt(SO_REUSEPORT)");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -134,14 +135,15 @@ int olsr_init_socket(void){
|
|||||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) {
|
if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) {
|
||||||
WHY_perror("Bind failed");
|
WHY_perror("Bind failed");
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_watch.poll.fd = fd;
|
read_watch.poll.fd = fd;
|
||||||
|
|
||||||
watch(&read_watch);
|
watch(&read_watch);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
DEFINE_TRIGGER(conf_change, olsr_init_socket);
|
||||||
|
|
||||||
|
|
||||||
static void parse_frame(struct overlay_buffer *buff){
|
static void parse_frame(struct overlay_buffer *buff){
|
||||||
struct overlay_frame frame;
|
struct overlay_frame frame;
|
||||||
|
@ -50,7 +50,12 @@ static int overlay_mdp_service_stun(struct internal_mdp_header *header, struct o
|
|||||||
|
|
||||||
// only trust stun responses from our directory service or about the packet sender.
|
// only trust stun responses from our directory service or about the packet sender.
|
||||||
if (directory_service == header->source || subscriber == header->source){
|
if (directory_service == header->source || subscriber == header->source){
|
||||||
struct network_destination *destination = create_unicast_destination(&addr, NULL);
|
overlay_interface *interface = overlay_interface_find(addr.inet.sin_addr, 1);
|
||||||
|
if (!interface){
|
||||||
|
WARNF("Can't find interface for %s", alloca_socket_address(&addr));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
struct network_destination *destination = create_unicast_destination(&addr, interface);
|
||||||
if (destination){
|
if (destination){
|
||||||
overlay_send_probe(subscriber, destination, OQ_MESH_MANAGEMENT);
|
overlay_send_probe(subscriber, destination, OQ_MESH_MANAGEMENT);
|
||||||
release_destination_ref(destination);
|
release_destination_ref(destination);
|
||||||
|
@ -160,6 +160,7 @@ void rhizome_fetch_status(struct sched_ent *alarm)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
unsigned total=0;
|
||||||
for(i=0;i<NQUEUES;i++){
|
for(i=0;i<NQUEUES;i++){
|
||||||
struct rhizome_fetch_queue *q=&rhizome_fetch_queues[i];
|
struct rhizome_fetch_queue *q=&rhizome_fetch_queues[i];
|
||||||
unsigned candidates=0;
|
unsigned candidates=0;
|
||||||
@ -174,6 +175,7 @@ void rhizome_fetch_status(struct sched_ent *alarm)
|
|||||||
}
|
}
|
||||||
if (candidates == 0 && q->active.state==RHIZOME_FETCH_FREE)
|
if (candidates == 0 && q->active.state==RHIZOME_FETCH_FREE)
|
||||||
continue;
|
continue;
|
||||||
|
total+=candidates;
|
||||||
DEBUGF(rhizome_rx, "Fetch slot %d, candidates %u of %u %"PRIu64" bytes, %s %"PRIu64" of %"PRIu64,
|
DEBUGF(rhizome_rx, "Fetch slot %d, candidates %u of %u %"PRIu64" bytes, %s %"PRIu64" of %"PRIu64,
|
||||||
i, candidates, q->candidate_queue_size, candidate_size,
|
i, candidates, q->candidate_queue_size, candidate_size,
|
||||||
fetch_state(q->active.state),
|
fetch_state(q->active.state),
|
||||||
@ -181,9 +183,10 @@ void rhizome_fetch_status(struct sched_ent *alarm)
|
|||||||
q->active.manifest?q->active.manifest->filesize:0
|
q->active.manifest?q->active.manifest->filesize:0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
rhizome_sync_status();
|
if (total){
|
||||||
time_ms_t now = gettime_ms();
|
time_ms_t now = gettime_ms();
|
||||||
RESCHEDULE(alarm, now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
RESCHEDULE(alarm, now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rhizome_fetch_status_html(strbuf b)
|
int rhizome_fetch_status_html(strbuf b)
|
||||||
@ -951,6 +954,8 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
|
|||||||
sched_activate.deadline = sched_activate.alarm + config.rhizome.idle_timeout;
|
sched_activate.deadline = sched_activate.alarm + config.rhizome.idle_timeout;
|
||||||
schedule(&sched_activate);
|
schedule(&sched_activate);
|
||||||
}
|
}
|
||||||
|
if (IF_DEBUG(rhizome) && !is_scheduled(&ALARM_STRUCT(rhizome_fetch_status)))
|
||||||
|
RESCHEDULE(&ALARM_STRUCT(rhizome_fetch_status), gettime_ms() + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
||||||
|
|
||||||
RETURN(0);
|
RETURN(0);
|
||||||
OUT();
|
OUT();
|
||||||
|
@ -98,11 +98,6 @@ static int sync_status(void **record, void *UNUSED(context))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rhizome_sync_status()
|
|
||||||
{
|
|
||||||
enum_subscribers(NULL, sync_status, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token, unsigned char forwards)
|
static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token, unsigned char forwards)
|
||||||
{
|
{
|
||||||
struct internal_mdp_header header;
|
struct internal_mdp_header header;
|
||||||
@ -516,14 +511,22 @@ static void sync_send_response(struct subscriber *dest, int forwards, uint64_t t
|
|||||||
|
|
||||||
void rhizome_sync_announce(struct sched_ent *alarm)
|
void rhizome_sync_announce(struct sched_ent *alarm)
|
||||||
{
|
{
|
||||||
if (!is_rhizome_advertise_enabled())
|
if (!(is_rhizome_advertise_enabled() && link_has_neighbours()))
|
||||||
return;
|
return;
|
||||||
int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
|
int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
|
||||||
sync_send_response(NULL, 0, HEAD_FLAG, 5);
|
sync_send_response(NULL, 0, HEAD_FLAG, 5);
|
||||||
sqlite_set_tracefunc(oldfunc);
|
sqlite_set_tracefunc(oldfunc);
|
||||||
alarm->alarm = gettime_ms()+config.rhizome.advertise.interval;
|
time_ms_t now = gettime_ms();
|
||||||
|
alarm->alarm = now+config.rhizome.advertise.interval;
|
||||||
alarm->deadline = alarm->alarm+10000;
|
alarm->deadline = alarm->alarm+10000;
|
||||||
schedule(alarm);
|
schedule(alarm);
|
||||||
|
if (IF_DEBUG(rhizome)){
|
||||||
|
static time_ms_t next_debug = TIME_MS_NEVER_HAS;
|
||||||
|
if (next_debug < now){
|
||||||
|
enum_subscribers(NULL, sync_status, NULL);
|
||||||
|
next_debug = now + 3000;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void neighbour_changed(struct subscriber *UNUSED(neighbour), uint8_t UNUSED(found), unsigned count)
|
static void neighbour_changed(struct subscriber *UNUSED(neighbour), uint8_t UNUSED(found), unsigned count)
|
||||||
|
11
route_link.c
11
route_link.c
@ -190,16 +190,7 @@ struct network_destination * new_destination(struct overlay_interface *interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct network_destination * create_unicast_destination(struct socket_address *addr, struct overlay_interface *interface){
|
struct network_destination * create_unicast_destination(struct socket_address *addr, struct overlay_interface *interface){
|
||||||
if (!interface && addr->addr.sa_family == AF_INET)
|
assert(interface && interface->state==INTERFACE_STATE_UP);
|
||||||
interface = overlay_interface_find(addr->inet.sin_addr, 1);
|
|
||||||
if (!interface){
|
|
||||||
WHY("I don't know which interface to use");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (interface->state!=INTERFACE_STATE_UP){
|
|
||||||
WHY("The interface is down.");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (addr->addr.sa_family == AF_INET && (addr->inet.sin_addr.s_addr==0 || addr->inet.sin_port==0))
|
if (addr->addr.sa_family == AF_INET && (addr->inet.sin_addr.s_addr==0 || addr->inet.sin_port==0))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!interface->ifconfig.unicast.send)
|
if (!interface->ifconfig.unicast.send)
|
||||||
|
7
serval.h
7
serval.h
@ -233,11 +233,9 @@ int vomp_received_audio(struct vomp_call_state *call, int audio_codec, int time,
|
|||||||
void monitor_get_all_supported_codecs(unsigned char *codecs);
|
void monitor_get_all_supported_codecs(unsigned char *codecs);
|
||||||
|
|
||||||
int directory_registration();
|
int directory_registration();
|
||||||
int directory_service_init();
|
|
||||||
|
|
||||||
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||||
|
|
||||||
int monitor_setup_sockets();
|
|
||||||
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
int monitor_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||||
int monitor_tell_clients(char *msg, int msglen, int mask);
|
int monitor_tell_clients(char *msg, int msglen, int mask);
|
||||||
int monitor_tell_formatted(int mask, char *fmt, ...);
|
int monitor_tell_formatted(int mask, char *fmt, ...);
|
||||||
@ -247,12 +245,9 @@ int scrapeProcNetRoute();
|
|||||||
int lsif();
|
int lsif();
|
||||||
int doifaddrs();
|
int doifaddrs();
|
||||||
|
|
||||||
int dna_helper_start();
|
|
||||||
int dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did);
|
|
||||||
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
||||||
|
|
||||||
extern uint16_t mdp_loopback_port;
|
extern uint16_t mdp_loopback_port;
|
||||||
int overlay_mdp_setup_sockets();
|
|
||||||
|
|
||||||
int overlay_packetradio_setup_port(struct overlay_interface *interface);
|
int overlay_packetradio_setup_port(struct overlay_interface *interface);
|
||||||
int overlay_send_probe(struct subscriber *peer, struct network_destination *destination, int queue);
|
int overlay_send_probe(struct subscriber *peer, struct network_destination *destination, int queue);
|
||||||
@ -266,7 +261,6 @@ void monitor_poll(struct sched_ent *alarm);
|
|||||||
void rhizome_fetch_poll(struct sched_ent *alarm);
|
void rhizome_fetch_poll(struct sched_ent *alarm);
|
||||||
void rhizome_server_poll(struct sched_ent *alarm);
|
void rhizome_server_poll(struct sched_ent *alarm);
|
||||||
|
|
||||||
int olsr_init_socket(void);
|
|
||||||
int olsr_send(struct overlay_frame *frame);
|
int olsr_send(struct overlay_frame *frame);
|
||||||
|
|
||||||
int pack_uint(unsigned char *buffer, uint64_t v);
|
int pack_uint(unsigned char *buffer, uint64_t v);
|
||||||
@ -274,6 +268,5 @@ int measure_packed_uint(uint64_t v);
|
|||||||
int unpack_uint(unsigned char *buffer, int buff_size, uint64_t *v);
|
int unpack_uint(unsigned char *buffer, int buff_size, uint64_t *v);
|
||||||
|
|
||||||
void rhizome_fetch_log_short_status();
|
void rhizome_fetch_log_short_status();
|
||||||
extern char crash_handler_clue[1024];
|
|
||||||
|
|
||||||
#endif // __SERVAL_DNA__SERVAL_H
|
#endif // __SERVAL_DNA__SERVAL_H
|
||||||
|
@ -50,6 +50,9 @@ void servald_features()
|
|||||||
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_RESPONSE);
|
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_RESPONSE);
|
||||||
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_MANIFEST_REQUEST);
|
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_MANIFEST_REQUEST);
|
||||||
|
|
||||||
|
USE_FEATURE(dna_helper);
|
||||||
|
USE_FEATURE(directory_client);
|
||||||
|
|
||||||
USE_FEATURE(http_server);
|
USE_FEATURE(http_server);
|
||||||
USE_FEATURE(http_rhizome);
|
USE_FEATURE(http_rhizome);
|
||||||
USE_FEATURE(http_rhizome_direct);
|
USE_FEATURE(http_rhizome_direct);
|
||||||
|
@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "servald_main.h"
|
#include "servald_main.h"
|
||||||
#include "commandline.h"
|
#include "commandline.h"
|
||||||
|
#include "cli_stdio.h"
|
||||||
#include "sighandlers.h"
|
#include "sighandlers.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
@ -47,7 +48,15 @@ int servald_main(int argc, char **argv)
|
|||||||
signal(SIGPIPE, sigPipeHandler);
|
signal(SIGPIPE, sigPipeHandler);
|
||||||
signal(SIGIO, sigIoHandler);
|
signal(SIGIO, sigIoHandler);
|
||||||
|
|
||||||
int status = commandline_main_stdio(stdout, argv[0], argc - 1, (const char*const*)&argv[1]);
|
struct cli_context_stdio cli_context_stdio = {
|
||||||
|
.fp = stdout
|
||||||
|
};
|
||||||
|
struct cli_context cli_context = {
|
||||||
|
.vtable = &cli_vtable_stdio,
|
||||||
|
.context = &cli_context_stdio
|
||||||
|
};
|
||||||
|
|
||||||
|
int status = commandline_main(&cli_context, argv[0], argc - 1, (const char*const*)&argv[1]);
|
||||||
|
|
||||||
#if defined WIN32
|
#if defined WIN32
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
@ -55,12 +64,9 @@ int servald_main(int argc, char **argv)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
char crash_handler_clue[1024] = "no clue";
|
|
||||||
|
|
||||||
static void crash_handler(int signum)
|
static void crash_handler(int signum)
|
||||||
{
|
{
|
||||||
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", alloca_signal_name(signum));
|
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", alloca_signal_name(signum));
|
||||||
LOGF(LOG_LEVEL_FATAL, "The following clue may help: %s", crash_handler_clue);
|
|
||||||
dump_stack(LOG_LEVEL_FATAL);
|
dump_stack(LOG_LEVEL_FATAL);
|
||||||
BACKTRACE;
|
BACKTRACE;
|
||||||
// Exit with a status code indicating the caught signal. This involves removing the signal
|
// Exit with a status code indicating the caught signal. This involves removing the signal
|
||||||
|
40
server.c
40
server.c
@ -253,22 +253,15 @@ int server_bind()
|
|||||||
sigaction(SIGINT, &sig, NULL);
|
sigaction(SIGINT, &sig, NULL);
|
||||||
sigaction(SIGIO, &sig, NULL);
|
sigaction(SIGIO, &sig, NULL);
|
||||||
|
|
||||||
/* Setup up client API sockets before writing our PID file
|
// Perform additional startup, which should be limited to tasks like binding sockets
|
||||||
We want clients to be able to connect to our sockets as soon
|
// So that clients can initiate a connection once servald start has returned.
|
||||||
as servald start has returned. But we don't want servald start
|
// serverMode should be cleared to indicate failures
|
||||||
to take very long.
|
// Any CPU or IO heavy initialisation should be performed in a config changed trigger
|
||||||
Try to perform only minimal CPU or IO processing here.
|
|
||||||
*/
|
CALL_TRIGGER(startup);
|
||||||
if (overlay_mdp_setup_sockets()==-1){
|
if (serverMode == 0)
|
||||||
serverMode = 0;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor_setup_sockets()==-1){
|
|
||||||
serverMode = 0;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start the HTTP server if enabled
|
// start the HTTP server if enabled
|
||||||
if (httpd_server_start(config.rhizome.http.port, config.rhizome.http.port + HTTPD_PORT_RANGE)==-1) {
|
if (httpd_server_start(config.rhizome.http.port, config.rhizome.http.port + HTTPD_PORT_RANGE)==-1) {
|
||||||
serverMode = 0;
|
serverMode = 0;
|
||||||
@ -295,8 +288,6 @@ int server_bind()
|
|||||||
|
|
||||||
time_ms_t now = gettime_ms();
|
time_ms_t now = gettime_ms();
|
||||||
|
|
||||||
olsr_init_socket();
|
|
||||||
|
|
||||||
/* Calculate (and possibly show) CPU usage stats periodically */
|
/* Calculate (and possibly show) CPU usage stats periodically */
|
||||||
RESCHEDULE(&ALARM_STRUCT(fd_periodicstats), now+3000, TIME_MS_NEVER_WILL, now+3500);
|
RESCHEDULE(&ALARM_STRUCT(fd_periodicstats), now+3000, TIME_MS_NEVER_WILL, now+3500);
|
||||||
|
|
||||||
@ -639,17 +630,6 @@ static void server_on_config_change()
|
|||||||
|
|
||||||
time_ms_t now = gettime_ms();
|
time_ms_t now = gettime_ms();
|
||||||
|
|
||||||
// TODO move to their own trigger
|
|
||||||
dna_helper_start();
|
|
||||||
directory_service_init();
|
|
||||||
|
|
||||||
overlay_interface_config_change();
|
|
||||||
|
|
||||||
if (link_has_neighbours())
|
|
||||||
// send rhizome sync periodically
|
|
||||||
RESCHEDULE(&ALARM_STRUCT(rhizome_sync_announce),
|
|
||||||
now+1000, now+1000, TIME_MS_NEVER_WILL);
|
|
||||||
|
|
||||||
if (config.server.watchdog.executable[0])
|
if (config.server.watchdog.executable[0])
|
||||||
RESCHEDULE(&ALARM_STRUCT(server_watchdog),
|
RESCHEDULE(&ALARM_STRUCT(server_watchdog),
|
||||||
now+config.server.watchdog.interval_ms,
|
now+config.server.watchdog.interval_ms,
|
||||||
@ -667,8 +647,6 @@ static void server_on_config_change()
|
|||||||
if (config.rhizome.enable){
|
if (config.rhizome.enable){
|
||||||
rhizome_opendb();
|
rhizome_opendb();
|
||||||
RESCHEDULE(&ALARM_STRUCT(rhizome_clean_db), now + 30*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
RESCHEDULE(&ALARM_STRUCT(rhizome_clean_db), now + 30*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
||||||
if (IF_DEBUG(rhizome))
|
|
||||||
RESCHEDULE(&ALARM_STRUCT(rhizome_fetch_status), now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
|
|
||||||
}else if(rhizome_db){
|
}else if(rhizome_db){
|
||||||
rhizome_close_db();
|
rhizome_close_db();
|
||||||
}
|
}
|
||||||
@ -721,7 +699,6 @@ static void server_stop_alarms()
|
|||||||
unschedule(&ALARM_STRUCT(server_watchdog));
|
unschedule(&ALARM_STRUCT(server_watchdog));
|
||||||
unschedule(&ALARM_STRUCT(server_config_reload));
|
unschedule(&ALARM_STRUCT(server_config_reload));
|
||||||
unschedule(&ALARM_STRUCT(rhizome_clean_db));
|
unschedule(&ALARM_STRUCT(rhizome_clean_db));
|
||||||
unschedule(&ALARM_STRUCT(rhizome_fetch_status));
|
|
||||||
}
|
}
|
||||||
DEFINE_TRIGGER(shutdown, server_stop_alarms);
|
DEFINE_TRIGGER(shutdown, server_stop_alarms);
|
||||||
|
|
||||||
@ -771,7 +748,6 @@ static void signal_handler(int signum)
|
|||||||
// fall through...
|
// fall through...
|
||||||
default:
|
default:
|
||||||
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", alloca_signal_name(signum));
|
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", alloca_signal_name(signum));
|
||||||
LOGF(LOG_LEVEL_FATAL, "The following clue may help: %s", crash_handler_clue);
|
|
||||||
dump_stack(LOG_LEVEL_FATAL);
|
dump_stack(LOG_LEVEL_FATAL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
1
server.h
1
server.h
@ -54,6 +54,7 @@ int server_unlink_proc_state(const char *path);
|
|||||||
|
|
||||||
void server_rhizome_add_bundle(uint64_t rowid);
|
void server_rhizome_add_bundle(uint64_t rowid);
|
||||||
|
|
||||||
|
DECLARE_TRIGGER(startup);
|
||||||
DECLARE_TRIGGER(shutdown);
|
DECLARE_TRIGGER(shutdown);
|
||||||
|
|
||||||
#endif // __SERVAL_DNA__SERVER_H
|
#endif // __SERVAL_DNA__SERVER_H
|
||||||
|
Loading…
Reference in New Issue
Block a user