Skip to content

Commit

Permalink
connectd: rename struct peer in peer_exchange_initmsg to early_peer.
Browse files Browse the repository at this point in the history
We want to have a real (persistent) struct peer eventually.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Dec 29, 2021
1 parent d287d7d commit 4ef2367
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions connectd/peer_exchange_initmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <wire/peer_wire.h>

/* Temporary structure for us to read peer message in */
struct peer {
struct early_peer {
struct daemon *daemon;

/* The ID of the peer */
Expand Down Expand Up @@ -38,10 +38,10 @@ static bool contains_common_chain(struct bitcoin_blkid *chains)
}

/* Here in case we need to read another message. */
static struct io_plan *read_init(struct io_conn *conn, struct peer *peer);
static struct io_plan *read_init(struct io_conn *conn, struct early_peer *peer);

static struct io_plan *peer_init_received(struct io_conn *conn,
struct peer *peer)
struct early_peer *peer)
{
u8 *msg = cryptomsg_decrypt_body(tmpctx, &peer->cs, peer->msg);
u8 *globalfeatures, *features;
Expand Down Expand Up @@ -89,6 +89,9 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
* window where it was: combine the two. */
features = featurebits_or(tmpctx, take(features), globalfeatures);

/* We can dispose of peer after next call. */
tal_steal(tmpctx, peer);

/* Usually return io_close_taken_fd, but may wait for old peer to
* be disconnected if it's a reconnect. */
return peer_connected(conn, peer->daemon, &peer->id,
Expand All @@ -98,7 +101,7 @@ static struct io_plan *peer_init_received(struct io_conn *conn,
}

static struct io_plan *peer_init_hdr_received(struct io_conn *conn,
struct peer *peer)
struct early_peer *peer)
{
u16 len;

Expand All @@ -111,7 +114,7 @@ static struct io_plan *peer_init_hdr_received(struct io_conn *conn,
peer_init_received, peer);
}

static struct io_plan *read_init(struct io_conn *conn, struct peer *peer)
static struct io_plan *read_init(struct io_conn *conn, struct early_peer *peer)
{
/* Free our sent init msg. */
tal_free(peer->msg);
Expand All @@ -128,14 +131,14 @@ static struct io_plan *read_init(struct io_conn *conn, struct peer *peer)

#if DEVELOPER
static struct io_plan *peer_write_postclose(struct io_conn *conn,
struct peer *peer)
struct early_peer *peer)
{
dev_sabotage_fd(io_conn_fd(conn), true);
return read_init(conn, peer);
}

static struct io_plan *peer_write_post_sabotage(struct io_conn *conn,
struct peer *peer)
struct early_peer *peer)
{
dev_sabotage_fd(io_conn_fd(conn), false);
return read_init(conn, peer);
Expand All @@ -151,8 +154,8 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
bool incoming)
{
/* If conn is closed, forget peer */
struct peer *peer = tal(conn, struct peer);
struct io_plan *(*next)(struct io_conn *, struct peer *);
struct early_peer *peer = tal(conn, struct early_peer);
struct io_plan *(*next)(struct io_conn *, struct early_peer *);
struct tlv_init_tlvs *tlvs;

peer->daemon = daemon;
Expand Down

0 comments on commit 4ef2367

Please sign in to comment.