mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
wip: migrate to libp2p 0.53.2
This commit is contained in:
parent
b18ba95e8c
commit
a56435aa8d
2344
Cargo.lock
generated
2344
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [ "monero-harness", "monero-rpc", "swap", "monero-wallet" ]
|
||||
members = [ "monero-harness", "monero-rpc", "swap", "monero-wallet", "watchtower" ]
|
||||
|
||||
[patch.crates-io]
|
||||
# patch until new release https://github.com/thomaseizinger/rust-jsonrpc-client/pull/51
|
||||
|
@ -34,9 +34,10 @@ hex = "0.4"
|
||||
itertools = "0.13"
|
||||
jsonrpsee = { version = "0.16.2", features = [ "server" ] }
|
||||
jsonrpsee-core = "0.16.2"
|
||||
libp2p = { version = "0.42.2", default-features = false, features = [ "tcp-tokio", "yamux", "mplex", "dns-tokio", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
|
||||
libp2p = { version = "0.53.2", default-features = false, features = [ "tcp", "yamux", "dns", "noise", "request-response", "websocket", "ping", "rendezvous", "identify" ] }
|
||||
monero = { version = "0.12", features = [ "serde_support" ] }
|
||||
monero-rpc = { path = "../monero-rpc" }
|
||||
watchtower = { path = "../watchtower" }
|
||||
pem = "3.0"
|
||||
proptest = "1"
|
||||
qrcode = "0.14"
|
||||
|
@ -12,7 +12,7 @@ use anyhow::{Context, Result};
|
||||
use futures::future;
|
||||
use futures::future::{BoxFuture, FutureExt};
|
||||
use futures::stream::{FuturesUnordered, StreamExt};
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::request_response::{InboundRequestId, OutboundRequestId, ResponseChannel};
|
||||
use libp2p::swarm::SwarmEvent;
|
||||
use libp2p::{PeerId, Swarm};
|
||||
use rust_decimal::Decimal;
|
||||
@ -62,7 +62,7 @@ where
|
||||
|
||||
/// Tracks [`transfer_proof::Request`]s which are currently inflight and
|
||||
/// awaiting an acknowledgement.
|
||||
inflight_transfer_proofs: HashMap<RequestId, bmrng::Responder<()>>,
|
||||
inflight_transfer_proofs: HashMap<OutboundRequestId, bmrng::Responder<()>>,
|
||||
}
|
||||
|
||||
impl<LR> EventLoop<LR>
|
||||
@ -334,10 +334,10 @@ where
|
||||
SwarmEvent::IncomingConnectionError { send_back_addr: address, error, .. } => {
|
||||
tracing::warn!(%address, "Failed to set up connection with peer: {:#}", error);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established: 0, endpoint, cause: Some(error) } => {
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established: 0, endpoint, cause: Some(error), connection_id } => {
|
||||
tracing::debug!(%peer, address = %endpoint.get_remote_address(), "Lost connection to peer: {:#}", error);
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established: 0, endpoint, cause: None } => {
|
||||
SwarmEvent::ConnectionClosed { peer_id: peer, num_established: 0, endpoint, cause: None, connection_id } => {
|
||||
tracing::info!(%peer, address = %endpoint.get_remote_address(), "Successfully closed connection");
|
||||
}
|
||||
SwarmEvent::NewListenAddr{address, ..} => {
|
||||
|
@ -11,32 +11,27 @@ use crate::network::{
|
||||
use crate::protocol::alice::State3;
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use futures::FutureExt;
|
||||
use libp2p::core::connection::ConnectionId;
|
||||
use libp2p::core::muxing::StreamMuxerBox;
|
||||
use libp2p::core::transport::Boxed;
|
||||
use libp2p::dns::TokioDnsConfig;
|
||||
use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent};
|
||||
use libp2p::ping::{Ping, PingConfig, PingEvent};
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::request_response::{ResponseChannel};
|
||||
use libp2p::swarm::dial_opts::PeerCondition;
|
||||
use libp2p::swarm::{
|
||||
IntoProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction, PollParameters,
|
||||
ProtocolsHandler,
|
||||
NetworkBehaviour
|
||||
};
|
||||
use libp2p::tcp::TokioTcpConfig;
|
||||
use libp2p::websocket::WsConfig;
|
||||
use libp2p::{identity, Multiaddr, NetworkBehaviour, PeerId, Transport};
|
||||
use libp2p::{Multiaddr, PeerId, Transport};
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub mod transport {
|
||||
use libp2p::{dns, identity, tcp, websocket::WsConfig};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Creates the libp2p transport for the ASB.
|
||||
pub fn new(identity: &identity::Keypair) -> Result<Boxed<(PeerId, StreamMuxerBox)>> {
|
||||
let tcp = TokioTcpConfig::new().nodelay(true);
|
||||
let tcp_with_dns = TokioDnsConfig::system(tcp)?;
|
||||
let tcp = tcp::Config::new().nodelay(true);
|
||||
let tcp_with_dns = dns::ResolverConfig::default::system(tcp)?;
|
||||
let websocket_with_dns = WsConfig::new(tcp_with_dns.clone());
|
||||
|
||||
let transport = tcp_with_dns.or_transport(websocket_with_dns).boxed();
|
||||
|
@ -10,17 +10,16 @@ use crate::protocol::bob::State2;
|
||||
use crate::{bitcoin, env};
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use libp2p::core::Multiaddr;
|
||||
use libp2p::identify::{Identify, IdentifyConfig, IdentifyEvent};
|
||||
use libp2p::ping::{Ping, PingConfig, PingEvent};
|
||||
use libp2p::request_response::{RequestId, ResponseChannel};
|
||||
use libp2p::{identity, NetworkBehaviour, PeerId};
|
||||
use libp2p::request_response::{ResponseChannel, InboundRequestId};
|
||||
use libp2p::swarm::{NetworkBehaviour};
|
||||
use libp2p::{identify, identity, ping, PeerId};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum OutEvent {
|
||||
QuoteReceived {
|
||||
id: RequestId,
|
||||
id: InboundRequestId,
|
||||
response: BidQuote,
|
||||
},
|
||||
SwapSetupCompleted(Box<Result<State2>>),
|
||||
@ -30,15 +29,15 @@ pub enum OutEvent {
|
||||
peer: PeerId,
|
||||
},
|
||||
EncryptedSignatureAcknowledged {
|
||||
id: RequestId,
|
||||
id: InboundRequestId,
|
||||
},
|
||||
CooperativeXmrRedeemFulfilled {
|
||||
id: RequestId,
|
||||
id: InboundRequestId,
|
||||
s_a: Scalar,
|
||||
swap_id: uuid::Uuid,
|
||||
},
|
||||
CooperativeXmrRedeemRejected {
|
||||
id: RequestId,
|
||||
id: InboundRequestId,
|
||||
reason: CooperativeXmrRedeemRejectReason,
|
||||
swap_id: uuid::Uuid,
|
||||
},
|
||||
@ -81,12 +80,12 @@ pub struct Behaviour {
|
||||
pub cooperative_xmr_redeem: cooperative_xmr_redeem_after_punish::Behaviour,
|
||||
pub encrypted_signature: encrypted_signature::Behaviour,
|
||||
pub redial: redial::Behaviour,
|
||||
pub identify: Identify,
|
||||
pub identify: identify::Behaviour,
|
||||
|
||||
/// Ping behaviour that ensures that the underlying network connection is
|
||||
/// still alive. If the ping fails a connection close event will be
|
||||
/// emitted that is picked up as swarm event.
|
||||
ping: Ping,
|
||||
ping: ping::Behaviour,
|
||||
}
|
||||
|
||||
impl Behaviour {
|
||||
@ -98,7 +97,7 @@ impl Behaviour {
|
||||
) -> Self {
|
||||
let agentVersion = format!("cli/{} ({})", env!("CARGO_PKG_VERSION"), identify_params.1);
|
||||
let protocolVersion = "/comit/xmr/btc/1.0.0".to_string();
|
||||
let identifyConfig = IdentifyConfig::new(protocolVersion, identify_params.0.public())
|
||||
let identifyConfig = identify::Config::new(protocolVersion, identify_params.0.public())
|
||||
.with_agent_version(agentVersion);
|
||||
|
||||
Self {
|
||||
@ -121,14 +120,14 @@ impl Behaviour {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PingEvent> for OutEvent {
|
||||
fn from(_: PingEvent) -> Self {
|
||||
impl From<ping::Event> for OutEvent {
|
||||
fn from(_: ping::Event) -> Self {
|
||||
OutEvent::Other
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IdentifyEvent> for OutEvent {
|
||||
fn from(_: IdentifyEvent) -> Self {
|
||||
impl From<identify::Event> for OutEvent {
|
||||
fn from(_: identify::Event) -> Self {
|
||||
OutEvent::Other
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::bitcoin::EncryptedSignature;
|
||||
use crate::cli::behaviour::{Behaviour, OutEvent};
|
||||
use libp2p::swarm::NetworkBehaviour;
|
||||
use crate::monero;
|
||||
use crate::network::cooperative_xmr_redeem_after_punish::{Request, Response};
|
||||
use crate::network::encrypted_signature;
|
||||
@ -202,10 +203,10 @@ impl EventLoop {
|
||||
SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } if peer_id == self.alice_peer_id => {
|
||||
tracing::info!(peer_id = %endpoint.get_remote_address(), "Connected to Alice");
|
||||
}
|
||||
SwarmEvent::Dialing(peer_id) if peer_id == self.alice_peer_id => {
|
||||
tracing::debug!(%peer_id, "Dialling Alice");
|
||||
SwarmEvent::Dialing { peer_id: Some(alice_peer_id), connection_id } if alice_peer_id == self.alice_peer_id => {
|
||||
tracing::debug!(%alice_peer_id, "Dialling Alice");
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id, endpoint, num_established, cause: Some(error) } if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
SwarmEvent::ConnectionClosed { peer_id, endpoint, num_established, cause: Some(error), connection_id } if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
tracing::warn!(peer_id = %endpoint.get_remote_address(), cause = %error, "Lost connection to Alice");
|
||||
}
|
||||
SwarmEvent::ConnectionClosed { peer_id, num_established, cause: None, .. } if peer_id == self.alice_peer_id && num_established == 0 => {
|
||||
@ -213,7 +214,7 @@ impl EventLoop {
|
||||
tracing::info!("Successfully closed connection to Alice");
|
||||
return;
|
||||
}
|
||||
SwarmEvent::OutgoingConnectionError { peer_id: Some(alice_peer_id), error } if alice_peer_id == self.alice_peer_id => {
|
||||
SwarmEvent::OutgoingConnectionError { peer_id: Some(alice_peer_id), error, connection_id } if alice_peer_id == self.alice_peer_id => {
|
||||
tracing::warn!(%error, "Failed to dial Alice");
|
||||
|
||||
if let Some(duration) = self.swarm.behaviour_mut().redial.until_next_redial() {
|
||||
|
@ -5,7 +5,6 @@ use libp2p::core::multiaddr::{Multiaddr, Protocol};
|
||||
use libp2p::core::transport::TransportError;
|
||||
use libp2p::core::Transport;
|
||||
use libp2p::tcp::tokio::{Tcp, TcpStream};
|
||||
use libp2p::tcp::TcpListenStream;
|
||||
use std::borrow::Cow;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use std::{fmt, io};
|
||||
@ -34,7 +33,7 @@ impl Transport for TorDialOnlyTransport {
|
||||
Err(TransportError::MultiaddrNotSupported(addr))
|
||||
}
|
||||
|
||||
fn dial(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
fn dial(&mut self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
let address = TorCompatibleAddress::from_multiaddr(Cow::Borrowed(&addr))?;
|
||||
|
||||
if address.is_certainly_not_reachable_via_tor_daemon() {
|
||||
@ -60,7 +59,7 @@ impl Transport for TorDialOnlyTransport {
|
||||
fn address_translation(&self, _: &Multiaddr, _: &Multiaddr) -> Option<Multiaddr> {
|
||||
None
|
||||
}
|
||||
fn dial_as_listener(self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
fn dial_as_listener(&mut self, addr: Multiaddr) -> Result<Self::Dial, TransportError<Self::Error>> {
|
||||
let address = TorCompatibleAddress::from_multiaddr(Cow::Borrowed(&addr))?;
|
||||
|
||||
if address.is_certainly_not_reachable_via_tor_daemon() {
|
||||
|
1
watchtower
Submodule
1
watchtower
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 825166e948ceccc9e6378a5d34fb29b062301327
|
Loading…
Reference in New Issue
Block a user