minimal implementation of alert message

This commit is contained in:
Tamas Blummer 2018-02-10 16:47:46 +01:00
parent 01e164025a
commit 9fbe941621
1 changed files with 6 additions and 1 deletions

View File

@ -114,10 +114,12 @@ pub enum NetworkMessage {
/// `ping` /// `ping`
Ping(u64), Ping(u64),
/// `pong` /// `pong`
Pong(u64) Pong(u64),
// TODO: reject, // TODO: reject,
// TODO: bloom filtering // TODO: bloom filtering
// TODO: alert // TODO: alert
/// `alert`
Alert(Vec<u8>)
} }
impl RawNetworkMessage { impl RawNetworkMessage {
@ -138,6 +140,7 @@ impl RawNetworkMessage {
NetworkMessage::GetAddr => "getaddr", NetworkMessage::GetAddr => "getaddr",
NetworkMessage::Ping(_) => "ping", NetworkMessage::Ping(_) => "ping",
NetworkMessage::Pong(_) => "pong", NetworkMessage::Pong(_) => "pong",
NetworkMessage::Alert(_) => "alert",
}.to_owned() }.to_owned()
} }
} }
@ -162,6 +165,7 @@ impl<S: SimpleEncoder> ConsensusEncodable<S> for RawNetworkMessage {
NetworkMessage::GetAddr => Ok(vec![]), NetworkMessage::GetAddr => Ok(vec![]),
NetworkMessage::Ping(ref dat) => serialize(dat), NetworkMessage::Ping(ref dat) => serialize(dat),
NetworkMessage::Pong(ref dat) => serialize(dat), NetworkMessage::Pong(ref dat) => serialize(dat),
NetworkMessage::Alert(ref dat) => serialize(dat)
}.unwrap()).consensus_encode(s)); }.unwrap()).consensus_encode(s));
Ok(()) 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)))), "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)))), "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)))), "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))) cmd => return Err(d.error(format!("unrecognized network command `{}`", cmd)))
}; };
Ok(RawNetworkMessage { Ok(RawNetworkMessage {