Introduce transcoder parameter to Wire & Transport
This commit is contained in:
parent
6b87eed670
commit
56fb4d67a9
|
|
@ -10,6 +10,7 @@ use crate::clock::RefClock;
|
||||||
use crate::profile::Profile;
|
use crate::profile::Profile;
|
||||||
use crate::service::routing;
|
use crate::service::routing;
|
||||||
use crate::transport::Transport;
|
use crate::transport::Transport;
|
||||||
|
use crate::wire::transcoder::PlainTranscoder;
|
||||||
use crate::wire::Wire;
|
use crate::wire::Wire;
|
||||||
use crate::{address, service};
|
use crate::{address, service};
|
||||||
|
|
||||||
|
|
@ -130,9 +131,11 @@ impl<R: Reactor> Client<R> {
|
||||||
rng,
|
rng,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let transcode = PlainTranscoder::default();
|
||||||
|
|
||||||
self.reactor.run(
|
self.reactor.run(
|
||||||
&config.listen,
|
&config.listen,
|
||||||
Transport::new(Wire::new(service)),
|
Transport::new(Wire::new(service, transcode)),
|
||||||
self.events,
|
self.events,
|
||||||
self.commands,
|
self.commands,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use crate::crypto;
|
||||||
use crate::service::routing;
|
use crate::service::routing;
|
||||||
use crate::service::{Command, DisconnectReason, Event, Service};
|
use crate::service::{Command, DisconnectReason, Event, Service};
|
||||||
use crate::storage::WriteStorage;
|
use crate::storage::WriteStorage;
|
||||||
|
use crate::wire::transcoder::Transcode;
|
||||||
use crate::wire::Wire;
|
use crate::wire::Wire;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -19,13 +20,13 @@ struct Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Transport<R, S, T, G> {
|
pub struct Transport<R, S, W, G, T: Transcode> {
|
||||||
_peers: HashMap<net::IpAddr, Peer>,
|
_peers: HashMap<net::IpAddr, Peer>,
|
||||||
inner: Wire<R, S, T, G>,
|
inner: Wire<R, S, W, G, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Transport<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Transport<R, S, W, G, T> {
|
||||||
pub fn new(inner: Wire<R, S, T, G>) -> Self {
|
pub fn new(inner: Wire<R, S, W, G, T>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
_peers: HashMap::default(),
|
_peers: HashMap::default(),
|
||||||
inner,
|
inner,
|
||||||
|
|
@ -33,12 +34,13 @@ impl<R, S, T, G> Transport<R, S, T, G> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> nakamoto::Protocol for Transport<R, S, T, G>
|
impl<R, S, W, G, T> nakamoto::Protocol for Transport<R, S, W, G, T>
|
||||||
where
|
where
|
||||||
R: routing::Store,
|
R: routing::Store,
|
||||||
T: WriteStorage + 'static,
|
W: WriteStorage + 'static,
|
||||||
S: address::Store,
|
S: address::Store,
|
||||||
G: crypto::Signer,
|
G: crypto::Signer,
|
||||||
|
T: Transcode,
|
||||||
{
|
{
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
type Command = Command;
|
type Command = Command;
|
||||||
|
|
@ -86,7 +88,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Iterator for Transport<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Iterator for Transport<R, S, W, G, T> {
|
||||||
type Item = Io<Event, DisconnectReason>;
|
type Item = Io<Event, DisconnectReason>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
|
@ -94,15 +96,15 @@ impl<R, S, T, G> Iterator for Transport<R, S, T, G> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Deref for Transport<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Deref for Transport<R, S, W, G, T> {
|
||||||
type Target = Service<R, S, T, G>;
|
type Target = Service<R, S, W, G>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.inner
|
&self.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> DerefMut for Transport<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> DerefMut for Transport<R, S, W, G, T> {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.inner
|
&mut self.inner
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod message;
|
pub mod message;
|
||||||
|
pub mod transcoder;
|
||||||
|
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
@ -25,6 +26,7 @@ use crate::service::{filter, routing};
|
||||||
use crate::storage::refs::Refs;
|
use crate::storage::refs::Refs;
|
||||||
use crate::storage::refs::SignedRefs;
|
use crate::storage::refs::SignedRefs;
|
||||||
use crate::storage::WriteStorage;
|
use crate::storage::WriteStorage;
|
||||||
|
use crate::wire::transcoder::Transcode;
|
||||||
|
|
||||||
/// The default type we use to represent sizes on the wire.
|
/// The default type we use to represent sizes on the wire.
|
||||||
///
|
///
|
||||||
|
|
@ -423,33 +425,32 @@ impl Decode for node::Features {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Wire<R, S, T, G> {
|
pub struct Wire<R, S, W, G, T: Transcode> {
|
||||||
inboxes: HashMap<net::SocketAddr, Decoder>,
|
inboxes: HashMap<net::SocketAddr, Decoder>,
|
||||||
inner: service::Service<R, S, T, G>,
|
inner: service::Service<R, S, W, G>,
|
||||||
|
#[allow(dead_code)]
|
||||||
|
transcoder: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Wire<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Wire<R, S, W, G, T> {
|
||||||
pub fn new(inner: service::Service<R, S, T, G>) -> Self {
|
pub fn new(inner: service::Service<R, S, W, G>, transcoder: T) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inboxes: HashMap::new(),
|
inboxes: HashMap::new(),
|
||||||
inner,
|
inner,
|
||||||
|
transcoder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Wire<R, S, T, G>
|
impl<R, S, W, G, T> Wire<R, S, W, G, T>
|
||||||
where
|
where
|
||||||
R: routing::Store,
|
R: routing::Store,
|
||||||
S: address::Store,
|
S: address::Store,
|
||||||
T: WriteStorage + 'static,
|
W: WriteStorage + 'static,
|
||||||
G: Signer,
|
G: Signer,
|
||||||
|
T: Transcode,
|
||||||
{
|
{
|
||||||
pub fn connected(
|
pub fn connected(&mut self, addr: net::SocketAddr, local_addr: &net::SocketAddr, link: Link) {
|
||||||
&mut self,
|
|
||||||
addr: net::SocketAddr,
|
|
||||||
local_addr: &net::SocketAddr,
|
|
||||||
link: Link,
|
|
||||||
) {
|
|
||||||
self.inboxes.insert(addr, Decoder::new(256));
|
self.inboxes.insert(addr, Decoder::new(256));
|
||||||
self.inner.connected(addr, local_addr, link)
|
self.inner.connected(addr, local_addr, link)
|
||||||
}
|
}
|
||||||
|
|
@ -459,7 +460,7 @@ where
|
||||||
addr: &net::SocketAddr,
|
addr: &net::SocketAddr,
|
||||||
reason: nakamoto::DisconnectReason<service::DisconnectReason>,
|
reason: nakamoto::DisconnectReason<service::DisconnectReason>,
|
||||||
) {
|
) {
|
||||||
self.inboxes.remove(&addr);
|
self.inboxes.remove(addr);
|
||||||
self.inner.disconnected(addr, &reason)
|
self.inner.disconnected(addr, &reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,7 +487,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Iterator for Wire<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Iterator for Wire<R, S, W, G, T> {
|
||||||
type Item = nakamoto::Io<service::Event, service::DisconnectReason>;
|
type Item = nakamoto::Io<service::Event, service::DisconnectReason>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
|
@ -511,15 +512,15 @@ impl<R, S, T, G> Iterator for Wire<R, S, T, G> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> Deref for Wire<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> Deref for Wire<R, S, W, G, T> {
|
||||||
type Target = service::Service<R, S, T, G>;
|
type Target = service::Service<R, S, W, G>;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.inner
|
&self.inner
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R, S, T, G> DerefMut for Wire<R, S, T, G> {
|
impl<R, S, W, G, T: Transcode> DerefMut for Wire<R, S, W, G, T> {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.inner
|
&mut self.inner
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
pub trait Transcode {}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct PlainTranscoder;
|
||||||
|
|
||||||
|
impl Transcode for PlainTranscoder {}
|
||||||
Loading…
Reference in New Issue