Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Move to stable MSRV 1.85

## [0.7.0] - 2024-10-21

### Added
Expand All @@ -18,15 +22,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add network version to handshake messages
- Add Ray-ID to MessageInfo for message tracking
- Add warning when discarding incomplete messages
- Add tracing when broadcasting to an eclipsed network
- Add tracing when broadcasting to an eclipsed network

### Fixed

- Fix raptorQ cache default config
- Fix ObjectTransmissionInformation deserialization
- Fix duplicate processing for messages with different RaptorQ configurations
- Fix idle nodes removal on maintainance
- Fix `find_new_nodes` to query the proper buckets
- Fix `find_new_nodes` to query the proper buckets

### Changed

Expand Down Expand Up @@ -61,22 +65,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.5.0] - 2023-05-17

### Added

- Add network blocklist implementation [#117]

### Changed
### Changed

- Change `Peer::new` to return a Result [#115]
- Change `blake2` dependency from `0.9` to `0.10` [#115]

## [0.4.1] - 2022-07-27

### Added

- Remove idle nodes during bucket mantainance [#108]

### Fixed

- Use provided nonce instead of regenerate it [#110]
- Network bootstrap after being disconnected [#112]

## [0.4.0] - 2022-07-06

### Added

- Add `kadcast::Config` [#96]
Expand All @@ -92,6 +101,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Dupemap cache expiring [#101]

## [0.3.0] - 2022-01-07

### Added

- Add network transport configuration [#72] [#76]
Expand All @@ -107,7 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Deadlock in `RWLock.write()` [#80]
- Preserve propagation in some edge-corner cases
- Messages from buckets full are correctly handled
- Messages from buckets full are correctly handled
- Empty payload NodesMessage decoding [#90]

## [0.2.0] - 2021-12-16
Expand Down Expand Up @@ -175,7 +185,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.7.0]: https://github.com/dusk-network/kadcast/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/dusk-network/kadcast/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/dusk-network/kadcast/compare/v0.5.0...v0.6.0
[0.5.1]: https://github.com/dusk-network/kadcast/compare/v0.4.1...v0.5.0
[0.5.0]: https://github.com/dusk-network/kadcast/compare/v0.4.1...v0.5.0
[0.4.1]: https://github.com/dusk-network/kadcast/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/dusk-network/kadcast/compare/v0.3.0...v0.4.0
[0.3.0]: https://github.com/dusk-network/kadcast/compare/v0.2.0...v0.3.0
Expand Down
14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ license = "MPL-2.0"
repository = "https://github.com/dusk-network/kadcast"
publish = true

rust-version = "1.85"

exclude = [".git*", "ARCHITECTURE.md", "architecture.jpg"]

[dependencies]
arrayvec = "0.7"
blake2 = "0.10"
rand = "0.8"
tokio = { version = "1", features = ["rt", "net", "sync", "time", "io-std", "rt-multi-thread", "macros"] }
tokio = { version = "1", features = [
"rt",
"net",
"sync",
"time",
"io-std",
"rt-multi-thread",
"macros",
] }
raptorq = { version = "2.0", optional = true }
tracing = "0.1"
itertools = "0.10"
Expand All @@ -35,7 +45,7 @@ tracing-subscriber = "0.2"
toml = "0.5"

[features]
default = [ "raptorq" ]
default = ["raptorq"]
diagnostics = []

[[example]]
Expand Down
7 changes: 0 additions & 7 deletions examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ use clap::{App, Arg};
use kadcast::config::Config;
use kadcast::{MessageInfo, NetworkListen, Peer};
use rustc_tools_util::{get_version_info, VersionInfo};
use serde_derive::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct General {
kadcast: kadcast::config::Config,
}

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
let crate_info = get_version_info!();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-05-22"
channel = "stable"
components = ["rustfmt", "clippy"]
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
max_width = 80
newline_style = "Unix"
wrap_comments = true
4 changes: 2 additions & 2 deletions src/encoding/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::io::{self, Error, ErrorKind, Read, Write};
use std::io::{self, Error, Read, Write};

use super::Marshallable;
use crate::{kbucket::BinaryID, K_ID_LEN_BYTES, K_NONCE_LEN};
Expand All @@ -26,7 +26,7 @@ impl Header {
impl Marshallable for Header {
fn marshal_binary<W: Write>(&self, writer: &mut W) -> io::Result<()> {
if !self.binary_id.verify_nonce() {
return Err(Error::new(ErrorKind::Other, "Invalid Nonce"));
return Err(Error::other("Invalid Nonce"));
}
writer.write_all(self.binary_id.as_binary())?;
writer.write_all(self.binary_id.nonce())?;
Expand Down
10 changes: 5 additions & 5 deletions src/encoding/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::io::{self, Error, ErrorKind, Read, Write};
use std::io::{self, Error, Read, Write};

use semver::Version;

Expand Down Expand Up @@ -159,10 +159,10 @@ impl Marshallable for Message {
let payload = BroadcastPayload::unmarshal_binary(reader)?;
Ok(Message::broadcast(header, payload))
}
unknown => Err(Error::new(
ErrorKind::Other,
format!("Invalid message type: '{}'", unknown),
)),
unknown => Err(Error::other(format!(
"Invalid message type: '{}'",
unknown
))),
}
}
}
12 changes: 6 additions & 6 deletions src/kbucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use bucket::InsertOk;
pub use bucket::{NodeInsertError, NodeInsertOk};
use itertools::Itertools;
pub use key::MAX_BUCKET_HEIGHT;
pub use key::{BinaryID, BinaryKey, BinaryNonce};
pub use key::{BinaryID, BinaryKey};
pub use node::Node;
use std::collections::hash_map::Entry;
use tracing::info;
Expand All @@ -35,7 +35,7 @@ impl<V> Tree<V> {
pub fn insert(
&mut self,
node: Node<V>,
) -> Result<InsertOk<V>, InsertError<V>> {
) -> Result<InsertOk<'_, V>, InsertError<V>> {
if self.root().network_id != node.network_id {
return Err(NodeInsertError::MismatchNetwork(node));
}
Expand All @@ -48,7 +48,7 @@ impl<V> Tree<V> {
pub fn refresh(
&mut self,
node: Node<V>,
) -> Result<InsertOk<V>, InsertError<V>> {
) -> Result<InsertOk<'_, V>, InsertError<V>> {
if self.root().network_id != node.network_id {
return Err(NodeInsertError::MismatchNetwork(node));
}
Expand All @@ -59,10 +59,10 @@ impl<V> Tree<V> {
}

fn get_or_create_bucket(&mut self, height: BucketHeight) -> &mut Bucket<V> {
return match self.buckets.entry(height) {
match self.buckets.entry(height) {
Entry::Occupied(o) => o.into_mut(),
Entry::Vacant(v) => v.insert(Bucket::new(self.config)),
};
}
}

// iter the buckets (up to max_height, inclusive) and pick at most Beta
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<V> Tree<V> {
pub(crate) fn is_bucket_full(&self, height: BucketHeight) -> bool {
self.buckets
.get(&height)
.map_or(false, |bucket| bucket.is_full())
.is_some_and(|bucket| bucket.is_full())
}

pub(crate) fn bucket_size(&self, height: BucketHeight) -> usize {
Expand Down
9 changes: 4 additions & 5 deletions src/kbucket/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<V> Bucket<V> {
pub fn insert(
&mut self,
node: Node<V>,
) -> Result<InsertOk<V>, InsertError<V>> {
) -> Result<InsertOk<'_, V>, InsertError<V>> {
if !node.id().verify_nonce() {
return Err(NodeInsertError::Invalid(node));
}
Expand Down Expand Up @@ -199,7 +199,7 @@ impl<V> Bucket<V> {
pub fn refresh(
&mut self,
node: Node<V>,
) -> Result<InsertOk<V>, InsertError<V>> {
) -> Result<InsertOk<'_, V>, InsertError<V>> {
if !node.id().verify_nonce() {
return Err(NodeInsertError::Invalid(node));
}
Expand Down Expand Up @@ -243,7 +243,7 @@ impl<V> Bucket<V> {

/// Checks if the bucket has at least one idle node.
pub(crate) fn has_idle(&self) -> bool {
self.nodes.first().map_or(false, |n| {
self.nodes.first().is_some_and(|n| {
n.seen_at.elapsed() > self.bucket_config.bucket_ttl
})
}
Expand Down Expand Up @@ -286,13 +286,12 @@ impl<V> Bucket<V> {
let node_idx =
self.nodes.iter().position(|s| s.id().as_binary() == id)?;

self.nodes.pop_at(node_idx).map(|removed| {
self.nodes.pop_at(node_idx).inspect(|_| {
if let Some(pending) = self.pending_node.take() {
if pending.is_alive(self.bucket_config.node_ttl) {
self.nodes.push(pending);
}
}
removed
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/kbucket/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl BinaryID {
if ret.verify_nonce() {
Ok(ret)
} else {
Err(io::Error::new(io::ErrorKind::Other, "Invalid Nonce"))
Err(io::Error::other("Invalid Nonce"))
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ impl BinaryID {
where
I: Iterator<Item = &'a u8>,
{
bytes.next().map_or(false, |b| {
bytes.next().is_some_and(|b| {
if difficulty <= 8 {
b.trailing_zeros() as usize >= difficulty
} else if b != &0 {
Expand Down
12 changes: 4 additions & 8 deletions src/transport/encoding/raptorq/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ impl Decoder for RaptorQDecoder {
})
}
Err(e) => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!(
"Invalid transmission info {e:?}",
),
));
return Err(io::Error::other(format!(
"Invalid transmission info {e:?}",
)));
}
}
}
Expand Down Expand Up @@ -213,15 +210,14 @@ impl Decoder for RaptorQDecoder {
// cache with new status. This
// will drop useless Decoder and avoid
// to propagate already processed messages
.map(|decoded| {
.inspect(|_decoded| {
self.cache.insert(
ray_id,
CacheStatus::Processed(
Instant::now() + self.conf.cache_ttl,
),
);
trace!("> Broadcast message decoded!");
decoded
})
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/transport/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl MultipleOutSocket {

let send = timeout(self.udp_send_retry_interval, send_fn)
.await
.map_err(|_| io::Error::new(io::ErrorKind::Other, "TIMEOUT"));
.map_err(|_| io::Error::other("TIMEOUT"));

match send {
Ok(Ok(_)) => {
Expand Down