Skip to content

Commit

Permalink
Merge pull request #128 from LNP-BP/v0.1
Browse files Browse the repository at this point in the history
v0.1 release candidate
  • Loading branch information
dr-orlovsky authored Oct 9, 2020
2 parents f648eab + 8dad7e4 commit 55519da
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 70 deletions.
19 changes: 5 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lnpbp"
version = "0.1.0"
version = "0.1.0-rc.1"
license = "MIT"
authors = ["Dr. Maxim Orlovsky <orlovsky@pandoracore.com>"]
description = "LNP/BP Core Library implementing LNPBP specifications & standards"
Expand Down Expand Up @@ -40,9 +40,8 @@ lnpbp_derive = { path = "derive" }
# ----------------------------------------------------
bitcoin = "~0.25.0"
bitcoin_hashes = "~0.9.0" # we need macro from here
lightning = { version = "~0.0.11", optional = true }
miniscript = "~2.0.0" # TODO: (new) Upgrade to 2.0.0 (requires rebasing
# `develop` branch in miniscript fork
# lightning = { version = "~0.0.11", optional = true }
miniscript = "~2.0.0"
bech32 = "~0.7.2"
# Used only as a part of RGB for encoding Ed25519 key data (for instance as
# a part of Tor address)
Expand Down Expand Up @@ -82,11 +81,11 @@ num-derive = "~0.3.0"
# 3. Once async traits will get to rust compiler, this one will be also not
# needed
async-trait = { version = "~0.1.30", optional = true }
torut = { version = "~0.1.6", features = ["v2", "v3"] }

[dev-dependencies]
miniscript = { version = "~2.0.0", features = ["compiler"] }
bitcoin = { version = "~0.25.0", branch = "develop", features = ["rand"] }
torut = { version = "~0.1.6", features = ["v2", "v3"] }
bitcoin = { version = "~0.25.0", features = ["rand"] }

# Forked dependencies
# -------------------
Expand All @@ -102,11 +101,12 @@ torut = { version = "~0.1.6", features = ["v2", "v3"] }
# NB: These patches MUST be applied in exactly same manner by any library which
# uses this as a dependency
[patch.crates-io]
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", branch = "develop" }
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-beta-4" }
lightning = { git = "https://github.com/LNP-BP/rust-lightning", branch = "develop", optional = true }
# No changes here, just need to import forked `bitcoin` library
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", branch = "develop" }
# We need this b/c of breaking change in tagged hash type generation
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-rc1" }
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", tag = "lnpbp-v0.1.0-rc1" }
# We need custom branches here just to depend on the same bitcoin master and do
# not have secp256k1 version conflict
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", tag = "lnpbp-v0.1.0-rc1" }

# Features
# ========
Expand All @@ -126,7 +126,7 @@ all = [
"tor", "url", "websockets", "vendored_openssl"]
# High-level library components
# -----------------------------
lnp = ["lightning", "async", "zmq"]
lnp = ["async", "zmq"]
rgb = ["bulletproofs", "ed25519-dalek", "deflate", "inflate"]
# Exposing core rust componens
# ----------------------------
Expand All @@ -145,6 +145,6 @@ tor = ["amplify/tor"] # Exposes dependency feature
vendored_openssl = ["torut/vendored_openssl"]

[workspace]
members = ["derive", "."]
default-members = ["derive", "."]
members = [".", "derive"]
default-members = [".", "derive"]
exclude = ["dep_test"]
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ section:
```toml
lnpbp = { git = "https://github.com/lnp-bp/rust-lnpbp.git", branch = "master" }

[patch.crates-io]
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", branch = "develop" }
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-beta-4" }
lightning = { git = "https://github.com/LNP-BP/rust-lightning", branch = "develop", optional = true }
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", branch = "develop" }
# TODO: (new) remove them before 1.0 release
amplify = { git = "https://github.com/LNP-BP/rust-amplify", branch = "develop" }
torut = { git = "https://github.com/LNP-BP/torut", branch = "develop" }
# We need this b/c of breaking change in tagged hash type generation
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-rc1" }
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", tag = "lnpbp-v0.1.0-rc1" }
# We need custom branches here just to depend on the same bitcoin master and do
# not have secp256k1 version conflict
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", tag = "lnpbp-v0.1.0-rc1" }
```
NB: These patches MUST be applied in exactly same manner by any library which
uses LNP/BP Core library as a dependency for now
Expand Down
13 changes: 6 additions & 7 deletions contrib/depCargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
lnpbp = { path = "..", features = ["all"] }

