lightningd/peer_control: embed id, don't use pointer.

We always know it now we have struct connection, so we don't need a pointer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-06-06 12:38:42 +09:30
parent 3c105bd8db
commit f7a22b699e
5 changed files with 16 additions and 19 deletions

View File

@ -125,7 +125,7 @@ static void json_dev_newhtlc(struct command *cmd,
/* This is the last hop so set an empty channel_id */
memset(&hopsdata[0].channel_id, 0, sizeof(hopsdata[0].channel_id));
path[0] = *peer->id;
path[0] = peer->id;
randombytes_buf(&sessionkey, sizeof(sessionkey));
packet = create_onionpacket(cmd, path, hopsdata, sessionkey, rhash.u.u8,
sizeof(rhash), &shared_secrets);

View File

@ -36,7 +36,7 @@ static void peer_bad_message(struct subd *gossip, const u8 *msg)
fatal("Gossip gave bad peerid %"PRIu64, unique_id);
log_debug(gossip->log, "Peer %s gave bad msg %s",
type_to_string(msg, struct pubkey, peer->id),
type_to_string(msg, struct pubkey, &peer->id),
tal_hex(msg, msg));
peer_fail(peer, "Bad message %s during gossip phase",
gossip_wire_type_name(fromwire_peektype(msg)));
@ -58,7 +58,7 @@ static void peer_failed(struct subd *gossip, const u8 *msg)
fatal("Gossip gave bad peerid %"PRIu64, unique_id);
log_unusual(gossip->log, "Peer %s failed: %.*s",
type_to_string(msg, struct pubkey, peer->id),
type_to_string(msg, struct pubkey, &peer->id),
(int)tal_len(err), (const char *)err);
peer_fail(peer, "Error during gossip phase");
}

View File

@ -55,9 +55,7 @@ static int hsm_msg(struct subd *hsm, const u8 *msg, const int *fds)
/* "Shouldn't happen" */
errx(1, "HSM says bad cmd from %"PRIu64" (%s): %s",
id,
peer ? (peer->id ? type_to_string(msg, struct pubkey,
peer->id)
: "pubkey not yet known")
peer ? type_to_string(msg, struct pubkey, &peer->id)
: "unknown peer",
tal_hex(msg, badmsg));

View File

@ -58,7 +58,7 @@ static struct peer *peer_by_pubkey(struct lightningd *ld, const struct pubkey *i
{
struct peer *peer;
list_for_each(&ld->peers, peer, list) {
if (pubkey_cmp(id, peer->id) == 0)
if (pubkey_cmp(id, &peer->id) == 0)
return peer;
}
return NULL;
@ -89,7 +89,7 @@ static void try_reconnect(struct peer *peer)
return;
}
c = new_connection(peer, peer->ld, NULL, peer->id);
c = new_connection(peer, peer->ld, NULL, &peer->id);
/* FIXME: Combine known address with gossip addresses and possibly
* DNS seed addresses. */
@ -288,7 +288,7 @@ void add_peer(struct lightningd *ld, u64 unique_id,
peer->unique_id = unique_id;
peer->owner = NULL;
peer->scid = NULL;
peer->id = tal_dup(peer, struct pubkey, id);
peer->id = *id;
peer->fd = fd;
peer->gossip_client_fd = -1;
peer->cs = tal_dup(peer, struct crypto_state, cs);
@ -348,7 +348,7 @@ struct peer *peer_by_id(struct lightningd *ld, const struct pubkey *id)
struct peer *p;
list_for_each(&ld->peers, p, list)
if (pubkey_eq(p->id, id))
if (pubkey_eq(&p->id, id))
return p;
return NULL;
}
@ -579,8 +579,7 @@ static void json_getpeers(struct command *cmd,
json_add_string(response, "state", peer_state_name(p->state));
json_add_string(response, "netaddr",
netaddr_name(response, &p->netaddr));
if (p->id)
json_add_pubkey(response, "peerid", p->id);
json_add_pubkey(response, "peerid", &p->id);
if (p->owner)
json_add_string(response, "owner", p->owner->name);
if (p->scid)
@ -1549,7 +1548,7 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
peer->push_msat,
peer->seed,
&peer->ld->dstate.id,
peer->id,
&peer->id,
time_to_msec(cfg->commit_time),
cfg->deadline_blocks,
peer->funding_signed);
@ -1816,7 +1815,7 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer)
&min_effective_htlc_capacity_msat);
peer->seed = tal(peer, struct privkey);
derive_peer_seed(ld, peer->seed, peer->id);
derive_peer_seed(ld, peer->seed, &peer->id);
msg = towire_opening_init(peer, &peer->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,
@ -1891,7 +1890,7 @@ static bool gossip_peer_released(struct subd *gossip,
&min_effective_htlc_capacity_msat);
fc->peer->seed = tal(fc->peer, struct privkey);
derive_peer_seed(ld, fc->peer->seed, fc->peer->id);
derive_peer_seed(ld, fc->peer->seed, &fc->peer->id);
msg = towire_opening_init(fc, &fc->peer->our_config,
max_to_self_delay,
min_effective_htlc_capacity_msat,

View File

@ -17,9 +17,12 @@ struct crypto_state;
struct peer {
struct lightningd *ld;
/* Unique ID (works before we know their pubkey) */
/* Unique ID of connection (works even if we have multiple to same id) */
u64 unique_id;
/* ID of peer */
struct pubkey id;
/* What's happening. */
enum peer_state state;
@ -36,9 +39,6 @@ struct peer {
struct log_book *log_book;
struct log *log;
/* ID of peer (NULL before initial handshake). */
struct pubkey *id;
/* Our fd to the peer (-1 when we don't have it). */
int fd;