routing: Cleaning up old hostname and port handling

The single string-based hostname and port has been retired in favor of
having multiple `struct ipaddr`s from the `node_announcement`. This
breaks the hostnames and ports from IRC, but I didn't bother to
backport ipaddr for it since it is only used in the legacy daemon.
This commit is contained in:
Christian Decker 2017-05-08 23:41:23 +02:00 committed by Rusty Russell
parent e972b208c7
commit 2d76b066c2
7 changed files with 11 additions and 53 deletions

View File

@ -177,9 +177,7 @@ static void handle_irc_node_announcement(
char **splits)
{
struct pubkey *pk = talz(msg, struct pubkey);
char *hostname = tal_strdup(msg, splits[2]);
int port = atoi(splits[3]);
if (!pubkey_from_hexstr(splits[1], strlen(splits[1]), pk) || port < 1)
if (!pubkey_from_hexstr(splits[1], strlen(splits[1]), pk))
return;
if (!verify_signed_privmsg(istate, pk, msg)) {
@ -191,7 +189,7 @@ static void handle_irc_node_announcement(
splits[1]);
}
struct node *node = add_node(istate->dstate->rstate, pk, hostname, port);
struct node *node = add_node(istate->dstate->rstate, pk);
if (splits[4] != NULL){
tal_free(node->alias);
node->alias = tal_hexdata(node, splits[4], strlen(splits[4]));
@ -233,8 +231,7 @@ static void handle_irc_command(struct ircstate *istate, const struct irccommand
log_debug(dstate->base_log, "Detected my own IP as %s", dstate->external_ip);
// Add our node to the node_map for completeness
add_node(istate->dstate->rstate, &dstate->id,
dstate->external_ip, dstate->portnum);
add_node(istate->dstate->rstate, &dstate->id);
} else if (streq(cmd->command, "JOIN")) {
unsigned int delay;

View File

@ -74,9 +74,7 @@ struct node *new_node(struct routing_state *rstate,
n->id = *id;
n->in = tal_arr(n, struct node_connection *, 0);
n->out = tal_arr(n, struct node_connection *, 0);
n->port = 0;
n->alias = NULL;
n->hostname = NULL;
n->node_announcement = NULL;
n->last_timestamp = 0;
n->addresses = tal_arr(n, struct ipaddr, 0);
@ -88,9 +86,7 @@ struct node *new_node(struct routing_state *rstate,
struct node *add_node(
struct routing_state *rstate,
const struct pubkey *pk,
char *hostname,
int port)
const struct pubkey *pk)
{
struct node *n = get_node(rstate, pk);
if (!n) {
@ -101,8 +97,6 @@ struct node *add_node(
log_debug_struct(rstate->base_log, "Update existing node %s",
struct pubkey, pk);
}
n->hostname = tal_steal(n, hostname);
n->port = port;
return n;
}
@ -916,13 +910,6 @@ void handle_node_announcement(
node->addresses = tal_steal(node, ipaddrs);
node->last_timestamp = timestamp;
node->hostname = tal_free(node->hostname);
if (!read_ip(node, addresses, &node->hostname, &node->port)) {
/* FIXME: SHOULD fail connection here. */
tal_free(serialized);
return;
}
memcpy(node->rgb_color, rgb_color, 3);

View File

@ -46,8 +46,6 @@ struct node {
/* IP/Hostname and port of this node (may be NULL) */
struct ipaddr *addresses;
char *hostname;
int port;
u32 last_timestamp;
@ -112,9 +110,7 @@ s64 connection_fee(const struct node_connection *c, u64 msatoshi);
/* Updates existing node, or creates a new one as required. */
struct node *add_node(struct routing_state *rstate,
const struct pubkey *pk,
char *hostname,
int port);
const struct pubkey *pk);
/* Updates existing connection, or creates new one as required. */
struct node_connection *add_connection(struct routing_state *rstate,

View File

@ -136,6 +136,7 @@ static void json_getnodes(struct command *cmd,
struct json_result *response = new_json_result(cmd);
struct node *n;
struct node_map_iter i;
size_t j;
n = node_map_first(cmd->dstate->rstate->nodes, &i);
@ -145,12 +146,11 @@ static void json_getnodes(struct command *cmd,
while (n != NULL) {
json_object_start(response, NULL);
json_add_pubkey(response, "nodeid", &n->id);
json_add_num(response, "port", n->port);
if (!n->port)
json_add_null(response, "hostname");
else
json_add_string(response, "hostname", n->hostname);
json_array_start(response, "addresses");
for (j=0; j<tal_count(n->addresses); j++) {
json_add_address(response, NULL, &n->addresses[j]);
}
json_array_end(response);
json_object_end(response);
n = node_map_next(cmd->dstate->rstate->nodes, &i);
}

View File

@ -570,8 +570,6 @@ static struct io_plan *getnodes(struct io_conn *conn, struct daemon *daemon)
while (n != NULL) {
tal_resize(&nodes, node_count + 1);
nodes[node_count].nodeid = n->id;
nodes[node_count].hostname = n->hostname;
nodes[node_count].port = n->port;
nodes[node_count].addresses = n->addresses;
node_count++;
n = node_map_next(daemon->rstate->nodes, &i);

View File

@ -3,7 +3,6 @@
void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry)
{
u8 hostnamelen;
u8 numaddresses, i;
fromwire_pubkey(pptr, max, &entry->nodeid);
numaddresses = fromwire_u8(pptr, max);
@ -12,15 +11,9 @@ void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *m
for (i=0; i<numaddresses; i++) {
fromwire_ipaddr(pptr, max, entry->addresses);
}
hostnamelen = fromwire_u8(pptr, max);
entry->hostname = tal_arr(ctx, char, hostnamelen);
fromwire_u8_array(pptr, max, (u8*)entry->hostname, hostnamelen);
entry->port = fromwire_u16(pptr, max);
}
void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry)
{
u8 hostnamelen;
u8 i, numaddresses = tal_count(entry->addresses);
towire_pubkey(pptr, &entry->nodeid);
towire_u8(pptr, numaddresses);
@ -28,17 +21,6 @@ void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry
for (i=0; i<numaddresses; i++) {
towire_ipaddr(pptr, &entry->addresses[i]);
}
if (entry->hostname) {
hostnamelen = strlen(entry->hostname);
towire_u8(pptr, hostnamelen);
towire_u8_array(pptr, (u8*)entry->hostname, hostnamelen);
}else {
/* If we don't have a hostname just write an empty string */
hostnamelen = 0;
towire_u8(pptr, hostnamelen);
}
towire_u16(pptr, entry->port);
}
void fromwire_route_hop(const u8 **pptr, size_t *max, struct route_hop *entry)

View File

@ -7,8 +7,6 @@
struct gossip_getnodes_entry {
struct pubkey nodeid;
struct ipaddr *addresses;
char *hostname;
u16 port;
};
struct gossip_getchannels_entry {