Skip to content

(3/4) Conduit fixups from 494 #693

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
244faa7
Squash changes from 494 into a single commit
julianknutsen Sep 15, 2020
ba37213
Fix compilation bug in 494.
julianknutsen Sep 15, 2020
98bc0da
tests: Add unit tests to handshake/mod.rs
julianknutsen Aug 16, 2020
52da509
delete: Remove duplicate tests
julianknutsen Aug 17, 2020
bfe6c4c
refactor: Create enum-dispatch NOISE state machine
julianknutsen Aug 17, 2020
c154f09
refactor: Use new state machine in PeerHandshake
julianknutsen Aug 19, 2020
9445fea
refactor: Move helper functions to the states.rs
julianknutsen Aug 19, 2020
a0d6690
refactor: Structure initialize_state based on RFC
julianknutsen Aug 19, 2020
a68af2d
refactor: Structure calculate_act_message based on RFC
julianknutsen Aug 19, 2020
abf9241
refactor: Structure process_act_message based on RFC
julianknutsen Aug 20, 2020
3eb3146
refactor: Structure creation of Act3 based on RFC
julianknutsen Aug 20, 2020
dbd1a21
refactor: Structure receiving of Act3 data based on RFC
julianknutsen Aug 20, 2020
c88535a
refactor: Inline single use constructors
julianknutsen Aug 20, 2020
41a8ac0
refactor: Pull public key generation to the initial states
julianknutsen Aug 20, 2020
8f17345
refactor: Remove HandshakeHash wrapper struct
julianknutsen Aug 20, 2020
988e767
refactor: Combine duplicate code path for act1 and act2
julianknutsen Aug 20, 2020
1e81642
refactor: Introduce ChainingKey type alias
julianknutsen Aug 20, 2020
de5a2e8
refactor: Remove Act object
julianknutsen Aug 20, 2020
e0a1e71
refactor: Remove get_remote_pubkey interface
julianknutsen Aug 20, 2020
2f67eed
refactor: Clean up process_peer_data
julianknutsen Aug 20, 2020
ab4ff64
refactor: Doc and variable name cleanup in handshake/mod.rs
julianknutsen Aug 20, 2020
f29936b
tests: Finish testing handshake/mod.rs
julianknutsen Aug 20, 2020
ab277b4
refactor: Clean up use of Sha256 in states.rs
julianknutsen Aug 20, 2020
57f95fe
refactor: Clean up hkdf::derive and add test
julianknutsen Aug 22, 2020
ea0ff51
refactor: Rename Handshake2 and related structs/enums
julianknutsen Aug 20, 2020
816a83c
refactor: Clean up visibility/imports in handshake/
julianknutsen Aug 20, 2020
9c5a4b7
tests: Leverage RFC test vectors in unit tests
julianknutsen Aug 21, 2020
3ae7604
refactor: Simplify logic for init message sending
julianknutsen Aug 21, 2020
afd0334
refactor: Clean up unused variable warnings
julianknutsen Aug 21, 2020
ab2258c
refactor: Hide empty next() requirement inside PeerHandshake
julianknutsen Aug 21, 2020
cc5cc9a
refactor: Remove unnecessary copy_from_slice calls in states.rs
julianknutsen Aug 24, 2020
b617dfa
tests: Add new fuzz testing for PeerHandshake
julianknutsen Aug 23, 2020
4435b12
delete: Remove peer_channel_encryptor.rs
julianknutsen Aug 23, 2020
a123f5e
fix: Allow partial act messages to be received
julianknutsen Aug 24, 2020
070d19b
fix: Conduit::Decryptor should not panic on decryption failure
julianknutsen Aug 24, 2020
3a43c21
test: Update handshake fuzz test to cover more cases
julianknutsen Aug 24, 2020
ec5803c
review: Split outbound initialization into new()/set_up()
julianknutsen Aug 25, 2020
1189e84
feature: Tighten the constraints for act message sizes
julianknutsen Aug 26, 2020
229c35f
perf: Replace Vec w/ static arrays for act buffers
julianknutsen Aug 26, 2020
753b517
perf: Remove Vec from chacha::encrypt/decrypt
julianknutsen Aug 26, 2020
a7a25ca
review: Non-controversial renames, nits, small fixups
julianknutsen Sep 2, 2020
b8136be
review: rename hkdf -> hkdf5869rfc.rs
julianknutsen Sep 2, 2020
8c6da10
review: Explicitly set version in Act creation
julianknutsen Sep 2, 2020
19a0f42
review: ActBuilder::fill() returns the number of bytes consumed
julianknutsen Sep 2, 2020
30286c0
docs: Add license to new peers/ files
julianknutsen Sep 18, 2020
e4b8a59
refactor: Abstract SocketDescriptor writing queue
julianknutsen Sep 1, 2020
bf9edf3
review: Move IHandshakeState code move to separate patch
julianknutsen Sep 16, 2020
8bdb638
refactor: Abstract Transport layer and test it
julianknutsen Sep 4, 2020
62789ff
rename: s/is_ready_for_encryption/is_connected/g
julianknutsen Sep 1, 2020
d595445
refactor: Move drain_messages() behind Transport
julianknutsen Sep 1, 2020
22d3db2
refactor: remove duplicate assert
julianknutsen Aug 31, 2020
05dc443
refactor: Move all enqueue logging to Transport
julianknutsen Sep 1, 2020
a672649
refactor: Make Transport the source of their_node_id
julianknutsen Sep 4, 2020
ec07cbc
tests: Add unit tests for PeerManager
julianknutsen Sep 4, 2020
3218522
refactor: Destructure read_event() path
julianknutsen Sep 5, 2020
b1ae365
fix: Fix reentrancy bug in read_event()
julianknutsen Sep 5, 2020
8ac0737
refactor: Continue constricting interfaces in message queue path
julianknutsen Sep 16, 2020
9de58d8
review: Move PayloadQueuer trait move to a separate commit
julianknutsen Sep 16, 2020
3a9eb14
refactor: Clean up event handling path w.r.t connected state
julianknutsen Sep 6, 2020
13b762b
refactor: Introduce PostInitState
julianknutsen Sep 7, 2020
c44d42b
fix: Don't allow peer_disconnect before peer_connected callbacks
julianknutsen Sep 8, 2020
a5acccd
refactor: Clean up the previously destructured read_event() path
julianknutsen Sep 8, 2020
0359955
refactor: Remove scoping from do_read_event()
julianknutsen Sep 8, 2020
51a3460
refactor: Clean up the PeerHolder access/iteration/remove
julianknutsen Sep 8, 2020
e5d6c2f
fix: Handle Ok(false) from route_handler callbacks in event path
julianknutsen Sep 8, 2020
e316138
fix: Use a separate lock for the ephemeral_key_midstate
julianknutsen Sep 8, 2020
8d5611c
rename: s/pending_outbound_buffer/outbound_queue/
julianknutsen Sep 8, 2020
b618350
Remove peers_needing_send set
julianknutsen Sep 10, 2020
4aababb
review: Small nits, documentation, and fixups
julianknutsen Sep 16, 2020
93a70ce
review: Catch duplicate connection after NOISE before INIT
julianknutsen Sep 17, 2020
e5268bb
review: Remove legacy (local/global) feature flag notation
julianknutsen Sep 17, 2020
bf76e7c
review: Collapse OutboundQueue/Transport traits
julianknutsen Oct 2, 2020
3ab11f2
Move Conduit decryption into read()
julianknutsen Sep 4, 2020
2b8d24d
perf: Decryptor can now read from input slice when appropriate
julianknutsen Sep 8, 2020
d5573ed
refactor: Use a real struct instead of conduit_and_remote_pubkey tuple
julianknutsen Sep 9, 2020
51da20d
refactor: Make Conduit a simple wrapper
julianknutsen Sep 9, 2020
59728dc
refactor: Remove Conduit object
julianknutsen Sep 9, 2020
f4c76a9
refactor: Rename conduit.rs and clean up remaining references
julianknutsen Sep 9, 2020
62820fe
fix: Don't panic during valid decryption states
julianknutsen Sep 16, 2020
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: 10 additions & 10 deletions fuzz/src/full_stack.rs

Large diffs are not rendered by default.

550 changes: 492 additions & 58 deletions fuzz/src/peer_crypt.rs

Large diffs are not rendered by default.

41 changes: 22 additions & 19 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! type ChainFilter = dyn lightning::chain::Filter;
//! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::chain::keysinterface::InMemoryChannelKeys, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>>;
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>;
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>;
//! type PeerManager = lightning::ln::peers::handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, ChainAccess, Logger>;
//!
//! // Connect to node with pubkey their_node_id at addr:
//! async fn connect_to_node(peer_manager: PeerManager, chain_monitor: Arc<ChainMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) {
Expand Down Expand Up @@ -78,8 +78,8 @@ use tokio::{io, time};
use tokio::sync::mpsc;
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};

use lightning::ln::peer_handler;
use lightning::ln::peer_handler::SocketDescriptor as LnSocketTrait;
use lightning::ln::peers::handler;
use lightning::ln::peers::handler::SocketDescriptor as LnSocketTrait;
use lightning::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
use lightning::util::logger::Logger;

Expand Down Expand Up @@ -134,7 +134,7 @@ impl Connection {
_ => panic!()
}
}
async fn schedule_read<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) where
async fn schedule_read<CMH, RMH, L>(peer_manager: Arc<handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, us: Arc<Mutex<Self>>, mut reader: io::ReadHalf<TcpStream>, mut read_wake_receiver: mpsc::Receiver<()>, mut write_avail_receiver: mpsc::Receiver<()>) where
CMH: ChannelMessageHandler + 'static,
RMH: RoutingMessageHandler + 'static,
L: Logger + 'static + ?Sized {
Expand Down Expand Up @@ -190,17 +190,20 @@ impl Connection {
Ok(len) => {
prepare_read_write_call!();
let read_res = peer_manager.read_event(&mut our_descriptor, &buf[0..len]);
let mut us_lock = us.lock().unwrap();
match read_res {
Ok(pause_read) => {
if pause_read {
us_lock.read_paused = true;
}
Self::event_trigger(&mut us_lock);
},
Err(e) => shutdown_socket!(e, Disconnect::CloseConnection),
{
let mut us_lock = us.lock().unwrap();
match read_res {
Ok(pause_read) => {
if pause_read {
us_lock.read_paused = true;
}
Self::event_trigger(&mut us_lock);
},
Err(e) => shutdown_socket!(e, Disconnect::CloseConnection),
}
us_lock.block_disconnect_socket = false;
}
us_lock.block_disconnect_socket = false;
peer_manager.process_events();
},
Err(e) => shutdown_socket!(e, Disconnect::PeerDisconnected),
},
Expand Down Expand Up @@ -247,7 +250,7 @@ impl Connection {
/// not need to poll the provided future in order to make progress.
///
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
pub fn setup_inbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> where
pub fn setup_inbound<CMH, RMH, L>(peer_manager: Arc<handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, stream: TcpStream) -> impl std::future::Future<Output=()> where
CMH: ChannelMessageHandler + 'static,
RMH: RoutingMessageHandler + 'static,
L: Logger + 'static + ?Sized {
Expand Down Expand Up @@ -289,7 +292,7 @@ pub fn setup_inbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<So
/// not need to poll the provided future in order to make progress.
///
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
pub fn setup_outbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> where
pub fn setup_outbound<CMH, RMH, L>(peer_manager: Arc<handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, stream: TcpStream) -> impl std::future::Future<Output=()> where
CMH: ChannelMessageHandler + 'static,
RMH: RoutingMessageHandler + 'static,
L: Logger + 'static + ?Sized {
Expand Down Expand Up @@ -361,7 +364,7 @@ pub fn setup_outbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<S
/// make progress.
///
/// See the module-level documentation for how to handle the event_notify mpsc::Sender.
pub async fn connect_outbound<CMH, RMH, L>(peer_manager: Arc<peer_handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> where
pub async fn connect_outbound<CMH, RMH, L>(peer_manager: Arc<handler::PeerManager<SocketDescriptor, Arc<CMH>, Arc<RMH>, Arc<L>>>, event_notify: mpsc::Sender<()>, their_node_id: PublicKey, addr: SocketAddr) -> Option<impl std::future::Future<Output=()>> where
CMH: ChannelMessageHandler + 'static,
RMH: RoutingMessageHandler + 'static,
L: Logger + 'static + ?Sized {
Expand Down Expand Up @@ -412,7 +415,7 @@ impl SocketDescriptor {
Self { conn, id }
}
}
impl peer_handler::SocketDescriptor for SocketDescriptor {
impl handler::SocketDescriptor for SocketDescriptor {
fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize {
// To send data, we take a lock on our Connection to access the WriteHalf of the TcpStream,
// writing to it if there's room in the kernel buffer, or otherwise create a new Waker with
Expand Down Expand Up @@ -504,7 +507,7 @@ impl Hash for SocketDescriptor {
mod tests {
use lightning::ln::features::*;
use lightning::ln::msgs::*;
use lightning::ln::peer_handler::{MessageHandler, PeerManager};
use lightning::ln::peers::handler::{MessageHandler, PeerManager};
use lightning::util::events::*;
use bitcoin::secp256k1::{Secp256k1, SecretKey, PublicKey};

Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ impl<T: sealed::StaticRemoteKey> Features<T> {
pub(crate) fn requires_static_remote_key(&self) -> bool {
<T as sealed::StaticRemoteKey>::requires_feature(&self.flags)
}
#[cfg(test)]
pub(crate) fn clear_requires_static_remote_key(&mut self) {
<T as sealed::StaticRemoteKey>::clear_bits(&mut self.flags)
}
}

impl<T: sealed::InitialRoutingSync> Features<T> {
Expand Down
8 changes: 1 addition & 7 deletions lightning/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@

pub mod channelmanager;
pub mod msgs;
pub mod peer_handler;
pub mod peers;
pub mod chan_utils;
pub mod features;
pub(crate) mod onchaintx;

#[cfg(feature = "fuzztarget")]
pub mod peer_channel_encryptor;
#[cfg(not(feature = "fuzztarget"))]
pub(crate) mod peer_channel_encryptor;

mod channel;
mod onion_utils;
mod wire;
Expand All @@ -53,4 +48,3 @@ mod reorg_tests;
#[allow(unused_mut)]
mod onion_route_tests;

pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
1 change: 1 addition & 0 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ pub enum ErrorAction {
}

/// An Err type for failure to process messages.
#[derive(Clone)]
pub struct LightningError {
/// A human-readable message describing the error
pub err: String,
Expand Down
Loading