[patch.crates-io]
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", branch = "develop" }
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-beta-4" }
lightning = { git = "https://github.com/LNP-BP/rust-lightning", branch = "develop", optional = true }
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", branch = "develop" }
# TODO: (new) remove them before 1.0 release
amplify = { git = "https://github.com/LNP-BP/rust-amplify", branch = "develop" }
torut = { git = "https://github.com/LNP-BP/torut", branch = "develop" }
# We need this b/c of breaking change in tagged hash type generation
bitcoin_hashes = { git = "https://github.com/LNP-BP/bitcoin_hashes", tag = "lnpbp-v0.1.0-rc1" }
bitcoin = { git = "https://github.com/LNP-BP/rust-bitcoin", tag = "lnpbp-v0.1.0-rc1" }
# We need custom branches here just to depend on the same bitcoin master and do
# not have secp256k1 version conflict
miniscript = { git = "https://github.com/LNP-BP/rust-miniscript", tag = "lnpbp-v0.1.0-rc1" }

[workspace]
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lnpbp_derive"
version = "0.1.0"
version = "0.1.0-rc.1"
license = "MIT"
authors = ["Dr. Maxim Orlovsky <orlovsky@pandoracore.com>"]
description = "LNP/BP Core Library derive macros"
Expand Down
10 changes: 10 additions & 0 deletions src/lnp/application/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ pub struct PeerOutput {
}

