mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-20 20:18:18 -04:00
Use rendezvous branch of libp2p
This commit is contained in:
parent
00b015f0fb
commit
d4f9acc1b1
4 changed files with 139 additions and 73 deletions
156
Cargo.lock
generated
156
Cargo.lock
generated
|
@ -1414,13 +1414,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hmac-drbg"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6e570451493f10f6581b48cdd530413b63ea9e780f544bfd3bdcaa0d89d1a7b"
|
||||
checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1"
|
||||
dependencies = [
|
||||
"digest 0.8.1",
|
||||
"generic-array 0.12.4",
|
||||
"hmac 0.7.1",
|
||||
"digest 0.9.0",
|
||||
"generic-array 0.14.4",
|
||||
"hmac 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1770,9 +1770,8 @@ checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
|
|||
|
||||
[[package]]
|
||||
name = "libp2p"
|
||||
version = "0.38.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebbb17eece4aec5bb970880c73825c16ca59ca05a4e41803751e68c7e5f0c618"
|
||||
version = "0.39.0"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"atomic",
|
||||
"bytes 1.0.1",
|
||||
|
@ -1780,16 +1779,18 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"libp2p-core",
|
||||
"libp2p-dns",
|
||||
"libp2p-identify",
|
||||
"libp2p-mplex",
|
||||
"libp2p-noise",
|
||||
"libp2p-ping",
|
||||
"libp2p-rendezvous",
|
||||
"libp2p-request-response",
|
||||
"libp2p-swarm",
|
||||
"libp2p-swarm-derive",
|
||||
"libp2p-tcp",
|
||||
"libp2p-websocket",
|
||||
"libp2p-yamux",
|
||||
"parity-multiaddr",
|
||||
"multiaddr",
|
||||
"parking_lot 0.11.1",
|
||||
"pin-project 1.0.5",
|
||||
"smallvec",
|
||||
|
@ -1798,9 +1799,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libp2p-core"
|
||||
version = "0.28.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "554d3e7e9e65f939d66b75fd6a4c67f258fe250da61b91f46c545fc4a89b51d9"
|
||||
version = "0.29.0"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"asn1_der",
|
||||
"bs58",
|
||||
|
@ -1812,9 +1812,9 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"log 0.4.14",
|
||||
"multiaddr",
|
||||
"multihash",
|
||||
"multistream-select",
|
||||
"parity-multiaddr",
|
||||
"parking_lot 0.11.1",
|
||||
"pin-project 1.0.5",
|
||||
"prost",
|
||||
|
@ -1843,6 +1843,21 @@ dependencies = [
|
|||
"trust-dns-resolver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-identify"
|
||||
version = "0.30.0"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"libp2p-core",
|
||||
"libp2p-swarm",
|
||||
"log 0.4.14",
|
||||
"prost",
|
||||
"prost-build",
|
||||
"smallvec",
|
||||
"wasm-timer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-mplex"
|
||||
version = "0.28.0"
|
||||
|
@ -1898,6 +1913,28 @@ dependencies = [
|
|||
"wasm-timer",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-rendezvous"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"asynchronous-codec",
|
||||
"bimap",
|
||||
"futures",
|
||||
"libp2p-core",
|
||||
"libp2p-swarm",
|
||||
"log 0.4.14",
|
||||
"prost",
|
||||
"prost-build",
|
||||
"rand 0.8.3",
|
||||
"sha2 0.9.5",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"unsigned-varint 0.7.0",
|
||||
"uuid",
|
||||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libp2p-request-response"
|
||||
version = "0.11.0"
|
||||
|
@ -1920,9 +1957,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libp2p-swarm"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e04d8e1eef675029ec728ba14e8d0da7975d84b6679b699b4ae91a1de9c3a92"
|
||||
version = "0.30.0"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"either",
|
||||
"futures",
|
||||
|
@ -1937,8 +1973,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "libp2p-swarm-derive"
|
||||
version = "0.23.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "365b0a699fea5168676840567582a012ea297b1ca02eee467e58301b9c9c5eed"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"quote 1.0.9",
|
||||
"syn 1.0.64",
|
||||
|
@ -1994,20 +2029,52 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libsecp256k1"
|
||||
version = "0.3.5"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fc1e2c808481a63dc6da2074752fdd4336a3c8fcc68b83db6f1fd5224ae7962"
|
||||
checksum = "bd1137239ab33b41aa9637a88a28249e5e70c40a42ccc92db7f12cc356c1fcd7"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"crunchy",
|
||||
"digest 0.8.1",
|
||||
"base64 0.12.3",
|
||||
"digest 0.9.0",
|
||||
"hmac-drbg",
|
||||
"libsecp256k1-core",
|
||||
"libsecp256k1-gen-ecmult",
|
||||
"libsecp256k1-gen-genmult",
|
||||
"rand 0.7.3",
|
||||
"sha2 0.8.2",
|
||||
"subtle 2.4.0",
|
||||
"serde",
|
||||
"sha2 0.9.5",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-core"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ee11012b293ea30093c129173cac4335513064094619f4639a25b310fd33c11"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
"digest 0.9.0",
|
||||
"subtle 2.4.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-ecmult"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32239626ffbb6a095b83b37a02ceb3672b2443a87a000a884fc3c4d16925c9c0"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-genmult"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76acb433e21d10f5f9892b1962c2856c58c7f39a9e4bd68ac82b9436a0ffd5b9"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libz-sys"
|
||||
version = "1.1.2"
|
||||
|
@ -2282,6 +2349,24 @@ dependencies = [
|
|||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multiaddr"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7139982f583d7e53879d9f611fe48ced18e77d684309484f2252c76bcd39f549"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"bs58",
|
||||
"byteorder",
|
||||
"data-encoding",
|
||||
"multihash",
|
||||
"percent-encoding 2.1.0",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"unsigned-varint 0.7.0",
|
||||
"url 2.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multihash"
|
||||
version = "0.13.2"
|
||||
|
@ -2317,9 +2402,8 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
|
|||
|
||||
[[package]]
|
||||
name = "multistream-select"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d91ec0a2440aaff5f78ec35631a7027d50386c6163aa975f7caa0d5da4b6ff8"
|
||||
version = "0.10.3"
|
||||
source = "git+https://github.com/comit-network/rust-libp2p.git?rev=96002105b0a7019330413826a332b3a12a7e8a57#96002105b0a7019330413826a332b3a12a7e8a57"
|
||||
dependencies = [
|
||||
"bytes 1.0.1",
|
||||
"futures",
|
||||
|
@ -2472,24 +2556,6 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||
|
||||
[[package]]
|
||||
name = "parity-multiaddr"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58341485071825827b7f03cf7efd1cb21e6a709bea778fb50227fd45d2f361b4"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"bs58",
|
||||
"byteorder",
|
||||
"data-encoding",
|
||||
"multihash",
|
||||
"percent-encoding 2.1.0",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"unsigned-varint 0.7.0",
|
||||
"url 2.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.10.2"
|
||||
|
|
|
@ -29,8 +29,8 @@ ecdsa_fun = { git = "https://github.com/LLFourn/secp256kfun", default-features =
|
|||
ed25519-dalek = "1"
|
||||
futures = { version = "0.3", default-features = false }
|
||||
itertools = "0.10"
|
||||
libp2p = { version = "0.38", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping" ] }
|
||||
miniscript = { version = "5", features = [ "serde" ] }
|
||||
libp2p = { git = "https://github.com/comit-network/rust-libp2p.git", rev = "96002105b0a7019330413826a332b3a12a7e8a57", default-features = false, features = ["rendezvous", "request-response", "websocket", "ping", "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "identify"] }
|
||||
miniscript = { version = "5", features = ["serde"] }
|
||||
monero = { version = "0.12", features = [ "serde_support" ] }
|
||||
monero-rpc = { path = "../monero-rpc" }
|
||||
pem = "0.8"
|
||||
|
|
|
@ -148,9 +148,9 @@ where
|
|||
|
||||
loop {
|
||||
tokio::select! {
|
||||
swarm_event = self.swarm.next_event() => {
|
||||
swarm_event = self.swarm.next() => {
|
||||
match swarm_event {
|
||||
SwarmEvent::Behaviour(OutEvent::SwapSetupInitiated { mut send_wallet_snapshot }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::SwapSetupInitiated { mut send_wallet_snapshot })) => {
|
||||
|
||||
let (btc, responder) = send_wallet_snapshot.recv().await.expect("TODO: handle error");
|
||||
|
||||
|
@ -165,13 +165,13 @@ where
|
|||
// Ignore result, we should never hit this because the receiver will alive as long as the connection is.
|
||||
let _ = responder.respond(wallet_snapshot);
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::SwapSetupCompleted{peer_id, swap_id, state3}) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::SwapSetupCompleted{peer_id, swap_id, state3})) => {
|
||||
let _ = self.handle_execution_setup_done(peer_id, swap_id, *state3).await;
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::SwapDeclined { peer, error }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::SwapDeclined { peer, error })) => {
|
||||
tracing::warn!(%peer, "Ignoring spot price request because: {}", error);
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::QuoteRequested { channel, peer }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::QuoteRequested { channel, peer })) => {
|
||||
let quote = match self.make_quote(self.min_buy, self.max_buy).await {
|
||||
Ok(quote) => quote,
|
||||
Err(error) => {
|
||||
|
@ -184,13 +184,13 @@ where
|
|||
tracing::debug!(%peer, "Failed to respond with quote");
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::TransferProofAcknowledged { peer, id }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::TransferProofAcknowledged { peer, id })) => {
|
||||
tracing::debug!(%peer, "Bob acknowledged transfer proof");
|
||||
if let Some(responder) = self.inflight_transfer_proofs.remove(&id) {
|
||||
let _ = responder.respond(());
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::EncryptedSignatureReceived{ msg, channel, peer }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::EncryptedSignatureReceived{ msg, channel, peer })) => {
|
||||
let swap_id = msg.swap_id;
|
||||
let swap_peer = self.db.get_peer_id(swap_id);
|
||||
|
||||
|
@ -239,12 +239,12 @@ where
|
|||
channel
|
||||
}.boxed());
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::Failure {peer, error}) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::Failure {peer, error})) => {
|
||||
tracing::error!(
|
||||
%peer,
|
||||
"Communication error. Error {:#}", error);
|
||||
}
|
||||
SwarmEvent::ConnectionEstablished { peer_id: peer, endpoint, .. } => {
|
||||
Some(SwarmEvent::ConnectionEstablished { peer_id: peer, endpoint, .. }) => {
|
||||
tracing::debug!(%peer, address = %endpoint.get_remote_address(), "New connection established");
|
||||
|
||||
if let Some(transfer_proofs) = self.buffered_transfer_proofs.remove(&peer) {
|
||||
|
@ -256,16 +256,16 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
SwarmEvent::IncomingConnectionError { send_back_addr: address, error, .. } => {
|
||||
Some(SwarmEvent::IncomingConnectionError { send_back_addr: address, error, .. }) => {
|
||||
tracing::warn!(%address, "Failed to set up connection with peer. Error {:#}", error);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established, endpoint, cause: Some(error) } if num_established == 0 => {
|
||||
Some(SwarmEvent::ConnectionClosed { peer_id: peer, num_established, endpoint, cause: Some(error) }) if num_established == 0 => {
|
||||
tracing::warn!(%peer, address = %endpoint.get_remote_address(), "Lost connection. Error {:#}", error);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established, endpoint, cause: None } if num_established == 0 => {
|
||||
Some(SwarmEvent::ConnectionClosed { peer_id: peer, num_established, endpoint, cause: None }) if num_established == 0 => {
|
||||
tracing::info!(%peer, address = %endpoint.get_remote_address(), "Successfully closed connection");
|
||||
}
|
||||
SwarmEvent::NewListenAddr(address) => {
|
||||
Some(SwarmEvent::NewListenAddr(address)) => {
|
||||
tracing::info!(%address, "New listen address detected");
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -93,19 +93,19 @@ impl EventLoop {
|
|||
loop {
|
||||
// Note: We are making very elaborate use of `select!` macro's feature here. Make sure to read the documentation thoroughly: https://docs.rs/tokio/1.4.0/tokio/macro.select.html
|
||||
tokio::select! {
|
||||
swarm_event = self.swarm.next_event().fuse() => {
|
||||
match swarm_event {
|
||||
SwarmEvent::Behaviour(OutEvent::QuoteReceived { id, response }) => {
|
||||
swarm_event = self.swarm.next().fuse() => {
|
||||
match swarm_event{
|
||||
Some(SwarmEvent::Behaviour(OutEvent::QuoteReceived { id, response })) => {
|
||||
if let Some(responder) = self.inflight_quote_requests.remove(&id) {
|
||||
let _ = responder.respond(response);
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::SwapSetupCompleted(response)) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::SwapSetupCompleted(response))) => {
|
||||
if let Some(responder) = self.inflight_swap_setup.take() {
|
||||
let _ = responder.respond(*response);
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::TransferProofReceived { msg, channel, peer }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::TransferProofReceived { msg, channel, peer })) => {
|
||||
let swap_id = msg.swap_id;
|
||||
|
||||
if peer != self.alice_peer_id {
|
||||
|
@ -141,34 +141,34 @@ impl EventLoop {
|
|||
channel
|
||||
}.boxed()));
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::EncryptedSignatureAcknowledged { id }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::EncryptedSignatureAcknowledged { id })) => {
|
||||
if let Some(responder) = self.inflight_encrypted_signature_requests.remove(&id) {
|
||||
let _ = responder.respond(());
|
||||
}
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::AllRedialAttemptsExhausted { peer }) if peer == self.alice_peer_id => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::AllRedialAttemptsExhausted { peer })) if peer == self.alice_peer_id => {
|
||||
tracing::error!("Exhausted all re-dial attempts to Alice");
|
||||
return;
|
||||
}
|
||||
SwarmEvent::Behaviour(OutEvent::Failure { peer, error }) => {
|
||||
Some(SwarmEvent::Behaviour(OutEvent::Failure { peer, error })) => {
|
||||
tracing::warn!(%peer, "Communication error: {:#}", error);
|
||||
return;
|
||||
}
|
||||
SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } if peer_id == self.alice_peer_id => {
|
||||
Some(SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. }) if peer_id == self.alice_peer_id => {
|
||||
tracing::info!("Connected to Alice at {}", endpoint.get_remote_address());
|
||||
}
|
||||
SwarmEvent::Dialing(peer_id) if peer_id == self.alice_peer_id => {
|
||||
Some(SwarmEvent::Dialing(peer_id)) if peer_id == self.alice_peer_id => {
|
||||
tracing::debug!("Dialling Alice at {}", peer_id);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id, endpoint, num_established, cause: Some(error) } if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
Some(SwarmEvent::ConnectionClosed { peer_id, endpoint, num_established, cause: Some(error) }) if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
tracing::warn!("Lost connection to Alice at {}, cause: {}", endpoint.get_remote_address(), error);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id, num_established, cause: None, .. } if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
Some(SwarmEvent::ConnectionClosed { peer_id, num_established, cause: None, .. }) if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
// no error means the disconnection was requested
|
||||
tracing::info!("Successfully closed connection to Alice");
|
||||
return;
|
||||
}
|
||||
SwarmEvent::UnreachableAddr { peer_id, address, attempts_remaining, error } if peer_id == self.alice_peer_id && attempts_remaining == 0 => {
|
||||
Some(SwarmEvent::UnreachableAddr { peer_id, address, attempts_remaining, error }) if peer_id == self.alice_peer_id && attempts_remaining == 0 => {
|
||||
tracing::warn!(%address, "Failed to dial Alice: {}", error);
|
||||
|
||||
if let Some(duration) = self.swarm.behaviour_mut().redial.until_next_redial() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue