Merge pull request #41 from tamasblummer/minimal_alert_message

minimal implementation of alert message
This commit is contained in:
Andrew Poelstra 2018-02-18 15:00:55 +00:00 committed by GitHub
commit 9562d8afac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -114,10 +114,12 @@ pub enum NetworkMessage {
/// `ping`
Ping(u64),
/// `pong`
Pong(u64)
Pong(u64),
// TODO: reject,
// TODO: bloom filtering
// TODO: alert
/// `alert`
Alert(Vec<u8>)
}
impl RawNetworkMessage {
@ -138,6 +140,7 @@ impl RawNetworkMessage {
NetworkMessage::GetAddr => "getaddr",
NetworkMessage::Ping(_) => "ping",
NetworkMessage::Pong(_) => "pong",
NetworkMessage::Alert(_) => "alert",
}.to_owned()
}
}
@ -162,6 +165,7 @@ impl<S: SimpleEncoder> ConsensusEncodable<S> for RawNetworkMessage {
NetworkMessage::GetAddr => Ok(vec![]),
NetworkMessage::Ping(ref dat) => serialize(dat),
NetworkMessage::Pong(ref dat) => serialize(dat),
NetworkMessage::Alert(ref dat) => serialize(dat)
}.unwrap()).consensus_encode(s));
Ok(())
}
@ -192,6 +196,7 @@ impl<D: SimpleDecoder<Error=util::Error>> ConsensusDecodable<D> for RawNetworkMe
"ping" => NetworkMessage::Ping(try!(propagate_err("ping".to_owned(), ConsensusDecodable::consensus_decode(&mut mem_d)))),
"pong" => NetworkMessage::Pong(try!(propagate_err("pong".to_owned(), ConsensusDecodable::consensus_decode(&mut mem_d)))),
"tx" => NetworkMessage::Tx(try!(propagate_err("tx".to_owned(), ConsensusDecodable::consensus_decode(&mut mem_d)))),
"alert" => NetworkMessage::Alert(try!(propagate_err("alert".to_owned(), ConsensusDecodable::consensus_decode(&mut mem_d)))),
cmd => return Err(d.error(format!("unrecognized network command `{}`", cmd)))
};
Ok(RawNetworkMessage {