-
Notifications
You must be signed in to change notification settings - Fork 419
Implement DisconnectPeer event + test #43
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// This file is auto-generated by gen_target.sh based on msg_target_template.txt | ||
// To modify it, modify msg_target_template.txt and run gen_target.sh instead. | ||
|
||
extern crate lightning; | ||
|
||
use lightning::ln::msgs; | ||
use lightning::util::reset_rng_state; | ||
|
||
use lightning::ln::msgs::{MsgEncodable, MsgDecodable}; | ||
|
||
mod utils; | ||
|
||
#[inline] | ||
pub fn do_test(data: &[u8]) { | ||
reset_rng_state(); | ||
test_msg!(msgs::ErrorMessage, data); | ||
} | ||
|
||
#[cfg(feature = "afl")] | ||
extern crate afl; | ||
#[cfg(feature = "afl")] | ||
fn main() { | ||
afl::read_stdio_bytes(|data| { | ||
do_test(&data); | ||
}); | ||
} | ||
|
||
#[cfg(feature = "honggfuzz")] | ||
#[macro_use] extern crate honggfuzz; | ||
#[cfg(feature = "honggfuzz")] | ||
fn main() { | ||
loop { | ||
fuzz!(|data| { | ||
do_test(data); | ||
}); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use utils::extend_vec_from_hex; | ||
#[test] | ||
fn duplicate_crash() { | ||
let mut a = Vec::new(); | ||
extend_vec_from_hex("00", &mut a); | ||
super::do_test(&a); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,11 @@ pub struct Init { | |
pub local_features: LocalFeatures, | ||
} | ||
|
||
pub struct ErrorMessage { | ||
pub channel_id: [u8; 32], | ||
pub data: String, | ||
} | ||
|
||
pub struct Ping { | ||
pub ponglen: u16, | ||
pub byteslen: u16, | ||
|
@@ -375,6 +380,10 @@ pub enum ErrorAction { | |
DisconnectPeer, | ||
/// The peer did something harmless that we weren't able to process, just log and ignore | ||
IgnoreError, | ||
/// The peer did something incorrect. Tell them. | ||
SendErrorMessage { | ||
msg: ErrorMessage | ||
}, | ||
} | ||
|
||
pub struct HandleError { //TODO: rename me | ||
|
@@ -1562,3 +1571,35 @@ impl MsgEncodable for OnionErrorPacket { | |
res | ||
} | ||
} | ||
|
||
impl MsgEncodable for ErrorMessage { | ||
fn encode(&self) -> Vec<u8> { | ||
let mut res = Vec::with_capacity(34 + self.data.len()); | ||
res.extend_from_slice(&self.channel_id); | ||
res.extend_from_slice(&byte_utils::be16_to_array(self.data.len() as u16)); | ||
res.extend_from_slice(&self.data.as_bytes()); | ||
res | ||
} | ||
} | ||
|
||
impl MsgDecodable for ErrorMessage { | ||
fn decode(v: &[u8]) -> Result<Self,DecodeError> { | ||
if v.len() < 34 { | ||
return Err(DecodeError::WrongLength); | ||
} | ||
let len = byte_utils::slice_to_be16(&v[33..34]); | ||
let mut data = String::new(); | ||
if len > 0 { | ||
data = String::from_utf8(v[35..len as usize].to_vec()).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unwrap() here can panic if the message contains non-utf-8 crap. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, some of the indexing is off in the decoder here. |
||
if len != data.len() as u16 { | ||
return Err(DecodeError::WrongLength); | ||
} | ||
} | ||
let mut channel_id = [0; 32]; | ||
channel_id[..].copy_from_slice(&v[0..32]); | ||
Ok(Self { | ||
channel_id, | ||
data: data, | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a TODO for MsgDecodable for ErrorMessage? We should obviously also support receiving them.