connectd/peer_exchange_initmsg: handle peer comms ourselves.

connectd is the only user of the cryptomsg async APIs; better to
open-code it here.  We need to expose a little from cryptomsg(),
but we remove the 'struct peer' entirely from connectd.

One trick is that we still need to defer telling lightningd when a
peer reconnects (until it tells us the old one is disconnected).  So
now we generate the message for lightningd and send it once we're woken.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-09-28 06:34:19 +09:30
parent cfd54d67cb
commit a1bdaa8f99
7 changed files with 290 additions and 146 deletions

View File

@@ -315,7 +315,7 @@ u8 *cryptomsg_encrypt_msg(const tal_t *ctx,
tal_hexstr(trc, msg, mlen),
tal_hexstr(trc, npub, sizeof(npub)),
tal_hexstr(trc, &cs->sk, sizeof(cs->sk)),
tal_hexstr(trc, out + 18, clen));
tal_hexstr(trc, out + CRYPTOMSG_HDR_SIZE, clen));
#endif
maybe_rotate_key(&cs->sn, &cs->sk, &cs->s_ck);

View File

@@ -36,6 +36,22 @@ struct io_plan *peer_write_message(struct io_conn *conn,
const u8 *msg,
struct io_plan *(*next)(struct io_conn *,
struct peer *));
/* BOLT #8:
*
* ### Receiving and Decrypting Messages
*
* In order to decrypt the _next_ message in the network stream, the
* following steps are completed:
*
* 1. Read _exactly_ 18 bytes from the network buffer.
*/
#define CRYPTOMSG_HDR_SIZE 18
/* BOLT #8:
*
* 4. Read _exactly_ `l+16` bytes from the network buffer
*/
#define CRYPTOMSG_BODY_OVERHEAD 16
/* Low-level functions for sync comms: doesn't discard unknowns! */
u8 *cryptomsg_encrypt_msg(const tal_t *ctx,