Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHIA-878: New peer implementation #611

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ zstd = "0.13.2"
blocking-threadpool = "1.0.1"
libfuzzer-sys = "0.4"
wasm-bindgen = "0.2.92"
log = "0.4.22"
native-tls = "0.2.12"
env_logger = "0.11.3"
15 changes: 13 additions & 2 deletions crates/chia-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ workspace = true
[dependencies]
chia-protocol = { workspace = true }
chia-traits = { workspace = true }
tokio = { workspace = true, features = ["rt", "sync"] }
tokio-tungstenite = { workspace = true }
tokio = { workspace = true, features = ["rt", "sync", "time"] }
tokio-tungstenite = { workspace = true, features = ["native-tls"] }
futures-util = { workspace = true }
tungstenite = { workspace = true }
thiserror = { workspace = true }
sha2 = { workspace = true }
log = { workspace = true }
native-tls = { workspace = true }
hex-literal = { workspace = true }
hex = { workspace = true }

[dev-dependencies]
chia-ssl = { path = "../chia-ssl" }
tokio = { workspace = true, features = ["full"] }
anyhow = { workspace = true }
env_logger = { workspace = true }
41 changes: 41 additions & 0 deletions crates/chia-client/examples/peer_connection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::{env, net::SocketAddr};

use chia_client::{create_tls_connector, Peer};
use chia_protocol::{Handshake, NodeType};
use chia_ssl::ChiaCertificate;
use chia_traits::Streamable;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let ssl = ChiaCertificate::generate()?;
let tls_connector = create_tls_connector(ssl.cert_pem.as_bytes(), ssl.key_pem.as_bytes())?;
let (peer, mut receiver) = Peer::connect(
SocketAddr::new(env::var("PEER")?.parse()?, 58444),
tls_connector,
)
.await?;

peer.send(Handshake {
network_id: "testnet11".to_string(),
protocol_version: "0.0.34".to_string(),
software_version: "0.0.0".to_string(),
server_port: 0,
node_type: NodeType::Wallet,
capabilities: vec![
(1, "1".to_string()),
(2, "1".to_string()),
(3, "1".to_string()),
],
})
.await?;

let message = receiver.recv().await.unwrap();
let handshake = Handshake::from_bytes(&message.data)?;
println!("{handshake:#?}");

while let Some(message) = receiver.recv().await {
println!("{message:?}");
}

Ok(())
}
Loading
Loading