return true;
}
-int check_port(meshlink_handle_t *mesh) {
+static int check_port(meshlink_handle_t *mesh) {
for(int i = 0; i < 1000; i++) {
int port = 0x1000 + (rand() & 0x7fff);
return -1;
}
- return atoi(mesh->myport);
+ int port;
+
+ pthread_mutex_lock(&(mesh->mesh_mutex));
+ port = atoi(mesh->myport);
+ pthread_mutex_unlock(&(mesh->mesh_mutex));
+
+ return port;
}
bool meshlink_set_port(meshlink_handle_t *mesh, int port) {
}
void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb) {
- (void)mesh;
+ if(!mesh || !channel) {
+ meshlink_errno = MESHLINK_EINVAL;
+ return;
+ }
+
+ pthread_mutex_lock(&mesh->mesh_mutex);
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, (cb || channel->aio_send) ? channel_poll : NULL);
+ pthread_mutex_unlock(&mesh->mesh_mutex);
}
void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) {
return NULL;
}
+ pthread_mutex_lock(&mesh->mesh_mutex);
+
node_t *n = (node_t *)node;
if(!n->utcp) {
if(!n->utcp) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
+ pthread_mutex_unlock(&mesh->mesh_mutex);
return NULL;
}
}
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
+ pthread_mutex_unlock(&mesh->mesh_mutex);
return NULL;
}
channel->receive_cb = cb;
channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags);
+ pthread_mutex_unlock(&mesh->mesh_mutex);
+
if(!channel->c) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
free(channel);
extern void update_node_pmtu(meshlink_handle_t *mesh, struct node_t *n);
extern meshlink_log_level_t global_log_level;
extern meshlink_log_cb_t global_log_cb;
-extern int check_port(meshlink_handle_t *mesh);
extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n);
extern void handle_network_change(meshlink_handle_t *mesh, bool online);