2021-12-04 11:23:56 +00:00
|
|
|
#include "config.h"
|
2017-02-21 04:45:29 +00:00
|
|
|
#include <ccan/read_write_all/read_write_all.h>
|
2017-08-28 17:05:01 +01:00
|
|
|
#include <common/cryptomsg.h>
|
2018-08-02 07:49:55 +01:00
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 13:23:29 +00:00
|
|
|
#include <common/peer_io.h>
|
2019-06-03 19:11:25 +01:00
|
|
|
#include <common/per_peer_state.h>
|
2017-08-28 17:05:01 +01:00
|
|
|
#include <common/status.h>
|
2017-02-24 05:52:56 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
2018-08-09 01:30:30 +01:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2021-09-19 12:07:58 +01:00
|
|
|
#include <sys/socket.h>
|
2017-05-24 11:10:16 +01:00
|
|
|
#include <wire/wire.h>
|
2022-01-08 13:22:29 +00:00
|
|
|
#include <wire/wire_io.h>
|
|
|
|
#include <wire/wire_sync.h>
|
2017-02-21 04:45:29 +00:00
|
|
|
|
2022-01-08 13:23:29 +00:00
|
|
|
void peer_write(struct per_peer_state *pps, const void *msg TAKES)
|
2017-02-21 04:45:29 +00:00
|
|
|
{
|
2019-11-17 11:42:33 +00:00
|
|
|
status_peer_io(LOG_IO_OUT, NULL, msg);
|
2018-02-05 04:09:28 +00:00
|
|
|
|
2022-01-11 01:17:30 +00:00
|
|
|
/* We ignore write errors; we might still have something to read,
|
|
|
|
* so we'd rather fail there. */
|
|
|
|
wire_sync_write(pps->peer_fd, msg);
|
2017-02-21 04:45:29 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 13:23:29 +00:00
|
|
|
u8 *peer_read(const tal_t *ctx, struct per_peer_state *pps)
|
2017-02-21 04:45:29 +00:00
|
|
|
{
|
2022-01-11 01:15:58 +00:00
|
|
|
u8 *msg = wire_sync_read(ctx, pps->peer_fd);
|
|
|
|
if (!msg)
|
2018-08-02 07:49:55 +01:00
|
|
|
peer_failed_connection_lost();
|
2022-01-08 13:22:29 +00:00
|
|
|
|
2022-01-11 01:15:58 +00:00
|
|
|
status_peer_io(LOG_IO_IN, NULL, msg);
|
2018-02-05 04:09:28 +00:00
|
|
|
|
2022-01-11 01:15:58 +00:00
|
|
|
return msg;
|
2017-02-21 04:45:29 +00:00
|
|
|
}
|