Skip to content

(4/4) Merge upstream/master #694

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
wants to merge 104 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
eb6a371
build scaffold for handshake module substitution support
arik-so Feb 12, 2020
b71b7ea
change peer_handler.rs to use modular handshake and encryption handle…
arik-so Feb 12, 2020
92eac9b
make ephemeral private key explicit for handshake (todo: remove it fr…
arik-so Feb 12, 2020
986f25f
remove import of rand
arik-so Feb 12, 2020
ffbf5ec
make linter complain less about docs
arik-so Feb 12, 2020
19b7700
allocate act messages without vector prevarication
arik-so Feb 13, 2020
17fda75
reduce vector allocations for message encryption
arik-so Feb 13, 2020
8169b31
address some of Jeff's comments pertaining to message decryption, con…
arik-so Feb 19, 2020
f1002c5
Use type standin for remaining act lengths when parsing. Use the same…
arik-so Feb 19, 2020
f0fc10b
Improve comments and type aliasing for handshake module.
arik-so Feb 20, 2020
eb297f9
Merge branch 'master' into modular_handshake
arik-so Feb 20, 2020
5492717
Merge branch 'master' into modular_handshake
arik-so Feb 20, 2020
256b6f5
Reflect new modular encryption mechanism in tock ping message creation.
arik-so Feb 20, 2020
b4921e9
Elaborate on lightning codec in conduit's decrypt method.
arik-so Feb 21, 2020
299b6f7
Split up conduit unit tests by tested functionality.
arik-so Feb 21, 2020
944177a
Make handshake store the remote public key instead of passing an opti…
arik-so Feb 21, 2020
0fbd895
Panic when attempting invalid state transitions.
arik-so Feb 27, 2020
6cf5a07
Merge branch 'master' into modular_handshake
arik-so Mar 12, 2020
6f4e76a
Group peer handler's connected state checks instead of repeating them…
arik-so Mar 12, 2020
c2227b6
Fix missing init message send upon connection initiation.
arik-so Mar 13, 2020
6bae489
Merge branch 'master' into modular_handshake
arik-so Apr 9, 2020
2df93ca
fix some unit tests
arik-so Apr 9, 2020
eda13bf
Disconnect peer if act message is too short.
arik-so Apr 9, 2020
4e6b25a
Replace unwrapping public keys with handleable errors in handshake mo…
arik-so Apr 9, 2020
f1940e9
Merge branch 'master' into modular_handshake
arik-so Apr 11, 2020
4deb290
Split conduit into encryptor and decryptor components (to allow for b…
arik-so Apr 30, 2020
5e9c350
Fix conduit constructor bugs and revert indentation for message proce…
arik-so Apr 30, 2020
4b4cb98
Merge remote-tracking branch 'upstream/master' into modular_handshake
arik-so Apr 30, 2020
029bb66
Replace hashing and secp256k1 dependencies with components of the bit…
arik-so Apr 30, 2020
54b7464
Restrict conduit borrow scope for compatibility with Rust 1.22.0.
arik-so Apr 30, 2020
fe705a9
Fix lightning-net-tokio peer handler import.
arik-so Apr 30, 2020
be5e2a5
Apply message handling extraction to relocated peer handler.
arik-so Jun 12, 2020
2e4e659
Merge branch 'master' into modular_handshake
arik-so Jun 12, 2020
a4fff76
Fix unit tests
arik-so Jun 13, 2020
bac4bab
tests: Add unit tests to handshake/mod.rs
julianknutsen Aug 16, 2020
65e4340
delete: Remove duplicate tests
julianknutsen Aug 17, 2020
12df425
refactor: Create enum-dispatch NOISE state machine
julianknutsen Aug 17, 2020
55ad1c7
refactor: Use new state machine in PeerHandshake
julianknutsen Aug 19, 2020
6b2db7f
refactor: Move helper functions to the states.rs
julianknutsen Aug 19, 2020
42138cf
refactor: Structure initialize_state based on RFC
julianknutsen Aug 19, 2020
0dfc966
refactor: Structure calculate_act_message based on RFC
julianknutsen Aug 19, 2020
4da51c6
refactor: Structure process_act_message based on RFC
julianknutsen Aug 20, 2020
7051068
refactor: Structure creation of Act3 based on RFC
julianknutsen Aug 20, 2020
2d51b98
refactor: Structure receiving of Act3 data based on RFC
julianknutsen Aug 20, 2020
14d5c22
refactor: Inline single use constructors
julianknutsen Aug 20, 2020
51ecdd0
refactor: Pull public key generation to the initial states
julianknutsen Aug 20, 2020
fadf6f6
refactor: Remove HandshakeHash wrapper struct
julianknutsen Aug 20, 2020
43bfce2
refactor: Combine duplicate code path for act1 and act2
julianknutsen Aug 20, 2020
23c3cc5
refactor: Introduce ChainingKey type alias
julianknutsen Aug 20, 2020
fcb6c96
refactor: Remove Act object
julianknutsen Aug 20, 2020
35bf1cc
refactor: Remove get_remote_pubkey interface
julianknutsen Aug 20, 2020
872bc4e
refactor: Clean up process_peer_data
julianknutsen Aug 20, 2020
c35f1b2
refactor: Doc and variable name cleanup in handshake/mod.rs
julianknutsen Aug 20, 2020
378c17d
tests: Finish testing handshake/mod.rs
julianknutsen Aug 20, 2020
506315d
refactor: Clean up use of Sha256 in states.rs
julianknutsen Aug 20, 2020
155f90e
refactor: Clean up hkdf::derive and add test
julianknutsen Aug 22, 2020
fc4d7ef
refactor: Rename Handshake2 and related structs/enums
julianknutsen Aug 20, 2020
8096367
refactor: Clean up visibility/imports in handshake/
julianknutsen Aug 20, 2020
3755dfb
tests: Leverage RFC test vectors in unit tests
julianknutsen Aug 21, 2020
8d46a1a
refactor: Simplify logic for init message sending
julianknutsen Aug 21, 2020
85f0238
refactor: Clean up unused variable warnings
julianknutsen Aug 21, 2020
faa60f1
refactor: Hide empty next() requirement inside PeerHandshake
julianknutsen Aug 21, 2020
a2828ab
refactor: Remove unnecessary copy_from_slice calls in states.rs
julianknutsen Aug 24, 2020
db6bf0a
tests: Add new fuzz testing for PeerHandshake
julianknutsen Aug 23, 2020
c049519
delete: Remove peer_channel_encryptor.rs
julianknutsen Aug 23, 2020
076a8bf
fix: Allow partial act messages to be received
julianknutsen Aug 24, 2020
e7fbab9
fix: Conduit::Decryptor should not panic on decryption failure
julianknutsen Aug 24, 2020
4f1e6a9
test: Update handshake fuzz test to cover more cases
julianknutsen Aug 24, 2020
4e23b88
review: Split outbound initialization into new()/set_up()
julianknutsen Aug 25, 2020
d7b5f4a
feature: Tighten the constraints for act message sizes
julianknutsen Aug 26, 2020
5f69b6a
perf: Replace Vec w/ static arrays for act buffers
julianknutsen Aug 26, 2020
2843289
perf: Remove Vec from chacha::encrypt/decrypt
julianknutsen Aug 26, 2020
0c528bc
review: Non-controversial renames, nits, small fixups
julianknutsen Sep 2, 2020
1481fe9
review: rename hkdf -> hkdf5869rfc.rs
julianknutsen Sep 2, 2020
206c219
review: Explicitly set version in Act creation
julianknutsen Sep 2, 2020
080f5e3
review: ActBuilder::fill() returns the number of bytes consumed
julianknutsen Sep 2, 2020
ed77a47
refactor: Abstract SocketDescriptor writing queue
julianknutsen Sep 1, 2020
d2ac3f7
refactor: Abstract Transport layer and test it
julianknutsen Sep 4, 2020
96296fc
rename: s/is_ready_for_encryption/is_connected/g
julianknutsen Sep 1, 2020
31bef74
refactor: Move drain_messages() behind Transport
julianknutsen Sep 1, 2020
8904b23
refactor: remove duplicate assert
julianknutsen Aug 31, 2020
f781569
refactor: Move all enqueue logging to Transport
julianknutsen Sep 1, 2020
94721bd
refactor: Make Transport the source of their_node_id
julianknutsen Sep 4, 2020
ada2a7f
tests: Add unit tests for PeerManager
julianknutsen Sep 4, 2020
eadc443
refactor: Destructure read_event() path
julianknutsen Sep 5, 2020
1cca59a
fix: Fix reentrancy bug in read_event()
julianknutsen Sep 5, 2020
75da46b
refactor: Continue constricting interfaces in message queue path
julianknutsen Sep 5, 2020
1cf81e5
refactor: Clean up event handling path w.r.t connected state
julianknutsen Sep 6, 2020
b28cc2a
refactor: Introduce PostInitState
julianknutsen Sep 7, 2020
b395e5f
fix: Don't allow peer_disconnect before peer_connected callbacks
julianknutsen Sep 8, 2020
2a790cc
refactor: Clean up the previously destructured read_event() path
julianknutsen Sep 8, 2020
6e7f4e1
refactor: Remove scoping from do_read_event()
julianknutsen Sep 8, 2020
249c414
refactor: Clean up the PeerHolder access/iteration/remove
julianknutsen Sep 8, 2020
d043d76
fix: Handle Ok(false) from route_handler callbacks in event path
julianknutsen Sep 8, 2020
f4238be
fix: Use a separate lock for the ephemeral_key_midstate
julianknutsen Sep 8, 2020
ab2c8cf
rename: s/pending_outbound_buffer/outbound_queue/
julianknutsen Sep 8, 2020
6be0880
Remove peers_needing_send set
julianknutsen Sep 10, 2020
41c7374
Move Conduit decryption into read()
julianknutsen Sep 4, 2020
810b491
perf: Decryptor can now read from input slice when appropriate
julianknutsen Sep 8, 2020
6b4e8bb
refactor: Use a real struct instead of conduit_and_remote_pubkey tuple
julianknutsen Sep 9, 2020
0ea0979
refactor: Make Conduit a simple wrapper
julianknutsen Sep 9, 2020
57322e7
refactor: Remove Conduit object
julianknutsen Sep 9, 2020
7173215
refactor: Rename conduit.rs and clean up remaining references
julianknutsen Sep 9, 2020
d2859fa
Merge upstream/master
julianknutsen Sep 9, 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.

540 changes: 482 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 @@ -37,7 +37,7 @@
//! type ChainWatchInterface = dyn lightning::chain::chaininterface::ChainWatchInterface;
//! type ChannelMonitor = lightning::ln::channelmonitor::SimpleManyChannelMonitor<lightning::chain::transaction::OutPoint, lightning::chain::keysinterface::InMemoryChannelKeys, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>, Arc<ChainWatchInterface>>;
//! type ChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<ChannelMonitor, TxBroadcaster, FeeEstimator, Logger>;
//! type PeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChannelMonitor, TxBroadcaster, FeeEstimator, ChainWatchInterface, Logger>;
//! type PeerManager = lightning::ln::peers::handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChannelMonitor, TxBroadcaster, FeeEstimator, ChainWatchInterface, Logger>;
//!
//! // Connect to node with pubkey their_node_id at addr:
//! async fn connect_to_node(peer_manager: PeerManager, channel_monitor: Arc<ChannelMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) {
Expand Down Expand Up @@ -77,8 +77,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 @@ -133,7 +133,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 @@ -189,17 +189,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 @@ -246,7 +249,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 @@ -288,7 +291,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 @@ -360,7 +363,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 @@ -411,7 +414,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 @@ -503,7 +506,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
9 changes: 1 addition & 8 deletions lightning/src/ln/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
pub mod channelmanager;
pub mod channelmonitor;
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 @@ -50,5 +45,3 @@ mod functional_tests;
mod chanmon_update_fail_tests;
#[cfg(test)]
mod reorg_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