Skip to content

Commit

Permalink
Merge branch 'master' into feat/deprecate-noise
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Apr 26, 2023
2 parents 3718257 + 5808541 commit c9d2da8
Show file tree
Hide file tree
Showing 103 changed files with 912 additions and 783 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[alias]
# Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped.
custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -D warnings"
custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -W unreachable_pub -D warnings"
8 changes: 8 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ pull_request_rules:
message: Approvals have been dismissed because the PR was updated after the `send-it` label was applied.
changes_requested: false

- name: Approve trivial maintainer PRs
conditions:
- base=master
- label=trivial
- author=@libp2p/rust-libp2p-maintainers
actions:
review:

queue_rules:
- name: default
conditions: []
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ env:
jobs:
test:
name: Test ${{ matrix.crate }}
runs-on: ubuntu-latest
runs-on: ${{ fromJSON(
github.repository == 'libp2p/rust-libp2p' && (
(contains(fromJSON('["libp2p-webrtc", "libp2p"]'), matrix.crate) && '["self-hosted", "linux", "x64", "2xlarge"]') ||
(contains(fromJSON('["libp2p-quic", "libp2p-perf"]'), matrix.crate) && '["self-hosted", "linux", "x64", "xlarge"]') ||
'["self-hosted", "linux", "x64", "large"]'
) || '"ubuntu-latest"') }}
timeout-minutes: 10
needs: gather_published_crates
strategy:
fail-fast: false
matrix:
crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }}
steps:
- name: Install Protoc
run: sudo apt-get install protobuf-compiler
run: sudo apt-get install -y protobuf-compiler

- uses: dtolnay/rust-toolchain@stable

- uses: actions/checkout@v3

Expand All @@ -33,6 +41,7 @@ jobs:
run: |
RUST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.crate }}") | .rust_version')
echo "version=${RUST_VERSION}" >> $GITHUB_OUTPUT
shell: bash

- name: Install Rust ${{ steps.parse-msrv.outputs.version }} for MSRV check
uses: dtolnay/rust-toolchain@master
Expand Down Expand Up @@ -158,7 +167,7 @@ jobs:
fail-fast: false
matrix:
rust-version: [
1.68.0, # current stable
1.69.0, # current stable
beta
]
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/interop-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
run-multidim-interop:
name: Run multidimensional interoperability tests
runs-on: ubuntu-22.04
runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "xlarge"]' || '"ubuntu-latest"') }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
Expand Down
22 changes: 11 additions & 11 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
- Deprecate `{In,Out}boundUpgradeExt`, as they are not used in rust-libp2p.
See [PR 3807].

- Deprecate `OptionalUpgrade` without replacement.
See [PR 3806].

[PR 3747]: https://github.com/libp2p/rust-libp2p/pull/3747
[PR 3807]: https://github.com/libp2p/rust-libp2p/pull/3807
[PR 3806]: https://github.com/libp2p/rust-libp2p/pull/3806

## 0.39.1

Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod proto {
#![allow(unreachable_pub)]
include!("generated/mod.rs");
pub use self::{
envelope_proto::*, peer_record_proto::mod_PeerRecord::*, peer_record_proto::PeerRecord,
Expand Down
2 changes: 1 addition & 1 deletion core/src/signed_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod tests {
use super::*;

#[test]
pub fn test_roundtrip() {
fn test_roundtrip() {
let kp = Keypair::generate_ed25519();
let payload = "some payload".as_bytes();
let domain_separation = "domain separation".to_string();
Expand Down
2 changes: 1 addition & 1 deletion core/src/transport/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::{
};

/// Creates a new [`Boxed`] transport from the given transport.
pub fn boxed<T>(transport: T) -> Boxed<T::Output>
pub(crate) fn boxed<T>(transport: T) -> Boxed<T::Output>
where
T: Transport + Send + Unpin + 'static,
T::Error: Send + Sync,
Expand Down
6 changes: 3 additions & 3 deletions core/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ pub use self::{
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
denied::DeniedUpgrade,
error::UpgradeError,
optional::OptionalUpgrade,
pending::PendingUpgrade,
ready::ReadyUpgrade,
select::SelectUpgrade,
transfer::{read_length_prefixed, read_varint, write_length_prefixed, write_varint},
};
pub use crate::Negotiated;
pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version};

#[allow(deprecated)]
pub use map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr};
pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version};
#[allow(deprecated)]
pub use optional::OptionalUpgrade;

/// Types serving as protocol names.
///
Expand Down
4 changes: 2 additions & 2 deletions core/src/upgrade/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use log::debug;
use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture};
use std::{iter, mem, pin::Pin, task::Context, task::Poll};

pub use multistream_select::Version;
pub(crate) use multistream_select::Version;
use smallvec::SmallVec;
use std::fmt;

Expand Down Expand Up @@ -275,7 +275,7 @@ impl<N: ProtocolName> AsRef<[u8]> for NameWrap<N> {
}

/// Wrapper for printing a [`ProtocolName`] that is expected to be mostly ASCII
pub(crate) struct DisplayProtocolName<N>(pub N);
pub(crate) struct DisplayProtocolName<N>(pub(crate) N);

impl<N: ProtocolName> fmt::Display for DisplayProtocolName<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
5 changes: 5 additions & 0 deletions core/src/upgrade/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

#![allow(deprecated)]

use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo};

