|
11 | 11 | //! rust-lightning with native TcpStreams.
|
12 | 12 | //!
|
13 | 13 | //! Designed to be as simple as possible, the high-level usage is almost as simple as "hand over a
|
14 |
| -//! TcpStream and a reference to a PeerManager and the rest is handled", except for the |
15 |
| -//! [Event](../lightning/util/events/enum.Event.html) handling mechanism; see example below. |
| 14 | +//! TcpStream and a reference to a PeerManager and the rest is handled". |
16 | 15 | //!
|
17 |
| -//! The PeerHandler, due to the fire-and-forget nature of this logic, must be an Arc, and must use |
18 |
| -//! the SocketDescriptor provided here as the PeerHandler's SocketDescriptor. |
| 16 | +//! The PeerHandler, due to the fire-and-forget nature of this logic, must be a reference, (e.g. an |
| 17 | +//! `Arc`) and must use the SocketDescriptor provided here as the PeerHandler's SocketDescriptor. |
19 | 18 | //!
|
20 | 19 | //! Three methods are exposed to register a new connection for handling in tokio::spawn calls; see
|
21 | 20 | //! their individual docs for details.
|
22 |
| -//! |
23 |
| -//! # Example |
24 |
| -//! ``` |
25 |
| -//! use std::net::TcpStream; |
26 |
| -//! use bitcoin::secp256k1::PublicKey; |
27 |
| -//! use lightning::util::events::{Event, EventHandler, EventsProvider}; |
28 |
| -//! use std::net::SocketAddr; |
29 |
| -//! use std::sync::Arc; |
30 |
| -//! |
31 |
| -//! // Define concrete types for our high-level objects: |
32 |
| -//! type TxBroadcaster = dyn lightning::chain::chaininterface::BroadcasterInterface + Send + Sync; |
33 |
| -//! type FeeEstimator = dyn lightning::chain::chaininterface::FeeEstimator + Send + Sync; |
34 |
| -//! type Logger = dyn lightning::util::logger::Logger + Send + Sync; |
35 |
| -//! type NodeSigner = dyn lightning::chain::keysinterface::NodeSigner + Send + Sync; |
36 |
| -//! type UtxoLookup = dyn lightning::routing::utxo::UtxoLookup + Send + Sync; |
37 |
| -//! type ChainFilter = dyn lightning::chain::Filter + Send + Sync; |
38 |
| -//! type DataPersister = dyn lightning::chain::chainmonitor::Persist<lightning::chain::keysinterface::InMemorySigner> + Send + Sync; |
39 |
| -//! type ChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::chain::keysinterface::InMemorySigner, Arc<ChainFilter>, Arc<TxBroadcaster>, Arc<FeeEstimator>, Arc<Logger>, Arc<DataPersister>>; |
40 |
| -//! type ChannelManager = Arc<lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor, TxBroadcaster, FeeEstimator, Logger>>; |
41 |
| -//! type PeerManager = Arc<lightning::ln::peer_handler::SimpleArcPeerManager<lightning_net_tokio::SocketDescriptor, ChainMonitor, TxBroadcaster, FeeEstimator, UtxoLookup, Logger>>; |
42 |
| -//! |
43 |
| -//! // Connect to node with pubkey their_node_id at addr: |
44 |
| -//! async fn connect_to_node(peer_manager: PeerManager, chain_monitor: Arc<ChainMonitor>, channel_manager: ChannelManager, their_node_id: PublicKey, addr: SocketAddr) { |
45 |
| -//! lightning_net_tokio::connect_outbound(peer_manager, their_node_id, addr).await; |
46 |
| -//! loop { |
47 |
| -//! let event_handler = |event: Event| { |
48 |
| -//! // Handle the event! |
49 |
| -//! }; |
50 |
| -//! channel_manager.await_persistable_update(); |
51 |
| -//! channel_manager.process_pending_events(&event_handler); |
52 |
| -//! chain_monitor.process_pending_events(&event_handler); |
53 |
| -//! } |
54 |
| -//! } |
55 |
| -//! |
56 |
| -//! // Begin reading from a newly accepted socket and talk to the peer: |
57 |
| -//! async fn accept_socket(peer_manager: PeerManager, chain_monitor: Arc<ChainMonitor>, channel_manager: ChannelManager, socket: TcpStream) { |
58 |
| -//! lightning_net_tokio::setup_inbound(peer_manager, socket); |
59 |
| -//! loop { |
60 |
| -//! let event_handler = |event: Event| { |
61 |
| -//! // Handle the event! |
62 |
| -//! }; |
63 |
| -//! channel_manager.await_persistable_update(); |
64 |
| -//! channel_manager.process_pending_events(&event_handler); |
65 |
| -//! chain_monitor.process_pending_events(&event_handler); |
66 |
| -//! } |
67 |
| -//! } |
68 |
| -//! ``` |
69 | 21 |
|
70 | 22 | // Prefix these with `rustdoc::` when we update our MSRV to be >= 1.52 to remove warnings.
|
71 | 23 | #![deny(broken_intra_doc_links)]
|
|
0 commit comments