Skip to content

Commit

Permalink
Merge pull request ntop#439 from fcarli3/dev
Browse files Browse the repository at this point in the history
Add new federation flag to community structure
  • Loading branch information
lucaderi authored Sep 25, 2020
2 parents 644ea6c + 31269dd commit 277b8ba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/n2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ typedef struct sn_stats
struct sn_community
{
char community[N2N_COMMUNITY_SIZE];
uint8_t is_federation; /* if not-zero, then the current community is the federation of supernodes */
uint8_t purgeable; /* indicates purgeable community (fixed-name, predetermined (-c parameter) communties usually are unpurgeable) */
uint8_t header_encryption; /* Header encryption indicator. */
he_context_t *header_encryption_ctx; /* Header encryption cipher context. */
Expand Down Expand Up @@ -491,6 +492,7 @@ int quick_edge_init(char *device_name, char *community_name,
char *local_ip_address,
char *supernode_ip_address_port,
int *keep_on_running);
int comm_init(struct sn_community *comm, char *cmn);
int sn_init(n2n_sn_t *sss);
void sn_term(n2n_sn_t *sss);
int run_sn_loop(n2n_sn_t *sss, int *keep_running);
Expand Down
4 changes: 4 additions & 0 deletions include/n2n_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
#define N2N_COMPRESSION_ID_ZSTD 3 /* set if '-z2' cli option is present, available only if compiled with zstd lib */
#define ZSTD_COMPRESSION_LEVEL 7 /* 1 (faster) ... 22 (more compression) */

/* Federation name and indicators */
#define FEDERATION_NAME "*Federation"
enum federation{IS_NO_FEDERATION = 0,IS_FEDERATION = 1};

/* (un)purgeable community indicator (supernode) */
#define COMMUNITY_UNPURGEABLE 0
#define COMMUNITY_PURGEABLE 1
Expand Down
4 changes: 2 additions & 2 deletions src/sn.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
}

HASH_ITER(hh, sss->communities, s, tmp) {
if(s->is_federation) continue;
HASH_DEL(sss->communities, s);
if (NULL != s->header_encryption_ctx)
free (s->header_encryption_ctx);
Expand Down Expand Up @@ -90,10 +91,9 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
}

s = (struct sn_community*)calloc(1,sizeof(struct sn_community));
comm_init(s,cmn_str);

if(s != NULL) {
strncpy((char*)s->community, cmn_str, N2N_COMMUNITY_SIZE-1);
s->community[N2N_COMMUNITY_SIZE-1] = '\0';
/* loaded from file, this community is unpurgeable */
s->purgeable = COMMUNITY_UNPURGEABLE;
/* we do not know if header encryption is used in this community,
Expand Down
16 changes: 13 additions & 3 deletions src/sn_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ static int try_broadcast(n2n_sn_t * sss,
return 0;
}

/** Initialise some fields of the community structure **/
int comm_init(struct sn_community *comm, char *cmn){

strncpy((char*)comm->community, cmn, N2N_COMMUNITY_SIZE-1);
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
comm->is_federation = IS_NO_FEDERATION;

return 0; /* OK */
}


/** Initialise the supernode structure */
int sn_init(n2n_sn_t *sss) {
Expand Down Expand Up @@ -969,11 +979,11 @@ static int process_udp(n2n_sn_t * sss,
}

if(!comm && (!sss->lock_communities || (match == 1))) {
comm = calloc(1, sizeof(struct sn_community));

comm = (struct sn_community*)calloc(1,sizeof(struct sn_community));
comm_init(comm,(char *)cmn.community);

if(comm) {
strncpy(comm->community, (char*)cmn.community, N2N_COMMUNITY_SIZE-1);
comm->community[N2N_COMMUNITY_SIZE-1] = '\0';
/* new communities introduced by REGISTERs could not have had encrypted header... */
comm->header_encryption = HEADER_ENCRYPTION_NONE;
comm->header_encryption_ctx = NULL;
Expand Down

0 comments on commit 277b8ba

Please sign in to comment.