Skip to content

Commit

Permalink
Merge #51: overhaul dependencies
Browse files Browse the repository at this point in the history
f889ad6 deps: update umio to mio v1 (Cameron Garnham)
e952875 deps: add umio as contrib package (Cameron Garnham)
0e26eb7 docs: update main readme todo (Cameron Garnham)
066008d rework: upgrade all dependencies (Cameron Garnham)

Pull request description:

  closes: #19, closes: #20, closes #21, closes: #22, closes: #23, closes: #25

  Todo:
  - [x] Update Readme

ACKs for top commit:
  da2ce7:
    ACK f889ad6

Tree-SHA512: 21ee2614de6df9dc3669d14512d1fdae2258e5368624fcec3624b7f128816756c66076d6983758689235b0466da2c2decbf0049ba75180492902df82646d9933
  • Loading branch information
da2ce7 committed Aug 24, 2024
2 parents 0b9ca27 + f889ad6 commit 24c4707
Show file tree
Hide file tree
Showing 189 changed files with 11,146 additions and 7,645 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"contrib/umio",
"examples/get_metadata",
"examples/simple_torrent",
"packages/bencode",
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ In this fork we have:
- [x] Implemented continuous integration using github workflows. ([#8])
- [x] Update some of the project dependencies. ([#9], [#17], [#26], [#27])
- [x] Preformed a general cleanup of the codebase. ([#10], [#16], [#18], [#29], [#31])
- [x] Updated all dependencies to modern versions. ( [#19], [#20], [#21], [#22], [#23], [#25])

The future goals are:

- [ ] Update the other dependencies (__Significant Work Required__). ( [#19], [#20], [#21], [#22], [#23], [#25])
The future goals are:
- [ ] Publish updated versions of the crates. ([#37])
- [ ] Increase coverage of unit tests. ([#38])
- [ ] Remove dependency on umio in `utracker` package. Instead use Tokio. ([#53])
- [ ] Overhaul the old `mio` architecture in the `dht` package. Making better use of Tokio. ([#54])

__We would like to make a special thanks to all the developers who had contributed to and created this great project.__

Expand Down Expand Up @@ -94,6 +96,9 @@ additional terms or conditions.
[#25]: https://github.com/torrust/bittorrent-infrastructure-project/issues/25
[#37]: https://github.com/torrust/bittorrent-infrastructure-project/issues/37
[#38]: https://github.com/torrust/bittorrent-infrastructure-project/issues/38
[#53]: https://github.com/torrust/bittorrent-infrastructure-project/issues/53
[#54]: https://github.com/torrust/bittorrent-infrastructure-project/issues/54


[t_i37]: https://img.shields.io/github/issues/detail/title/torrust/bittorrent-infrastructure-project/37?style=for-the-badge&
[s_i37]: https://img.shields.io/github/issues/detail/state/torrust/bittorrent-infrastructure-project/37?style=for-the-badge&label=%E3%80%80
Expand All @@ -113,4 +118,4 @@ additional terms or conditions.
[c_bip_select]: https://crates.io/crates/bip_select
[c_bip_dht]: https://crates.io/crates/bip_dht
[c_bip_metainfo]: https://crates.io/crates/bip_metainfo
[c_bip_utracker]: https://crates.io/crates/bip_utracker
[c_bip_utracker]: https://crates.io/crates/bip_utracker
4 changes: 4 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
"codegen",
"compat",
"concated",
"Condvar",
"coppersurfer",
"cpupool",
"curr",
"cust",
"cvar",
"Cyberneering",
"demonii",
"Deque",
Expand All @@ -51,6 +53,7 @@
"metainfo",
"mpmc",
"myapp",
"nanos",
"natted",
"nextest",
"Oneshot",
Expand All @@ -65,6 +68,7 @@
"rebootstrapping",
"recvd",
"reqq",
"reregister",
"ringbuffer",
"rpath",
"rqst",
Expand Down
23 changes: 23 additions & 0 deletions contrib/umio/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
authors = ["Andrew <[email protected]>"]
description = "Message Based Readiness API In Rust"
keywords = ["message", "mio", "readyness"]
name = "umio"
readme = "README.md"

categories.workspace = true
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
publish.workspace = true

repository.workspace = true
version.workspace = true

[dependencies]
mio = { version = "1", features = ["net", "os-poll"] }
tracing = "0"

[dev-dependencies]
tracing-subscriber = "0"
23 changes: 23 additions & 0 deletions contrib/umio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
umio-rs
=======
Message Based Readiness API In Rust.

Thin layer over mio for working with a single udp socket while retaining access to timers and event loop channels.


License
-------

Licensed under either of

* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

Contribution
------------

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
127 changes: 127 additions & 0 deletions contrib/umio/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use std::ops::{Deref, DerefMut};

use tracing::instrument;

#[allow(clippy::module_name_repetitions)]
pub struct BufferPool {
// Use Stack For Temporal Locality
buffers: Vec<Buffer>,
buffer_size: usize,
}

impl std::fmt::Debug for BufferPool {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BufferPool")
.field("buffers_len", &self.buffers.len())
.field("buffer_size", &self.buffer_size)
.finish()
}
}

impl BufferPool {
#[instrument(skip())]
pub fn new(buffer_size: usize) -> BufferPool {
let buffers = Vec::new();

BufferPool { buffers, buffer_size }
}

#[instrument(skip(self), fields(remaining= %self.buffers.len()))]
pub fn pop(&mut self) -> Buffer {
if let Some(buffer) = self.buffers.pop() {
tracing::trace!(?buffer, "popping old buffer taken from pool");
buffer
} else {
let buffer = Buffer::new(self.buffer_size);
tracing::trace!(?buffer, "creating new buffer...");
buffer
}
}

#[instrument(skip(self, buffer), fields(existing= %self.buffers.len()))]
pub fn push(&mut self, mut buffer: Buffer) {
tracing::trace!("Pushing buffer back to pool");
buffer.reset_position();
self.buffers.push(buffer);
}
}

//----------------------------------------------------------------------------//

/// Reusable region of memory for incoming and outgoing messages.
pub struct Buffer {
buffer: std::io::Cursor<Vec<u8>>,
}

impl std::fmt::Debug for Buffer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Buffer").field("buffer", &self.as_ref()).finish()
}
}

impl Buffer {
#[instrument(skip())]
fn new(len: usize) -> Buffer {
Buffer {
buffer: std::io::Cursor::new(vec![0_u8; len]),
}
}

fn reset_position(&mut self) {
self.set_position(0);
}
}

impl Deref for Buffer {
type Target = std::io::Cursor<Vec<u8>>;

fn deref(&self) -> &Self::Target {
&self.buffer
}
}

impl DerefMut for Buffer {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.buffer
}
}

impl AsRef<[u8]> for Buffer {
fn as_ref(&self) -> &[u8] {
self.get_ref().split_at(self.buffer.position().try_into().unwrap()).0
}
}

impl AsMut<[u8]> for Buffer {
fn as_mut(&mut self) -> &mut [u8] {
let pos = self.buffer.position().try_into().unwrap();
self.get_mut().split_at_mut(pos).1
}
}

#[cfg(test)]
mod tests {

use super::{Buffer, BufferPool};

const DEFAULT_BUFFER_SIZE: usize = 1500;

#[test]
fn positive_buffer_pool_buffer_len() {
let mut buffers = BufferPool::new(DEFAULT_BUFFER_SIZE);
let mut buffer = buffers.pop();

assert_eq!(buffer.as_mut().len(), DEFAULT_BUFFER_SIZE);
assert_eq!(buffer.as_ref().len(), 0);
}

#[test]
fn positive_buffer_len_update() {
let mut buffer = Buffer::new(DEFAULT_BUFFER_SIZE);

buffer.set_position((DEFAULT_BUFFER_SIZE - 1).try_into().unwrap());

assert_eq!(buffer.as_mut().len(), 1);
assert_eq!(buffer.as_ref().len(), DEFAULT_BUFFER_SIZE - 1);
}
}
Loading

0 comments on commit 24c4707

Please sign in to comment.