Browse Source

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>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
f7a22b699e
  1. 2
      lightningd/dev_newhtlc.c
  2. 4
      lightningd/gossip_control.c
  3. 4
      lightningd/hsm_control.c
  4. 17
      lightningd/peer_control.c
  5. 8
      lightningd/peer_control.h

2
lightningd/dev_newhtlc.c

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

4
lightningd/gossip_control.c

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

4
lightningd/hsm_control.c

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

17
lightningd/peer_control.c

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

8
lightningd/peer_control.h

@ -17,9 +17,12 @@ struct crypto_state;
struct peer { struct peer {
struct lightningd *ld; 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; u64 unique_id;
/* ID of peer */
struct pubkey id;
/* What's happening. */ /* What's happening. */
enum peer_state state; enum peer_state state;
@ -36,9 +39,6 @@ struct peer {
struct log_book *log_book; struct log_book *log_book;
struct log *log; 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). */ /* Our fd to the peer (-1 when we don't have it). */
int fd; int fd;

Loading…
Cancel
Save