Skip to content

Commit

Permalink
feat: Add Vasil / Babbage compatibility (#126)
Browse files Browse the repository at this point in the history
* feat: Bump n2n protocol versions for Babbage (#125)
* feat: Allow a specified timeout on tcp connection (#127)
* feat: Add Babbage primitives (#128)
* fix: Inaccurate header-body CDDL (#129)
* fix: Babbage CBOR codec issues (#130)
* feat: Include Babbage in traverse lib
* Parse Babbage headers (#131)
* Add Babbage nonce/leader vrf extension (#132)

Co-authored-by: Andrew Westberg <andrewwestberg@gmail.com>
  • Loading branch information
scarmuega and AndrewWestberg authored Jun 21, 2022
1 parent 879d702 commit f67d36e
Show file tree
Hide file tree
Showing 22 changed files with 1,831 additions and 95 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Cargo.lock

scratchpad
.DS_Store
RELEASE.md
RELEASE.md
.idea
2 changes: 1 addition & 1 deletion pallas-codec/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
}

/// Wraps a struct so that it is encoded/decoded as a cbor bytes
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct CborWrap<T>(pub T);

impl<'b, C, T> minicbor::Decode<'b, C> for CborWrap<T>
Expand Down
22 changes: 22 additions & 0 deletions pallas-miniprotocols/src/handshake/n2n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const PROTOCOL_V4: u64 = 4;
const PROTOCOL_V5: u64 = 5;
const PROTOCOL_V6: u64 = 6;
const PROTOCOL_V7: u64 = 7;
const PROTOCOL_V8: u64 = 8;
const PROTOCOL_V9: u64 = 9;
const PROTOCOL_V10: u64 = 10;

impl VersionTable {
pub fn v4_and_above(network_magic: u64) -> VersionTable {
Expand All @@ -16,6 +19,9 @@ impl VersionTable {
(PROTOCOL_V5, VersionData::new(network_magic, false)),
(PROTOCOL_V6, VersionData::new(network_magic, false)),
(PROTOCOL_V7, VersionData::new(network_magic, false)),
(PROTOCOL_V8, VersionData::new(network_magic, false)),
(PROTOCOL_V9, VersionData::new(network_magic, false)),
(PROTOCOL_V10, VersionData::new(network_magic, false)),
]
.into_iter()
.collect::<HashMap<u64, VersionData>>();
Expand All @@ -27,6 +33,22 @@ impl VersionTable {
let values = vec![
(PROTOCOL_V6, VersionData::new(network_magic, false)),
(PROTOCOL_V7, VersionData::new(network_magic, false)),
(PROTOCOL_V8, VersionData::new(network_magic, false)),
(PROTOCOL_V9, VersionData::new(network_magic, false)),
(PROTOCOL_V10, VersionData::new(network_magic, false)),
]
.into_iter()
.collect::<HashMap<u64, VersionData>>();

VersionTable { values }
}

pub fn v7_and_above(network_magic: u64) -> VersionTable {
let values = vec![
(PROTOCOL_V7, VersionData::new(network_magic, false)),
(PROTOCOL_V8, VersionData::new(network_magic, false)),
(PROTOCOL_V9, VersionData::new(network_magic, false)),
(PROTOCOL_V10, VersionData::new(network_magic, false)),
]
.into_iter()
.collect::<HashMap<u64, VersionData>>();
Expand Down
13 changes: 12 additions & 1 deletion pallas-multiplexer/src/bearers.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use byteorder::{ByteOrder, NetworkEndian, WriteBytesExt};
use log::{debug, log_enabled, trace};
use std::io::{Read, Write};
use std::net::{TcpListener, ToSocketAddrs};
use std::net::{SocketAddr, TcpListener, ToSocketAddrs};
use std::{net::TcpStream, time::Instant};

use crate::Payload;

#[cfg(target_family = "unix")]
use std::os::unix::net::UnixStream;
use std::time::Duration;

pub struct Segment {
pub protocol: u16,
Expand Down Expand Up @@ -110,6 +111,16 @@ impl Bearer {
Ok(Bearer::Tcp(bearer))
}

pub fn connect_tcp_timeout(
addr: &SocketAddr,
timeout: Duration,
) -> Result<Self, std::io::Error> {
let bearer = TcpStream::connect_timeout(addr, timeout)?;
bearer.set_nodelay(true)?;

Ok(Bearer::Tcp(bearer))
}

pub fn accept_tcp(server: TcpListener) -> Result<Self, std::io::Error> {
let (bearer, _) = server.accept().unwrap();
bearer.set_nodelay(true)?;
Expand Down
Loading

0 comments on commit f67d36e

Please sign in to comment.