#include "system.h"
-#include "cipher.h"
#include "connection.h"
-#include "crypto.h"
#include "logger.h"
+#include "meshlink_internal.h"
#include "net.h"
#include "netutl.h"
#include "node.h"
static bool mykeyused = false;
void send_key_changed(void) {
- send_request(everyone, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+ send_request(mesh->everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name);
/* Force key exchange for connections using SPTPS */
- for splay_each(node_t, n, node_tree)
+ for splay_each(node_t, n, mesh->nodes)
if(n->status.reachable && n->status.validkey)
sptps_force_kex(&n->sptps);
}
to->sptps.send_data = send_sptps_data;
char buf[len * 4 / 3 + 5];
b64encode(data, buf, len);
- return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf);
+ return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, to->name, REQ_KEY, buf);
}
bool send_req_key(node_t *to) {
if(!node_read_ecdsa_public_key(to)) {
logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", to->name, to->hostname);
- send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, REQ_PUBKEY);
+ send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY);
return true;
}
if(to->sptps.label)
logger(DEBUG_ALWAYS, LOG_DEBUG, "send_req_key(%s) called while sptps->label != NULL!", to->name);
- char label[25 + strlen(myself->name) + strlen(to->name)];
- snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name);
+ char label[25 + strlen(mesh->self->name) + strlen(to->name)];
+ snprintf(label, sizeof label, "tinc UDP key expansion %s %s", mesh->self->name, to->name);
sptps_stop(&to->sptps);
to->status.validkey = false;
to->status.waitingforkey = true;
to->last_req_key = now.tv_sec;
- to->incompression = myself->incompression;
- return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
+ to->incompression = mesh->self->incompression;
+ return sptps_start(&to->sptps, to, true, true, mesh->self->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
}
/* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */
static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, int reqno) {
switch(reqno) {
case REQ_PUBKEY: {
- char *pubkey = ecdsa_get_base64_public_key(myself->connection->ecdsa);
- send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, from->name, ANS_PUBKEY, pubkey);
+ char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa);
+ send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, mesh->self->name, from->name, ANS_PUBKEY, pubkey);
free(pubkey);
return true;
}
case REQ_KEY: {
if(!node_read_ecdsa_public_key(from)) {
logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", from->name, from->hostname);
- send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, from->name, REQ_PUBKEY);
+ send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
return true;
}
return true;
}
- char label[25 + strlen(from->name) + strlen(myself->name)];
- snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, myself->name);
+ char label[25 + strlen(from->name) + strlen(mesh->self->name)];
+ snprintf(label, sizeof label, "tinc UDP key expansion %s %s", from->name, mesh->self->name);
sptps_stop(&from->sptps);
from->status.validkey = false;
from->status.waitingforkey = true;
from->last_req_key = now.tv_sec;
- sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record);
+ sptps_start(&from->sptps, from, false, true, mesh->self->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record);
sptps_receive_data(&from->sptps, buf, len);
return true;
}
/* Check if this key request is for us */
- if(to == myself) { /* Yes */
+ if(to == mesh->self) { /* Yes */
/* Is this an extended REQ_KEY message? */
if(reqno)
return req_key_ext_h(c, request, from, reqno);
/* Forward it if necessary */
- if(to != myself) {
+ if(to != mesh->self) {
if(!to->status.reachable) {
logger(DEBUG_ALWAYS, LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
"ANS_KEY", c->name, c->hostname, to_name);