Browse Source

Merge pull request #439 from fcarli3/dev

Add new federation flag to community structure
pull/443/head
Luca Deri 4 years ago
committed by GitHub
parent
commit
277b8ba4f4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      include/n2n.h
  2. 4
      include/n2n_define.h
  3. 4
      src/sn.c
  4. 16
      src/sn_utils.c

2
include/n2n.h

@ -358,6 +358,7 @@ typedef struct sn_stats
struct sn_community struct sn_community
{ {
char community[N2N_COMMUNITY_SIZE]; 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 purgeable; /* indicates purgeable community (fixed-name, predetermined (-c parameter) communties usually are unpurgeable) */
uint8_t header_encryption; /* Header encryption indicator. */ uint8_t header_encryption; /* Header encryption indicator. */
he_context_t *header_encryption_ctx; /* Header encryption cipher context. */ he_context_t *header_encryption_ctx; /* Header encryption cipher context. */
@ -491,6 +492,7 @@ int quick_edge_init(char *device_name, char *community_name,
char *local_ip_address, char *local_ip_address,
char *supernode_ip_address_port, char *supernode_ip_address_port,
int *keep_on_running); int *keep_on_running);
int comm_init(struct sn_community *comm, char *cmn);
int sn_init(n2n_sn_t *sss); int sn_init(n2n_sn_t *sss);
void sn_term(n2n_sn_t *sss); void sn_term(n2n_sn_t *sss);
int run_sn_loop(n2n_sn_t *sss, int *keep_running); int run_sn_loop(n2n_sn_t *sss, int *keep_running);

4
include/n2n_define.h

@ -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 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) */ #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) */ /* (un)purgeable community indicator (supernode) */
#define COMMUNITY_UNPURGEABLE 0 #define COMMUNITY_UNPURGEABLE 0
#define COMMUNITY_PURGEABLE 1 #define COMMUNITY_PURGEABLE 1

4
src/sn.c

@ -45,6 +45,7 @@ static int load_allowed_sn_community(n2n_sn_t *sss, char *path) {
} }
HASH_ITER(hh, sss->communities, s, tmp) { HASH_ITER(hh, sss->communities, s, tmp) {
if(s->is_federation) continue;
HASH_DEL(sss->communities, s); HASH_DEL(sss->communities, s);
if (NULL != s->header_encryption_ctx) if (NULL != s->header_encryption_ctx)
free (s->header_encryption_ctx); free (s->header_encryption_ctx);
@ -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)); s = (struct sn_community*)calloc(1,sizeof(struct sn_community));
comm_init(s,cmn_str);
if(s != NULL) { 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 */ /* loaded from file, this community is unpurgeable */
s->purgeable = COMMUNITY_UNPURGEABLE; s->purgeable = COMMUNITY_UNPURGEABLE;
/* we do not know if header encryption is used in this community, /* we do not know if header encryption is used in this community,

16
src/sn_utils.c

@ -202,6 +202,16 @@ static int try_broadcast(n2n_sn_t * sss,
return 0; 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 */ /** Initialise the supernode structure */
int sn_init(n2n_sn_t *sss) { int sn_init(n2n_sn_t *sss) {
@ -969,11 +979,11 @@ static int process_udp(n2n_sn_t * sss,
} }
if(!comm && (!sss->lock_communities || (match == 1))) { 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) { 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... */ /* new communities introduced by REGISTERs could not have had encrypted header... */
comm->header_encryption = HEADER_ENCRYPTION_NONE; comm->header_encryption = HEADER_ENCRYPTION_NONE;
comm->header_encryption_ctx = NULL; comm->header_encryption_ctx = NULL;

Loading…
Cancel
Save