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

swarm/src/lib: Remove Deref and DerefMut impls on Swarm #1995

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let addr: Multiaddr = to_dial.parse()?;
Swarm::dial_addr(&mut swarm, addr)?;
swarm.dial_addr(addr)?;
println!("Dialed {:?}", to_dial)
}

// Read full lines from stdin
let mut stdin = io::BufReader::new(io::stdin()).lines();

// Listen on all interfaces and whatever port the OS assigns
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

// Kick it off
let mut listening = false;
Expand All @@ -166,7 +166,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
};
if let Some((topic, line)) = to_publish {
swarm.floodsub.publish(topic, line.as_bytes());
swarm.behaviour_mut().floodsub.publish(topic, line.as_bytes());
}
if !listening {
for addr in Swarm::listeners(&swarm) {
Expand Down
8 changes: 5 additions & 3 deletions examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,24 @@ fn main() -> Result<(), Box<dyn Error>> {
// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let addr: Multiaddr = to_dial.parse()?;
Swarm::dial_addr(&mut swarm, addr)?;
swarm.dial_addr(addr)?;
println!("Dialed {:?}", to_dial)
}

// Read full lines from stdin
let mut stdin = io::BufReader::new(io::stdin()).lines();

// Listen on all interfaces and whatever port the OS assigns
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

// Kick it off
let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => swarm.floodsub.publish(floodsub_topic.clone(), line.as_bytes()),
Poll::Ready(Some(line)) => swarm.behaviour_mut()
.floodsub
.publish(floodsub_topic.clone(), line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break
}
Expand Down
4 changes: 2 additions & 2 deletions examples/distributed-key-value-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut stdin = io::BufReader::new(io::stdin()).lines();

// Listen on all interfaces and whatever port the OS assigns.
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

// Kick it off.
let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => handle_input_line(&mut swarm.kademlia, line),
Poll::Ready(Some(line)) => handle_input_line(&mut swarm.behaviour_mut().kademlia, line),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break
}
Expand Down
6 changes: 3 additions & 3 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ fn main() -> Result<(), Box<dyn Error>> {
};

// Listen on all interfaces and whatever port the OS assigns
libp2p::Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse().unwrap()).unwrap();
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap()).unwrap();

// Reach out to another node if specified
if let Some(to_dial) = std::env::args().nth(1) {
let dialing = to_dial.clone();
match to_dial.parse() {
Ok(to_dial) => match libp2p::Swarm::dial_addr(&mut swarm, to_dial) {
Ok(to_dial) => match swarm.dial_addr(to_dial) {
Ok(_) => println!("Dialed {:?}", dialing),
Err(e) => println!("Dial {:?} failed: {:?}", dialing, e),
},
Expand All @@ -137,7 +137,7 @@ fn main() -> Result<(), Box<dyn Error>> {
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => swarm.publish(topic.clone(), line.as_bytes()),
Poll::Ready(Some(line)) => swarm.behaviour_mut().publish(topic.clone(), line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Poll::Pending => break,
} {
Expand Down
2 changes: 1 addition & 1 deletion examples/ipfs-kad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main() -> Result<(), Box<dyn Error>> {
};

println!("Searching for the closest peers to {:?}", to_search);
swarm.get_closest_peers(to_search);
swarm.behaviour_mut().get_closest_peers(to_search);

// Kick it off!
task::block_on(async move {
Expand Down
5 changes: 3 additions & 2 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,23 @@ fn main() -> Result<(), Box<dyn Error>> {
// Reach out to other nodes if specified
for to_dial in std::env::args().skip(1) {
let addr: Multiaddr = parse_legacy_multiaddr(&to_dial)?;
Swarm::dial_addr(&mut swarm, addr)?;
swarm.dial_addr(addr)?;
println!("Dialed {:?}", to_dial)
}

// Read full lines from stdin
let mut stdin = io::BufReader::new(io::stdin()).lines();

// Listen on all interfaces and whatever port the OS assigns
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

// Kick it off
let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
loop {
if let Err(e) = match stdin.try_poll_next_unpin(cx)? {
Poll::Ready(Some(line)) => swarm
.behaviour_mut()
.gossipsub
.publish(gossipsub_topic.clone(), line.as_bytes()),
Poll::Ready(None) => panic!("Stdin closed"),
Expand Down
2 changes: 1 addition & 1 deletion examples/mdns-passive-discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Note that the MDNS behaviour itself will not actually inititiate any connections,
// as it only uses UDP.
let mut swarm = Swarm::new(transport, behaviour, peer_id);
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

loop {
match swarm.next().await {
Expand Down
4 changes: 2 additions & 2 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ fn main() -> Result<(), Box<dyn Error>> {
// command-line argument, if any.
if let Some(addr) = std::env::args().nth(1) {
let remote = addr.parse()?;
Swarm::dial_addr(&mut swarm, remote)?;
swarm.dial_addr(remote)?;
println!("Dialed {}", addr)
}

// Tell the swarm to listen on all interfaces and a random, OS-assigned port.
Swarm::listen_on(&mut swarm, "/ip4/0.0.0.0/tcp/0".parse()?)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;

let mut listening = false;
task::block_on(future::poll_fn(move |cx: &mut Context<'_>| {
Expand Down
2 changes: 1 addition & 1 deletion protocols/gossipsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
//!
//! // Listen on a memory transport.
//! let memory: Multiaddr = libp2p_core::multiaddr::Protocol::Memory(10).into();
//! let addr = libp2p_swarm::Swarm::listen_on(&mut swarm, memory).unwrap();
//! let addr = swarm.listen_on(memory).unwrap();
//! println!("Listening on {:?}", addr);
//! ```

Expand Down
6 changes: 3 additions & 3 deletions protocols/gossipsub/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn build_node() -> (Multiaddr, Swarm<Gossipsub>) {

let port = 1 + random::<u64>();
let mut addr: Multiaddr = Protocol::Memory(port).into();
Swarm::listen_on(&mut swarm, addr.clone()).unwrap();
swarm.listen_on(addr.clone()).unwrap();

addr = addr.with(libp2p_core::multiaddr::Protocol::P2p(
public_key.into_peer_id().into(),
Expand All @@ -196,7 +196,7 @@ fn multi_hop_propagation() {
// Subscribe each node to the same topic.
let topic = Topic::new("test-net");
for (_addr, node) in &mut graph.nodes {
node.subscribe(&topic).unwrap();
node.behaviour_mut().subscribe(&topic).unwrap();
}

// Wait for all nodes to be subscribed.
Expand All @@ -223,7 +223,7 @@ fn multi_hop_propagation() {
graph = graph.drain_poll();

// Publish a single message.
graph.nodes[0].1.publish(topic, vec![1, 2, 3]).unwrap();
graph.nodes[0].1.behaviour_mut().publish(topic, vec![1, 2, 3]).unwrap();

// Wait for all nodes to receive the published message.
let mut received_msgs = 0;
Expand Down
4 changes: 2 additions & 2 deletions protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mod tests {
(swarm, pubkey)
};

Swarm::listen_on(&mut swarm1, "/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();
swarm1.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();

let listen_addr = async_std::task::block_on(async {
loop {
Expand All @@ -330,7 +330,7 @@ mod tests {
}
}
});
Swarm::dial_addr(&mut swarm2, listen_addr).unwrap();
swarm2.dial_addr(listen_addr).unwrap();

// nb. Either swarm may receive the `Identified` event first, upon which
// it will permit the connection to be closed, as defined by
Expand Down
Loading