Skip to content

Commit

Permalink
Merge pull request #29 from hamishcoleman/main
Browse files Browse the repository at this point in the history
TCP mode bug fixes and more
  • Loading branch information
hamishcoleman authored May 9, 2024
2 parents b8016db + b9e1f1e commit 5b0c562
Show file tree
Hide file tree
Showing 29 changed files with 535 additions and 362 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Install essential
run: |
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install build-essential autoconf
- name: generate a makefile and use it to install more packages
run: |
Expand Down Expand Up @@ -313,6 +313,7 @@ jobs:
dpkg -I n3n_*.deb
dpkg --contents n3n_*.deb
echo "-------------------------------"
git status
- name: Upload dpkg
uses: actions/upload-artifact@v3
Expand Down
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
*.a
*.gz
*.exe

# Files created by autogen
configure
include/config.h.in
scripts/config.guess
scripts/config.sub

# Files created by configure
config.log
config.mak
config.rpath
config.status
include/config.h
include/config.h.in
autom4te.cache
packages/debian/debian/files

*dSYM*

__pycache__
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ OBJS=\
CFLAGS_src/speck.c := -Wno-maybe-uninitialized

ifneq (,$(findstring mingw,$(CONFIG_HOST_OS)))
OBJS+=src/win32/edge_rc.o
OBJS+=src/win32/edge_utils_win32.o
OBJS+=src/win32/getopt1.o
OBJS+=src/win32/getopt.o
OBJS+=src/win32/getopt1.o
OBJS+=src/win32/win32.o
OBJS+=src/win32/wintap.o
OBJS+=src/win32/edge_rc.o
endif

src/management.o: src/management_index.html.h
Expand Down
6 changes: 3 additions & 3 deletions apps/example_sn_embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/


