mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-24 15:10:51 +01:00
dev_disconnect: rename to dev_disconnect_out, in preparation for incoming filters.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e3a08b315d
commit
44c6a22e5f
4 changed files with 26 additions and 26 deletions
|
@ -50,20 +50,20 @@ void dev_disconnect_init(int fd)
|
|||
dev_disconnect_fd = fd;
|
||||
}
|
||||
|
||||
enum dev_disconnect dev_disconnect(const struct node_id *id, int pkt_type)
|
||||
enum dev_disconnect_out dev_disconnect_out(const struct node_id *id, int pkt_type)
|
||||
{
|
||||
if (dev_disconnect_fd == -1)
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
return DEV_DISCONNECT_OUT_NORMAL;
|
||||
|
||||
if (!dev_disconnect_count)
|
||||
next_dev_disconnect();
|
||||
|
||||
if (!dev_disconnect_line[0]
|
||||
|| !streq(peer_wire_name(pkt_type), dev_disconnect_line+1))
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
return DEV_DISCONNECT_OUT_NORMAL;
|
||||
|
||||
if (--dev_disconnect_count != 0) {
|
||||
return DEV_DISCONNECT_NORMAL;
|
||||
return DEV_DISCONNECT_OUT_NORMAL;
|
||||
}
|
||||
|
||||
if (lseek(dev_disconnect_fd, dev_disconnect_len+1, SEEK_CUR) < 0) {
|
||||
|
|
|
@ -5,23 +5,23 @@
|
|||
|
||||
struct node_id;
|
||||
|
||||
enum dev_disconnect {
|
||||
enum dev_disconnect_out {
|
||||
/* Do nothing. */
|
||||
DEV_DISCONNECT_NORMAL = '=',
|
||||
DEV_DISCONNECT_OUT_NORMAL = '=',
|
||||
/* Close connection before sending packet. */
|
||||
DEV_DISCONNECT_BEFORE = '-',
|
||||
DEV_DISCONNECT_OUT_BEFORE = '-',
|
||||
/* Close connection after sending packet. */
|
||||
DEV_DISCONNECT_AFTER = '+',
|
||||
DEV_DISCONNECT_OUT_AFTER = '+',
|
||||
/* Drop message (don't send to peer) */
|
||||
DEV_DISCONNECT_DROP = '$',
|
||||
DEV_DISCONNECT_OUT_DROP = '$',
|
||||
/* Swallow all writes from now on, and do no more reads. */
|
||||
DEV_DISCONNECT_BLACKHOLE = '0',
|
||||
DEV_DISCONNECT_OUT_BLACKHOLE = '0',
|
||||
/* Don't use connection after sending packet, but don't close. */
|
||||
DEV_DISCONNECT_DISABLE_AFTER = 'x',
|
||||
DEV_DISCONNECT_OUT_DISABLE_AFTER = 'x',
|
||||
};
|
||||
|
||||
/* Force a close fd before or after a certain packet type */
|
||||
enum dev_disconnect dev_disconnect(const struct node_id *id, int pkt_type);
|
||||
enum dev_disconnect_out dev_disconnect_out(const struct node_id *id, int pkt_type);
|
||||
|
||||
/* Make next write on fd fail as if they'd disconnected. */
|
||||
void dev_sabotage_fd(int fd, bool close_fd);
|
||||
|
|
|
@ -415,25 +415,25 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
|
|||
{
|
||||
int type = fromwire_peektype(msg);
|
||||
|
||||
switch (dev_disconnect(&peer->id, type)) {
|
||||
case DEV_DISCONNECT_BEFORE:
|
||||
switch (dev_disconnect_out(&peer->id, type)) {
|
||||
case DEV_DISCONNECT_OUT_BEFORE:
|
||||
if (taken(msg))
|
||||
tal_free(msg);
|
||||
return io_close(peer->to_peer);
|
||||
case DEV_DISCONNECT_AFTER:
|
||||
case DEV_DISCONNECT_OUT_AFTER:
|
||||
/* Disallow reads from now on */
|
||||
peer->dev_read_enabled = false;
|
||||
/* Using io_close here can lose the data we're about to send! */
|
||||
next = io_sock_shutdown_cb;
|
||||
break;
|
||||
case DEV_DISCONNECT_BLACKHOLE:
|
||||
case DEV_DISCONNECT_OUT_BLACKHOLE:
|
||||
/* Disable both reads and writes from now on */
|
||||
peer->dev_read_enabled = false;
|
||||
peer->dev_writes_enabled = talz(peer, u32);
|
||||
break;
|
||||
case DEV_DISCONNECT_NORMAL:
|
||||
case DEV_DISCONNECT_OUT_NORMAL:
|
||||
break;
|
||||
case DEV_DISCONNECT_DROP:
|
||||
case DEV_DISCONNECT_OUT_DROP:
|
||||
/* Drop this message and continue */
|
||||
if (taken(msg))
|
||||
tal_free(msg);
|
||||
|
@ -441,7 +441,7 @@ static struct io_plan *encrypt_and_send(struct peer *peer,
|
|||
io_wake(&peer->subds);
|
||||
return msg_queue_wait(peer->to_peer, peer->peer_outq,
|
||||
next, peer);
|
||||
case DEV_DISCONNECT_DISABLE_AFTER:
|
||||
case DEV_DISCONNECT_OUT_DISABLE_AFTER:
|
||||
peer->dev_read_enabled = false;
|
||||
peer->dev_writes_enabled = tal(peer, u32);
|
||||
*peer->dev_writes_enabled = 1;
|
||||
|
|
|
@ -280,21 +280,21 @@ struct io_plan *peer_exchange_initmsg(struct io_conn *conn,
|
|||
peer->msg = cryptomsg_encrypt_msg(peer, &peer->cs, take(peer->msg));
|
||||
|
||||
next = read_init;
|
||||
switch (dev_disconnect(&peer->id, WIRE_INIT)) {
|
||||
case DEV_DISCONNECT_BEFORE:
|
||||
switch (dev_disconnect_out(&peer->id, WIRE_INIT)) {
|
||||
case DEV_DISCONNECT_OUT_BEFORE:
|
||||
dev_sabotage_fd(io_conn_fd(conn), true);
|
||||
break;
|
||||
case DEV_DISCONNECT_AFTER:
|
||||
case DEV_DISCONNECT_OUT_AFTER:
|
||||
next = dev_peer_write_postclose;
|
||||
break;
|
||||
case DEV_DISCONNECT_BLACKHOLE:
|
||||
case DEV_DISCONNECT_OUT_BLACKHOLE:
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Blackhole not supported during handshake");
|
||||
break;
|
||||
case DEV_DISCONNECT_NORMAL:
|
||||
case DEV_DISCONNECT_DROP:
|
||||
case DEV_DISCONNECT_OUT_NORMAL:
|
||||
case DEV_DISCONNECT_OUT_DROP:
|
||||
break;
|
||||
case DEV_DISCONNECT_DISABLE_AFTER:
|
||||
case DEV_DISCONNECT_OUT_DISABLE_AFTER:
|
||||
next = dev_peer_write_post_sabotage;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue