void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
if(c->edge) {
if(report) {
send_del_edge(mesh, mesh->everyone, c->edge, 0);
if(c->edge) {
if(report) {
send_del_edge(mesh, mesh->everyone, c->edge, 0);
if(!sptps_force_kex(&c->sptps)) {
logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for connection with %s failed", c->name);
terminate_connection(mesh, c, true);
if(!sptps_force_kex(&c->sptps)) {
logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for connection with %s failed", c->name);
terminate_connection(mesh, c, true);
if(mesh->contradicting_del_edge > 100 && mesh->contradicting_add_edge > 100) {
logger(mesh, MESHLINK_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", mesh->sleeptime);
struct timespec ts = {mesh->sleeptime, 0};
if(mesh->contradicting_del_edge > 100 && mesh->contradicting_add_edge > 100) {
logger(mesh, MESHLINK_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", mesh->sleeptime);
struct timespec ts = {mesh->sleeptime, 0};
if(n->status.validkey && n->last_req_key + 3600 < mesh->loop.now.tv_sec) {
logger(mesh, MESHLINK_DEBUG, "SPTPS key renewal for node %s", n->name);
if(n->status.validkey && n->last_req_key + 3600 < mesh->loop.now.tv_sec) {
logger(mesh, MESHLINK_DEBUG, "SPTPS key renewal for node %s", n->name);
if(!sptps_force_kex(&n->sptps)) {
logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for node %s failed", n->name);
n->status.validkey = false;
sptps_stop(&n->sptps);
n->status.waitingforkey = false;
if(!sptps_force_kex(&n->sptps)) {
logger(mesh, MESHLINK_ERROR, "SPTPS key renewal for node %s failed", n->name);
n->status.validkey = false;
sptps_stop(&n->sptps);
n->status.waitingforkey = false;