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 f795948d2f
commit 4915d14cd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();

View file

@ -1,5 +1,8 @@
use pallas::network::{
miniprotocols::{chainsync, handshake, localstate, Point, MAINNET_MAGIC},
miniprotocols::{
chainsync, handshake, localstate, Point, MAINNET_MAGIC, PROTOCOL_N2C_CHAIN_SYNC,
PROTOCOL_N2C_HANDSHAKE, PROTOCOL_N2C_STATE_QUERY,
},
multiplexer::{self, bearers::Bearer},
};
@ -75,19 +78,19 @@ fn main() {
// setup the multiplexer by specifying the bearer and the IDs of the
// miniprotocols to use
let mut plexer = multiplexer::StdPlexer::new(bearer);
let channel0 = plexer.use_channel(0);
let channel7 = plexer.use_channel(7);
let channel5 = plexer.use_channel(5);
let handshake = plexer.use_channel(PROTOCOL_N2C_HANDSHAKE);
let statequery = plexer.use_channel(PROTOCOL_N2C_STATE_QUERY);
let chainsync = plexer.use_channel(PROTOCOL_N2C_CHAIN_SYNC);
plexer.muxer.spawn();
plexer.demuxer.spawn();
// execute the required handshake against the relay
do_handshake(channel0);
do_handshake(handshake);
// execute an arbitrary "Local State" query against the node
do_localstate_query(channel7);
do_localstate_query(statequery);
// execute the chainsync flow from an arbitrary point in the chain
do_chainsync(channel5);
do_chainsync(chainsync);
}

View file

@ -1,5 +1,8 @@
use pallas::network::{
miniprotocols::{blockfetch, chainsync, handshake, Point, MAINNET_MAGIC},
miniprotocols::{
blockfetch, chainsync, handshake, Point, MAINNET_MAGIC, PROTOCOL_N2N_BLOCK_FETCH,
PROTOCOL_N2N_CHAIN_SYNC, PROTOCOL_N2N_HANDSHAKE,
},
multiplexer::{bearers::Bearer, StdChannel, StdPlexer},
};
@ -83,19 +86,19 @@ fn main() {
// setup the multiplexer by specifying the bearer and the IDs of the
// miniprotocols to use
let mut plexer = StdPlexer::new(bearer);
let channel0 = plexer.use_channel(0);
let channel3 = plexer.use_channel(3);
let channel2 = plexer.use_channel(2);
let handshake = plexer.use_channel(PROTOCOL_N2N_HANDSHAKE);
let blockfetch = plexer.use_channel(PROTOCOL_N2N_BLOCK_FETCH);
let chainsync = plexer.use_channel(PROTOCOL_N2N_CHAIN_SYNC);
plexer.muxer.spawn();
plexer.demuxer.spawn();
// execute the required handshake against the relay
do_handshake(channel0);
do_handshake(handshake);
// fetch an arbitrary batch of block
do_blockfetch(channel3);
do_blockfetch(blockfetch);
// execute the chainsync flow from an arbitrary point in the chain
do_chainsync(channel2);
do_chainsync(chainsync);
}