@@ -56,6 +56,7 @@ struct io_conn {
5656static struct secret notsosecret ;
5757static bool no_gossip = false, all_gossip = false;
5858static unsigned long max_messages = -1UL ;
59+ static u16 * accept_messages = NULL ;
5960
6061/* Empty stubs to make us compile */
6162void status_peer_io (enum log_level iodir ,
@@ -101,6 +102,18 @@ bool is_unknown_msg_discardable(const u8 *cursor)
101102 return false;
102103}
103104
105+ static bool accept_message (const u8 * msg )
106+ {
107+ u16 type = fromwire_peektype (msg );
108+ if (!accept_messages )
109+ return true;
110+ for (size_t i = 0 ; i < tal_count (accept_messages ); i ++ ) {
111+ if (type == accept_messages [i ])
112+ return true;
113+ }
114+ return false;
115+ }
116+
104117static struct io_plan * simple_write (struct io_conn * conn ,
105118 const void * data , size_t len ,
106119 struct io_plan * (* next )(struct io_conn * , void * ),
@@ -240,6 +253,10 @@ static struct io_plan *handshake_success(struct io_conn *conn,
240253 msg = sync_crypto_read (NULL , peer_fd , cs );
241254 if (!msg )
242255 err (1 , "Reading msg" );
256+ if (!accept_message (msg )) {
257+ tal_free (msg );
258+ continue ;
259+ }
243260 if (hex ) {
244261 printf ("%s\n" , tal_hex (msg , msg ));
245262 } else {
@@ -248,8 +265,8 @@ static struct io_plan *handshake_success(struct io_conn *conn,
248265 || !write_all (STDOUT_FILENO , msg , tal_bytelen (msg )))
249266 err (1 , "Writing out msg" );
250267 }
251- tal_free (msg );
252268 -- max_messages ;
269+ tal_free (msg );
253270 }
254271 }
255272
@@ -284,6 +301,15 @@ static char *opt_set_features(const char *arg, u8 **features)
284301 return NULL ;
285302}
286303
304+ static char * opt_set_filter (const char * arg , u16 * * accept )
305+ {
306+ char * * elems = tal_strsplit (tmpctx , arg , "," , STR_EMPTY_OK );
307+ * accept = tal_arr (NULL , u16 , tal_count (elems )- 1 );
308+ for (size_t i = 0 ; elems [i ]; i ++ )
309+ (* accept )[i ] = atoi (elems [i ]);
310+ return NULL ;
311+ }
312+
287313int main (int argc , char * argv [])
288314{
289315 struct io_conn * conn = tal (NULL , struct io_conn );
@@ -306,6 +332,8 @@ int main(int argc, char *argv[])
306332 "Stream complete gossip history at start" );
307333 opt_register_noarg ("--no-gossip" , opt_set_bool , & no_gossip ,
308334 "Suppress all gossip at start" );
335+ opt_register_arg ("--filter" , opt_set_filter , NULL , & accept_messages ,
336+ "Only process these message types" );
309337 opt_register_arg ("--max-messages" , opt_set_ulongval , opt_show_ulongval ,
310338 & max_messages ,
311339 "Terminate after reading this many messages" );
0 commit comments