impl Peer {
#[cfg(feature = "lightning")]
pub async fn new_outbound(
node: NodeAddr,
private_key: &secp256k1::SecretKey,
ephemeral_private_key: &secp256k1::SecretKey,
) -> Result<Self, ConnectionError> {
unimplemented!()
}

#[cfg(not(feature = "lightning"))]
pub async fn new_outbound(
node: NodeAddr,
private_key: &secp256k1::SecretKey,
Expand Down
2 changes: 1 addition & 1 deletion src/lnp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ pub use session::{
};
pub use transport::{tcp, tor, websocket, zmq};

pub use lightning::ln::peers::encryption::LN_MAX_MSG_LEN as LNP_MSG_MAX_LEN;
pub const LNP_MSG_MAX_LEN: usize = u64::MAX as usize;

pub const LIGHTNING_P2P_DEFAULT_PORT: u16 = 9735;
4 changes: 4 additions & 0 deletions src/lnp/presentation/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// If not, see <https://opensource.org/licenses/MIT>.

use crate::strict_encoding;

#[cfg(feature = "lightning")]
use lightning::ln::msgs::DecodeError;

#[derive(Clone, PartialEq, Eq, Debug, Display, Error, From)]
#[display(Debug)]
#[non_exhaustive]
pub enum Error {
#[from(std::io::Error)]
Io,
Expand All @@ -35,6 +38,7 @@ pub enum Error {
TlvRecordInvalidLen,
}

#[cfg(feature = "lightning")]
impl From<DecodeError> for Error {
fn from(err: DecodeError) -> Self {
match err {
Expand Down
5 changes: 2 additions & 3 deletions src/lnp/presentation/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use super::tlv;
use super::{
Encode, Error, EvenOdd, UnknownTypeError, Unmarshall, UnmarshallFn,
};
use crate::lnp::presentation::tlv::Stream;
use crate::strict_encoding::{StrictDecode, StrictEncode};

wrapper!(
Expand Down Expand Up @@ -80,8 +79,8 @@ impl Message for RawMessage {
Payload(vec![Arc::new(self.payload.clone())])
}

fn get_tlvs(&self) -> Stream {
Stream::new()
fn get_tlvs(&self) -> tlv::Stream {
tlv::Stream::new()
}
}

Expand Down
27 changes: 24 additions & 3 deletions src/lnp/presentation/tlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use std::collections::BTreeMap;
use std::io;
use std::sync::Arc;

use lightning::util::ser::{BigSize, Readable};
#[cfg(feature = "lightning")]
use lightning::{
ln::msgs::DecodeError,
util::ser::{BigSize, Readable},
};

use super::{Error, EvenOdd, Unmarshall, UnmarshallFn};
use crate::lnp::LNP_MSG_MAX_LEN;
use lightning::ln::msgs::DecodeError;

wrapper!(
Type,
Expand Down Expand Up @@ -73,6 +75,17 @@ impl Unmarshall for Unmarshaller {
type Data = Stream;
type Error = Error;

// TODO: (v0.2.0) Right now TLV implementation uses BigInt from lightning
// library. It has to be re-implemented in order to get TLVs working
#[cfg(not(feature = "lightning"))]
fn unmarshall(
&self,
data: &dyn Borrow<[u8]>,
) -> Result<Stream, Self::Error> {
unimplemented!()
}

#[cfg(feature = "lightning")]
fn unmarshall(
&self,
data: &dyn Borrow<[u8]>,
Expand Down Expand Up @@ -151,6 +164,14 @@ impl Unmarshaller {
}
}

// TODO: (v0.2.0) Right now TLV implementation uses BigInt from lightning
// library. It has to be re-implemented in order to get TLVs working
#[cfg(not(feature = "lightning"))]
fn raw_parser(reader: &mut dyn io::Read) -> Result<Arc<dyn Any>, Error> {
unimplemented!()
}

#[cfg(feature = "lightning")]
fn raw_parser(
mut reader: &mut dyn io::Read,
) -> Result<Arc<dyn Any>, Error> {
Expand Down
31 changes: 15 additions & 16 deletions src/lnp/session/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,27 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use std::convert::TryInto;
use std::io;
use std::net::SocketAddr;

#[cfg(feature = "tokio")]
#[cfg(all(feature = "tokio", feature = "lightning"))]
use tokio::io::AsyncReadExt;
#[cfg(feature = "tokio")]
#[cfg(all(feature = "tokio", feature = "lightning"))]
use tokio::io::AsyncWriteExt;
#[cfg(feature = "tokio")]
#[cfg(all(feature = "tokio"))]
use tokio::net::{tcp, TcpStream};

#[cfg(not(feature = "tokio"))]
use std::io::{Read as IoRead, Write as IoWrite};
#[cfg(not(feature = "tokio"))]
use std::net::TcpStream;

use bitcoin::secp256k1;

#[cfg(feature = "tokio")]
#[cfg(all(feature = "tokio", feature = "lightning"))]
use lightning::ln::peers::encryption::{Decryptor, Encryptor};
use lightning::ln::peers::handshake::CompletedHandshakeInfo as Transcoder;
use lightning::ln::peers::handshake::PeerHandshake;
use lightning::ln::peers::transport::IPeerHandshake;

use super::NodeAddr;
use super::MAX_TRANSPORT_FRAME_SIZE;
//use crate::lnp::transport::{Read, Write};
#[cfg(feature = "lightning")]
use lightning::ln::peers::{
handshake::{CompletedHandshakeInfo as Transcoder, PeerHandshake},
transport::IPeerHandshake,
};

#[derive(Debug, Display)]
#[display(Debug)]
Expand All @@ -56,25 +50,28 @@ impl From<io::Error> for ConnectionError {
pub struct Connection {
pub stream: TcpStream,
pub outbound: bool,
#[allow(dead_code)]
#[cfg(feature = "lightning")]
transcoder: Transcoder,
}

#[cfg(feature = "tokio")]
pub struct ConnectionInput {
pub istream: tcp::OwnedReadHalf,
pub outbound: bool,
#[cfg(feature = "lightning")]
pub decryptor: Decryptor,
}

#[cfg(feature = "tokio")]
pub struct ConnectionOutput {
pub ostream: tcp::OwnedWriteHalf,
pub outbound: bool,
#[cfg(feature = "lightning")]
pub encryptor: Encryptor,
}

impl Connection {
#[cfg(feature = "lightning")]
pub async fn new(
node: &NodeAddr,
private_key: &secp256k1::SecretKey,
Expand Down Expand Up @@ -183,11 +180,13 @@ impl Connection {
ConnectionInput {
istream,
outbound: self.outbound,
#[cfg(feature = "lightning")]
decryptor: self.transcoder.decryptor,
},
ConnectionOutput {
ostream,
outbound: self.outbound,
#[cfg(feature = "lightning")]
encryptor: self.transcoder.encryptor,
},
)
Expand Down
Loading

0 comments on commit 55519da

Please sign in to comment.