return hostname;
}
-static char *get_my_hostname(meshlink_handle_t* mesh) {
+static char *get_my_hostname(meshlink_handle_t *mesh) {
char *hostname = NULL;
char *port = NULL;
char *hostport = NULL;
if(!data || !*data)
return NULL;
- if(!**data) {
+ if(! **data) {
*data = NULL;
return NULL;
}
}
static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) {
- meshlink_handle_t* mesh = handle;
+ meshlink_handle_t *mesh = handle;
while(len) {
int result = send(mesh->sock, data, len, 0);
if(result == -1 && errno == EINTR)
}
static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) {
- meshlink_handle_t* mesh = handle;
+ meshlink_handle_t *mesh = handle;
switch(type) {
case SPTPS_HANDSHAKE:
return sptps_send_record(&(mesh->sptps), 0, mesh->cookie, sizeof(mesh)->cookie);
return true;
}
-static bool recvline(meshlink_handle_t* mesh, size_t len) {
+static bool recvline(meshlink_handle_t *mesh, size_t len) {
char *newline = NULL;
if(!mesh->sock)
return true;
}
-meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char* appname, dev_class_t devclass) {
+meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const char *appname, dev_class_t devclass) {
// Validate arguments provided by the application
bool usingname = false;
return false;
}
- mesh->threadstarted=true;
+ mesh->threadstarted = true;
if(mesh->discovery)
discovery_start(mesh);
mesh->threadstarted = false;
+ // Close all metaconnections
+ if(mesh->connections) {
+ for(list_node_t *node = mesh->connections->head, *next; node; node = next) {
+ next = node->next;
+ connection_t *c = node->data;
+ c->outgoing = NULL;
+ terminate_connection(mesh, c, false);
+ }
+ }
+
+ if(mesh->outgoings)
+ list_delete_list(mesh->outgoings);
+ mesh->outgoings = NULL;
+
pthread_mutex_unlock(&(mesh->mesh_mutex));
}
memset(hdr, 0, sizeof(*hdr));
// leave the last byte as 0 to make sure strings are always
// null-terminated if they are longer than the buffer
- strncpy(hdr->destination, destination->name, (sizeof(hdr)->destination) - 1);
- strncpy(hdr->source, mesh->self->name, (sizeof(hdr)->source) -1);
+ strncpy((char *)hdr->destination, destination->name, (sizeof(hdr)->destination) - 1);
+ strncpy((char *)hdr->source, mesh->self->name, (sizeof(hdr)->source) - 1);
memcpy(packet->data + sizeof(*hdr), data, len);
}
// Notify event loop
- signal_trigger(&(mesh->loop),&(mesh->datafromapp));
+ signal_trigger(&(mesh->loop), &(mesh->datafromapp));
return true;
}
if(fread(buf + len - fsize - 1, fsize, 1, f) != 1) {
logger(mesh, MESHLINK_DEBUG, "Error reading from %s: %s\n", filename, strerror(errno));
fclose(f);
+ free(buf);
meshlink_errno = MESHLINK_ESTORAGE;
pthread_mutex_unlock(&(mesh->mesh_mutex));
return NULL;
pthread_mutex_lock(&(mesh->mesh_mutex));
node_t *n;
- n = (node_t*)node;
- n->status.blacklisted=true;
- logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n",node->name);
+ n = (node_t *)node;
+ n->status.blacklisted = true;
+ logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
//Make blacklisting persistent in the config file
append_config_file(mesh, n->name, "blacklisted", "yes");
if(host && port) {
xasprintf(&str, "%s %s", host, port);
- if((strncmp("fe80",host,4) != 0) && (strncmp("127.",host,4) != 0) && (strcmp("localhost",host) !=0))
- append_config_file(mesh, node->name, "Address", str);
+ if((strncmp("fe80", host, 4) != 0) && (strncmp("127.", host, 4) != 0) && (strcmp("localhost", host) != 0))
+ modify_config_file(mesh, node->name, "Address", str, 5);
else
logger(mesh, MESHLINK_DEBUG, "Not adding Link Local IPv6 Address to config\n");
}
// if result is smaller than edges, we have to dealloc all the excess meshlink_edge_t
if(result_size > *nmemb)
- result = realloc(edges, result_size * sizeof(meshlink_edge_t*));
+ result = realloc(edges, result_size * sizeof(meshlink_edge_t *));
else
result = edges;
copy = xzalloc(sizeof(*copy));
else
copy = *p;
- copy->from = (meshlink_node_t*)e->from;
- copy->to = (meshlink_node_t*)e->to;
+ copy->from = (meshlink_node_t *)e->from;
+ copy->to = (meshlink_node_t *)e->to;
copy->address = e->address.storage;
copy->options = e->options;
copy->weight = e->weight;
// shrink result to the actual amount of memory used
for(int i = *nmemb; i > result_size; i--)
free(result[i - 1]);
- result = realloc(result, result_size * sizeof(meshlink_edge_t*));
+ result = realloc(result, result_size * sizeof(meshlink_edge_t *));
*nmemb = result_size;
} else {
*nmemb = 0;
}
static bool channel_pre_accept(struct utcp *utcp, uint16_t port) {
- //TODO: implement
- return true;
+ node_t *n = utcp->priv;
+ meshlink_handle_t *mesh = n->mesh;
+ return mesh->channel_accept_cb;
}
static ssize_t channel_recv(struct utcp_connection *connection, const void *data, size_t len) {
abort();
node_t *n = channel->node;
meshlink_handle_t *mesh = n->mesh;
- if(channel->receive_cb)
+ if(n->status.destroyed)
+ meshlink_channel_close(mesh, channel);
+ else if(channel->receive_cb)
channel->receive_cb(mesh, channel, data, len);
return len;
}
}
/// Device class traits
-dev_class_traits_t dev_class_traits[_DEV_CLASS_MAX +1] = {
+dev_class_traits_t dev_class_traits[_DEV_CLASS_MAX + 1] = {
{ .min_connects = 3, .max_connects = 10000, .edge_weight = 1 }, // DEV_CLASS_BACKBONE
{ .min_connects = 3, .max_connects = 100, .edge_weight = 3 }, // DEV_CLASS_STATIONARY
{ .min_connects = 3, .max_connects = 3, .edge_weight = 6 }, // DEV_CLASS_PORTABLE