/** * Create a set of connection, according to the .ini file's options * and put it in the global ag->connArr (struct Connexion array) */ void createInterfaces(struct agrego *ag) { char arg[50]; char *ipadress; int port; char *ipadress_dest; int port_dest; int ponderation; int i; for (i = 0; i < ag->nbConn; i++) { sprintf(arg, "Link_%d:%s_ip_address_private", i+1, getEndpoint()); ipadress = xiniparser_getstring(arg, NULL); if (ipadress == NULL || strlen(ipadress) == 0) { sprintf(arg, "Link_%d:%s_ip_address_public", i+1, getEndpoint()); ipadress = xiniparser_getstring(arg, NULL); if (ipadress == NULL) { fprintf(stderr, "cannot read the %s_ip_address in the .ini file: %s\n", getEndpoint(), arg); exit(EXIT_FAILURE); } } sprintf(arg, "Link_%d:%s_port", i+1, getEndpoint()); port = xiniparser_getint(arg, -1); if (port == -1) { fprintf(stderr, "cannot read the %s_port in the .ini file: %s\n", getEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:%s_ip_address_public", i+1, getOtherEndpoint()); ipadress_dest = xiniparser_getstring(arg, NULL); if (ipadress_dest == NULL) { fprintf(stderr, "cannot read the %s_ip_address in the .ini file: %s\n", getOtherEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:%s_port", i+1, getOtherEndpoint()); port_dest = xiniparser_getint(arg, -1); if (port_dest == -1) { fprintf(stderr, "cannot read the %s_port in the .ini file: %s\n", getOtherEndpoint(), arg); exit(EXIT_FAILURE); } sprintf(arg, "Link_%d:coefficient", i+1); ponderation = xiniparser_getint(arg, -1); ag->maxWeight = (ag->maxWeight < ponderation) ? ponderation : ag->maxWeight; if (ponderation == -1) { fprintf(stderr, "cannot read the coefficient in the .ini file: %s\n", arg); exit(EXIT_FAILURE); } ag->connArr[i] = initConnexion(port, ipadress, port_dest, ipadress_dest, ponderation); } }
// Manages the cycle stack void Graph::updateCycle(int edgeIndex, int toNode) { auto edge = edges[edgeIndex]; int fromNode = edge.getOtherEndpoint(toNode); if (!inStack(edge.cycleID)) // if current cycle is not on the stack { cycleStack.push_back(edge.cycleID); cycleStartNodes[edge.cycleID] = fromNode; } if (toNode == cycleStartNodes[edge.cycleID]) // If the cycle is finished { cycleStack.pop_back(); } }