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

Add message receiving USDTs (PoC) #788

Draft
wants to merge 1 commit into
base: xla/disable-rere
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions librad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ uuid = { version = "0.8", features = ["v4"] }
webpki = "0.21"
xorf = "0.7"

[build-dependencies.sonde]
git = "https://github.com/viraptor/sonde-rs"
rev = "88c3b872eaa7fdfe6ffbef34e1c920d4c9401544"
optional = true

[dependencies.deadpool]
version = "0.7"
default-features = false
Expand Down Expand Up @@ -143,3 +148,6 @@ features = ["serde"]
[dependencies.zeroize]
version = "1.1"
features = ["zeroize_derive"]

[features]
usdt = ["sonde"]
6 changes: 6 additions & 0 deletions librad/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
#[cfg(feature = "usdt")]
sonde::Builder::new()
.file("./radicle_link.d")
.compile();
}
4 changes: 4 additions & 0 deletions librad/radicle_link.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider radicle_link {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of this file in the setup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defines the probe signatures. It's used to transform lines like probe have_recv(char*, char*); into:

#include <sys/sdt.h>
...
#define RADICLE_LINK_HAVE_RECV(arg1, arg2) \
DTRACE_PROBE2 (radicle_link, have_recv, arg1, arg2)

(or similar, depending on your system and implementation) in the header.

This gets consumed to compile a library which can be extern'ed in the rust code.

Behold artist representation:

             build.rs                                           build.rs
                |                                                  |
radicle_link.d -> dtrace -h -> radicle_link-(rand).h -\            |
             \--> dtrace -G -> radicle_link-(rand).o -+--> $SONDE_RUST_API_FILE -> pub mod usdt;

probe have_recv(char*, char*);
probe want_recv(char*, char*);
};
5 changes: 5 additions & 0 deletions librad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#![feature(try_trait_v2)]
#![feature(control_flow_enum)]

#[cfg(feature = "usdt")]
pub mod usdt {
include!(env!("SONDE_RUST_API_FILE"));
}

#[macro_use]
extern crate async_trait;
#[macro_use]
Expand Down
23 changes: 23 additions & 0 deletions librad/src/net/peer/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ pub fn urn_context(local_peer_id: PeerId, urn: Either<Urn, Originates<Urn>>) ->
}
}

#[cfg(feature = "usdt")]
fn report_have(peer: &PeerId, urn: &Urn) {
let p: &str = &peer.default_encoding();
let u: &str = &urn.encode_id();
crate::usdt::radicle_link::have_recv(p.as_ptr() as *mut _, u.as_ptr() as *mut _);
}

#[cfg(not(feature = "usdt"))]
fn report_have(peer: &PeerId, urn: &Urn) { }

#[cfg(feature = "usdt")]
fn report_want(peer: &Option<PeerId>, urn: &Urn) {
let p: &str = &peer.map_or_else(|| "unknown".to_owned(), |o| o.default_encoding());
let u: &str = &urn.encode_id();
crate::usdt::radicle_link::want_recv(p.as_ptr() as *mut _, u.as_ptr() as *mut _);
}
#[cfg(not(feature = "usdt"))]
fn report_want(peer: &Option<PeerId>, urn: &Urn) { }

#[async_trait]
impl broadcast::LocalStorage<SocketAddr> for Storage {
type Update = gossip::Payload;
Expand All @@ -187,6 +206,8 @@ impl broadcast::LocalStorage<SocketAddr> for Storage {

let (provider, addr_hints) = provider.into();

report_have(&provider, &has.urn);

// If the `has` doesn't tell us to look into a specific remote-tracking
// branch, assume we want the `provider`'s.
let origin = has.origin.unwrap_or(provider);
Expand Down Expand Up @@ -258,6 +279,8 @@ impl broadcast::LocalStorage<SocketAddr> for Storage {

#[tracing::instrument(level = "debug", skip(self))]
async fn ask(&self, want: Self::Update) -> bool {
report_want(&want.origin, &want.urn);

self.git_has(
match want.origin {
Some(origin) => Right(Originates {
Expand Down