2017-04-01 12:25:59 +02:00
|
|
|
#include <wire/peer_wire.h>
|
|
|
|
|
2020-08-31 03:13:25 +02:00
|
|
|
static bool unknown_type(enum peer_wire t)
|
2017-04-01 12:25:59 +02:00
|
|
|
{
|
|
|
|
switch (t) {
|
2021-02-02 13:46:01 +01:00
|
|
|
case WIRE_WARNING:
|
2017-04-01 12:25:59 +02:00
|
|
|
case WIRE_INIT:
|
|
|
|
case WIRE_ERROR:
|
|
|
|
case WIRE_OPEN_CHANNEL:
|
|
|
|
case WIRE_ACCEPT_CHANNEL:
|
|
|
|
case WIRE_FUNDING_CREATED:
|
|
|
|
case WIRE_FUNDING_SIGNED:
|
|
|
|
case WIRE_FUNDING_LOCKED:
|
|
|
|
case WIRE_SHUTDOWN:
|
|
|
|
case WIRE_CLOSING_SIGNED:
|
|
|
|
case WIRE_UPDATE_ADD_HTLC:
|
|
|
|
case WIRE_UPDATE_FULFILL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
|
|
|
|
case WIRE_COMMITMENT_SIGNED:
|
|
|
|
case WIRE_REVOKE_AND_ACK:
|
|
|
|
case WIRE_UPDATE_FEE:
|
2021-06-10 19:54:08 +02:00
|
|
|
case WIRE_UPDATE_BLOCKHEIGHT:
|
2017-06-20 07:40:03 +02:00
|
|
|
case WIRE_CHANNEL_REESTABLISH:
|
2017-04-01 12:25:59 +02:00
|
|
|
case WIRE_ANNOUNCEMENT_SIGNATURES:
|
|
|
|
case WIRE_CHANNEL_ANNOUNCEMENT:
|
|
|
|
case WIRE_NODE_ANNOUNCEMENT:
|
|
|
|
case WIRE_CHANNEL_UPDATE:
|
2017-04-12 18:10:10 +02:00
|
|
|
case WIRE_PING:
|
|
|
|
case WIRE_PONG:
|
2018-06-04 06:18:25 +02:00
|
|
|
case WIRE_QUERY_SHORT_CHANNEL_IDS:
|
|
|
|
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
|
|
|
|
case WIRE_QUERY_CHANNEL_RANGE:
|
|
|
|
case WIRE_REPLY_CHANNEL_RANGE:
|
|
|
|
case WIRE_GOSSIP_TIMESTAMP_FILTER:
|
2021-09-21 23:15:26 +02:00
|
|
|
case WIRE_ONION_MESSAGE:
|
2021-09-21 07:23:38 +02:00
|
|
|
case WIRE_OBS_ONION_MESSAGE:
|
2020-09-09 09:20:53 +02:00
|
|
|
case WIRE_TX_ADD_INPUT:
|
|
|
|
case WIRE_TX_REMOVE_INPUT:
|
|
|
|
case WIRE_TX_ADD_OUTPUT:
|
|
|
|
case WIRE_TX_REMOVE_OUTPUT:
|
|
|
|
case WIRE_TX_COMPLETE:
|
|
|
|
case WIRE_TX_SIGNATURES:
|
|
|
|
case WIRE_OPEN_CHANNEL2:
|
|
|
|
case WIRE_ACCEPT_CHANNEL2:
|
|
|
|
case WIRE_INIT_RBF:
|
2021-01-12 20:05:41 +01:00
|
|
|
case WIRE_ACK_RBF:
|
2021-05-31 05:07:50 +02:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
case WIRE_STFU:
|
|
|
|
#endif
|
2017-04-01 12:25:59 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-08 04:17:05 +01:00
|
|
|
bool is_msg_for_gossipd(const u8 *cursor)
|
2017-05-05 08:41:45 +02:00
|
|
|
{
|
2020-08-31 03:13:25 +02:00
|
|
|
switch ((enum peer_wire)fromwire_peektype(cursor)) {
|
2017-05-05 08:41:45 +02:00
|
|
|
case WIRE_CHANNEL_ANNOUNCEMENT:
|
|
|
|
case WIRE_NODE_ANNOUNCEMENT:
|
|
|
|
case WIRE_CHANNEL_UPDATE:
|
2018-06-04 06:18:25 +02:00
|
|
|
case WIRE_QUERY_SHORT_CHANNEL_IDS:
|
|
|
|
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
|
|
|
|
case WIRE_QUERY_CHANNEL_RANGE:
|
|
|
|
case WIRE_REPLY_CHANNEL_RANGE:
|
2018-07-24 02:26:43 +02:00
|
|
|
case WIRE_PING:
|
|
|
|
case WIRE_PONG:
|
2021-09-21 23:15:26 +02:00
|
|
|
case WIRE_ONION_MESSAGE:
|
2021-09-21 07:23:38 +02:00
|
|
|
case WIRE_OBS_ONION_MESSAGE:
|
2017-05-05 08:41:45 +02:00
|
|
|
return true;
|
2021-02-02 13:46:01 +01:00
|
|
|
case WIRE_WARNING:
|
2017-05-05 08:41:45 +02:00
|
|
|
case WIRE_INIT:
|
|
|
|
case WIRE_ERROR:
|
|
|
|
case WIRE_OPEN_CHANNEL:
|
|
|
|
case WIRE_ACCEPT_CHANNEL:
|
|
|
|
case WIRE_FUNDING_CREATED:
|
|
|
|
case WIRE_FUNDING_SIGNED:
|
|
|
|
case WIRE_FUNDING_LOCKED:
|
|
|
|
case WIRE_SHUTDOWN:
|
|
|
|
case WIRE_CLOSING_SIGNED:
|
|
|
|
case WIRE_UPDATE_ADD_HTLC:
|
|
|
|
case WIRE_UPDATE_FULFILL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_HTLC:
|
|
|
|
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
|
|
|
|
case WIRE_COMMITMENT_SIGNED:
|
|
|
|
case WIRE_REVOKE_AND_ACK:
|
|
|
|
case WIRE_UPDATE_FEE:
|
2021-06-10 19:54:08 +02:00
|
|
|
case WIRE_UPDATE_BLOCKHEIGHT:
|
2018-03-08 04:17:05 +01:00
|
|
|
case WIRE_CHANNEL_REESTABLISH:
|
|
|
|
case WIRE_ANNOUNCEMENT_SIGNATURES:
|
2019-06-03 20:19:25 +02:00
|
|
|
case WIRE_GOSSIP_TIMESTAMP_FILTER:
|
2020-09-09 09:20:53 +02:00
|
|
|
case WIRE_TX_ADD_INPUT:
|
|
|
|
case WIRE_TX_REMOVE_INPUT:
|
|
|
|
case WIRE_TX_ADD_OUTPUT:
|
|
|
|
case WIRE_TX_REMOVE_OUTPUT:
|
|
|
|
case WIRE_TX_COMPLETE:
|
|
|
|
case WIRE_TX_SIGNATURES:
|
|
|
|
case WIRE_OPEN_CHANNEL2:
|
|
|
|
case WIRE_ACCEPT_CHANNEL2:
|
|
|
|
case WIRE_INIT_RBF:
|
2021-01-12 20:05:41 +01:00
|
|
|
case WIRE_ACK_RBF:
|
2021-05-31 05:07:50 +02:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
case WIRE_STFU:
|
|
|
|
#endif
|
2017-05-05 08:41:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-01 12:25:59 +02:00
|
|
|
/* Return true if it's an unknown ODD message. cursor is a tal ptr. */
|
2017-06-27 04:50:10 +02:00
|
|
|
bool is_unknown_msg_discardable(const u8 *cursor)
|
2017-04-01 12:25:59 +02:00
|
|
|
{
|
2020-08-31 03:13:25 +02:00
|
|
|
enum peer_wire t = fromwire_peektype(cursor);
|
2017-04-01 12:25:59 +02:00
|
|
|
return unknown_type(t) && (t & 1);
|
|
|
|
}
|
2018-01-10 05:47:22 +01:00
|
|
|
|
|
|
|
/* Extract channel_id from various packets, return true if possible. */
|
|
|
|
bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
|
|
|
|
{
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat ignored_sat;
|
|
|
|
struct amount_msat ignored_msat;
|
2018-01-10 05:47:22 +01:00
|
|
|
u64 ignored_u64;
|
|
|
|
u32 ignored_u32;
|
|
|
|
u16 ignored_u16;
|
|
|
|
u8 ignored_u8;
|
|
|
|
struct pubkey ignored_pubkey;
|
|
|
|
struct bitcoin_blkid ignored_chainhash;
|
2020-06-22 07:06:03 +02:00
|
|
|
struct secret ignored_secret;
|
|
|
|
struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(tmpctx);
|
2021-06-04 07:13:45 +02:00
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
struct tlv_channel_reestablish_tlvs *reestab_tlvs = tlv_channel_reestablish_tlvs_new(tmpctx);
|
|
|
|
#endif
|
2018-01-10 05:47:22 +01:00
|
|
|
|
2018-02-20 21:59:09 +01:00
|
|
|
if (fromwire_channel_reestablish(in_pkt, channel_id,
|
2020-06-22 07:06:03 +02:00
|
|
|
&ignored_u64, &ignored_u64,
|
2021-06-04 07:13:45 +02:00
|
|
|
&ignored_secret, &ignored_pubkey
|
|
|
|
#if EXPERIMENTAL_FEATURES
|
|
|
|
, reestab_tlvs
|
|
|
|
#endif
|
|
|
|
))
|
2018-01-10 05:47:22 +01:00
|
|
|
return true;
|
2018-02-20 21:59:09 +01:00
|
|
|
if (fromwire_open_channel(in_pkt, &ignored_chainhash,
|
2019-02-21 04:45:55 +01:00
|
|
|
channel_id, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_sat,
|
|
|
|
&ignored_msat, &ignored_u32,
|
2018-01-10 05:47:22 +01:00
|
|
|
&ignored_u16, &ignored_u16,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
|
|
|
&ignored_pubkey, &ignored_pubkey,
|
2020-06-22 07:06:03 +02:00
|
|
|
&ignored_u8, tlvs))
|
2018-01-10 05:47:22 +01:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|