sync_crypto_write/sync_crypto_read: just fail, don't return NULL.

There's only one thing the caller ever does, just do that internally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-08-02 16:19:55 +09:30
parent 09cce4a9c7
commit 0b08601951
9 changed files with 53 additions and 80 deletions

View File

@@ -2,6 +2,7 @@
#include <common/crypto_sync.h>
#include <common/cryptomsg.h>
#include <common/dev_disconnect.h>
#include <common/peer_failed.h>
#include <common/status.h>
#include <common/utils.h>
#include <errno.h>
@@ -9,14 +10,13 @@
#include <wire/wire.h>
#include <wire/wire_sync.h>
bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
void sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
{
#if DEVELOPER
bool post_sabotage = false;
int type = fromwire_peektype(msg);
#endif
u8 *enc;
bool ret;
status_peer_io(LOG_IO_OUT, msg);
enc = cryptomsg_encrypt_msg(NULL, cs, msg);
@@ -25,7 +25,7 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
switch (dev_disconnect(type)) {
case DEV_DISCONNECT_BEFORE:
dev_sabotage_fd(fd);
return false;
peer_failed_connection_lost();
case DEV_DISCONNECT_DROPPKT:
enc = tal_free(enc); /* FALL THRU */
case DEV_DISCONNECT_AFTER:
@@ -38,14 +38,14 @@ bool sync_crypto_write(struct crypto_state *cs, int fd, const void *msg TAKES)
break;
}
#endif
ret = write_all(fd, enc, tal_count(enc));
if (!write_all(fd, enc, tal_count(enc)))
peer_failed_connection_lost();
tal_free(enc);
#if DEVELOPER
if (post_sabotage)
dev_sabotage_fd(fd);
#endif
return ret;
}
u8 *sync_crypto_read(const tal_t *ctx, struct crypto_state *cs, int fd)
@@ -55,24 +55,24 @@ u8 *sync_crypto_read(const tal_t *ctx, struct crypto_state *cs, int fd)
if (!read_all(fd, hdr, sizeof(hdr))) {
status_trace("Failed reading header: %s", strerror(errno));
return NULL;
peer_failed_connection_lost();
}
if (!cryptomsg_decrypt_header(cs, hdr, &len)) {
status_trace("Failed hdr decrypt with rn=%"PRIu64, cs->rn-1);
return NULL;
peer_failed_connection_lost();
}
enc = tal_arr(ctx, u8, len + 16);
if (!read_all(fd, enc, tal_count(enc))) {
status_trace("Failed reading body: %s", strerror(errno));
return tal_free(enc);
peer_failed_connection_lost();
}
dec = cryptomsg_decrypt_body(ctx, cs, enc);
tal_free(enc);
if (!dec)
status_trace("Failed body decrypt with rn=%"PRIu64, cs->rn-2);
peer_failed_connection_lost();
else
status_peer_io(LOG_IO_IN, dec);