Merge pull request #178 from TheBlueMatt/2018-09-channel_reestablish
[rust-lightning] / src / ln / peer_handler.rs
index 4e710117bb805037a80457086a434de70a0bb29b..81ae8ca3863363e17aeca9ac6fb3bfc61a78bb04 100644 (file)
@@ -465,6 +465,10 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                                                                local_features,
                                                                                                        }, 16);
                                                                                                }
+
+                                                                                               for msg in self.message_handler.chan_handler.peer_connected(&peer.their_node_id.unwrap()) {
+                                                                                                       encode_and_send_msg!(msg, 136);
+                                                                                               }
                                                                                        },
                                                                                        17 => {
                                                                                                let msg = try_potential_decodeerror!(msgs::ErrorMessage::read(&mut reader));
@@ -596,7 +600,31 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                                                let msg = try_potential_decodeerror!(msgs::UpdateFee::read(&mut reader));
                                                                                                try_potential_handleerror!(self.message_handler.chan_handler.handle_update_fee(&peer.their_node_id.unwrap(), &msg));
                                                                                        },
-                                                                                       136 => { }, // TODO: channel_reestablish
+                                                                                       136 => {
+                                                                                               let msg = try_potential_decodeerror!(msgs::ChannelReestablish::read(&mut reader));
+                                                                                               let (funding_locked, revoke_and_ack, commitment_update) = try_potential_handleerror!(self.message_handler.chan_handler.handle_channel_reestablish(&peer.their_node_id.unwrap(), &msg));
+                                                                                               if let Some(lock_msg) = funding_locked {
+                                                                                                       encode_and_send_msg!(lock_msg, 36);
+                                                                                               }
+                                                                                               if let Some(revoke_msg) = revoke_and_ack {
+                                                                                                       encode_and_send_msg!(revoke_msg, 133);
+                                                                                               }
+                                                                                               match commitment_update {
+                                                                                                       Some(resps) => {
+                                                                                                               for resp in resps.update_add_htlcs {
+                                                                                                                       encode_and_send_msg!(resp, 128);
+                                                                                                               }
+                                                                                                               for resp in resps.update_fulfill_htlcs {
+                                                                                                                       encode_and_send_msg!(resp, 130);
+                                                                                                               }
+                                                                                                               for resp in resps.update_fail_htlcs {
+                                                                                                                       encode_and_send_msg!(resp, 131);
+                                                                                                               }
+                                                                                                               encode_and_send_msg!(resps.commitment_signed, 132);
+                                                                                                       },
+                                                                                                       None => {},
+                                                                                               }
+                                                                                       },
 
                                                                                        // Routing control:
                                                                                        259 => {