/*
buffer.c -- buffer management
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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 "buffer.h"
#include "xalloc.h"
-void buffer_compact(buffer_t *buffer, int maxsize) {
+void buffer_compact(buffer_t *buffer, size_t maxsize) {
if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) {
memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset);
buffer->len -= buffer->offset;
// Make sure we can add size bytes to the buffer, and return a pointer to the start of those bytes.
-char *buffer_prepare(buffer_t *buffer, int size) {
+char *buffer_prepare(buffer_t *buffer, size_t size) {
if(!buffer->data) {
buffer->maxlen = size;
buffer->data = xmalloc(size);
// Copy data into the buffer.
-void buffer_add(buffer_t *buffer, const char *data, int size) {
+void buffer_add(buffer_t *buffer, const char *data, size_t size) {
memcpy(buffer_prepare(buffer, size), data, size);
}
// Remove given number of bytes from the buffer, return a pointer to the start of them.
-static char *buffer_consume(buffer_t *buffer, int size) {
+static char *buffer_consume(buffer_t *buffer, size_t size) {
char *start = buffer->data + buffer->offset;
buffer->offset += size;
if(!newline)
return NULL;
- int len = newline + 1 - (buffer->data + buffer->offset);
+ size_t len = newline + 1 - (buffer->data + buffer->offset);
*newline = 0;
return buffer_consume(buffer, len);
}
// Check if we have enough bytes in the buffer, and if so, return a pointer to the start of them.
-char *buffer_read(buffer_t *buffer, int size) {
+char *buffer_read(buffer_t *buffer, size_t size) {
if(buffer->len - buffer->offset < size)
return NULL;
typedef struct buffer_t {
char *data;
- int maxlen;
- int len;
- int offset;
+ size_t maxlen;
+ size_t len;
+ size_t offset;
} buffer_t;
-extern void buffer_compact(buffer_t *buffer, int maxsize);
-extern char *buffer_prepare(buffer_t *buffer, int size);
-extern void buffer_add(buffer_t *buffer, const char *data, int size);
+extern void buffer_compact(buffer_t *buffer, size_t maxsize);
+extern char *buffer_prepare(buffer_t *buffer, size_t size);
+extern void buffer_add(buffer_t *buffer, const char *data, size_t size);
extern char *buffer_readline(buffer_t *buffer);
-extern char *buffer_read(buffer_t *buffer, int size);
+extern char *buffer_read(buffer_t *buffer, size_t size);
extern void buffer_clear(buffer_t *buffer);
#endif
pthread_mutex_lock(&(mesh->mesh_mutex));
devtool_edge_t *result = NULL;
- int result_size = 0;
+ unsigned int result_size = 0;
result_size = mesh->edges->count / 2;
// if result is smaller than edges, we have to dealloc all the excess devtool_edge_t
- if(result_size > *nmemb)
+ if((size_t)result_size > *nmemb)
result = realloc(edges, result_size * sizeof(*result));
else
result = edges;
if(result) {
devtool_edge_t *p = result;
- int n = 0;
+ unsigned int n = 0;
for splay_each(edge_t, e, mesh->edges) {
// skip edges that do not represent a two-directional connection
}
static void discovery_entry_group_callback(CattaServer *server, CattaSEntryGroup *group, CattaEntryGroupState state, void *userdata) {
+ (void)server;
+ (void)group;
meshlink_handle_t *mesh = userdata;
// asserts
}
static void discovery_server_callback(CattaServer *server, CattaServerState state, void *userdata) {
+ (void)server;
meshlink_handle_t *mesh = userdata;
// asserts
}
static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfIndex interface_, CattaProtocol protocol, CattaResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const CattaAddress *address, uint16_t port, CattaStringList *txt, CattaLookupResultFlags flags, void *userdata) {
+ (void)interface_;
+ (void)protocol;
meshlink_handle_t *mesh = userdata;
// asserts
}
static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfIndex interface_, CattaProtocol protocol, CattaBrowserEvent event, const char *name, const char *type, const char *domain, CattaLookupResultFlags flags, void *userdata) {
+ (void)browser;
+ (void)flags;
meshlink_handle_t *mesh = userdata;
// asserts
/*
ecdsa.c -- ECDSA key handling
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
size_t ecdsa_size(ecdsa_t *ecdsa) {
+ (void)ecdsa;
return 64;
}
/*
event.c -- I/O, timeout and signal event handling
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
static void signalio_handler(event_loop_t *loop, void *data, int flags) {
+ (void)data;
+ (void)flags;
unsigned char signum;
if(read(loop->pipefd[0], &signum, 1) != 1)
return;
typedef struct list_t {
list_node_t *head;
list_node_t *tail;
- int count;
+ unsigned int count;
/* Callbacks */
/*
logger.c -- logging code
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
int len = vsnprintf(message, sizeof(message), format, ap);
va_end(ap);
- if(len > 0 && len < sizeof(message) && message[len - 1] == '\n')
+ if(len > 0 && (size_t)len < sizeof(message) && message[len - 1] == '\n')
message[len - 1] = 0;
if(mesh)
static char line[1024];
const char *end = strchr(*data, '\n');
- size_t len = end ? end - *data : strlen(*data);
+ size_t len = end ? (size_t)(end - *data) : strlen(*data);
if(len >= sizeof(line)) {
logger(NULL, MESHLINK_ERROR, "Maximum line length exceeded!\n");
return NULL;
}
static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) {
+ (void)type;
meshlink_handle_t *mesh = handle;
while(len) {
int result = send(mesh->sock, data, len, 0);
mesh->blen += result;
}
- if(newline - mesh->buffer >= len)
+ if((size_t)(newline - mesh->buffer) >= len)
return false;
len = newline - mesh->buffer;
blen = vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
- if(blen < 1 || blen >= sizeof(buffer))
+ if(blen < 1 || (size_t)blen >= sizeof(buffer))
return false;
buffer[blen] = '\n';
};
const char *meshlink_strerror(meshlink_errno_t err) {
- if(err < 0 || err >= sizeof(errstr) / sizeof(*errstr))
+ if((int)err < 0 || err >= sizeof(errstr) / sizeof(*errstr))
return "Invalid error code";
return errstr[err];
}
}
static struct timeval idle(event_loop_t *loop, void *data) {
+ (void)loop;
meshlink_handle_t *mesh = data;
struct timeval t, tmin = {3600, 0};
for splay_each(node_t, n, mesh->nodes) {
usingname = true;
}
- if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
+ if((int)devclass < 0 || devclass > _DEV_CLASS_MAX) {
logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n");
meshlink_errno = MESHLINK_EINVAL;
return NULL;
}
void meshlink_send_from_queue(event_loop_t *loop, meshlink_handle_t *mesh) {
+ (void)loop;
vpn_packet_t *packet = meshlink_queue_pop(&mesh->outpacketqueue);
if(!packet)
return;
}
static bool channel_pre_accept(struct utcp *utcp, uint16_t port) {
+ (void)port;
node_t *n = utcp->priv;
meshlink_handle_t *mesh = n->mesh;
return mesh->channel_accept_cb;
static ssize_t channel_send(struct utcp *utcp, const void *data, size_t len) {
node_t *n = utcp->priv;
meshlink_handle_t *mesh = n->mesh;
- return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? len : -1;
+ return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? (ssize_t)len : -1;
}
void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_receive_cb_t cb) {
}
static void channel_receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) {
+ (void)mesh;
node_t *n = (node_t *)source;
if(!n->utcp)
abort();
}
void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb) {
+ (void)mesh;
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, cb ? channel_poll : NULL);
}
}
meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) {
+ if(data || len)
+ abort(); // TODO: handle non-NULL data
+
if(!mesh || !node) {
meshlink_errno = MESHLINK_EINVAL;
return NULL;
/*
meta.c -- handle the meta communication
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>,
+ Copyright (C) 2014-2017 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 "xalloc.h"
bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) {
+ (void)type;
connection_t *c = handle;
meshlink_handle_t *mesh = c->mesh;
/* Are we receiving a TCPpacket? */
if(c->tcplen) {
- if(length != c->tcplen)
- return false;
- receive_tcppacket(mesh, c, request, length);
- c->tcplen = 0;
- return true;
+ abort(); // TODO: get rid of tcplen altogether
}
/* Change newline to null byte, just like non-SPTPS requests */
/*
net.c -- most of the network code
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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 <assert.h>
#if !defined(min)
-static const int min(int a, int b) {
+static inline int min(int a, int b) {
return a < b ? a : b;
}
#endif
// get cur_connects
- int cur_connects = 0;
+ unsigned int cur_connects = 0;
for list_each(connection_t, c, mesh->connections) {
if(c->status.active)
assert(mesh->devclass >= 0 && mesh->devclass <= _DEV_CLASS_MAX);
- int min_connects = dev_class_traits[mesh->devclass].min_connects;
- int max_connects = dev_class_traits[mesh->devclass].max_connects;
+ unsigned int min_connects = dev_class_traits[mesh->devclass].min_connects;
+ unsigned int max_connects = dev_class_traits[mesh->devclass].max_connects;
logger(mesh, MESHLINK_DEBUG, "* min_connects = %d", min_connects);
logger(mesh, MESHLINK_DEBUG, "* max_connects = %d", max_connects);
if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) {
unsigned int connects = 0;
- for(int devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass)
connects += 1;
if(min_connects < cur_connects /*&& cur_connects <= max_connects*/) {
unsigned int connects = 0;
- for(int devclass = 0; devclass <= mesh->devclass; ++devclass) {
+ for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) {
for list_each(connection_t, c, mesh->connections) {
if(c->status.active && c->node && c->node->devclass == devclass)
connects += 1;
extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len);
extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
-extern void receive_tcppacket(struct meshlink_handle *mesh, struct connection_t *, const char *, int);
extern void broadcast_packet(struct meshlink_handle *mesh, const struct node_t *, struct vpn_packet_t *);
extern char *get_name(struct meshlink_handle *mesh);
extern void load_all_nodes(struct meshlink_handle *mesh);
/*
net_packet.c -- Handles in- and outgoing VPN packets
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
}
-static uint16_t compress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) {
- abort();
-}
-
-static uint16_t uncompress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) {
- abort();
-}
-
/* VPN packet I/O */
static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) {
}
static bool try_mac(meshlink_handle_t *mesh, node_t *n, const vpn_packet_t *inpkt) {
+ (void)mesh;
return sptps_verify_datagram(&n->sptps, inpkt->data, inpkt->len);
}
sptps_receive_data(&n->sptps, inpkt->data, inpkt->len);
}
-void receive_tcppacket(meshlink_handle_t *mesh, connection_t *c, const char *buffer, int len) {
- vpn_packet_t outpkt;
-
- if(len > sizeof(outpkt).data)
- return;
-
- outpkt.len = len;
- outpkt.tcp = true;
- memcpy(outpkt.data, buffer, len);
-
- receive_packet(mesh, c->node, &outpkt);
-}
-
static void send_sptps_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *origpkt) {
if(!n->status.validkey) {
logger(mesh, MESHLINK_INFO, "No valid key known yet for %s", n->name);
return;
}
- vpn_packet_t outpkt;
-
if(n->outcompression) {
- int len = compress_packet(outpkt.data, origpkt->data, origpkt->len, n->outcompression);
- if(len < 0)
- logger(mesh, MESHLINK_ERROR, "Error while compressing packet to %s", n->name);
- else if(len < origpkt->len) {
- outpkt.len = len;
- origpkt = &outpkt;
- type |= PKT_COMPRESSED;
- }
+ logger(mesh, MESHLINK_ERROR, "Error while compressing packet to %s", n->name);
+ return;
}
sptps_send_record(&n->sptps, type, origpkt->data, origpkt->len);
}
if(type & PKT_COMPRESSED) {
- uint16_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression);
- if(ulen < 0)
- return false;
- else
- inpkt.len = ulen;
- if(inpkt.len > MAXSIZE)
- abort();
- } else {
- memcpy(inpkt.data, data, len);
- inpkt.len = len;
+ logger(mesh, MESHLINK_ERROR, "Error while decompressing packet from %s", from->name);
+ return false;
}
+ memcpy(inpkt.data, data, len); // TODO: get rid of memcpy
+ inpkt.len = len;
+
receive_packet(mesh, from, &inpkt);
return true;
}
}
void handle_incoming_vpn_data(event_loop_t *loop, void *data, int flags) {
+ (void)flags;
meshlink_handle_t *mesh = loop->data;
listen_socket_t *ls = data;
vpn_packet_t pkt;
char *hostname;
- sockaddr_t from = {{0}};
+ sockaddr_t from = {};
socklen_t fromlen = sizeof(from);
node_t *n;
int len;
/*
net_setup.c -- Setup.
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
free(p);
}
- if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
+ if((int)n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
n->devclass = _DEV_CLASS_MAX;
exit:
bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) {
- if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
+ if((int)n->devclass < 0 || n->devclass > _DEV_CLASS_MAX)
return false;
bool result = false;
*address = 0;
}
- struct addrinfo *ai, hint = {0};
+ struct addrinfo *ai, hint = {};
hint.ai_family = addressfamily;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;
/*
net_socket.c -- Handle various kinds of sockets.
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, MSG_NOSIGNAL);
if(outlen <= 0) {
- if(!errno || errno == EPIPE)
+ if(!errno || errno == EPIPE) {
logger(mesh, MESHLINK_INFO, "Connection closed by %s", c->name);
- else if(sockwouldblock(sockerrno)) {
- logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s would block", c->outbuf.len - c->outbuf.offset, c->name);
+ } else if(sockwouldblock(sockerrno)) {
+ logger(mesh, MESHLINK_DEBUG, "Sending %lu bytes to %s would block", (unsigned long)(c->outbuf.len - c->outbuf.offset), c->name);
return;
- } else
- logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s: %s", c->outbuf.len - c->outbuf.offset, c->name, strerror(errno));
+ } else {
+ logger(mesh, MESHLINK_ERROR, "Could not send %lu bytes of data to %s: %s", (unsigned long)(c->outbuf.len - c->outbuf.offset), c->name, strerror(errno));
+ }
terminate_connection(mesh, c, c->status.active);
return;
new connection
*/
void handle_new_meta_connection(event_loop_t *loop, void *data, int flags) {
+ (void)flags;
meshlink_handle_t *mesh = loop->data;
listen_socket_t *l = data;
connection_t *c;
/*
netutl.c -- some supporting network utility code
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
Return NULL on failure.
*/
struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) {
- struct addrinfo *ai, hint = {0};
+ struct addrinfo *ai, hint = {};
int err;
hint.ai_family = addressfamily;
}
sockaddr_t str2sockaddr(const char *address, const char *port) {
- struct addrinfo *ai, hint = {0};
- sockaddr_t result = {{0}};
+ struct addrinfo *ai, hint = {};
+ sockaddr_t result = {};
int err;
hint.ai_family = AF_UNSPEC;
/*
protocol.c -- handle the meta-protocol, basic functions
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
static void age_past_requests(event_loop_t *loop, void *data) {
+ (void)data;
meshlink_handle_t *mesh = loop->data;
int left = 0, deleted = 0;
}
bool seen_request(meshlink_handle_t *mesh, const char *request) {
- past_request_t *new, p = {NULL};
+ past_request_t *new, p = {};
p.request = request;
extern bool send_id(struct meshlink_handle *mesh, struct connection_t *);
extern bool send_ack(struct meshlink_handle *mesh, struct connection_t *);
-extern bool send_status(struct meshlink_handle *mesh, struct connection_t *, int, const char *);
-extern bool send_error(struct meshlink_handle *mesh, struct connection_t *, int, const char *);
-extern bool send_termreq(struct meshlink_handle *mesh, struct connection_t *);
extern bool send_ping(struct meshlink_handle *mesh, struct connection_t *);
extern bool send_pong(struct meshlink_handle *mesh, struct connection_t *);
extern bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *);
extern bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *);
extern void send_key_changed(struct meshlink_handle *mesh);
extern bool send_req_key(struct meshlink_handle *mesh, struct node_t *);
-extern bool send_ans_key(struct meshlink_handle *mesh, struct node_t *);
-extern bool send_tcppacket(struct meshlink_handle *mesh, struct connection_t *, const struct vpn_packet_t *);
/* Request handlers */
/*
protocol_auth.c -- handle the meta-protocol, authentication
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data, uint16_t len) {
+ (void)len;
if(strchr(data, '\n')) {
logger(mesh, MESHLINK_ERROR, "Received invalid key from invited node %s!\n", c->name);
return false;
/*
protocol_key.c -- handle the meta-protocol, key exchange
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
}
static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) {
+ (void)type;
node_t *to = handle;
meshlink_handle_t *mesh = to->mesh;
to->sptps.send_data = send_sptps_data;
/* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */
static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *request, node_t *from, int reqno) {
+ (void)c;
switch(reqno) {
case REQ_PUBKEY: {
char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa);
if(reqno)
return req_key_ext_h(mesh, c, request, from, reqno);
- /* No, just send our key back */
- send_ans_key(mesh, from);
+ /* This should never happen. Ignore it, unless it came directly from the connected peer, in which case we disconnect. */
+ return from->connection != c;
} else {
if(!to->status.reachable) {
logger(mesh, MESHLINK_WARNING, "Got %s from %s destination %s which is not reachable",
}
bool send_ans_key(meshlink_handle_t *mesh, node_t *to) {
+ (void)mesh;
+ (void)to;
abort();
}
/*
protocol_misc.c -- handle the meta-protocol, miscellaneous functions
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
/* Status and error notification routines */
-bool send_status(meshlink_handle_t *mesh, connection_t *c, int statusno, const char *statusstring) {
- if(!statusstring)
- statusstring = "Status";
-
- return send_request(mesh, c, "%d %d %s", STATUS, statusno, statusstring);
-}
-
bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
int statusno;
char statusstring[MAX_STRING_SIZE];
return true;
}
-bool send_error(meshlink_handle_t *mesh, connection_t *c, int err, const char *errstring) {
- if(!errstring)
- errstring = "Error";
-
- return send_request(mesh, c, "%d %d %s", ERROR, err, errstring);
-}
-
bool error_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
int err;
char errorstring[MAX_STRING_SIZE];
return false;
}
-bool send_termreq(meshlink_handle_t *mesh, connection_t *c) {
- return send_request(mesh, c, "%d", TERMREQ);
-}
-
bool termreq_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+ (void)mesh;
+ (void)c;
+ (void)request;
return false;
}
}
bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+ (void)request;
return send_pong(mesh, c);
}
}
bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+ (void)mesh;
+ (void)request;
c->status.pinged = false;
/* Succesful connection, reset timeout if this is an outgoing connection. */
/* Sending and receiving packets via TCP */
-bool send_tcppacket(meshlink_handle_t *mesh, connection_t *c, const vpn_packet_t *packet) {
- /* If there already is a lot of data in the outbuf buffer, discard this packet.
- We use a very simple Random Early Drop algorithm. */
-
- if(2.0 * c->outbuf.len / (float)maxoutbufsize - 1 > (float)rand() / (float)RAND_MAX)
- return true;
-
- if(!send_request(mesh, c, "%d %hd", PACKET, packet->len))
- return false;
-
- return send_meta(mesh, c, (char *)packet->data, packet->len);
-}
-
bool tcppacket_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
short int len;
return false;
}
- /* Set reqlen to len, this will tell receive_meta() that a tcppacket is coming. */
-
- c->tcplen = len;
-
- return true;
+ // This should never happen with MeshLink.
+ return false;
}
/*
splay_tree.c -- splay tree and linked list convenience
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
/* Splay operation */
static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) {
- splay_node_t left = {NULL}, right = {NULL};
+ splay_node_t left = {}, right = {};
splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild;
splay_node_t *root = tree->root;
int c;
splay_compare_t compare;
splay_action_t delete;
- int count;
+ unsigned int count;
} splay_tree_t;
/*
sptps.c -- Simple Peer-to-Peer Security
- Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+ Copyright (C) 2014-2017 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
*/
void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap) {
+ (void)s;
+ (void)s_errno;
+ (void)format;
+ (void)ap;
}
void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) {
+ (void)s;
+ (void)s_errno;
vfprintf(stderr, format, ap);
fputc('\n', stderr);
}
// Receive an ACKnowledgement record.
static bool receive_ack(sptps_t *s, const char *data, uint16_t len) {
+ (void)data;
if(len)
return error(s, EIO, "Invalid ACK record length");
// We receive a secondary KEX request, first respond by sending our own.
if(!send_kex(s))
return false;
+ // fallthrough
case SPTPS_KEX:
// We have sent our KEX request, we expect our peer to sent one as well.
if(!receive_kex(s, data, len))
return error(s, EIO, "Received late or replayed packet, seqno %d, last received %d\n", seqno, s->inseqno);
} else {
// We missed some packets. Mark them in the bitmap as being late.
- for(int i = s->inseqno; i < seqno; i++)
+ for(uint32_t i = s->inseqno; i < seqno; i++)
s->late[(i / 8) % s->replaywin] |= 1 << i % 8;
}
}
-Subproject commit 1d8aa0d5a55bb871ce56bca355ade80b08a7c1e5
+Subproject commit 558c6d183e2a580b811c5603dd48c33b01a3dc7e