#include <n3n/initfuncs.h> // for n3n_initfuncs()
#include <n3n/supernode.h> // for sn_init_conf_defaults
#include <stdbool.h>
#include <stdlib.h> // for exit
Expand All @@ -38,9 +39,8 @@ int main () {
int rc;
struct sockaddr_in local_address;

#ifdef _WIN32
initWin32();
#endif
// Do this early to register all internals
n3n_initfuncs();

sn_init_conf_defaults(&sss_node,"supernode");
int lport = 1234; // Main UDP listen port
Expand Down
4 changes: 0 additions & 4 deletions apps/n3n-edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#ifdef _WIN32
#include "../src/win32/defs.h" // FIXME: untangle the include path
#else
#include <arpa/inet.h> // for inet_addr, inet_ntop
#include <netinet/in.h> // for INADDR_ANY, INADDR_NONE, ntohl
#include <pwd.h> // for getpwnam, passwd
#include <sys/select.h> // for select, FD_ISSET, FD_SET, FD_ZERO
Expand Down Expand Up @@ -755,9 +754,6 @@ int main (int argc, char* argv[]) {
#ifdef HAVE_LIBCAP
cap_t caps;
#endif
#ifdef _WIN32
initWin32();
#endif

// Do this early to register all internals
n3n_initfuncs();
Expand Down
6 changes: 1 addition & 5 deletions apps/n3n-supernode.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,6 @@ static void term_handler (int sig)
/** Main program entry point from kernel. */
int main (int argc, char * argv[]) {

#ifdef _WIN32
initWin32();
#endif

// Do this early to register all internals
n3n_initfuncs();

Expand Down Expand Up @@ -539,7 +535,7 @@ int main (int argc, char * argv[]) {
}
#endif

sss_node.mgmt_slots = slots_malloc(5, 4000, 500);
sss_node.mgmt_slots = slots_malloc(5, 5000, 500);
if(!sss_node.mgmt_slots) {
abort();
}
Expand Down
4 changes: 4 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@

rm -f include/config.h include/config.h.in include/config.h.in~ config.mak configure

# The more I use autotools, the more I want to stop using autotools
cp -p scripts/config.sub.DIST scripts/config.sub
cp -p scripts/config.guess.DIST scripts/config.guess

echo "Wait please..."
autoreconf -if
1 change: 1 addition & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.debhelper/
autoreconf.after
autoreconf.before
changelog
debhelper-build-stamp
files
n3n.debhelper.log
Expand Down
51 changes: 37 additions & 14 deletions include/n3n/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,51 @@
#define _N2N_METRICS_H_

#include <connslot/strbuf.h>
#include <stdbool.h>

enum n3n_metrics_size {
n3n_metrics_invalid = 0,
n3n_metrics_uint32,
enum __attribute__((__packed__)) n3n_metrics_items_type {
n3n_metrics_type_invalid = 0,
n3n_metrics_type_uint32, // items_uint32 is valid
n3n_metrics_type_llu32,
};

struct n3n_metrics_item {
const char *name; // What is this metric called
const char *desc; // Short description
const int offset; // byte Offset from the start of the void
const enum n3n_metrics_size size; // The storage size
// type - today, they are all counters
// unit - today, they are all unitless
// The simplest type of metrics: everything is the same storage type, there are
// no custom labels are added to anything and only one instance is possible.
// The module definition points to an array of items, terminated with an entry
// that has item->name == NULL.
// This can be rendered with no callbacks by the metrics renderer
struct n3n_metrics_items_uint32 {
const char *name; // tail of the metrics name
const char *desc; // Help text for the metric
const int offset; // Offset from the start of the void
// const enum foo type - today, they are all counters
// const enum foo unit - today, they are all unitless
};

struct n3n_metrics_items_llu32_ent {
const char *val1;
const char *val2;
const int offset; // Offset from the start of the void
};

struct n3n_metrics_items_llu32 {
const char *name; // tail of the metrics name
const char *desc; // Help text for the metric
const char *name1;
const char *name2;
const struct n3n_metrics_items_llu32_ent items[];
// const enum foo type - today, they are all counters
// const enum foo unit - today, they are all unitless
};

struct n3n_metrics_module {
struct n3n_metrics_module *next; // the metrics.c manages this
const char *name; // What is this module called
void *data; // pointer to the data
const struct n3n_metrics_item *item;
bool enabled; // Allows the registering owner to disable
void *data; // opaque pointer to the data
union {
const struct n3n_metrics_items_uint32 *items_uint32;
const struct n3n_metrics_items_llu32 *items_llu32;
};
const enum n3n_metrics_items_type type;
};

// Register a block of metrics
Expand Down
2 changes: 1 addition & 1 deletion libs/connslot/connslot.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ int slots_listen_unix(slots_t *slots, char *path, int mode, int uid, int gid) {
int result = 0;

if(mode > 0) {
result += fchmod(server, mode);
result += chmod(path, mode);
}

if(uid != -1 && gid != -1) {
Expand Down
10 changes: 10 additions & 0 deletions libs/connslot/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void sb_zero(strbuf_t *p) {
STRBUF_METRIC(zero);
p->wr_pos = 0;
p->rd_pos = 0;
p->overflowed = false;
p->str[0] = 0;
}

Expand Down Expand Up @@ -73,6 +74,7 @@ strbuf_t *sb_realloc(strbuf_t **pp, size_t size) {
strbuf_t *p = *pp;
if (size > p->capacity_max) {
STRBUF_METRIC(realloc_full);
p->overflowed = true;
size = p->capacity_max;
}

Expand Down Expand Up @@ -126,6 +128,13 @@ bool sb_full(strbuf_t *p) {
return sb_avail(p) == 0;
}

/**
* Check if the buffer looks like it has overflowed.
*/
bool sb_overflowed(strbuf_t *p) {
return p->overflowed;
}

/**
* Appends (by copying) the given buffer to the strbuf.
* If the strbuf is not large enough to store the new buffer then as much as
Expand All @@ -146,6 +155,7 @@ size_t sb_append(strbuf_t *p, void *buf, ssize_t bufsize) {
if (avail < bufsize) {
// Truncate the new data to fit
STRBUF_METRIC(append_trunc);
p->overflowed = true;
bufsize = avail;
}

Expand Down
2 changes: 2 additions & 0 deletions libs/connslot/strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct strbuf {
unsigned int capacity_max; //!< The largest automatic allowed capacity
unsigned int wr_pos; //!< str[] append position (arriving data)
unsigned int rd_pos; //!< str[] read position (processing data)
bool overflowed; //!< set if the str is overflowed
char str[];
} strbuf_t;

Expand All @@ -46,6 +47,7 @@ strbuf_t *sb_realloc(strbuf_t **, size_t);
size_t sb_len(strbuf_t *);
ssize_t sb_avail(strbuf_t *);
bool sb_full(strbuf_t *);
bool sb_overflowed(strbuf_t *);
size_t sb_append(strbuf_t *, void *, ssize_t);
strbuf_t *sb_reappend(strbuf_t **, void *, size_t);
size_t sb_vprintf(strbuf_t *, const char *, va_list);
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5b0c562

Please sign in to comment.