2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2017-02-21 05:45:29 +01:00
|
|
|
#include <ccan/read_write_all/read_write_all.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/cryptomsg.h>
|
2018-08-02 08:49:55 +02:00
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 14:23:29 +01:00
|
|
|
#include <common/peer_io.h>
|
2019-06-03 20:11:25 +02:00
|
|
|
#include <common/per_peer_state.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/status.h>
|
2017-02-24 06:52:56 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
2018-08-09 02:30:30 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2021-09-19 13:07:58 +02:00
|
|
|
#include <sys/socket.h>
|
2017-05-24 12:10:16 +02:00
|
|
|
#include <wire/wire.h>
|
2022-01-08 14:22:29 +01:00
|
|
|
#include <wire/wire_io.h>
|
|
|
|
#include <wire/wire_sync.h>
|
2017-02-21 05:45:29 +01:00
|
|
|
|
2022-01-08 14:23:29 +01:00
|
|
|
void peer_write(struct per_peer_state *pps, const void *msg TAKES)
|
2017-02-21 05:45:29 +01:00
|
|
|
{
|
2019-11-17 12:42:33 +01:00
|
|
|
status_peer_io(LOG_IO_OUT, NULL, msg);
|
2018-02-05 05:09:28 +01:00
|
|
|
|
2022-01-11 02:17:30 +01: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 05:45:29 +01:00
|
|
|
}
|
|
|
|
|
2022-01-08 14:23:29 +01:00
|
|
|
u8 *peer_read(const tal_t *ctx, struct per_peer_state *pps)
|
2017-02-21 05:45:29 +01:00
|
|
|
{
|
2022-01-11 02:15:58 +01:00
|
|
|
u8 *msg = wire_sync_read(ctx, pps->peer_fd);
|
|
|
|
if (!msg)
|
2018-08-02 08:49:55 +02:00
|
|
|
peer_failed_connection_lost();
|
2022-01-08 14:22:29 +01:00
|
|
|
|
2022-01-11 02:15:58 +01:00
|
|
|
status_peer_io(LOG_IO_IN, NULL, msg);
|
2018-02-05 05:09:28 +01:00
|
|
|
|
2022-01-11 02:15:58 +01:00
|
|
|
return msg;
|
2017-02-21 05:45:29 +01:00
|
|
|
}
|