chore: fix pending code formatting (#270)
This commit is contained in:
parent
2dd9a98808
commit
e930267149
5 changed files with 25 additions and 23 deletions
|
|
@ -4,6 +4,7 @@ use thiserror::Error;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
|
use crate::miniprotocols::handshake::Confirmation;
|
||||||
use crate::{
|
use crate::{
|
||||||
miniprotocols::{
|
miniprotocols::{
|
||||||
blockfetch, chainsync, handshake, localstate, PROTOCOL_N2C_CHAIN_SYNC,
|
blockfetch, chainsync, handshake, localstate, PROTOCOL_N2C_CHAIN_SYNC,
|
||||||
|
|
@ -11,7 +12,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
multiplexer::{self, Bearer},
|
multiplexer::{self, Bearer},
|
||||||
};
|
};
|
||||||
use crate::miniprotocols::handshake::Confirmation;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
|
@ -89,8 +89,7 @@ pub struct NodeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeClient {
|
impl NodeClient {
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
#[cfg(not(target_os = "windows"))]
|
|
||||||
pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
|
pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
|
||||||
debug!("connecting");
|
debug!("connecting");
|
||||||
|
|
||||||
|
|
@ -128,7 +127,10 @@ impl NodeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub async fn handshake_query(path: impl AsRef<Path>, magic: u64) -> Result<handshake::n2c::VersionTable, Error> {
|
pub async fn handshake_query(
|
||||||
|
path: impl AsRef<Path>,
|
||||||
|
magic: u64,
|
||||||
|
) -> Result<handshake::n2c::VersionTable, Error> {
|
||||||
debug!("connecting");
|
debug!("connecting");
|
||||||
|
|
||||||
let bearer = Bearer::connect_unix(path)
|
let bearer = Bearer::connect_unix(path)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::fmt::Debug;
|
|
||||||
use pallas_codec::Fragment;
|
use pallas_codec::Fragment;
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use pallas_codec::minicbor::{decode, Decode, Decoder, encode, Encode, Encoder};
|
|
||||||
use pallas_codec::minicbor::data::Type;
|
use pallas_codec::minicbor::data::Type;
|
||||||
|
use pallas_codec::minicbor::{decode, encode, Decode, Decoder, Encode, Encoder};
|
||||||
|
|
||||||
use super::protocol::NetworkMagic;
|
use super::protocol::NetworkMagic;
|
||||||
|
|
||||||
|
|
@ -72,11 +72,9 @@ impl VersionTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn v15_with_query(network_magic: u64) -> VersionTable {
|
pub fn v15_with_query(network_magic: u64) -> VersionTable {
|
||||||
let values = vec![
|
let values = vec![(PROTOCOL_V15, VersionData(network_magic, Some(true)))]
|
||||||
(PROTOCOL_V15, VersionData(network_magic, Some(true))),
|
.into_iter()
|
||||||
]
|
.collect::<HashMap<u64, VersionData>>();
|
||||||
.into_iter()
|
|
||||||
.collect::<HashMap<u64, VersionData>>();
|
|
||||||
|
|
||||||
VersionTable { values }
|
VersionTable { values }
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +90,9 @@ impl Encode<()> for VersionData {
|
||||||
_ctx: &mut (),
|
_ctx: &mut (),
|
||||||
) -> Result<(), encode::Error<W::Error>> {
|
) -> Result<(), encode::Error<W::Error>> {
|
||||||
match self.1 {
|
match self.1 {
|
||||||
None => { e.u64(self.0)?; }
|
None => {
|
||||||
|
e.u64(self.0)?;
|
||||||
|
}
|
||||||
Some(is_query) => {
|
Some(is_query) => {
|
||||||
e.array(2)?;
|
e.array(2)?;
|
||||||
e.u64(self.0)?;
|
e.u64(self.0)?;
|
||||||
|
|
@ -117,9 +117,7 @@ impl<'b> Decode<'b, ()> for VersionData {
|
||||||
let is_query = d.bool()?;
|
let is_query = d.bool()?;
|
||||||
Ok(Self(network_magic, Some(is_query)))
|
Ok(Self(network_magic, Some(is_query)))
|
||||||
}
|
}
|
||||||
_ => Err(decode::Error::message(
|
_ => Err(decode::Error::message("unknown type for VersionData")),
|
||||||
"unknown type for VersionData",
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,9 @@ where
|
||||||
T: Debug + Clone + Decode<'b, ()>,
|
T: Debug + Clone + Decode<'b, ()>,
|
||||||
{
|
{
|
||||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||||
let len = d.map()?.ok_or(decode::Error::message("expected def-length map for versiontable"))?;
|
let len = d.map()?.ok_or(decode::Error::message(
|
||||||
|
"expected def-length map for versiontable",
|
||||||
|
))?;
|
||||||
let mut values = HashMap::new();
|
let mut values = HashMap::new();
|
||||||
|
|
||||||
for _ in 0..len {
|
for _ in 0..len {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use tokio::sync::mpsc::error::SendError;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error, trace};
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
use tokio::net::UnixStream;
|
use tokio::net::UnixStream;
|
||||||
|
|
||||||
const HEADER_LEN: usize = 8;
|
const HEADER_LEN: usize = 8;
|
||||||
|
|
@ -62,7 +62,7 @@ pub struct Segment {
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub enum Bearer {
|
pub enum Bearer {
|
||||||
Tcp(TcpStream)
|
Tcp(TcpStream),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
|
@ -84,7 +84,7 @@ impl Bearer {
|
||||||
Ok((Self::Tcp(stream), addr))
|
Ok((Self::Tcp(stream), addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub async fn connect_unix(path: impl AsRef<Path>) -> Result<Self, tokio::io::Error> {
|
pub async fn connect_unix(path: impl AsRef<Path>) -> Result<Self, tokio::io::Error> {
|
||||||
let stream = UnixStream::connect(path).await?;
|
let stream = UnixStream::connect(path).await?;
|
||||||
Ok(Self::Unix(stream))
|
Ok(Self::Unix(stream))
|
||||||
|
|
@ -93,7 +93,7 @@ impl Bearer {
|
||||||
pub async fn readable(&self) -> tokio::io::Result<()> {
|
pub async fn readable(&self) -> tokio::io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Bearer::Tcp(x) => x.readable().await,
|
Bearer::Tcp(x) => x.readable().await,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
Bearer::Unix(x) => x.readable().await,
|
Bearer::Unix(x) => x.readable().await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +101,7 @@ impl Bearer {
|
||||||
fn try_read(&mut self, buf: &mut [u8]) -> tokio::io::Result<usize> {
|
fn try_read(&mut self, buf: &mut [u8]) -> tokio::io::Result<usize> {
|
||||||
match self {
|
match self {
|
||||||
Bearer::Tcp(x) => x.try_read(buf),
|
Bearer::Tcp(x) => x.try_read(buf),
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
Bearer::Unix(x) => x.try_read(buf),
|
Bearer::Unix(x) => x.try_read(buf),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ impl Bearer {
|
||||||
async fn write_all(&mut self, buf: &[u8]) -> tokio::io::Result<()> {
|
async fn write_all(&mut self, buf: &[u8]) -> tokio::io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Bearer::Tcp(x) => x.write_all(buf).await,
|
Bearer::Tcp(x) => x.write_all(buf).await,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
Bearer::Unix(x) => x.write_all(buf).await,
|
Bearer::Unix(x) => x.write_all(buf).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ impl Bearer {
|
||||||
async fn flush(&mut self) -> tokio::io::Result<()> {
|
async fn flush(&mut self) -> tokio::io::Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Bearer::Tcp(x) => x.flush().await,
|
Bearer::Tcp(x) => x.flush().await,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
Bearer::Unix(x) => x.flush().await,
|
Bearer::Unix(x) => x.flush().await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue