Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/cargo/multiaddr-0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodolsky authored Dec 14, 2022
2 parents 954e437 + be3ec6c commit bde6dfa
Show file tree
Hide file tree
Showing 45 changed files with 1,088 additions and 579 deletions.
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ updates:
schedule:
interval: "daily"
open-pull-requests-limit: 9999

commit-message:
prefix: "deps"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
commit-message:
prefix: "deps"
10 changes: 10 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ pull_request_rules:
actions:
queue:

- name: Remove reviews on updates after PR is queued for merging
conditions:
- base=master
- label=send-it
- author!=@libp2p/rust-libp2p-maintainers
actions:
dismiss_reviews:
message: Approvals have been dismissed because the PR was updated after the `send-it` label was applied.
changes_requested: false

queue_rules:
- name: default
conditions: []
78 changes: 78 additions & 0 deletions .github/workflows/cache-factory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This workflow _produces_ caches which are used to speed up pull request builds.
# The caches are split by Rust version (stable vs MSRV per crate) because those caches cannot share any artifacts.

name: Cache factory

on:
push:
branches:
- master # Caches are only created on master branch.

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
gather_msrv_versions:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.find-rust-versions.outputs.versions }}
steps:
- uses: actions/checkout@v3

- id: find-rust-versions
run: |
RUST_VERSIONS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | map(.rust_version) | unique | del(..|nulls)')
echo "versions=${RUST_VERSIONS}" >> $GITHUB_OUTPUT
make_msrv_cache:
runs-on: ubuntu-latest
needs: gather_msrv_versions
strategy:
fail-fast: false
matrix:
rust: ${{ fromJSON(needs.gather_msrv_versions.outputs.versions) }}
steps:
- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: ${{ matrix.rust }}

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: msrv-cache

- name: Compile all crates which have MSRV ${{ matrix.rust }}
run: |
cargo metadata --format-version=1 --no-deps | \
jq -r '.packages[] | select(.rust_version == "${{ matrix.rust }}") | "+\(.rust_version) build --all-features --package \(.name)"' |
xargs --verbose -L 1 cargo
make_stable_rust_cache:
runs-on: ubuntu-latest
steps:
- name: Install Protoc
uses: arduino/setup-protoc@64c0c85d18e984422218383b81c52f8b077404d3 # v1.1.2

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
toolchain: stable

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: stable-cache

- name: Compile workspace with stable Rust
run: cargo test --all-features --all-targets --workspace --no-run

- name: Render docs
run: cargo doc --all-features --workspace

- name: Install tools
run: cargo install cargo-semver-checks --locked
50 changes: 36 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,33 @@ jobs:
with:
profile: minimal
toolchain: ${{ steps.parse-msrv.outputs.version }}
override: true

- name: Update to latest stable Rust
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
shared-key: msrv-cache
save-if: false

- name: Check if ${{ matrix.crate }} compiles on MSRV (Rust ${{ steps.parse-msrv.outputs.version }})
run: cargo +${{ steps.parse-msrv.outputs.version }} build --package ${{ matrix.crate }} --all-features

- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: stable
override: true

# By default, this action already includes the active Rust toolchain in the cache key.
# We also install a separate toolchain for the MSRV check so all we need to do is add that to the key to make sure it invalidates when we update the MSRV.
# cargo separates build artifacts by Rust compiler version, meaning we can compile with different versions but cache all artifacts.
- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
key: ${{ matrix.crate }}-msrv-${{ steps.parse-msrv.outputs.version }}

- name: Check if ${{ matrix.crate }} compiles on MSRV (Rust ${{ steps.parse-msrv.outputs.version }})
run: cargo +${{ steps.parse-msrv.outputs.version }} check --package ${{ matrix.crate }} --all-features

- name: Check if we compile without any features activated
run: cargo check --package ${{ matrix.crate }} --no-default-features
shared-key: stable-cache
save-if: false

- name: Run all tests
run: cargo test --package ${{ matrix.crate }} --all-features

- name: Check if we compile without any features activated
run: cargo build --package ${{ matrix.crate }} --no-default-features

- name: Check if crate has been released
id: check-released
run: |
Expand Down Expand Up @@ -138,8 +141,6 @@ jobs:
override: true

- uses: Swatinem/rust-cache@359a70e43a0bb8a13953b04a90f76428b4959bb6 # v2.2.0
with:
key: ${{ matrix.runtime }}

- run: cargo check --package libp2p --features="${{ matrix.features }}"

Expand Down Expand Up @@ -267,3 +268,24 @@ jobs:
run: |
WORKSPACE_MEMBERS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | .[] | select(.publish == null) | .name' | jq -s '.' | jq -c '.')
echo "members=${WORKSPACE_MEMBERS}" >> $GITHUB_OUTPUT
validate_pr_title:
name: Validate PR title
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: amannn/action-semantic-pull-request@01d5fd8a8ebb9aafe902c40c53f0f4744f7381eb # v5.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed (newline delimited).
types: |
feat
fix
chore
docs
deps
test
ci
refactor
require_scope: false
2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ First draft is in https://github.com/libp2p/rust-libp2p/pull/2828

| Category | Status | Target Completion | Tracking | Dependencies | Dependents |
|--------------|-------------|-------------------|-------------------------------------------------|--------------|------------|
| Optimization | in progress | Q1/2023 | https://github.com/libp2p/rust-libp2p/pull/2712 | | |
| Optimization | done | Q1/2023 | https://github.com/libp2p/rust-libp2p/pull/2712 | | |

Users of rust-libp2p like [iroh](https://github.com/n0-computer/iroh) need this for low latency
usage of `libp2p-kad`. The rust-libp2p maintainers can pick this up unless iroh folks finish the
Expand Down
2 changes: 1 addition & 1 deletion examples/chat-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}

