mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
per_peer_state: remove struct crypto_state
Now that connectd does the crypto, no need to hand around crypto_state. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ce8b69401c
commit
9c0bb444b7
@ -40,7 +40,6 @@ CHANNELD_COMMON_OBJS := \
|
||||
common/channel_config.o \
|
||||
common/channel_id.o \
|
||||
common/channel_type.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
@ -26,7 +26,6 @@ CLOSINGD_COMMON_OBJS := \
|
||||
common/bip32.o \
|
||||
common/channel_id.o \
|
||||
common/close_tx.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
@ -22,7 +22,6 @@ COMMON_SRC_NOGEN := \
|
||||
common/close_tx.c \
|
||||
common/coin_mvt.c \
|
||||
common/configdir.c \
|
||||
common/crypto_state.c \
|
||||
common/cryptomsg.c \
|
||||
common/daemon.c \
|
||||
common/daemon_conn.c \
|
||||
@ -97,6 +96,7 @@ COMMON_SRC_GEN := common/status_wiregen.c common/peer_status_wiregen.c
|
||||
|
||||
COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) \
|
||||
common/closing_fee.h \
|
||||
common/crypto_state.h \
|
||||
common/ecdh.h \
|
||||
common/errcode.h \
|
||||
common/gossip_constants.h \
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include "config.h"
|
||||
#include <common/crypto_state.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
void towire_crypto_state(u8 **ptr, const struct crypto_state *cs)
|
||||
{
|
||||
towire_u64(ptr, cs->rn);
|
||||
towire_u64(ptr, cs->sn);
|
||||
towire_secret(ptr, &cs->sk);
|
||||
towire_secret(ptr, &cs->rk);
|
||||
towire_secret(ptr, &cs->s_ck);
|
||||
towire_secret(ptr, &cs->r_ck);
|
||||
}
|
||||
|
||||
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs)
|
||||
{
|
||||
cs->rn = fromwire_u64(ptr, max);
|
||||
cs->sn = fromwire_u64(ptr, max);
|
||||
fromwire_secret(ptr, max, &cs->sk);
|
||||
fromwire_secret(ptr, max, &cs->rk);
|
||||
fromwire_secret(ptr, max, &cs->s_ck);
|
||||
fromwire_secret(ptr, max, &cs->r_ck);
|
||||
}
|
@ -12,7 +12,4 @@ struct crypto_state {
|
||||
struct secret s_ck, r_ck;
|
||||
};
|
||||
|
||||
void towire_crypto_state(u8 **pptr, const struct crypto_state *cs);
|
||||
void fromwire_crypto_state(const u8 **ptr, size_t *max, struct crypto_state *cs);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_CRYPTO_STATE_H */
|
||||
|
@ -19,12 +19,10 @@ static void destroy_per_peer_state(struct per_peer_state *pps)
|
||||
close(pps->gossip_store_fd);
|
||||
}
|
||||
|
||||
struct per_peer_state *new_per_peer_state(const tal_t *ctx,
|
||||
const struct crypto_state *cs)
|
||||
struct per_peer_state *new_per_peer_state(const tal_t *ctx)
|
||||
{
|
||||
struct per_peer_state *pps = tal(ctx, struct per_peer_state);
|
||||
|
||||
pps->cs = *cs;
|
||||
pps->gs = NULL;
|
||||
pps->peer_fd = pps->gossip_fd = pps->gossip_store_fd = -1;
|
||||
pps->grf = new_gossip_rcvd_filter(pps);
|
||||
@ -69,7 +67,6 @@ void fromwire_gossip_state(const u8 **cursor, size_t *max,
|
||||
|
||||
void towire_per_peer_state(u8 **pptr, const struct per_peer_state *pps)
|
||||
{
|
||||
towire_crypto_state(pptr, &pps->cs);
|
||||
towire_bool(pptr, pps->gs != NULL);
|
||||
if (pps->gs)
|
||||
towire_gossip_state(pptr, pps->gs);
|
||||
@ -89,11 +86,9 @@ void per_peer_state_fdpass_send(int fd, const struct per_peer_state *pps)
|
||||
struct per_peer_state *fromwire_per_peer_state(const tal_t *ctx,
|
||||
const u8 **cursor, size_t *max)
|
||||
{
|
||||
struct crypto_state cs;
|
||||
struct per_peer_state *pps;
|
||||
|
||||
fromwire_crypto_state(cursor, max, &cs);
|
||||
pps = new_per_peer_state(ctx, &cs);
|
||||
pps = new_per_peer_state(ctx);
|
||||
if (fromwire_bool(cursor, max)) {
|
||||
pps->gs = tal(pps, struct gossip_state);
|
||||
fromwire_gossip_state(cursor, max, pps->gs);
|
||||
|
@ -15,9 +15,6 @@ struct gossip_state {
|
||||
|
||||
/* Things we hand between daemons to talk to peers. */
|
||||
struct per_peer_state {
|
||||
/* Cryptographic state needed to exchange messages with the peer (as
|
||||
* featured in BOLT #8) */
|
||||
struct crypto_state cs;
|
||||
/* NULL if it's not initialized yet */
|
||||
struct gossip_state *gs;
|
||||
/* Cache of msgs we have received, to avoid re-xmitting from store */
|
||||
@ -28,8 +25,7 @@ struct per_peer_state {
|
||||
|
||||
/* Allocate a new per-peer state and add destructor to close fds if set;
|
||||
* sets fds to -1 and ->gs to NULL.. */
|
||||
struct per_peer_state *new_per_peer_state(const tal_t *ctx,
|
||||
const struct crypto_state *cs);
|
||||
struct per_peer_state *new_per_peer_state(const tal_t *ctx);
|
||||
|
||||
/* Initialize the fds (must be -1 previous) */
|
||||
void per_peer_state_set_fds(struct per_peer_state *pps,
|
||||
|
@ -42,7 +42,6 @@ CONNECTD_COMMON_OBJS := \
|
||||
common/bigsize.o \
|
||||
common/bip32.o \
|
||||
common/channel_id.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
@ -448,7 +448,7 @@ static struct peer *new_peer(struct daemon *daemon,
|
||||
struct peer *peer = tal(daemon, struct peer);
|
||||
|
||||
peer->id = *id;
|
||||
peer->pps = new_per_peer_state(peer, cs);
|
||||
peer->cs = *cs;
|
||||
peer->final_msg = NULL;
|
||||
peer->subd_in = NULL;
|
||||
peer->peer_in = NULL;
|
||||
@ -461,12 +461,6 @@ static struct peer *new_peer(struct daemon *daemon,
|
||||
if (!multiplex_subd_setup(peer, fd_for_subd))
|
||||
return tal_free(peer);
|
||||
|
||||
/* If gossipd can't give us a file descriptor, we give up connecting. */
|
||||
if (!get_gossipfds(daemon, id, their_features, peer->pps)) {
|
||||
close(*fd_for_subd);
|
||||
return tal_free(peer);
|
||||
}
|
||||
|
||||
peer->to_peer = tal_steal(peer, conn);
|
||||
peer_htable_add(&daemon->peers, peer);
|
||||
tal_add_destructor2(peer, destroy_peer, daemon);
|
||||
@ -488,6 +482,7 @@ struct io_plan *peer_connected(struct io_conn *conn,
|
||||
int unsup;
|
||||
size_t depender, missing;
|
||||
int subd_fd;
|
||||
struct per_peer_state *pps;
|
||||
|
||||
peer = peer_htable_get(&daemon->peers, id);
|
||||
if (peer)
|
||||
@ -545,20 +540,28 @@ struct io_plan *peer_connected(struct io_conn *conn,
|
||||
if (!peer)
|
||||
return io_close(conn);
|
||||
|
||||
pps = new_per_peer_state(tmpctx);
|
||||
|
||||
/* If gossipd can't give us a file descriptor, we give up connecting. */
|
||||
if (!get_gossipfds(daemon, id, their_features, pps)) {
|
||||
close(subd_fd);
|
||||
return tal_free(peer);
|
||||
}
|
||||
|
||||
/* Create message to tell master peer has connected. */
|
||||
msg = towire_connectd_peer_connected(NULL, id, addr, incoming,
|
||||
peer->pps, their_features);
|
||||
pps, their_features);
|
||||
|
||||
/*~ daemon_conn is a message queue for inter-daemon communication: we
|
||||
* queue up the `connect_peer_connected` message to tell lightningd
|
||||
* we have connected, and give the peer and gossip fds. */
|
||||
daemon_conn_send(daemon->master, take(msg));
|
||||
daemon_conn_send_fd(daemon->master, subd_fd);
|
||||
daemon_conn_send_fd(daemon->master, peer->pps->gossip_fd);
|
||||
daemon_conn_send_fd(daemon->master, peer->pps->gossip_store_fd);
|
||||
daemon_conn_send_fd(daemon->master, pps->gossip_fd);
|
||||
daemon_conn_send_fd(daemon->master, pps->gossip_store_fd);
|
||||
|
||||
/* Don't try to close these on freeing. */
|
||||
peer->pps->gossip_store_fd = peer->pps->gossip_fd = -1;
|
||||
pps->gossip_store_fd = pps->gossip_fd = -1;
|
||||
|
||||
/*~ Now we set up this connection to read/write from subd */
|
||||
return multiplex_peer_setup(conn, peer);
|
||||
|
@ -39,7 +39,7 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
|
||||
struct peer *peer))
|
||||
{
|
||||
/* We free this and the encrypted version in next write_to_peer */
|
||||
peer->sent_to_peer = cryptomsg_encrypt_msg(peer, &peer->pps->cs, msg);
|
||||
peer->sent_to_peer = cryptomsg_encrypt_msg(peer, &peer->cs, msg);
|
||||
return io_write(peer->to_peer,
|
||||
peer->sent_to_peer,
|
||||
tal_bytelen(peer->sent_to_peer),
|
||||
@ -127,7 +127,7 @@ static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
|
||||
{
|
||||
u8 *decrypted;
|
||||
|
||||
decrypted = cryptomsg_decrypt_body(NULL, &peer->pps->cs,
|
||||
decrypted = cryptomsg_decrypt_body(NULL, &peer->cs,
|
||||
peer->peer_in);
|
||||
if (!decrypted)
|
||||
return io_close(peer_conn);
|
||||
@ -145,7 +145,7 @@ static struct io_plan *read_body_from_peer(struct io_conn *peer_conn,
|
||||
{
|
||||
u16 len;
|
||||
|
||||
if (!cryptomsg_decrypt_header(&peer->pps->cs, peer->peer_in, &len))
|
||||
if (!cryptomsg_decrypt_header(&peer->cs, peer->peer_in, &len))
|
||||
return io_close(peer_conn);
|
||||
|
||||
tal_resize(&peer->peer_in, (u32)len + CRYPTOMSG_BODY_OVERHEAD);
|
||||
|
@ -2,12 +2,14 @@
|
||||
#define LIGHTNING_CONNECTD_MULTIPLEX_H
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/crypto_state.h>
|
||||
#include <common/msg_queue.h>
|
||||
#include <common/node_id.h>
|
||||
|
||||
struct peer {
|
||||
struct node_id id;
|
||||
struct per_peer_state *pps;
|
||||
/* Counters and keys for symmetric crypto */
|
||||
struct crypto_state cs;
|
||||
|
||||
/* Connection to the peer */
|
||||
struct io_conn *to_peer;
|
||||
|
@ -21,7 +21,6 @@ DEVTOOLS_COMMON_OBJS := \
|
||||
common/bolt11.o \
|
||||
common/blockheight_states.o \
|
||||
common/channel_id.o \
|
||||
common/crypto_state.o \
|
||||
common/decode_array.o \
|
||||
common/features.o \
|
||||
common/fee_states.o \
|
||||
|
@ -37,7 +37,6 @@ GOSSIPD_COMMON_OBJS := \
|
||||
common/blinding.o \
|
||||
common/blindedpath.o \
|
||||
common/channel_id.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
@ -81,7 +81,6 @@ LIGHTNINGD_COMMON_OBJS := \
|
||||
common/channel_type.o \
|
||||
common/coin_mvt.o \
|
||||
common/configdir.o \
|
||||
common/crypto_state.o \
|
||||
common/daemon.o \
|
||||
common/derive_basepoints.o \
|
||||
common/ecdh_hsmd.o \
|
||||
|
@ -41,7 +41,6 @@ OPENINGD_COMMON_OBJS := \
|
||||
common/channel_config.o \
|
||||
common/channel_id.o \
|
||||
common/channel_type.o \
|
||||
common/crypto_state.o \
|
||||
common/cryptomsg.o \
|
||||
common/daemon.o \
|
||||
common/daemon_conn.o \
|
||||
|
Loading…
Reference in New Issue
Block a user