From 8a2d3871018e95bc38ab1babc7afec435dda171b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 8 Apr 2019 09:22:19 +0930 Subject: [PATCH] devtools/gossipwith: add option to stream from stdin. Signed-off-by: Rusty Russell --- devtools/gossipwith.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c index e4f2a9808..2c0b74490 100644 --- a/devtools/gossipwith.c +++ b/devtools/gossipwith.c @@ -14,6 +14,7 @@ #define io_write_ simple_write #define io_read_ simple_read #define io_close simple_close +static bool stream_stdin = false; static struct io_plan *simple_write(struct io_conn *conn, const void *data, size_t len, @@ -130,6 +131,19 @@ static struct io_plan *handshake_success(struct io_conn *conn, tal_free(sync_crypto_read(NULL, &cs, conn->fd)); /* Did they ask us to send any messages? Do so now. */ + if (stream_stdin) { + beint16_t be_inlen; + + while (read_all(STDIN_FILENO, &be_inlen, sizeof(be_inlen))) { + u32 msglen = be16_to_cpu(be_inlen); + u8 *msg = tal_arr(NULL, u8, msglen); + + if (!read_all(STDIN_FILENO, msg, msglen)) + err(1, "Only read partial message"); + sync_crypto_write(&cs, conn->fd, take(msg)); + } + } + while (*args) { u8 *m = tal_hexdata(NULL, *args, strlen(*args)); if (!m) @@ -172,6 +186,8 @@ int main(int argc, char *argv[]) opt_register_arg("--max-messages", opt_set_ulongval, opt_show_ulongval, &max_messages, "Terminate after reading this many messages (> 0)"); + opt_register_noarg("--stdin", opt_set_bool, &stream_stdin, + "Stream gossip messages from stdin."); opt_register_noarg("--help|-h", opt_usage_and_exit, "id@addr[:port] [hex-msg-tosend...]\n" "Connect to a lightning peer and relay gossip messages from it",