// Create a Swarm to manage peers and events.
let mdns_behaviour = mdns::Behaviour::new(Default::default())?;
let mdns_behaviour = mdns::Behaviour::new(Default::default(), peer_id)?;
let behaviour = MyBehaviour {
floodsub: Floodsub::new(peer_id),
mdns: mdns_behaviour,
Expand Down
2 changes: 1 addition & 1 deletion examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Create a Swarm to manage peers and events
let mut swarm = {
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default())?;
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default(), local_peer_id)?;
let mut behaviour = MyBehaviour {
floodsub: Floodsub::new(local_peer_id),
mdns,
Expand Down
2 changes: 1 addition & 1 deletion examples/distributed-key-value-store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Create a Kademlia behaviour.
let store = MemoryStore::new(local_peer_id);
let kademlia = Kademlia::new(local_peer_id, store);
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default())?;
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default(), local_peer_id)?;
let behaviour = MyBehaviour { kademlia, mdns };
Swarm::with_async_std_executor(transport, behaviour, local_peer_id)
};
Expand Down
27 changes: 12 additions & 15 deletions examples/file-sharing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ mod network {
use libp2p::kad::record::store::MemoryStore;
use libp2p::kad::{GetProvidersOk, Kademlia, KademliaEvent, QueryId, QueryResult};
use libp2p::multiaddr::Protocol;
use libp2p::request_response::{
ProtocolSupport, RequestId, RequestResponse, RequestResponseCodec, RequestResponseEvent,
RequestResponseMessage, ResponseChannel,
};
use libp2p::request_response::{self, ProtocolSupport, RequestId, ResponseChannel};
use libp2p::swarm::{ConnectionHandlerUpgrErr, NetworkBehaviour, Swarm, SwarmEvent};
use std::collections::{hash_map, HashMap, HashSet};
use std::iter;
Expand Down Expand Up @@ -254,7 +251,7 @@ mod network {
libp2p::development_transport(id_keys).await?,
ComposedBehaviour {
kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)),
request_response: RequestResponse::new(
request_response: request_response::Behaviour::new(
FileExchangeCodec(),
iter::once((FileExchangeProtocol(), ProtocolSupport::Full)),
Default::default(),
Expand Down Expand Up @@ -459,9 +456,9 @@ mod network {
)) => {}
SwarmEvent::Behaviour(ComposedEvent::Kademlia(_)) => {}
SwarmEvent::Behaviour(ComposedEvent::RequestResponse(
RequestResponseEvent::Message { message, .. },
request_response::Event::Message { message, .. },
)) => match message {
RequestResponseMessage::Request {
request_response::Message::Request {
request, channel, ..
} => {
self.event_sender
Expand All @@ -472,7 +469,7 @@ mod network {
.await
.expect("Event receiver not to be dropped.");
}
RequestResponseMessage::Response {
request_response::Message::Response {
request_id,
response,
} => {
Expand All @@ -484,7 +481,7 @@ mod network {
}
},
SwarmEvent::Behaviour(ComposedEvent::RequestResponse(
RequestResponseEvent::OutboundFailure {
request_response::Event::OutboundFailure {
request_id, error, ..
},
)) => {
Expand All @@ -495,7 +492,7 @@ mod network {
.send(Err(Box::new(error)));
}
SwarmEvent::Behaviour(ComposedEvent::RequestResponse(
RequestResponseEvent::ResponseSent { .. },
request_response::Event::ResponseSent { .. },
)) => {}
SwarmEvent::NewListenAddr { address, .. } => {
let local_peer_id = *self.swarm.local_peer_id();
Expand Down Expand Up @@ -604,18 +601,18 @@ mod network {
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "ComposedEvent")]
struct ComposedBehaviour {
request_response: RequestResponse<FileExchangeCodec>,
request_response: request_response::Behaviour<FileExchangeCodec>,
kademlia: Kademlia<MemoryStore>,
}

#[derive(Debug)]
enum ComposedEvent {
RequestResponse(RequestResponseEvent<FileRequest, FileResponse>),
RequestResponse(request_response::Event<FileRequest, FileResponse>),
Kademlia(KademliaEvent),
}

impl From<RequestResponseEvent<FileRequest, FileResponse>> for ComposedEvent {
fn from(event: RequestResponseEvent<FileRequest, FileResponse>) -> Self {
impl From<request_response::Event<FileRequest, FileResponse>> for ComposedEvent {
fn from(event: request_response::Event<FileRequest, FileResponse>) -> Self {
ComposedEvent::RequestResponse(event)
}
}
Expand Down Expand Up @@ -682,7 +679,7 @@ mod network {
}

#[async_trait]
impl RequestResponseCodec for FileExchangeCodec {
impl request_response::Codec for FileExchangeCodec {
type Protocol = FileExchangeProtocol;
type Request = FileRequest;
type Response = FileResponse;
Expand Down
2 changes: 1 addition & 1 deletion examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Create a Swarm to manage peers and events
let mut swarm = {
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default())?;
let mdns = mdns::async_io::Behaviour::new(mdns::Config::default(), local_peer_id)?;
let behaviour = MyBehaviour { gossipsub, mdns };
Swarm::with_async_std_executor(transport, behaviour, local_peer_id)
};
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 @@ -39,7 +39,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let transport = libp2p::development_transport(id_keys).await?;

// Create an MDNS network behaviour.
let behaviour = mdns::async_io::Behaviour::new(mdns::Config::default())?;
let behaviour = mdns::async_io::Behaviour::new(mdns::Config::default(), peer_id)?;

// Create a Swarm that establishes connections through the given transport.
// Note that the MDNS behaviour itself will not actually inititiate any connections,
Expand Down
4 changes: 4 additions & 0 deletions protocols/autonat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# 0.10.0 [unreleased]

- Require the node's local `PeerId` to be passed into the constructor of `libp2p_autonat::Behaviour`. See [PR 3153].

- Update to `libp2p-request-response` `v0.24.0`.

- Update to `libp2p-swarm` `v0.42.0`.

[PR 3153]: https://github.com/libp2p/rust-libp2p/pull/3153

# 0.9.0

- Update to `libp2p-core` `v0.38.0`.
Expand Down
Loading

0 comments on commit bde6dfa

Please sign in to comment.