Reduce coupling with console, dna_helper, monitor & directory_client features

This commit is contained in:
Jeremy Lakeman 2018-04-03 14:32:06 +09:30
parent 331e0ae576
commit d844b0f6bd
20 changed files with 215 additions and 169 deletions

View File

@ -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 `__stop_tr_cmd_cleanup'
static void __dummy_on_cmd_cleanup();
DEFINE_TRIGGER(cmd_cleanup, __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);
}

View File

@ -41,6 +41,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "keyring.h"
#include "serval.h" // for overlay_send_frame()
#include "route_link.h"
#include "server.h"
#include "feature.h"
DEFINE_FEATURE(directory_client);
__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)) {
directory_service = NULL;
}else{
@ -126,8 +130,8 @@ int directory_service_init(){
}
unschedule(&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
int directory_registration(){
@ -140,10 +144,9 @@ int directory_registration(){
}
static void interface_change(struct overlay_interface *UNUSED(interface), unsigned count){
unschedule(&directory_alarm);
if (count)
directory_registration();
else
unschedule(&directory_alarm);
directory_update(&directory_alarm);
}
DEFINE_TRIGGER(iupdown, interface_change);

View File

@ -62,6 +62,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "overlay_address.h"
#include "server.h"
#include "debug.h"
#include "mdp_services.h"
#include "feature.h"
DEFINE_FEATURE(dna_helper);
static void dna_helper_shutdown();
@ -84,38 +89,6 @@ static void dna_helper_shutdown();
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 int dna_helper_stdin = -1;
static int dna_helper_stdout = -1;
@ -179,25 +152,29 @@ dna_helper_close_pipes()
}
}
int
dna_helper_start()
static void dna_helper_start()
{
dna_helper_shutdown();
if (!serverMode)
return;
if (!config.dna.helper.executable[0]) {
INFO("DNAHELPER none configured");
return 0;
return;
}
const char *mysid = alloca_tohex_sid_t(get_my_subscriber(1)->sid);
int stdin_fds[2], stdout_fds[2], stderr_fds[2];
if (pipe(stdin_fds) == -1)
return WHY_perror("pipe");
if (pipe(stdin_fds) == -1){
WHY_perror("pipe");
return;
}
if (pipe(stdout_fds) == -1) {
WHY_perror("pipe");
close(stdin_fds[0]);
close(stdin_fds[1]);
return -1;
return;
}
if (pipe(stderr_fds) == -1) {
WHY_perror("pipe");
@ -205,7 +182,7 @@ dna_helper_start()
close(stdin_fds[1]);
close(stdout_fds[0]);
close(stdout_fds[1]);
return -1;
return;
}
// Construct argv[] for execv() and log messages.
const char *argv[config.dna.helper.argv.ac + 2];
@ -246,7 +223,8 @@ dna_helper_start()
close(stdout_fds[1]);
close(stderr_fds[0]);
close(stderr_fds[1]);
return -1;
return;
default:
/* Parent, should put file descriptors into place for use */
close(stdin_fds[0]);
@ -279,10 +257,9 @@ dna_helper_start()
watch(&sched_replies);
watch(&sched_errors);
schedule(&sched_harvester);
return 0;
}
return -1;
}
DEFINE_TRIGGER(conf_change, dna_helper_start);
static int
dna_helper_kill()
@ -581,17 +558,21 @@ static void reply_timeout(struct sched_ent *alarm)
}
}
int
dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did)
static void dna_helper_enqueue(struct internal_mdp_header *header, 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));
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.
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 */
return WHY("DNAHELPER start failed");
WHY("DNAHELPER start failed");
return;
}
}
/* 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.
*/
if (dna_helper_stdin == -1)
return 0;
return;
if (request_bufptr && request_bufptr != request_buffer) {
WARNF("DNAHELPER currently sending request %s -- dropping new request", request_buffer);
return 0;
return;
}
if (awaiting_reply) {
WARN("DNAHELPER currently awaiting reply -- dropping new request");
return 0;
return;
}
char buffer[sizeof 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;
watch(&sched_requests);
}
return 1;
}
DEFINE_TRIGGER(dna_lookup, dna_helper_enqueue);

27
mdp_services.h Normal file
View 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

View File

@ -72,6 +72,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "server.h"
#include "route_link.h"
#include "debug.h"
#include "mdp_services.h"
#ifdef HAVE_UCRED_H
#include <ucred.h>
@ -117,8 +118,11 @@ struct sched_ent named_socket;
struct profile_total named_stats;
struct profile_total client_stats;
int monitor_setup_sockets()
static void monitor_setup_sockets()
{
if (serverMode==0)
return;
int sock = -1;
if ((sock = esocket(AF_UNIX, SOCK_STREAM, 0)) == -1)
goto error;
@ -139,13 +143,14 @@ int monitor_setup_sockets()
named_socket.poll.events=POLLIN;
watch(&named_socket);
INFOF("Monitor socket: fd=%d %s", sock, alloca_socket_address(&addr));
return 0;
return;
error:
if (sock != -1)
close(sock);
return -1;
serverMode=0;
}
DEFINE_TRIGGER(startup, monitor_setup_sockets);
#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){
@ -452,7 +457,11 @@ static int monitor_set(const struct cli_parsed *parsed, struct cli_context *cont
c->flags|=MONITOR_QUIT_ON_DISCONNECT;
}else if (strcase_startswith(parsed->args[1],"interface", NULL)){
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
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);
}
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)){
unsigned i = interface - overlay_interfaces;
if (interface->state==INTERFACE_STATE_UP)

View File

@ -116,15 +116,6 @@ static void 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)
{
switch(interface->state){
@ -307,7 +298,7 @@ overlay_interface * overlay_interface_find_name_addr(const char *name, struct so
int i;
assert(name || addr);
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;
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);
}
void overlay_interface_config_change()
static void overlay_interface_config_change()
{
if (!serverMode)
return;
unsigned i;
int real_interface = 0;
@ -1522,6 +1516,7 @@ void overlay_interface_config_change()
if (real_interface)
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) {
struct mallocbuf mb = STRUCT_MALLOCBUF_NULL;

View File

@ -108,7 +108,6 @@ struct network_destination * create_unicast_destination(struct socket_address *a
struct network_destination * add_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);
void overlay_interface_config_change();
struct config_mdp_iftype;
int overlay_destination_configure(struct network_destination *dest, const struct config_mdp_iftype *ifconfig);

View File

@ -113,6 +113,15 @@ struct network_destination *load_subscriber_address(struct subscriber *subscribe
addr.inet.sin_addr = hostc->address;
}
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));
return create_unicast_destination(&addr, interface);
}

View File

@ -246,23 +246,30 @@ static void 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. */
overlay_mdp_clean_socket_files();
if (mdp_sock.poll.fd == -1) {
mdp_sock.poll.fd = mdp_bind_socket("mdp.socket");
if (mdp_sock.poll.fd == -1)
return -1;
if (mdp_sock.poll.fd == -1){
serverMode=0;
return;
}
mdp_sock.poll.events = POLLIN;
watch(&mdp_sock);
}
if (mdp_sock2.poll.fd == -1) {
mdp_sock2.poll.fd = mdp_bind_socket("mdp.2.socket");
if (mdp_sock2.poll.fd == -1)
return -1;
if (mdp_sock2.poll.fd == -1){
serverMode=0;
return;
}
mdp_sock2.poll.events = POLLIN;
watch(&mdp_sock2);
}
@ -304,12 +311,13 @@ int overlay_mdp_setup_sockets()
if (fd!=-1){
close(fd);
return -1;
serverMode=0;
return;
}
}
}
return 0;
}
DEFINE_TRIGGER(startup, overlay_mdp_setup_sockets);
#define MDP_MAX_SOCKET_NAME_LEN 110

View File

@ -24,6 +24,38 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "keyring.h"
#include "overlay_buffer.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);
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
immediately, so as not to cause blockages and delays in servald.
*/
dna_helper_enqueue(header->source, header->source_port, did);
monitor_tell_formatted(MONITOR_DNAHELPER, "LOOKUP:%s:%d:%s\n",
alloca_tohex_sid_t(header->source->sid), header->source_port,
did);
CALL_TRIGGER(dna_lookup, header, did);
}
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);

View File

@ -83,15 +83,15 @@ static struct sched_ent read_watch={
.poll={.fd=-1,.events=POLLIN},
};
int olsr_init_socket(void){
static void olsr_init_socket(void){
int fd;
int reuseP = 1;
if (read_watch.poll.fd>=0)
return 0;
return;
if (!config.olsr.enable)
return 0;
return;
INFOF("Initialising olsr broadcast forwarding via ports %d-%d", config.olsr.local_port, config.olsr.remote_port);
struct sockaddr_in addr = {
@ -103,20 +103,21 @@ int olsr_init_socket(void){
fd = socket(AF_INET,SOCK_DGRAM,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) {
WHY_perror("setsockopt(SO_REUSEADR)");
close(fd);
return -1;
return;
}
#ifdef SO_REUSEPORT
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &reuseP, sizeof(reuseP)) < 0) {
WHY_perror("setsockopt(SO_REUSEPORT)");
close(fd);
return -1;
return;
}
#endif
@ -134,14 +135,15 @@ int olsr_init_socket(void){
if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) {
WHY_perror("Bind failed");
close(fd);
return -1;
return;
}
read_watch.poll.fd = fd;
watch(&read_watch);
return 0;
}
DEFINE_TRIGGER(conf_change, olsr_init_socket);
static void parse_frame(struct overlay_buffer *buff){
struct overlay_frame frame;

View File

@ -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.
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){
overlay_send_probe(subscriber, destination, OQ_MESH_MANAGEMENT);
release_destination_ref(destination);

View File

@ -160,6 +160,7 @@ void rhizome_fetch_status(struct sched_ent *alarm)
return;
unsigned i;
unsigned total=0;
for(i=0;i<NQUEUES;i++){
struct rhizome_fetch_queue *q=&rhizome_fetch_queues[i];
unsigned candidates=0;
@ -174,6 +175,7 @@ void rhizome_fetch_status(struct sched_ent *alarm)
}
if (candidates == 0 && q->active.state==RHIZOME_FETCH_FREE)
continue;
total+=candidates;
DEBUGF(rhizome_rx, "Fetch slot %d, candidates %u of %u %"PRIu64" bytes, %s %"PRIu64" of %"PRIu64,
i, candidates, q->candidate_queue_size, candidate_size,
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
);
}
rhizome_sync_status();
time_ms_t now = gettime_ms();
RESCHEDULE(alarm, now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
if (total){
time_ms_t now = gettime_ms();
RESCHEDULE(alarm, now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
}
}
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;
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);
OUT();

View File

@ -98,11 +98,6 @@ static int sync_status(void **record, void *UNUSED(context))
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)
{
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)
{
if (!is_rhizome_advertise_enabled())
if (!(is_rhizome_advertise_enabled() && link_has_neighbours()))
return;
int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
sync_send_response(NULL, 0, HEAD_FLAG, 5);
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;
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)

View File

@ -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){
if (!interface && addr->addr.sa_family == AF_INET)
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;
}
assert(interface && interface->state==INTERFACE_STATE_UP);
if (addr->addr.sa_family == AF_INET && (addr->inet.sin_addr.s_addr==0 || addr->inet.sin_port==0))
return NULL;
if (!interface->ifconfig.unicast.send)

View File

@ -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);
int directory_registration();
int directory_service_init();
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_tell_clients(char *msg, int msglen, int mask);
int monitor_tell_formatted(int mask, char *fmt, ...);
@ -247,12 +245,9 @@ int scrapeProcNetRoute();
int lsif();
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);
extern uint16_t mdp_loopback_port;
int overlay_mdp_setup_sockets();
int overlay_packetradio_setup_port(struct overlay_interface *interface);
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_server_poll(struct sched_ent *alarm);
int olsr_init_socket(void);
int olsr_send(struct overlay_frame *frame);
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);
void rhizome_fetch_log_short_status();
extern char crash_handler_clue[1024];
#endif // __SERVAL_DNA__SERVAL_H

View File

@ -50,6 +50,9 @@ void servald_features()
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_RESPONSE);
USE_FEATURE(mdp_binding_MDP_PORT_RHIZOME_MANIFEST_REQUEST);
USE_FEATURE(dna_helper);
USE_FEATURE(directory_client);
USE_FEATURE(http_server);
USE_FEATURE(http_rhizome);
USE_FEATURE(http_rhizome_direct);

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <signal.h>
#include "servald_main.h"
#include "commandline.h"
#include "cli_stdio.h"
#include "sighandlers.h"
#include "conf.h"
@ -47,7 +48,15 @@ int servald_main(int argc, char **argv)
signal(SIGPIPE, sigPipeHandler);
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
WSACleanup();
@ -55,12 +64,9 @@ int servald_main(int argc, char **argv)
return status;
}
char crash_handler_clue[1024] = "no clue";
static void crash_handler(int 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);
BACKTRACE;
// Exit with a status code indicating the caught signal. This involves removing the signal

View File

@ -253,22 +253,15 @@ int server_bind()
sigaction(SIGINT, &sig, NULL);
sigaction(SIGIO, &sig, NULL);
/* Setup up client API sockets before writing our PID file
We want clients to be able to connect to our sockets as soon
as servald start has returned. But we don't want servald start
to take very long.
Try to perform only minimal CPU or IO processing here.
*/
if (overlay_mdp_setup_sockets()==-1){
serverMode = 0;
// Perform additional startup, which should be limited to tasks like binding sockets
// So that clients can initiate a connection once servald start has returned.
// serverMode should be cleared to indicate failures
// Any CPU or IO heavy initialisation should be performed in a config changed trigger
CALL_TRIGGER(startup);
if (serverMode == 0)
return -1;
}
if (monitor_setup_sockets()==-1){
serverMode = 0;
return -1;
}
// start the HTTP server if enabled
if (httpd_server_start(config.rhizome.http.port, config.rhizome.http.port + HTTPD_PORT_RANGE)==-1) {
serverMode = 0;
@ -295,8 +288,6 @@ int server_bind()
time_ms_t now = gettime_ms();
olsr_init_socket();
/* Calculate (and possibly show) CPU usage stats periodically */
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();
// 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])
RESCHEDULE(&ALARM_STRUCT(server_watchdog),
now+config.server.watchdog.interval_ms,
@ -667,8 +647,6 @@ static void server_on_config_change()
if (config.rhizome.enable){
rhizome_opendb();
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){
rhizome_close_db();
}
@ -721,7 +699,6 @@ static void server_stop_alarms()
unschedule(&ALARM_STRUCT(server_watchdog));
unschedule(&ALARM_STRUCT(server_config_reload));
unschedule(&ALARM_STRUCT(rhizome_clean_db));
unschedule(&ALARM_STRUCT(rhizome_fetch_status));
}
DEFINE_TRIGGER(shutdown, server_stop_alarms);
@ -771,7 +748,6 @@ static void signal_handler(int signum)
// fall through...
default:
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);
break;
}

View File

@ -54,6 +54,7 @@ int server_unlink_proc_state(const char *path);
void server_rhizome_add_bundle(uint64_t rowid);
DECLARE_TRIGGER(startup);
DECLARE_TRIGGER(shutdown);
#endif // __SERVAL_DNA__SERVER_H