/// Upgrade that can be disabled at runtime.
///
/// Wraps around an `Option<T>` and makes it available or not depending on whether it contains or
/// not an upgrade.
#[derive(Debug, Clone)]
#[deprecated(
note = "Will be removed without replacement because it is not used within rust-libp2p."
)]
pub struct OptionalUpgrade<T>(Option<T>);

impl<T> OptionalUpgrade<T> {
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A set of examples showcasing how to use rust-libp2p.

## Individual libp2p features

- [Chat](./autonat) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols.
- [Chat](./chat-example) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols.
- [Distributed key-value store](./distributed-key-value-store) A basic key value store demonstrating libp2p and the mDNS and Kademlia protocol.

- [File sharing application](./file-sharing) Basic file sharing application with peers either providing or locating and getting files by name.
Expand Down
32 changes: 19 additions & 13 deletions examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::iter;
/// - The network event stream, e.g. for incoming requests.
///
/// - The network task driving the network itself.
pub async fn new(
pub(crate) async fn new(
secret_key_seed: Option<u8>,
) -> Result<(Client, impl Stream<Item = Event>, EventLoop), Box<dyn Error>> {
// Create a public/private key pair, either random or based on a seed.
Expand Down Expand Up @@ -82,13 +82,16 @@ pub async fn new(
}

#[derive(Clone)]
pub struct Client {
pub(crate) struct Client {
sender: mpsc::Sender<Command>,
}

impl Client {
/// Listen for incoming connections on the given address.
pub async fn start_listening(&mut self, addr: Multiaddr) -> Result<(), Box<dyn Error + Send>> {
pub(crate) async fn start_listening(
&mut self,
addr: Multiaddr,
) -> Result<(), Box<dyn Error + Send>> {
let (sender, receiver) = oneshot::channel();
self.sender
.send(Command::StartListening { addr, sender })
Expand All @@ -98,7 +101,7 @@ impl Client {
}

/// Dial the given peer at the given address.
pub async fn dial(
pub(crate) async fn dial(
&mut self,
peer_id: PeerId,
peer_addr: Multiaddr,
Expand All @@ -116,7 +119,7 @@ impl Client {
}

/// Advertise the local node as the provider of the given file on the DHT.
pub async fn start_providing(&mut self, file_name: String) {
pub(crate) async fn start_providing(&mut self, file_name: String) {
let (sender, receiver) = oneshot::channel();
self.sender
.send(Command::StartProviding { file_name, sender })
Expand All @@ -126,7 +129,7 @@ impl Client {
}

/// Find the providers for the given file on the DHT.
pub async fn get_providers(&mut self, file_name: String) -> HashSet<PeerId> {
pub(crate) async fn get_providers(&mut self, file_name: String) -> HashSet<PeerId> {
let (sender, receiver) = oneshot::channel();
self.sender
.send(Command::GetProviders { file_name, sender })
Expand All @@ -136,7 +139,7 @@ impl Client {
}

/// Request the content of the given file from the given peer.
pub async fn request_file(
pub(crate) async fn request_file(
&mut self,
peer: PeerId,
file_name: String,
Expand All @@ -154,15 +157,19 @@ impl Client {
}

/// Respond with the provided file content to the given request.
pub async fn respond_file(&mut self, file: Vec<u8>, channel: ResponseChannel<FileResponse>) {
pub(crate) async fn respond_file(
&mut self,
file: Vec<u8>,
channel: ResponseChannel<FileResponse>,
) {
self.sender
.send(Command::RespondFile { file, channel })
.await
.expect("Command receiver not to be dropped.");
}
}

pub struct EventLoop {
pub(crate) struct EventLoop {
swarm: Swarm<ComposedBehaviour>,
command_receiver: mpsc::Receiver<Command>,
event_sender: mpsc::Sender<Event>,
Expand Down Expand Up @@ -190,7 +197,7 @@ impl EventLoop {
}
}

pub async fn run(mut self) {
pub(crate) async fn run(mut self) {
loop {
futures::select! {
event = self.swarm.next() => self.handle_event(event.expect("Swarm stream to be infinite.")).await ,
Expand Down Expand Up @@ -452,7 +459,7 @@ enum Command {
}

#[derive(Debug)]
pub enum Event {
pub(crate) enum Event {
InboundRequest {
request: String,
channel: ResponseChannel<FileResponse>,
Expand All @@ -468,8 +475,7 @@ struct FileExchangeCodec();
#[derive(Debug, Clone, PartialEq, Eq)]
struct FileRequest(String);
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FileResponse(Vec<u8>);

pub(crate) struct FileResponse(Vec<u8>);
impl ProtocolName for FileExchangeProtocol {
fn protocol_name(&self) -> &[u8] {
"/file-exchange/1".as_bytes()
Expand Down
Loading

0 comments on commit c9d2da8

Please sign in to comment.