+impl wire::Type for () {
+ fn type_id(&self) -> u16 {
+ // We should never call this for `DummyCustomType`
+ unreachable!();
+ }
+}
+
+impl Writeable for () {
+ fn write<W: Writer>(&self, _: &mut W) -> Result<(), io::Error> {
+ unreachable!();
+ }
+}
+
+impl wire::CustomMessageReader for IgnoringMessageHandler {
+ type CustomMessage = ();
+ fn read<R: io::Read>(&self, _message_type: u16, _buffer: &mut R) -> Result<Option<Self::CustomMessage>, msgs::DecodeError> {
+ Ok(None)
+ }
+}
+
+impl CustomMessageHandler for IgnoringMessageHandler {
+ fn handle_custom_message(&self, _msg: Self::CustomMessage) -> Result<(), LightningError> {
+ // Since we always return `None` in the read the handle method should never be called.
+ unreachable!();
+ }
+
+ fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { Vec::new() }
+}
+
+/// A dummy struct which implements `ChannelMessageHandler` without having any channels.
+/// You can provide one of these as the route_handler in a MessageHandler.
+pub struct ErroringMessageHandler {
+ message_queue: Mutex<Vec<MessageSendEvent>>
+}
+impl ErroringMessageHandler {
+ /// Constructs a new ErroringMessageHandler
+ pub fn new() -> Self {
+ Self { message_queue: Mutex::new(Vec::new()) }
+ }
+ fn push_error(&self, node_id: &PublicKey, channel_id: [u8; 32]) {
+ self.message_queue.lock().unwrap().push(MessageSendEvent::HandleError {
+ action: msgs::ErrorAction::SendErrorMessage {
+ msg: msgs::ErrorMessage { channel_id, data: "We do not support channel messages, sorry.".to_owned() },
+ },
+ node_id: node_id.clone(),
+ });
+ }
+}
+impl MessageSendEventsProvider for ErroringMessageHandler {
+ fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
+ let mut res = Vec::new();
+ mem::swap(&mut res, &mut self.message_queue.lock().unwrap());
+ res
+ }
+}
+impl ChannelMessageHandler for ErroringMessageHandler {
+ // Any messages which are related to a specific channel generate an error message to let the
+ // peer know we don't care about channels.
+ fn handle_open_channel(&self, their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::OpenChannel) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id);
+ }
+ fn handle_accept_channel(&self, their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::AcceptChannel) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id);
+ }
+ fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &msgs::FundingCreated) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id);
+ }
+ fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_funding_locked(&self, their_node_id: &PublicKey, msg: &msgs::FundingLocked) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_shutdown(&self, their_node_id: &PublicKey, _their_features: &InitFeatures, msg: &msgs::Shutdown) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &msgs::ClosingSigned) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &msgs::RevokeAndACK) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) {
+ ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+ }
+ // msgs::ChannelUpdate does not contain the channel_id field, so we just drop them.
+ fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) {}
+ fn peer_disconnected(&self, _their_node_id: &PublicKey, _no_connection_possible: bool) {}
+ fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &msgs::Init) {}
+ fn handle_error(&self, _their_node_id: &PublicKey, _msg: &msgs::ErrorMessage) {}
+}
+impl Deref for ErroringMessageHandler {
+ type Target = ErroringMessageHandler;
+ fn deref(&self) -> &Self { self }
+}