feat: Add constants for known miniprotocols

* Add constants for known miniprotocols

Now consumers of the crate don't have to memorize what channel number means what

* Add myself to the crate authors
This commit is contained in:
Pi Lanningham 2023-02-05 06:13:55 -05:00 committed by GitHub
parent d869169e68
commit f9263a0eba
13 changed files with 122 additions and 79 deletions

View file

@ -2,7 +2,7 @@ use pallas::network::{
miniprotocols::{
blockfetch,
handshake::{self, n2n::VersionTable},
Point, TESTNET_MAGIC,
Point, PROTOCOL_N2N_BLOCK_FETCH, PROTOCOL_N2N_HANDSHAKE, TESTNET_MAGIC,
},
multiplexer::{bearers::Bearer, StdPlexer},
};
@ -13,14 +13,14 @@ fn main() {
let bearer = Bearer::connect_tcp("relays-new.cardano-testnet.iohkdev.io:3001").unwrap();
let mut plexer = StdPlexer::new(bearer);
let channel0 = plexer.use_channel(0);
let channel3 = plexer.use_channel(3);
let handshake = plexer.use_channel(PROTOCOL_N2N_HANDSHAKE);
let blockfetch = plexer.use_channel(PROTOCOL_N2N_BLOCK_FETCH);
plexer.muxer.spawn();
plexer.demuxer.spawn();
let versions = VersionTable::v4_and_above(TESTNET_MAGIC);
let mut hs_client = handshake::N2NClient::new(channel0);
let mut hs_client = handshake::N2NClient::new(handshake);
let handshake = hs_client.handshake(versions).unwrap();
assert!(matches!(handshake, handshake::Confirmation::Accepted(..)));
@ -30,7 +30,7 @@ fn main() {
hex::decode("3f3d81c7b88f0fa28867541c5fea8794125cccf6d6c9ee0037a1dbb064130dfd").unwrap(),
);
let mut bf_client = blockfetch::Client::new(channel3);
let mut bf_client = blockfetch::Client::new(blockfetch);
let block = bf_client.fetch_single(point).unwrap();