Skip to content

Commit

Permalink
Merge pull request #50 from hamishcoleman/main
Browse files Browse the repository at this point in the history
Add config option for rundir (and misc other changes)
  • Loading branch information
hamishcoleman authored Aug 2, 2024
2 parents 4b19a27 + dae535a commit 6b56d42
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 16 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ INSTALL_DOC=$(INSTALL) -m444
# DESTDIR set in debian make system
PREFIX=$(DESTDIR)/$(CONFIG_PREFIX)

# Note that both these install dirs are outside of the CONFIG_PREFIX.
# Note that these three install dirs are outside of the CONFIG_PREFIX.
# The ETCDIR is not configurable in the code, so no changes should be done
# without code changes.
# The systemd unit dir should default to /lib for most Debian packages (if
# CONFIG_PREFIX is /usr) otherwise it should be based on the prefix.
# The current autotools has hacks to apply this logic.
ETCDIR=$(DESTDIR)/etc/n3n
CONFIG_RUNDIR?=$(DESTDIR)/run
CONFIG_SYSTEMDDIR?=$(DESTDIR)/lib/systemd/system

CONFIG_BINDIR?=$(PREFIX)/bin
Expand All @@ -78,6 +79,8 @@ MAN7DIR=$(CONFIG_MANDIR)/man7
MAN8DIR=$(CONFIG_MANDIR)/man8
CONFIG_DOCDIR?=$(PREFIX)/share/doc/n3n

CFLAGS+=-DCONFIG_RUNDIR='"$(CONFIG_RUNDIR)"'

