/*
node.c -- node tree management
- Copyright (C) 2001-2013 Guus Sliepen <guus@tinc-vpn.org>,
- 2001-2005 Ivo Timmermans
+ Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>,
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "hash.h"
#include "logger.h"
+#include "meshlink_internal.h"
#include "net.h"
#include "netutl.h"
#include "node.h"
#include "utils.h"
#include "xalloc.h"
-splay_tree_t *node_tree;
static hash_t *node_udp_cache;
-node_t *myself;
-
static int node_compare(const node_t *a, const node_t *b) {
return strcmp(a->name, b->name);
}
void init_nodes(void) {
- node_tree = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node);
+ mesh->nodes = splay_alloc_tree((splay_compare_t) node_compare, (splay_action_t) free_node);
node_udp_cache = hash_alloc(0x100, sizeof(sockaddr_t));
}
void exit_nodes(void) {
hash_free(node_udp_cache);
- splay_delete_tree(node_tree);
+ splay_delete_tree(mesh->nodes);
}
node_t *new_node(void) {
sockaddrfree(&n->address);
- cipher_close(n->incipher);
- digest_close(n->indigest);
- cipher_close(n->outcipher);
- digest_close(n->outdigest);
-
ecdsa_free(n->ecdsa);
sptps_stop(&n->sptps);
}
void node_add(node_t *n) {
- splay_insert(node_tree, n);
+ splay_insert(mesh->nodes, n);
}
void node_del(node_t *n) {
for splay_each(edge_t, e, n->edge_tree)
edge_del(e);
- splay_delete(node_tree, n);
+ splay_delete(mesh->nodes, n);
}
node_t *lookup_node(char *name) {
n.name = name;
- return splay_search(node_tree, &n);
+ return splay_search(mesh->nodes, &n);
}
node_t *lookup_node_udp(const sockaddr_t *sa) {
}
void update_node_udp(node_t *n, const sockaddr_t *sa) {
- if(n == myself) {
- logger(DEBUG_ALWAYS, LOG_WARNING, "Trying to update UDP address of myself!");
+ if(n == mesh->self) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Trying to update UDP address of mesh->self!");
return;
}