2 protocol_edge.c -- handle the meta-protocol, edges
3 Copyright (C) 1999-2002 Ivo Timmermans <ivo@o2w.nl>,
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: protocol_edge.c,v 1.1.4.11 2002/09/09 19:40:04 guus Exp $
41 #include "connection.h"
48 int send_add_edge(connection_t *c, edge_t *e)
53 sockaddr2str(&e->address, &address, &port);
54 x = send_request(c, "%d %lx %s %s %s %s %lx %d", ADD_EDGE, random(),
55 e->from->name, e->to->name, address, port,
56 e->options, e->weight);
63 int add_edge_h(connection_t *c)
67 char from_name[MAX_STRING_SIZE];
68 char to_name[MAX_STRING_SIZE];
69 char to_address[MAX_STRING_SIZE];
70 char to_port[MAX_STRING_SIZE];
75 if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
76 from_name, to_name, to_address, to_port, &options, &weight) != 6)
78 syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name, c->hostname);
82 /* Check if names are valid */
84 if(check_id(from_name))
86 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name, c->hostname, _("invalid name"));
92 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_EDGE", c->name, c->hostname, _("invalid name"));
96 if(seen_request(c->buffer))
101 from = lookup_node(from_name);
106 from->name = xstrdup(from_name);
110 to = lookup_node(to_name);
115 to->name = xstrdup(to_name);
119 /* Convert addresses */
121 address = str2sockaddr(to_address, to_port);
123 /* Check if edge already exists */
125 e = lookup_edge(from, to);
129 if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address))
133 if(debug_lvl >= DEBUG_PROTOCOL)
134 syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not match existing entry"), "ADD_EDGE", c->name, c->hostname);
140 if(debug_lvl >= DEBUG_PROTOCOL)
141 syslog(LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"), "ADD_EDGE", c->name, c->hostname);
148 else if(from == myself)
150 if(debug_lvl >= DEBUG_PROTOCOL)
151 syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself which does not exist"), "ADD_EDGE", c->name, c->hostname);
163 e->address = address;
164 e->options = options;
168 /* Tell the rest about the new edge */
172 /* Run MST before or after we tell the rest? */
179 int send_del_edge(connection_t *c, edge_t *e)
182 return send_request(c, "%d %lx %s %s", DEL_EDGE, random(),
183 e->from->name, e->to->name);
186 int del_edge_h(connection_t *c)
189 char from_name[MAX_STRING_SIZE];
190 char to_name[MAX_STRING_SIZE];
193 if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING"", from_name, to_name) != 2)
195 syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_EDGE",
196 c->name, c->hostname);
200 /* Check if names are valid */
202 if(check_id(from_name))
204 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name, c->hostname, _("invalid name"));
208 if(check_id(to_name))
210 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_EDGE", c->name, c->hostname, _("invalid name"));
214 if(seen_request(c->buffer))
219 from = lookup_node(from_name);
223 if(debug_lvl >= DEBUG_PROTOCOL)
224 syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), "DEL_EDGE", c->name, c->hostname);
228 to = lookup_node(to_name);
232 if(debug_lvl >= DEBUG_PROTOCOL)
233 syslog(LOG_ERR, _("Got %s from %s (%s) which does not appear in the edge tree"), "DEL_EDGE", c->name, c->hostname);
237 /* Check if edge exists */
239 e = lookup_edge(from, to);
243 if(debug_lvl >= DEBUG_PROTOCOL)
244 syslog(LOG_WARNING, _("Got %s from %s (%s) which does not appear in the edge tree"), "DEL_EDGE", c->name, c->hostname);
248 if(e->from == myself)
250 if(debug_lvl >= DEBUG_PROTOCOL)
251 syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"), "DEL_EDGE", c->name, c->hostname);
252 send_add_edge(c, e); /* Send back a correction */
256 /* Tell the rest about the deleted edge */
260 /* Delete the edge */
264 /* Run MST before or after we tell the rest? */