/* * Remove an edge. */ static void delete_edge(edge * e) { point *u, *v; /* Cache origin and destination. */ u = Org(e); v = Dest(e); /* Adjust entry points. */ if (u->entry_pt == e) u->entry_pt = e->onext; if (v->entry_pt == e) v->entry_pt = e->dnext; /* Four edge links to change */ if (Org(e->onext) == u) e->onext->oprev = e->oprev; else e->onext->dprev = e->oprev; if (Org(e->oprev) == u) e->oprev->onext = e->onext; else e->oprev->dnext = e->onext; if (Org(e->dnext) == v) e->dnext->oprev = e->dprev; else e->dnext->dprev = e->dprev; if (Org(e->dprev) == v) e->dprev->onext = e->dnext; else e->dprev->dnext = e->dnext; free_edge(e); }
void free_edge(edge *e) { if (e) { free_edge(e->next_up); free((char *)e); } }
void free_vertex(vertex *v) { if (v) { free_vertex(v->left); free_vertex(v->right); free_edge(v->up); free((char *)v); } }
void remove_edge_raw (edge e) { remove_predictions_associated_with_edge (e); execute_on_shrinking_pred (e); disconnect_src (e); disconnect_dest (e); free_edge (e); }
bool dgraph_del_edge(struct dgraph_node *from, struct dgraph_node *to) { struct dgraph_edge *e, *next; dgraph_for_each_edge_safe(from, e, next, DGRAPH_FROM) { if (e->n[DGRAPH_TO] == to) { free_edge(e); return true; } } return false; }
void dgraph_clear_node(struct dgraph_node *n) { struct dgraph_edge *e; unsigned int i; for (i = DGRAPH_FROM; i <= DGRAPH_TO; i++) { while ((e = tlist_top(&n->edge[i], list[i])) != NULL) { assert(e->n[i] == n); free_edge(e); } } }
void clear_edges (void) { basic_block bb; edge e; edge_iterator ei; FOR_EACH_BB (bb) { FOR_EACH_EDGE (e, ei, bb->succs) free_edge (e); VEC_truncate (edge, bb->succs, 0); VEC_truncate (edge, bb->preds, 0); } FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs) free_edge (e); VEC_truncate (edge, EXIT_BLOCK_PTR->preds, 0); VEC_truncate (edge, ENTRY_BLOCK_PTR->succs, 0); gcc_assert (!n_edges); }
void clear_edges (struct function *fn) { basic_block bb; edge e; edge_iterator ei; FOR_EACH_BB_FN (bb, fn) { FOR_EACH_EDGE (e, ei, bb->succs) free_edge (fn, e); vec_safe_truncate (bb->succs, 0); vec_safe_truncate (bb->preds, 0); }
void clear_edges (void) { basic_block bb; edge e; edge_iterator ei; FOR_EACH_BB_FN (bb, cfun) { FOR_EACH_EDGE (e, ei, bb->succs) free_edge (e); vec_safe_truncate (bb->succs, 0); vec_safe_truncate (bb->preds, 0); }
bool add_edge_h(connection_t *c) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; char to_address[MAX_STRING_SIZE]; char to_port[MAX_STRING_SIZE]; sockaddr_t address; uint32_t options; int weight; if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %x %d", from_name, to_name, to_address, to_port, &options, &weight) != 6) { logger(LOG_ERR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name, c->hostname); return false; } /* Check if names are valid */ if(!check_id(from_name) || !check_id(to_name)) { logger(LOG_ERR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name, c->hostname, "invalid name"); return false; } if(seen_request(c->buffer)) return true; /* Lookup nodes */ from = lookup_node(from_name); to = lookup_node(to_name); if(tunnelserver && from != myself && from != c->node && to != myself && to != c->node) { /* ignore indirect edge registrations for tunnelserver */ ifdebug(PROTOCOL) logger(LOG_WARNING, "Ignoring indirect %s from %s (%s)", "ADD_EDGE", c->name, c->hostname); return true; } if(!from) { from = new_node(); from->name = xstrdup(from_name); node_add(from); } if(!to) { to = new_node(); to->name = xstrdup(to_name); node_add(to); } /* Convert addresses */ address = str2sockaddr(to_address, to_port); /* Check if edge already exists */ e = lookup_edge(from, to); if(e) { if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) { if(from == myself) { ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry", "ADD_EDGE", c->name, c->hostname); send_add_edge(c, e); return true; } else { ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) which does not match existing entry", "ADD_EDGE", c->name, c->hostname); edge_del(e); graph(); } } else return true; } else if(from == myself) { ifdebug(PROTOCOL) logger(LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist", "ADD_EDGE", c->name, c->hostname); contradicting_add_edge++; e = new_edge(); e->from = from; e->to = to; send_del_edge(c, e); free_edge(e); return true; } e = new_edge(); e->from = from; e->to = to; e->address = address; e->options = options; e->weight = weight; edge_add(e); /* Tell the rest about the new edge */ if(!tunnelserver) forward_request(c); /* Run MST before or after we tell the rest? */ graph(); return true; }
bool add_edge_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; int from_devclass; char to_name[MAX_STRING_SIZE]; char to_address[MAX_STRING_SIZE]; char to_port[MAX_STRING_SIZE]; int to_devclass; sockaddr_t address; uint32_t options; int weight; if(sscanf(request, "%*d %*x "MAX_STRING" %d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %x %d", from_name, &from_devclass, to_name, to_address, to_port, &to_devclass, &options, &weight) != 8) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name, c->hostname); return false; } /* Check if names are valid */ if(!check_id(from_name) || !check_id(to_name)) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name, c->hostname, "invalid name"); return false; } // Check if devclasses are valid if(from_devclass < 0 || from_devclass > _DEV_CLASS_MAX) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name, c->hostname, "from devclass invalid"); return false; } if(to_devclass < 0 || to_devclass > _DEV_CLASS_MAX) { logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name, c->hostname, "to devclass invalid"); return false; } if(seen_request(mesh, request)) return true; /* Lookup nodes */ from = lookup_node(mesh, from_name); to = lookup_node(mesh, to_name); if(!from) { from = new_node(); from->status.blacklisted = mesh->default_blacklist; from->name = xstrdup(from_name); node_add(mesh, from); } from->devclass = from_devclass; node_write_devclass(mesh, from); if(!to) { to = new_node(); to->status.blacklisted = mesh->default_blacklist; to->name = xstrdup(to_name); node_add(mesh, to); } to->devclass = to_devclass; node_write_devclass(mesh, to); /* Convert addresses */ address = str2sockaddr(to_address, to_port); /* Check if edge already exists */ e = lookup_edge(from, to); if(e) { if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) { if(from == mesh->self) { logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry", "ADD_EDGE", c->name, c->hostname); send_add_edge(mesh, c, e); return true; } else { logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) which does not match existing entry", "ADD_EDGE", c->name, c->hostname); edge_del(mesh, e); graph(mesh); } } else return true; } else if(from == mesh->self) { logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not exist", "ADD_EDGE", c->name, c->hostname); mesh->contradicting_add_edge++; e = new_edge(); e->from = from; e->to = to; send_del_edge(mesh, c, e); free_edge(e); return true; } e = new_edge(); e->from = from; e->to = to; e->address = address; e->options = options; e->weight = weight; edge_add(mesh, e); /* Tell the rest about the new edge */ forward_request(mesh, c, request); /* Run MST before or after we tell the rest? */ graph(mesh); return true; }