Skip to content

Return owned Strings for onion message message types #3273

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

Merged
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
8 changes: 5 additions & 3 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,19 @@ cargo test -p lightning --verbose --color always --no-default-features --feature
cargo test -p lightning --verbose --color always --features no-std

echo -e "\n\nTesting c_bindings builds"
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always
# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable doctests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always --lib --bins --tests

for DIR in lightning-invoice lightning-rapid-gossip-sync; do
# check if there is a conflict between no-std and the c_bindings cfg
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features
done

# Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively
# disable tests in `c_bindings` so we skip doctests entirely here.
# disable doctests in `c_bindings` so we skip doctests entirely here.
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std
RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std --lib --bins --tests

echo -e "\n\nTesting other crate-specific builds"
# Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
Expand Down
3 changes: 3 additions & 0 deletions lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ impl CustomOnionMessageHandler for IgnoringMessageHandler {

impl OnionMessageContents for Infallible {
fn tlv_type(&self) -> u64 { unreachable!(); }
#[cfg(c_bindings)]
fn msg_type(&self) -> String { unreachable!(); }
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str { unreachable!(); }
}

Expand Down
13 changes: 13 additions & 0 deletions lightning/src/onion_message/async_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ impl OnionMessageContents for ReleaseHeldHtlc {
fn tlv_type(&self) -> u64 {
RELEASE_HELD_HTLC_TLV_TYPE
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
"Release Held HTLC".to_string()
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
"Release Held HTLC"
}
Expand Down Expand Up @@ -107,6 +112,14 @@ impl OnionMessageContents for AsyncPaymentsMessage {
Self::ReleaseHeldHtlc(msg) => msg.tlv_type(),
}
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
match &self {
Self::HeldHtlcAvailable(_) => "Held HTLC Available".to_string(),
Self::ReleaseHeldHtlc(msg) => msg.msg_type(),
}
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
match &self {
Self::HeldHtlcAvailable(_) => "Held HTLC Available",
Expand Down
10 changes: 10 additions & 0 deletions lightning/src/onion_message/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ impl OnionMessageContents for TestCustomMessage {
TestCustomMessage::Pong => CUSTOM_PONG_MESSAGE_TYPE,
}
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
"Custom Message".to_string()
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
"Custom Message"
}
Expand Down Expand Up @@ -656,6 +661,11 @@ fn invalid_custom_message_type() {
// Onion message contents must have a TLV >= 64.
63
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
"Invalid Message".to_string()
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
"Invalid Message"
}
Expand Down
23 changes: 16 additions & 7 deletions lightning/src/onion_message/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ impl OffersMessage {
_ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
}
}

fn get_msg_type(&self) -> &'static str {
match &self {
OffersMessage::InvoiceRequest(_) => "Invoice Request",
OffersMessage::Invoice(_) => "Invoice",
#[cfg(async_payments)]
OffersMessage::StaticInvoice(_) => "Static Invoice",
OffersMessage::InvoiceError(_) => "Invoice Error",
}
}
}

impl fmt::Debug for OffersMessage {
Expand Down Expand Up @@ -131,14 +141,13 @@ impl OnionMessageContents for OffersMessage {
OffersMessage::InvoiceError(_) => INVOICE_ERROR_TLV_TYPE,
}
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
self.get_msg_type().to_string()
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
match &self {
OffersMessage::InvoiceRequest(_) => "Invoice Request",
OffersMessage::Invoice(_) => "Invoice",
#[cfg(async_payments)]
OffersMessage::StaticInvoice(_) => "Static Invoice",
OffersMessage::InvoiceError(_) => "Invoice Error",
}
self.get_msg_type()
}
}

Expand Down
15 changes: 15 additions & 0 deletions lightning/src/onion_message/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
&ParsedOnionMessageContents::Custom(ref msg) => msg.tlv_type(),
}
}
#[cfg(c_bindings)]
fn msg_type(&self) -> String {
match self {
ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
#[cfg(async_payments)]
ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.msg_type(),
ParsedOnionMessageContents::Custom(ref msg) => msg.msg_type(),
}
}
#[cfg(not(c_bindings))]
fn msg_type(&self) -> &'static str {
match self {
ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
Expand All @@ -174,6 +184,11 @@ pub trait OnionMessageContents: Writeable + core::fmt::Debug {
/// Returns the TLV type identifying the message contents. MUST be >= 64.
fn tlv_type(&self) -> u64;

#[cfg(c_bindings)]
/// Returns the message type
fn msg_type(&self) -> String;

#[cfg(not(c_bindings))]
/// Returns the message type
fn msg_type(&self) -> &'static str;
}
Expand Down
Loading