- if(!to) {
- logger(LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
- "REQ_KEY", c->name, c->hostname, to_name);
+ /* Send our canonical address to help with UDP hole punching */
+ send_canonical_address(mesh, to);
+
+ char label[sizeof(meshlink_udp_label) + strlen(mesh->self->name) + strlen(to->name) + 2];
+ snprintf(label, sizeof(label), "%s %s %s", meshlink_udp_label, mesh->self->name, to->name);
+ sptps_stop(&to->sptps);
+ to->status.validkey = false;
+ to->status.waitingforkey = true;
+ to->last_req_key = mesh->loop.now.tv_sec;
+ return sptps_start(&to->sptps, to, true, true, mesh->private_key, to->ecdsa, label, sizeof(label) - 1, 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(meshlink_handle_t *mesh, connection_t *c, const char *request, node_t *from, int reqno) {
+ (void)c;
+
+ if(!from->nexthop || !from->nexthop->connection) {
+ logger(mesh, MESHLINK_WARNING, "Cannot answer REQ_KEY from %s via %s", from->name, from->nexthop ? from->nexthop->name : from->name);