AFG messaging (#210)

* First draft of afg messaging

* AfgReceivedPrevote, AfgReceivedPrecommit and AfgFinalized added to rust backend

* Tidy up
This commit is contained in:
Maciej Hirsz
2019-12-06 18:21:25 +01:00
committed by GitHub
parent 92fb9d28de
commit 0a89382127
7 changed files with 190 additions and 10 deletions
+16 -2
View File
@@ -2,7 +2,7 @@ use std::time::{Duration, Instant};
use bytes::Bytes;
use actix::prelude::*;
use actix_web_actors::ws;
use crate::aggregator::{Aggregator, Connect, Disconnect, Subscribe};
use crate::aggregator::{Aggregator, Connect, Disconnect, Subscribe, SendFinality, NoMoreFinality};
use crate::chain::Unsubscribe;
use crate::feed::{FeedMessageSerializer, Pong};
use crate::util::fnv;
@@ -76,7 +76,7 @@ impl FeedConnector {
}
fn handle_cmd(&mut self, cmd: &str, payload: &str, ctx: &mut <Self as Actor>::Context) {
match cmd {
match cmd {
"subscribe" => {
match fnv(payload) {
hash if hash == self.chain_hash => return,
@@ -99,6 +99,18 @@ impl FeedConnector {
})
.wait(ctx);
}
"send-finality" => {
self.aggregator.do_send(SendFinality {
chain: payload.into(),
fid: self.fid_chain,
});
}
"no-more-finality" => {
self.aggregator.do_send(NoMoreFinality {
chain: payload.into(),
fid: self.fid_chain,
});
}
"ping" => {
self.serializer.push(Pong(payload));
if let Some(serialized) = self.serializer.finalize() {
@@ -141,6 +153,8 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for FeedConnector {
let cmd = &text[..idx];
let payload = &text[idx+1..];
info!("New FEED message: {}", cmd);
self.handle_cmd(cmd, payload, ctx);
}
}