1 #ifndef LIGHTNING_COMMON_READ_PEER_MSG_H 2 #define LIGHTNING_COMMON_READ_PEER_MSG_H 3 #include "config.h" 4 #include <ccan/short_types/short_types.h> 5 #include <ccan/tal/tal.h> 6 7 struct crypto_state; 8 struct channel_id; 9 struct per_peer_state; 10 11 /** 12 * peer_or_gossip_sync_read - read a peer message, or maybe a gossip msg. 13 * @ctx: context to allocate return packet from. 14 * @pps: the per-peer peer state and fds 15 * @from_gossipd: true if the msg was from gossipd, otherwise false. 16 * 17 * Will call peer_failed_connection_lost() or 18 * status_failed(STATUS_FAIL_GOSSIP_IO) or return a message. 19 * 20 * Usually, you should call handle_gossip_msg if *@from_gossipd is 21 * true, otherwise if is_peer_error() handle the error, otherwise if 22 * is_msg_for_gossipd() then send to gossipd, otherwise if is 23 * is_wrong_channel() send that as a reply. Otherwise it should be 24 * a valid message. 25 */ 26 u8 *peer_or_gossip_sync_read(const tal_t *ctx, 27 struct per_peer_state *pps, 28 bool *from_gossipd); 29 30 /** 31 * is_peer_error - if it's an error, describe if it applies to this channel. 32 * @ctx: context to allocate return from. 33 * @msg: the peer message. 34 * @channel_id: the channel id of the current channel. 35 * @desc: set to non-NULL if this describes a channel we care about. 36 * @warning: set to true if this is a warning, not an error. 37 * 38 * If @desc is NULL, ignore this message. Otherwise, that's usually passed 39 * to peer_failed_received_errmsg(). 40 */ 41 bool is_peer_error(const tal_t *ctx, const u8 *msg, 42 const struct channel_id *channel_id, 43 char **desc, bool *warning); 44 45 /** 46 * is_wrong_channel - if it's a message about a different channel, return true 47 * @msg: the peer message. 48 * @channel_id: the channel id of the current channel. 49 * @actual: set to the actual channel id if this returns false. 50 * 51 * Note that this only handles some message types, returning false for others. 52 */ 53 bool is_wrong_channel(const u8 *msg, const struct channel_id *expected, 54 struct channel_id *actual); 55 56 57 /** 58 * handle_peer_gossip_or_error - simple handler for all the above cases. 59 * @pps: per-peer state. 60 * @channel_id: the channel id of the current channel. 61 * @soft_error: tell lightningd that incoming error is non-fatal. 62 * @msg: the peer message (only taken if returns true). 63 * 64 * This returns true if it handled the packet: a gossip packet (forwarded 65 * to gossipd), or an error packet (causes peer_failed_received_errmsg or 66 * ignored), or a ping (may reply with pong). 67 */ 68 bool handle_peer_gossip_or_error(struct per_peer_state *pps, 69 const struct channel_id *channel_id, 70 bool soft_error, 71 const u8 *msg TAKES); 72 73 /** 74 * handle_timestamp_filter - deal with timestamp filter requests. 75 * @pps: per-peer state. 76 * @msg: the peer message (only taken if returns true). 77 */ 78 bool handle_timestamp_filter(struct per_peer_state *pps, const u8 *msg TAKES); 79 80 /* We got this message from gossipd: forward/quit as it asks. */ 81 void handle_gossip_msg(struct per_peer_state *pps, const u8 *msg TAKES); 82 #endif /* LIGHTNING_COMMON_READ_PEER_MSG_H */ 83