#######################################
# All the additiona needed for using the n3n library
#
Expand Down
13 changes: 12 additions & 1 deletion apps/n3n-edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,18 @@ int main (int argc, char* argv[]) {
traceEvent(TRACE_WARNING, "unable to retain permitted capabilities [%s]\n", strerror(errno));
#else
#ifndef __APPLE__
traceEvent(TRACE_WARNING, "n3n has not been compiled with libcap-dev; some commands may fail");
// TODO:
// - refactor and the libcap usage and prove exactly where any issues may
// occur
// - Output any informational warnings before taking those actions,
// instead of this nebulous warning at startup time
// - Continue improving the ability to run with reduced runtime permissions
// and incorporate that in the standard examples
traceEvent(
TRACE_WARNING,
"The build option to add libcap-dev was not used. "
"Some actions may cause permissions messages."
);
#endif
#endif /* HAVE_LIBCAP */

Expand Down
11 changes: 7 additions & 4 deletions config.mak.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Global configuration, included in top Makefile and exported from there.
# @configure_input@
#
# @configure_command@


CONFIG_HOST=@host@
CONFIG_HOST_OS=@host_os@

CONFIG_PREFIX=@CONFIG_PREFIX@
CONFIG_DOCDIR=$(DESTDIR)/@CONFIG_DOCDIR@
CONFIG_MANDIR=$(DESTDIR)/@CONFIG_MANDIR@
CONFIG_SYSTEMDDIR=$(DESTDIR)/@CONFIG_SYSTEMDDIR@
CONFIG_DOCDIR=$(DESTDIR)@CONFIG_DOCDIR@
CONFIG_MANDIR=$(DESTDIR)@CONFIG_MANDIR@
CONFIG_RUNDIR=$(DESTDIR)@CONFIG_RUNDIR@
CONFIG_SYSTEMDDIR=$(DESTDIR)@CONFIG_SYSTEMDDIR@

CONFIG_WITH_OPENSSL=@with_openssl@

Expand Down
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ case "$host_os" in
;;
esac

AC_ARG_WITH([rundir],
AS_HELP_STRING([--with-rundir=DIR], [location of the system /run dir]),
[rundir=$withval],
[rundir="/run"]
)

AC_ARG_WITH([systemddir],
AS_HELP_STRING([--with-systemddir=DIR], [Where to install systemd units]),
[systemddir=$withval],
Expand Down Expand Up @@ -134,13 +140,18 @@ AS_IF([test "x$systemddir" = "x" ],
CONFIG_DOCDIR=$(eval echo $(eval echo $docdir))
CONFIG_MANDIR=$(eval echo $(eval echo $mandir))
CONFIG_PREFIX=$prefix
CONFIG_RUNDIR=$rundir
CONFIG_SYSTEMDDIR=$systemddir

configure_command=$0$ac_configure_args_raw

AC_SUBST(CONFIG_DOCDIR)
AC_SUBST(CONFIG_MANDIR)
AC_SUBST(CONFIG_PREFIX)
AC_SUBST(CONFIG_RUNDIR)
AC_SUBST(CONFIG_SYSTEMDDIR)

AC_SUBST(configure_command)
AC_SUBST(host)
AC_SUBST(host_os)
AC_SUBST(EXE)
Expand Down
5 changes: 4 additions & 1 deletion doc/ReleaseProcess.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Release Process

## Regular release process
First, locally:
First, ensure that all the changes to be included in the release have been
committed and merged in to the main branch of the public repository.

Next, locally:
- edit `VERSION` file to new version, e.g. `4.0.1`
- `git add VERSION`
- `git commit -m "Bump version file"`
Expand Down
5 changes: 5 additions & 0 deletions doc/supernode.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ bind=7777
[supernode]
# Optionally specifies the allowed communities as listed in community.list file.
#community_file=/etc/n3n/community.list

# If multiple supernodes ("supernode federation") is desired, the following
# two options are needed:
# federation = yoursecret
# peer = other.node:7777
5 changes: 3 additions & 2 deletions include/n2n_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ enum n3n_event_topic {

#define N3N_EVENT_PEER_PURGE 1
#define N3N_EVENT_PEER_CLEAR 2
#define N3N_EVENT_PEER_DEL_P2P 3
#define N3N_EVENT_PEER_ADD_P2P 4
#define N3N_EVENT_PEER_P2P_ADD 3
#define N3N_EVENT_PEER_P2P_CHANGED 4
#define N3N_EVENT_PEER_P2P_EXPIRED 5

#define N3N_MGMT_PASSWORD "n3n" /* default password for management port access (so far, json only) */

Expand Down
2 changes: 1 addition & 1 deletion packages/openwrt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ endef
define Build/Configure
( cd $(PKG_BUILD_DIR); \
./autogen.sh; \
LDFLAGS=--static ./configure )
LDFLAGS=--static ./configure --with-rundir=/var/run )
endef

define Package/n3n-edge/conffiles
Expand Down
2 changes: 1 addition & 1 deletion src/conffile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ int n3n_config_setup_sessiondir (n2n_edge_conf_t *conf) {


#ifndef _WIN32
char *basedir = "/run/n3n";
char *basedir = CONFIG_RUNDIR "/n3n";
#endif
#ifdef _WIN32
char basedir[1024];
Expand Down
6 changes: 3 additions & 3 deletions src/edge_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static void peer_set_p2p_confirmed (struct n3n_runtime_data * eee,

HASH_ADD_PEER(eee->known_peers, scan);
scan->last_p2p = now;
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_ADD_P2P,scan);
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_P2P_ADD,scan);

traceEvent(TRACE_DEBUG, "p2p connection established: %s [%s]",
macaddr_str(mac_buf, mac),
Expand Down Expand Up @@ -1010,7 +1010,7 @@ static void check_known_peer_sock_change (struct n3n_runtime_data *eee,
sock_to_cstr(sockbuf2, peer));
/* The peer has changed public socket. It can no longer be assumed to be reachable. */
HASH_DEL(eee->known_peers, scan);
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_DEL_P2P,scan);
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_P2P_CHANGED,scan);
peer_info_free(scan);

register_with_new_peer(eee, from_supernode, via_multicast, mac, dev_addr, dev_desc, peer);
Expand Down Expand Up @@ -1975,7 +1975,7 @@ static int find_peer_destination (struct n3n_runtime_data * eee,
* since the peer address may have changed. */
traceEvent(TRACE_DEBUG, "refreshing idle known peer");
HASH_DEL(eee->known_peers, scan);
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_DEL_P2P,scan);
mgmt_event_post(N3N_EVENT_PEER,N3N_EVENT_PEER_P2P_EXPIRED,scan);
peer_info_free(scan);
/* NOTE: registration will be performed upon the receival of the next response packet */
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/management.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ static void event_test (strbuf_t *buf, enum n3n_event_topic topic, int data0, co
static const char *event_peer_actions[] = {
[N3N_EVENT_PEER_PURGE] = "purge",
[N3N_EVENT_PEER_CLEAR] = "clear",
[N3N_EVENT_PEER_DEL_P2P] = "del_p2p",
[N3N_EVENT_PEER_ADD_P2P] = "add_p2p",
[N3N_EVENT_PEER_P2P_ADD] = "p2p_add",
[N3N_EVENT_PEER_P2P_CHANGED] = "p2p_changed",
[N3N_EVENT_PEER_P2P_EXPIRED] = "p2p_expired",
};

static void event_peer (strbuf_t *buf, enum n3n_event_topic topic, int data0, const void *data1) {
Expand Down

0 comments on commit 6b56d42

Please sign in to comment.