#define CHAT_PORT 531
static void log_message(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
- const char *levelstr[] = {
+ (void) mesh;
+
+ static const char *levelstr[] = {
[MESHLINK_DEBUG] = "\x1b[34mDEBUG",
[MESHLINK_INFO] = "\x1b[32mINFO",
[MESHLINK_WARNING] = "\x1b[33mWARNING",
}
static bool channel_accept(meshlink_handle_t *mesh, meshlink_channel_t *channel, uint16_t port, const void *data, size_t len) {
+ (void)data;
+ (void)len;
+
// Only accept connections to the chat port
if(port != CHAT_PORT) {
fprintf(stderr, "Rejected incoming channel from '%s' to port %u\n", channel->node->name, port);
}
static void channel_poll(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t len) {
+ (void)len;
+
fprintf(stderr, "Channel to '%s' connected\n", channel->node->name);
meshlink_set_channel_poll_cb(mesh, channel, NULL);
}
static void node_status(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
+ (void)mesh;
+
if(reachable) {
printf("%s joined.\n", node->name);
} else {
return;
}
- invitation = meshlink_invite(mesh, arg);
+ invitation = meshlink_invite(mesh, NULL, arg);
if(!invitation) {
fprintf(stderr, "Could not invite '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
return;
}
- meshlink_blacklist(mesh, node);
+ if(!meshlink_blacklist(mesh, node)) {
+ fprintf(stderr, "Error blacklising '%s': %s", arg, meshlink_strerror(meshlink_errno));
+ return;
+ }
printf("Node '%s' blacklisted.\n", arg);
+ } else if(!strcasecmp(buf, "whitelist")) {
+ if(!arg) {
+ fprintf(stderr, "/whitelist requires an argument!\n");
+ return;
+ }
+
+ meshlink_node_t *node = meshlink_get_node(mesh, arg);
+
+ if(!node) {
+ fprintf(stderr, "Error looking up '%s': %s\n", arg, meshlink_strerror(meshlink_errno));
+ return;
+ }
+
+ if(!meshlink_whitelist(mesh, node)) {
+ fprintf(stderr, "Error whitelising '%s': %s", arg, meshlink_strerror(meshlink_errno));
+ return;
+ }
+
+ printf("Node '%s' whitelisted.\n", arg);
} else if(!strcasecmp(buf, "who")) {
if(!arg) {
nodes = meshlink_get_all_nodes(mesh, nodes, &nnodes);
} else {
printf("%zu known nodes:", nnodes);
- for(int i = 0; i < nnodes; i++) {
+ for(size_t i = 0; i < nnodes; i++) {
printf(" %s", nodes[i]->name);
}
// Commands start with '/'
if(*buf == '/') {
- return parse_command(mesh, buf + 1);
+ parse_command(mesh, buf + 1);
+ return;
}
// Lines in the form "name: message..." set the destination node.