mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-22 02:06:42 +00:00
commit
6516d6bb11
@ -74,6 +74,11 @@ int deadline(struct sched_ent *alarm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_scheduled(const struct sched_ent *alarm)
|
||||
{
|
||||
return alarm->_next || alarm->_prev || alarm == next_alarm || alarm == next_deadline;
|
||||
}
|
||||
|
||||
// add an alarm to the list of scheduled function calls.
|
||||
// simply populate .alarm with the absolute time, and .function with the method to call.
|
||||
// on calling .poll.revents will be zero.
|
||||
@ -84,8 +89,8 @@ int _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
|
||||
|
||||
struct sched_ent *node = next_alarm, *last = NULL;
|
||||
|
||||
if (alarm->_next || alarm->_prev || alarm==next_alarm || alarm==next_deadline)
|
||||
FATAL("Attempted to schedule an alarm that is still scheduled.");
|
||||
if (is_scheduled(alarm))
|
||||
FATAL("Scheduling an alarm that is already scheduled");
|
||||
|
||||
if (!alarm->function)
|
||||
return WHY("Can't schedule if you haven't set the function pointer");
|
||||
|
1
log.h
1
log.h
@ -137,6 +137,7 @@ void set_log_implementation(void (*log_function)(int level, struct strbuf *buf))
|
||||
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), "``") + 1 : (dstlen)), (dstlen), (const char *)(buf), (len), "``")
|
||||
#define alloca_str_toprint(str) toprint_str((char *)alloca(toprint_str_len(str, "``") + 1), -1, (str), "``")
|
||||
#define alloca_sockaddr(addr) strbuf_str(strbuf_append_sockaddr(strbuf_alloca(40), (const struct sockaddr *)(addr)))
|
||||
|
||||
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
|
||||
#define __NOWHERE__ ((struct __sourceloc){ .file = NULL, .line = 0, .function = NULL })
|
||||
|
@ -84,10 +84,6 @@ int overlayServerMode()
|
||||
send periodic traffic. This means we need to */
|
||||
INFO("Running in overlay mode.");
|
||||
|
||||
/* Make sure rhizome configured settings are known. */
|
||||
if (rhizome_fetch_interval_ms < 1)
|
||||
rhizome_configure();
|
||||
|
||||
/* Get keyring available for use.
|
||||
Required for MDP, and very soon as a complete replacement for the
|
||||
HLR for DNA lookups, even in non-overlay mode. */
|
||||
@ -165,11 +161,6 @@ schedule(&_sched_##X); }
|
||||
// preload directory service information
|
||||
directory_service_init();
|
||||
|
||||
/* Pick next rhizome files to grab every few seconds
|
||||
from the priority list continuously being built from observed
|
||||
bundle announcements */
|
||||
SCHEDULE(rhizome_enqueue_suggestions, rhizome_fetch_interval_ms, rhizome_fetch_interval_ms*3);
|
||||
|
||||
/* Periodically check for new interfaces */
|
||||
SCHEDULE(overlay_interface_discover, 1, 100);
|
||||
|
||||
|
19
rhizome.c
19
rhizome.c
@ -21,24 +21,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "rhizome.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static int rhizome_enabled_flag = -1; // unknown
|
||||
int rhizome_fetch_interval_ms = -1;
|
||||
static int _rhizome_enabled = -1;
|
||||
static int _rhizome_fetch_delay_ms = -1;
|
||||
|
||||
/* Configure rhizome.
|
||||
@author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int rhizome_configure()
|
||||
{
|
||||
rhizome_enabled_flag = confValueGetBoolean("rhizome.enable", 1);
|
||||
rhizome_fetch_interval_ms = (int) confValueGetInt64Range("rhizome.fetch_interval_ms", 3000, 1, 3600000);
|
||||
_rhizome_enabled = confValueGetBoolean("rhizome.enable", 1);
|
||||
_rhizome_fetch_delay_ms = (int) confValueGetInt64Range("rhizome.fetch_delay_ms", 50, 1, 3600000);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rhizome_enabled()
|
||||
{
|
||||
if (rhizome_enabled_flag < 0)
|
||||
if (_rhizome_enabled < 0)
|
||||
rhizome_configure();
|
||||
return rhizome_enabled_flag;
|
||||
return _rhizome_enabled;
|
||||
}
|
||||
|
||||
int rhizome_fetch_delay_ms()
|
||||
{
|
||||
if (_rhizome_fetch_delay_ms < 1)
|
||||
rhizome_configure();
|
||||
return _rhizome_fetch_delay_ms;
|
||||
}
|
||||
|
||||
/* Import a bundle from a pair of files, one containing the manifest and the optional other
|
||||
|
29
rhizome.h
29
rhizome.h
@ -150,10 +150,11 @@ typedef struct rhizome_manifest {
|
||||
#define RHIZOME_SERVICE_MESHMS "MeshMS1"
|
||||
|
||||
extern long long rhizome_space;
|
||||
extern int rhizome_fetch_interval_ms;
|
||||
extern unsigned short rhizome_http_server_port;
|
||||
|
||||
int rhizome_configure();
|
||||
int rhizome_enabled();
|
||||
int rhizome_fetch_delay_ms();
|
||||
|
||||
int rhizome_set_datastore_path(const char *path);
|
||||
|
||||
@ -284,7 +285,6 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
|
||||
int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar);
|
||||
long long rhizome_bar_version(unsigned char *bar);
|
||||
unsigned long long rhizome_bar_bidprefix_ll(unsigned char *bar);
|
||||
int rhizome_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip, int *manifest_kept);
|
||||
int rhizome_list_manifests(const char *service, const char *sender_sid, const char *recipient_sid, int limit, int offset);
|
||||
int rhizome_retrieve_manifest(const char *manifestid, rhizome_manifest **mp);
|
||||
int rhizome_retrieve_file(const char *fileid, const char *filepath,
|
||||
@ -325,10 +325,8 @@ int rhizome_sign_hash_with_key(rhizome_manifest *m,const unsigned char *sk,
|
||||
int rhizome_verify_bundle_privatekey(rhizome_manifest *m, const unsigned char *sk,
|
||||
const unsigned char *pk);
|
||||
int rhizome_find_bundle_author(rhizome_manifest *m);
|
||||
int rhizome_queue_ignore_manifest(rhizome_manifest *m,
|
||||
struct sockaddr_in *peerip,int timeout);
|
||||
int rhizome_ignore_manifest_check(rhizome_manifest *m,
|
||||
struct sockaddr_in *peerip);
|
||||
int rhizome_queue_ignore_manifest(rhizome_manifest *m, const struct sockaddr_in *peerip, int timeout);
|
||||
int rhizome_ignore_manifest_check(rhizome_manifest *m, const struct sockaddr_in *peerip);
|
||||
|
||||
/* one manifest is required per candidate, plus a few spare.
|
||||
so MAX_RHIZOME_MANIFESTS must be > MAX_CANDIDATES.
|
||||
@ -336,8 +334,7 @@ int rhizome_ignore_manifest_check(rhizome_manifest *m,
|
||||
#define MAX_RHIZOME_MANIFESTS 24
|
||||
#define MAX_CANDIDATES 16
|
||||
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m,
|
||||
struct sockaddr_in *peerip);
|
||||
int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sockaddr_in *peerip);
|
||||
|
||||
typedef struct rhizome_http_request {
|
||||
struct sched_ent alarm;
|
||||
@ -542,8 +539,20 @@ extern unsigned char favicon_bytes[];
|
||||
extern int favicon_len;
|
||||
|
||||
int rhizome_import_from_files(const char *manifestpath,const char *filepath);
|
||||
int rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip, const unsigned char *prefix, size_t prefix_length);
|
||||
int rhizome_count_queued_imports();
|
||||
|
||||
enum rhizome_start_fetch_result {
|
||||
STARTED = 0,
|
||||
SAMEBUNDLE,
|
||||
SAMEPAYLOAD,
|
||||
SUPERSEDED,
|
||||
OLDERBUNDLE,
|
||||
NEWERBUNDLE,
|
||||
IMPORTED,
|
||||
SLOTBUSY
|
||||
};
|
||||
|
||||
enum rhizome_start_fetch_result rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip, const unsigned char *prefix, size_t prefix_length);
|
||||
int rhizome_any_fetch_active();
|
||||
|
||||
struct http_response_parts {
|
||||
int code;
|
||||
|
@ -881,7 +881,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
/* Fetching the manifest, and then using it to see if we want to
|
||||
fetch the file for import is all handled asynchronously, so just
|
||||
wait for it to finish. */
|
||||
while (rhizome_count_queued_imports())
|
||||
while (rhizome_any_fetch_active())
|
||||
fd_poll();
|
||||
}
|
||||
|
||||
|
1188
rhizome_fetch.c
1188
rhizome_fetch.c
File diff suppressed because it is too large
Load Diff
2
serval.h
2
serval.h
@ -757,6 +757,7 @@ void sigIoHandler(int signal);
|
||||
|
||||
int overlay_mdp_setup_sockets();
|
||||
|
||||
int is_scheduled(const struct sched_ent *alarm);
|
||||
int _schedule(struct __sourceloc whence, struct sched_ent *alarm);
|
||||
int _unschedule(struct __sourceloc whence, struct sched_ent *alarm);
|
||||
int _watch(struct __sourceloc whence, struct sched_ent *alarm);
|
||||
@ -770,7 +771,6 @@ int fd_poll();
|
||||
void overlay_interface_discover(struct sched_ent *alarm);
|
||||
void overlay_dummy_poll(struct sched_ent *alarm);
|
||||
void overlay_route_tick(struct sched_ent *alarm);
|
||||
void rhizome_enqueue_suggestions(struct sched_ent *alarm);
|
||||
void server_shutdown_check(struct sched_ent *alarm);
|
||||
void overlay_mdp_poll(struct sched_ent *alarm);
|
||||
void fd_periodicstats(struct sched_ent *alarm);
|
||||
|
@ -22,6 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
static inline strbuf _toprint(strbuf sb, char c)
|
||||
{
|
||||
@ -198,3 +201,71 @@ strbuf strbuf_append_exit_status(strbuf sb, int status)
|
||||
#endif
|
||||
return sb;
|
||||
}
|
||||
|
||||
strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr)
|
||||
{
|
||||
const char *fam = NULL;
|
||||
switch (addr->sa_family) {
|
||||
case AF_UNSPEC: fam = "AF_UNSPEC"; break;
|
||||
case AF_UNIX: fam = "AF_UNIX"; break;
|
||||
case AF_INET: fam = "AF_INET"; break;
|
||||
case AF_AX25: fam = "AF_AX25"; break;
|
||||
case AF_IPX: fam = "AF_IPX"; break;
|
||||
case AF_APPLETALK: fam = "AF_APPLETALK"; break;
|
||||
case AF_NETROM: fam = "AF_NETROM"; break;
|
||||
case AF_BRIDGE: fam = "AF_BRIDGE"; break;
|
||||
case AF_ATMPVC: fam = "AF_ATMPVC"; break;
|
||||
case AF_X25: fam = "AF_X25"; break;
|
||||
case AF_INET6: fam = "AF_INET6"; break;
|
||||
case AF_ROSE: fam = "AF_ROSE"; break;
|
||||
case AF_DECnet: fam = "AF_DECnet"; break;
|
||||
case AF_NETBEUI: fam = "AF_NETBEUI"; break;
|
||||
case AF_SECURITY: fam = "AF_SECURITY"; break;
|
||||
case AF_KEY: fam = "AF_KEY"; break;
|
||||
case AF_NETLINK: fam = "AF_NETLINK"; break;
|
||||
case AF_PACKET: fam = "AF_PACKET"; break;
|
||||
case AF_ASH: fam = "AF_ASH"; break;
|
||||
case AF_ECONET: fam = "AF_ECONET"; break;
|
||||
case AF_ATMSVC: fam = "AF_ATMSVC"; break;
|
||||
case AF_SNA: fam = "AF_SNA"; break;
|
||||
case AF_IRDA: fam = "AF_IRDA"; break;
|
||||
case AF_PPPOX: fam = "AF_PPPOX"; break;
|
||||
case AF_WANPIPE: fam = "AF_WANPIPE"; break;
|
||||
case AF_LLC: fam = "AF_LLC"; break;
|
||||
case AF_TIPC: fam = "AF_TIPC"; break;
|
||||
case AF_BLUETOOTH: fam = "AF_BLUETOOTH"; break;
|
||||
}
|
||||
if (fam)
|
||||
strbuf_puts(sb, fam);
|
||||
else
|
||||
strbuf_sprintf(sb, "[%d]", addr->sa_family);
|
||||
switch (addr->sa_family) {
|
||||
case AF_UNIX:
|
||||
strbuf_putc(sb, ' ');
|
||||
if (addr->sa_data[0])
|
||||
strbuf_toprint_quoted_len(sb, addr->sa_data, "\"\"", sizeof addr->sa_data);
|
||||
else {
|
||||
strbuf_puts(sb, "abstract ");
|
||||
strbuf_toprint_quoted_len(sb, addr->sa_data, "\"\"", sizeof addr->sa_data);
|
||||
}
|
||||
break;
|
||||
case AF_INET: {
|
||||
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
|
||||
strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
|
||||
((unsigned char *) &addr_in->sin_addr.s_addr)[0],
|
||||
((unsigned char *) &addr_in->sin_addr.s_addr)[1],
|
||||
((unsigned char *) &addr_in->sin_addr.s_addr)[2],
|
||||
((unsigned char *) &addr_in->sin_addr.s_addr)[3],
|
||||
ntohs(addr_in->sin_port)
|
||||
);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
int i;
|
||||
for (i = 0; i < sizeof addr->sa_data; ++i)
|
||||
strbuf_sprintf(sb, " %02x", addr->sa_data[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
@ -80,4 +80,10 @@ strbuf strbuf_append_shell_quotemeta(strbuf sb, const char *word);
|
||||
*/
|
||||
strbuf strbuf_append_exit_status(strbuf sb, int status);
|
||||
|
||||
/* Append a textual description of a struct sockaddr_in.
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
struct sockaddr;
|
||||
strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *);
|
||||
|
||||
#endif //__STRBUF_HELPERS_H__
|
||||
|
@ -44,7 +44,6 @@ configure_servald_server() {
|
||||
executeOk_servald config set server.respawn_on_signal off
|
||||
executeOk_servald config set mdp.wifi.tick_ms 500
|
||||
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
|
||||
executeOk_servald config set rhizome.fetch_interval_ms 100
|
||||
}
|
||||
|
||||
setup_curl_7() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user