Skip to content

Commit

Permalink
WIP on channel creation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 28, 2020
1 parent da68272 commit 6f12d8f
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 66 deletions.
11 changes: 3 additions & 8 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ shellexpand = "~2.0.0"
configure_me_codegen = "~0.3.14"

[patch.crates-io]
# Use this for Android builds
# Remove this once https://github.com/jean-airoldie/zeromq-src-rs/pull/15 got merged
zeromq-src = { git = "https://github.com/LNP-BP/zeromq-src-rs", branch = "fix/cmake" }
# zeromq-src = { git = "https://github.com/LNP-BP/zeromq-src-rs", branch = "fix/cmake" }

# Recommended set of features:
# 1. Standalone node: `server` (=`node`+`shell`)
Expand Down
13 changes: 8 additions & 5 deletions src/channeld/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use core::convert::TryInto;

use lnpbp::bitcoin::secp256k1;
use lnpbp::lnp::transport::zmqsocket;
use lnpbp::lnp::{message, ChannelId, Messages, TypedEnum};
use lnpbp_services::esb;
use lnpbp_services::node::TryService;
Expand All @@ -26,7 +27,7 @@ use crate::{Config, DaemonId, Error};
pub fn run(config: Config, channel_id: ChannelId) -> Result<(), Error> {
debug!("Staring RPC service runtime");
let runtime = Runtime {};
let rpc = esb::Controller::init(
let mut rpc = esb::Controller::init(
DaemonId::Channel(channel_id),
map! {
Endpoints::Msg => rpc::EndpointCarrier::Address(
Expand All @@ -39,8 +40,10 @@ pub fn run(config: Config, channel_id: ChannelId) -> Result<(), Error> {
)
},
runtime,
zmqsocket::ApiType::EsbClient,
)?;
info!("channeld started");
rpc.send_to(Endpoints::Ctl, DaemonId::Lnpd, Request::Connect)?;
rpc.run_or_panic("channeld");
unreachable!()
}
Expand Down Expand Up @@ -73,10 +76,10 @@ impl Runtime {
fn handle_rpc_msg(
&mut self,
_senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("MSG RPC request: {}", request);
debug!("MSG RPC request from {}: {}", source, request);
match request {
Request::LnpwpMessage(_) => {
// Ignore the rest of LN peer messages
Expand All @@ -98,10 +101,10 @@ impl Runtime {
fn handle_rpc_ctl(
&mut self,
senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("CTL RPC request: {}", request);
debug!("CTL RPC request from {}: {}", source, request);
match request {
Request::CreateChannel(request::CreateChannel {
channel_req,
Expand Down
2 changes: 2 additions & 0 deletions src/cli/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use core::convert::TryInto;
use url::Url;

use lnpbp::lnp::transport::zmqsocket;
use lnpbp_services::esb;
use lnpbp_services::rpc::EndpointCarrier;

Expand All @@ -41,6 +42,7 @@ impl Runtime {

},
Handler,
zmqsocket::ApiType::EsbClient,
)?;

Ok(Self { client })
Expand Down
14 changes: 9 additions & 5 deletions src/connectiond/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ pub fn run(

debug!("Starting listening thread for messages from the remote peer");
let processor = Processor {
bridge: session::Raw::from_pair_socket(zmqsocket::ApiType::Esb, tx),
bridge: session::Raw::from_pair_socket(
zmqsocket::ApiType::EsbService,
tx,
),
};
let listener = peer::Listener::with(receiver, processor);
spawn(move || listener.run_or_panic("connectiond-listener"));
Expand All @@ -77,6 +80,7 @@ pub fn run(
Endpoints::Bridge => rpc::EndpointCarrier::Socket(rx)
},
runtime,
zmqsocket::ApiType::EsbService,
)?;

info!("connectiond started");
Expand Down Expand Up @@ -157,10 +161,10 @@ impl Runtime {
fn handle_rpc_msg(
&mut self,
_senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("MSG RPC request: {}", request);
debug!("MSG RPC request from {}: {}", source, request);
match request {
Request::LnpwpMessage(message) => {
// 1. Check permissions
Expand All @@ -185,10 +189,10 @@ impl Runtime {
fn handle_rpc_ctl(
&mut self,
_senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("CTL RPC request: {}", request);
debug!("CTL RPC request from {}: {}", source, request);
match request {
/* TODO: Move to connection initialization
Request::InitConnection => {
Expand Down
6 changes: 3 additions & 3 deletions src/daemon_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use lnpbp::lnp::NodeEndpoint;
use lnpbp::strict_encoding::{self, StrictDecode, StrictEncode};

/// Identifiers of daemons participating in LNP Node
#[derive(Clone, PartialEq, Eq, Debug, Display)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, Display)]
pub enum DaemonId {
#[display("lnpd")]
Lnpd,
Expand All @@ -47,8 +47,8 @@ impl AsRef<[u8]> for DaemonId {
DaemonId::Lnpd => "lnpd".as_bytes(),
DaemonId::Gossip => "gossipd".as_bytes(),
DaemonId::Routing => "routed".as_bytes(),
DaemonId::Connection(endpoint) => endpoint.as_ref(),
DaemonId::Channel(channel_id) => channel_id.as_ref(),
DaemonId::Connection(_endpoint) => "connection".as_bytes(), /* endpoint.as_ref(), */
DaemonId::Channel(_channel_id) => "channel".as_bytes(), /* channel_id.as_ref(), */
DaemonId::Foreign(name) => name.as_bytes(),
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// along with this software.
// If not, see <https://opensource.org/licenses/MIT>.

use std::io;

#[cfg(any(feature = "node", feature = "client"))]
use lnpbp::lnp::TypeId;
use lnpbp::lnp::{presentation, transport};
Expand All @@ -25,6 +27,10 @@ use crate::rpc::Endpoints;
#[display(doc_comments)]
#[non_exhaustive]
pub enum Error {
/// I/O error: {_0:?}
#[from]
Io(io::ErrorKind),

/// ZeroMQ error: {_0}
#[from]
#[cfg(feature = "zmq")]
Expand All @@ -50,10 +56,19 @@ pub enum Error {

/// Peer has misbehaved LN peer protocol rules
Misbehaving,

/// {_0}
Other(String),
}

impl lnpbp_services::error::Error for Error {}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err.kind())
}
}

impl From<presentation::Error> for Error {
fn from(err: presentation::Error) -> Self {
match err {
Expand Down
10 changes: 6 additions & 4 deletions src/gossipd/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use core::convert::TryInto;

use lnpbp::lnp::transport::zmqsocket;
use lnpbp::lnp::TypedEnum;
use lnpbp_services::esb;
use lnpbp_services::node::TryService;
Expand All @@ -38,6 +39,7 @@ pub fn run(config: Config) -> Result<(), Error> {
)
},
runtime,
zmqsocket::ApiType::EsbService,
)?;
info!("gossipd started");
rpc.run_or_panic("gossipd");
Expand Down Expand Up @@ -72,10 +74,10 @@ impl Runtime {
fn handle_rpc_msg(
&mut self,
_senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("MSG RPC request: {}", request);
debug!("MSG RPC request from {}: {}", source, request);
match request {
Request::LnpwpMessage(_message) => {
// TODO: Process message
Expand All @@ -96,10 +98,10 @@ impl Runtime {
fn handle_rpc_ctl(
&mut self,
_senders: &mut esb::Senders<Endpoints>,
_source: DaemonId,
source: DaemonId,
request: Request,
) -> Result<(), Error> {
debug!("CTL RPC request: {}", request);
debug!("CTL RPC request from {}: {}", source, request);
match request {
_ => {
error!("Request is not supported by the CTL interface");
Expand Down
Loading

0 comments on commit 6f12d8f

Please sign in to comment.