Send new handshake on reconnect

This commit is contained in:
Andrew Poelstra 2014-07-24 12:52:28 -07:00
parent 809bad5ff5
commit fe9ca39736
2 changed files with 12 additions and 4 deletions

View File

@ -79,7 +79,15 @@ pub trait Listener {
Err(e) => { Err(e) => {
println!("Received error {:} when decoding message. Pausing for 5 seconds then reconnecting.", e); println!("Received error {:} when decoding message. Pausing for 5 seconds then reconnecting.", e);
timer::sleep(5000); timer::sleep(5000);
sock.reconnect(); // Reconnect
sock.reconnect()
// Create version message
.and_then(|_| sock.version_message(0))
// Send it out
.and_then(|msg| sock.send_message(msg))
// For now, not much we can do on error
.unwrap_or_else(|e| println!("Error {} when reconnecting.", e));
handshake_complete = false;
} }
} }
} }

View File

@ -283,9 +283,9 @@ impl Serializable for VarInt {
fn serialize(&self) -> Vec<u8> { fn serialize(&self) -> Vec<u8> {
match *self { match *self {
VarU8(n) => Vec::from_slice(&[n]), VarU8(n) => Vec::from_slice(&[n]),
VarU16(n) => { let mut rv = n.serialize(); rv.unshift(0xFD); rv }, VarU16(n) => { let mut rv = n.serialize(); rv.insert(0, 0xFD); rv },
VarU32(n) => { let mut rv = n.serialize(); rv.unshift(0xFE); rv }, VarU32(n) => { let mut rv = n.serialize(); rv.insert(0, 0xFE); rv },
VarU64(n) => { let mut rv = n.serialize(); rv.unshift(0xFF); rv }, VarU64(n) => { let mut rv = n.serialize(); rv.insert(0, 0xFF); rv },
} }
} }