mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-11-17 00:07:55 +00:00
630faed263
* ci: install boost, include macos + windows * cryptonight: fix `MSVC` * cryptonight: use `flag_if_supported()` * fix cryptonight builds * update randomX * fix rx builds * add memwipe * include memwipe.c in build * spawn monerod in msys2 for windows * fix last commit * install dependencies before spawning monerod * remove --detach * try another way of spawning monerod * add /I * download and spawn monerod as a part of tests * add download.rs * extend time for monerod spawn * move sleep and show monerod output * fix clippy * change stdin to pipped * #[cfg(unix)] on bytes::Buf * fix macos capitalisation * remove tar.bz2 on macos expected dir * remove zip on windows expected dir * fix todo * add docs * fix a couple typos --------- Co-authored-by: Boog900 <54e72d8a-345f-4599-bd90-c6b9bc7d0ec5@aleeas.com> Co-authored-by: Boog900 <boog900@tutanota.com>
149 lines
4.2 KiB
Rust
149 lines
4.2 KiB
Rust
use std::sync::Arc;
|
|
|
|
use futures::{channel::mpsc, StreamExt};
|
|
use tokio::sync::{broadcast, Semaphore};
|
|
use tower::{Service, ServiceExt};
|
|
|
|
use cuprate_helper::network::Network;
|
|
use monero_wire::{common::PeerSupportFlags, BasicNodeData};
|
|
|
|
use monero_p2p::{
|
|
client::{ConnectRequest, Connector, DoHandshakeRequest, HandShaker},
|
|
network_zones::ClearNet,
|
|
ConnectionDirection,
|
|
};
|
|
|
|
use cuprate_test_utils::{
|
|
monerod::monerod,
|
|
test_netzone::{TestNetZone, TestNetZoneAddr},
|
|
};
|
|
use monero_p2p::client::InternalPeerID;
|
|
|
|
mod utils;
|
|
use utils::*;
|
|
|
|
#[tokio::test]
|
|
async fn handshake_cuprate_to_cuprate() {
|
|
// Tests a Cuprate <-> Cuprate handshake by making 2 handshake services and making them talk to
|
|
// each other.
|
|
|
|
let (broadcast_tx, _) = broadcast::channel(1); // this isn't actually used in this test.
|
|
let semaphore = Arc::new(Semaphore::new(10));
|
|
let permit_1 = semaphore.clone().acquire_owned().await.unwrap();
|
|
let permit_2 = semaphore.acquire_owned().await.unwrap();
|
|
|
|
let our_basic_node_data_1 = BasicNodeData {
|
|
my_port: 0,
|
|
network_id: Network::Mainnet.network_id().into(),
|
|
peer_id: 87980,
|
|
// TODO: This fails if the support flags are empty (0)
|
|
support_flags: PeerSupportFlags::from(1_u32),
|
|
rpc_port: 0,
|
|
rpc_credits_per_hash: 0,
|
|
};
|
|
// make sure both node IDs are different
|
|
let mut our_basic_node_data_2 = our_basic_node_data_1.clone();
|
|
our_basic_node_data_2.peer_id = 2344;
|
|
|
|
let mut handshaker_1 = HandShaker::<TestNetZone<true, true, true>, _, _, _>::new(
|
|
DummyAddressBook,
|
|
DummyCoreSyncSvc,
|
|
DummyPeerRequestHandlerSvc,
|
|
broadcast_tx.clone(),
|
|
our_basic_node_data_1,
|
|
);
|
|
|
|
let mut handshaker_2 = HandShaker::<TestNetZone<true, true, true>, _, _, _>::new(
|
|
DummyAddressBook,
|
|
DummyCoreSyncSvc,
|
|
DummyPeerRequestHandlerSvc,
|
|
broadcast_tx.clone(),
|
|
our_basic_node_data_2,
|
|
);
|
|
|
|
let (p1_sender, p2_receiver) = mpsc::channel(5);
|
|
let (p2_sender, p1_receiver) = mpsc::channel(5);
|
|
|
|
let p1_handshake_req = DoHandshakeRequest {
|
|
addr: InternalPeerID::KnownAddr(TestNetZoneAddr(888)),
|
|
peer_stream: p2_receiver.map(Ok).boxed(),
|
|
peer_sink: p2_sender.into(),
|
|
direction: ConnectionDirection::OutBound,
|
|
permit: permit_1,
|
|
};
|
|
|
|
let p2_handshake_req = DoHandshakeRequest {
|
|
addr: InternalPeerID::KnownAddr(TestNetZoneAddr(444)),
|
|
peer_stream: p1_receiver.boxed().map(Ok).boxed(),
|
|
peer_sink: p1_sender.into(),
|
|
direction: ConnectionDirection::InBound,
|
|
permit: permit_2,
|
|
};
|
|
|
|
let p1 = tokio::spawn(async move {
|
|
handshaker_1
|
|
.ready()
|
|
.await
|
|
.unwrap()
|
|
.call(p1_handshake_req)
|
|
.await
|
|
.unwrap()
|
|
});
|
|
|
|
let p2 = tokio::spawn(async move {
|
|
handshaker_2
|
|
.ready()
|
|
.await
|
|
.unwrap()
|
|
.call(p2_handshake_req)
|
|
.await
|
|
.unwrap()
|
|
});
|
|
|
|
let (res1, res2) = futures::join!(p1, p2);
|
|
res1.unwrap();
|
|
res2.unwrap();
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn handshake_cuprate_to_monerod() {
|
|
let (broadcast_tx, _) = broadcast::channel(1); // this isn't actually used in this test.
|
|
let semaphore = Arc::new(Semaphore::new(10));
|
|
let permit = semaphore.acquire_owned().await.unwrap();
|
|
|
|
let (monerod, _) = monerod(
|
|
vec!["--fixed-difficulty=1".into(), "--out-peers=0".into()],
|
|
false,
|
|
)
|
|
.await;
|
|
|
|
let our_basic_node_data = BasicNodeData {
|
|
my_port: 0,
|
|
network_id: Network::Mainnet.network_id().into(),
|
|
peer_id: 87980,
|
|
support_flags: PeerSupportFlags::from(1_u32),
|
|
rpc_port: 0,
|
|
rpc_credits_per_hash: 0,
|
|
};
|
|
|
|
let handshaker = HandShaker::<ClearNet, _, _, _>::new(
|
|
DummyAddressBook,
|
|
DummyCoreSyncSvc,
|
|
DummyPeerRequestHandlerSvc,
|
|
broadcast_tx,
|
|
our_basic_node_data,
|
|
);
|
|
|
|
let mut connector = Connector::new(handshaker);
|
|
|
|
connector
|
|
.ready()
|
|
.await
|
|
.unwrap()
|
|
.call(ConnectRequest {
|
|
addr: monerod,
|
|
permit,
|
|
})
|
|
.await
|
|
.unwrap();
|
|
}
|