Skip to content

Commit 5c6751c

Browse files
committed
f cleanup docs a bunch
1 parent 312e617 commit 5c6751c

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub struct MessageHandler<CM: Deref, RM: Deref> where
160160
CM::Target: ChannelMessageHandler,
161161
RM::Target: RoutingMessageHandler {
162162
/// A message handler which handles messages specific to channels. Usually this is just a
163-
/// [`ChannelManager`] object or a [`ErroringMessageHandler`].
163+
/// [`ChannelManager`] object or an [`ErroringMessageHandler`].
164164
///
165165
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
166166
pub chan_handler: CM,
@@ -191,20 +191,22 @@ pub trait SocketDescriptor : cmp::Eq + hash::Hash + Clone {
191191
/// Note that in the disconnected case, [`PeerManager::socket_disconnected`] must still be
192192
/// called and further write attempts may occur until that time.
193193
///
194-
/// If the returned size is smaller than data.len(), a
194+
/// If the returned size is smaller than `data.len()`, a
195195
/// [`PeerManager::write_buffer_space_avail`] call must be made the next time more data can be
196-
/// written. Additionally, until a send_data event completes fully, no further
196+
/// written. Additionally, until a `send_data` event completes fully, no further
197197
/// [`PeerManager::read_event`] calls should be made for the same peer! Because this is to
198198
/// prevent denial-of-service issues, you should not read or buffer any data from the socket
199199
/// until then.
200200
///
201201
/// If a [`PeerManager::read_event`] call on this descriptor had previously returned true
202202
/// (indicating that read events should be paused to prevent DoS in the send buffer),
203-
/// resume_read may be set indicating that read events on this descriptor should resume. A
204-
/// resume_read of false does *not* imply on its own that further read events should be paused.
203+
/// `resume_read` may be set indicating that read events on this descriptor should resume. A
204+
/// `resume_read` of false carries no meaning, and should not cause any action.
205205
fn send_data(&mut self, data: &[u8], resume_read: bool) -> usize;
206206
/// Disconnect the socket pointed to by this SocketDescriptor.
207-
/// No [`PeerManager::socket_disconnected`] call need be generated as a result of this call.
207+
///
208+
/// You do *not* need to call [`PeerManager::socket_disconnected`] with this socket after this
209+
/// call (doing so is a noop).
208210
fn disconnect_socket(&mut self);
209211
}
210212

@@ -319,16 +321,16 @@ pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArc
319321
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, M, T, F, L>, &'e NetGraphMsgHandler<&'g C, &'f L>, &'f L>;
320322

321323
/// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
322-
/// socket events into messages which it passes on to its MessageHandlers.
324+
/// socket events into messages which it passes on to its [`MessageHandler`].
323325
///
324326
/// Locks are taken internally, so you must never assume that reentrancy from a
325327
/// [`SocketDescriptor`] call back into [`PeerManager`] methods will not deadlock.
326328
///
327329
/// Calls to [`read_event`] will decode relevant messages and pass them to the
328330
/// [`ChannelMessageHandler`], likely doing message processing in-line. Thus, the primary form of
329-
/// parallelism in Rust-Lightning is parallelism in calls to [`read_event`]. Note, however, that
330-
/// calls to any [`PeerManager`] functions related to the same connection must occur only in
331-
/// serial, making new calls only after previous ones have returned.
331+
/// parallelism in Rust-Lightning is in calls to [`read_event`]. Note, however, that calls to any
332+
/// [`PeerManager`] functions related to the same connection must occur only in serial, making new
333+
/// calls only after previous ones have returned.
332334
///
333335
/// Rather than using a plain PeerManager, it is preferable to use either a SimpleArcPeerManager
334336
/// a SimpleRefPeerManager, for conciseness. See their documentation for more details, but
@@ -626,11 +628,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
626628
///
627629
/// May return an Err to indicate that the connection should be closed.
628630
///
629-
/// Will most likely call [`send_data`] on the descriptor passed in (or the descriptor handed
630-
/// into new_*\_connection) before returning. Thus, be very careful with reentrancy issues! The
631-
/// invariants around calling [`write_buffer_space_avail`] in case a write did not fully
632-
/// complete must still hold - be ready to call `[write_buffer_space_avail`] again if a write
633-
/// call generated here isn't sufficient!
631+
/// May call [`send_data`] on the descriptor passed in (or another provided descriptor) before
632+
/// returning. Thus, be very careful with reentrancy issues! The invariants around calling
633+
/// [`write_buffer_space_avail`] in case a write did not fully complete must still hold - be
634+
/// ready to call `[write_buffer_space_avail`] again if a write call generated here isnt'
635+
/// sufficient!
634636
///
635637
/// [`send_data`]: SocketDescriptor::send_data
636638
/// [`write_buffer_space_avail`]: PeerManager::write_buffer_space_avail
@@ -656,11 +658,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
656658
/// May return an Err to indicate that the connection should be closed.
657659
///
658660
/// Will *not* call back into [`send_data`] on any descriptors to avoid reentrancy complexity.
659-
/// Thus, however, you almost certainly want to call [`process_events`] after any read_event
660-
/// to generate [`send_data`] calls to handle responses.
661+
/// Thus, however, you should call [`process_events`] after any `read_event` to generate
662+
/// [`send_data`] calls to handle responses.
661663
///
662-
/// If Ok(true) is returned, further read_events should not be triggered until a [`send_data`]
663-
/// call on this descriptor has resume_read set (preventing DoS issues in the send buffer).
664+
/// If `Ok(true)` is returned, further read_events should not be triggered until a
665+
/// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
666+
/// send buffer).
664667
///
665668
/// [`send_data`]: SocketDescriptor::send_data
666669
/// [`process_events`]: PeerManager::process_events
@@ -1113,8 +1116,8 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
11131116
/// response messages as well as messages generated by calls to handler functions directly (eg
11141117
/// functions like [`ChannelManager::process_pending_htlc_forwards`] or [`send_payment`]).
11151118
///
1116-
/// Will most likely call [`send_data`] on descriptors previously provided to
1117-
/// new_*\_connection. Thus, be very careful with reentrancy issues!
1119+
/// May call [`send_data`] on [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1120+
/// issues!
11181121
///
11191122
/// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
11201123
/// [`ChannelManager::process_pending_htlc_forwards`]: crate::ln::channelmanager::ChannelManager::process_pending_htlc_forwards
@@ -1357,7 +1360,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
13571360

13581361
/// Disconnect a peer given its node id.
13591362
///
1360-
/// Set no_connection_possible to true to prevent any further connection with this peer,
1363+
/// Set `no_connection_possible` to true to prevent any further connection with this peer,
13611364
/// force-closing any channels we have with it.
13621365
///
13631366
/// If a peer is connected, this will call [`disconnect_socket`] on the descriptor for the
@@ -1375,10 +1378,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
13751378
}
13761379

13771380
/// This function should be called roughly once every 30 seconds.
1378-
/// It will send pings to each peer and disconnect those which did not respond to the last round of pings.
1381+
/// It will send pings to each peer and disconnect those which did not respond to the last
1382+
/// round of pings.
13791383
///
1380-
/// Will most likely call [`send_data`] all descriptors previously provided to
1381-
/// new_*\_connection. Thus, be very careful with reentrancy issues!
1384+
/// May call [`send_data`] all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
1385+
/// issues!
13821386
///
13831387
/// [`send_data`]: SocketDescriptor::send_data
13841388
pub fn timer_tick_occurred(&self) {

0 commit comments

Comments
 (0)