uint16_t pinged: 1; /* sent ping */
uint16_t active: 1; /* 1 if active.. */
uint16_t connecting: 1; /* 1 if we are waiting for a non-blocking connect() to finish */
- uint16_t mst: 1; /* 1 if this connection is part of a minimum spanning tree */
+ uint16_t unused: 1;
uint16_t control: 1; /* 1 if this is a control connection */
uint16_t pcap: 1; /* 1 if this is a control connection requesting packet capture */
uint16_t log: 1; /* 1 if this is a control connection requesting log dump */
#include "xalloc.h"
#include "graph.h"
-/* Implementation of Kruskal's algorithm.
- Running time: O(EN)
- Please note that sorting on weight is already done by add_edge().
-*/
-
-static void mst_kruskal(meshlink_handle_t *mesh) {
- /* Clear MST status on connections */
-
- for list_each(connection_t, c, mesh->connections) {
- c->status.mst = false;
- }
-
- logger(mesh, MESHLINK_DEBUG, "Running Kruskal's algorithm:");
-
- /* Clear visited status on nodes */
-
- for splay_each(node_t, n, mesh->nodes) {
- n->status.visited = false;
- }
-
- /* Starting point */
-
- for splay_each(edge_t, e, mesh->edges) {
- if(e->from->status.reachable) {
- e->from->status.visited = true;
- break;
- }
- }
-
- /* Add safe edges */
-
- bool skipped = false;
-
- for splay_each(edge_t, e, mesh->edges) {
- if(!e->reverse || (e->from->status.visited == e->to->status.visited)) {
- skipped = true;
- continue;
- }
-
- e->from->status.visited = true;
- e->to->status.visited = true;
-
- if(e->connection) {
- e->connection->status.mst = true;
- }
-
- if(e->reverse->connection) {
- e->reverse->connection->status.mst = true;
- }
-
- logger(mesh, MESHLINK_DEBUG, " Adding edge %s - %s weight %d", e->from->name, e->to->name, e->weight);
-
- if(skipped) {
- skipped = false;
- next = mesh->edges->head;
- }
- }
-}
-
/* Implementation of a simple breadth-first search algorithm.
Running time: O(E)
*/
void graph(meshlink_handle_t *mesh) {
sssp_bfs(mesh);
check_reachability(mesh);
- mst_kruskal(mesh);
}
extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len);
extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len);
extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *);
-extern void broadcast_packet(struct meshlink_handle *mesh, const struct node_t *, struct vpn_packet_t *);
extern char *get_name(struct meshlink_handle *mesh);
extern void load_all_nodes(struct meshlink_handle *mesh);
extern bool setup_myself_reloadable(struct meshlink_handle *mesh);
return;
}
-/* Broadcast a packet using the minimum spanning tree */
-
-void broadcast_packet(meshlink_handle_t *mesh, const node_t *from, vpn_packet_t *packet) {
- // Always give ourself a copy of the packet.
- if(from != mesh->self) {
- send_packet(mesh, mesh->self, packet);
- }
-
- logger(mesh, MESHLINK_INFO, "Broadcasting packet of %d bytes from %s", packet->len, from->name);
-
- for list_each(connection_t, c, mesh->connections)
- if(c->status.active && c->status.mst && c != from->nexthop->connection) {
- send_packet(mesh, c->node, packet);
- }
-}
-
static node_t *try_harder(meshlink_handle_t *mesh, const sockaddr_t *from, const vpn_packet_t *pkt) {
node_t *n = NULL;
bool hard = false;