| 144 | } |
| 145 | |
| 146 | static u8 *sync_crypto_read(const tal_t *ctx, int peer_fd, struct crypto_state *cs) |
| 147 | { |
| 148 | u8 hdr[18], *enc, *dec; |
| 149 | u16 len; |
| 150 | |
| 151 | if (!read_all(peer_fd, hdr, sizeof(hdr))) { |
| 152 | status_debug("Failed reading header: %s", strerror(errno)); |
| 153 | if (no_early_close) |
| 154 | exit(1); |
| 155 | exit(0); |
| 156 | } |
| 157 | |
| 158 | if (!cryptomsg_decrypt_header(cs, hdr, &len)) { |
| 159 | status_debug("Failed hdr decrypt with rn=%"PRIu64, |
| 160 | cs->rn-1); |
| 161 | exit(1); |
| 162 | } |
| 163 | |
| 164 | enc = tal_arr(ctx, u8, len + 16); |
| 165 | if (!read_all(peer_fd, enc, tal_count(enc))) { |
| 166 | status_debug("Failed reading body: %s", strerror(errno)); |
| 167 | exit(1); |
| 168 | } |
| 169 | |
| 170 | dec = cryptomsg_decrypt_body(ctx, cs, enc); |
| 171 | tal_free(enc); |
| 172 | if (!dec) |
| 173 | exit(1); |
| 174 | else |
| 175 | status_peer_io(LOG_IO_IN, NULL, dec); |
| 176 | |
| 177 | return dec; |
| 178 | } |
| 179 | |
| 180 | static struct io_plan *handshake_success(struct io_conn *conn, |
| 181 | const struct pubkey *them, |
no test coverage detected