Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 5c7c78d

Browse files
do not expose list protocols
1 parent 83381aa commit 5c7c78d

File tree

4 files changed

+6
-108
lines changed

4 files changed

+6
-108
lines changed

src/events.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
2020

2121
mod channel_request;
22-
pub mod events;
2322
mod jit_channel;
2423
mod transport;
2524
mod utils;

src/transport/message_handler.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::events::Event;
21
use crate::transport::msgs::{LSPSMessage, RawLSPSMessage, LSPS_MESSAGE_TYPE};
32
use crate::transport::protocol::LSPS0MessageHandler;
43

@@ -43,7 +42,6 @@ where
4342
ES::Target: EntropySource,
4443
{
4544
pending_messages: Arc<Mutex<Vec<(PublicKey, LSPSMessage)>>>,
46-
pending_events: Arc<Mutex<Vec<Event>>>,
4745
request_id_to_method_map: Mutex<HashMap<String, String>>,
4846
lsps0_message_handler: LSPS0MessageHandler<ES>,
4947
config: LSPConfig,
@@ -58,36 +56,18 @@ where
5856
/// Sets up all required protocol message handlers based on configuration passed in
5957
pub fn new(entropy_source: ES, config: LSPConfig) -> Self {
6058
let pending_messages = Arc::new(Mutex::new(vec![]));
61-
let pending_events = Arc::new(Mutex::new(vec![]));
6259

63-
let lsps0_message_handler = LSPS0MessageHandler::new(
64-
entropy_source,
65-
vec![],
66-
Arc::clone(&pending_messages),
67-
Arc::clone(&pending_events),
68-
);
60+
let lsps0_message_handler =
61+
LSPS0MessageHandler::new(entropy_source, vec![], Arc::clone(&pending_messages));
6962

7063
Self {
7164
pending_messages,
72-
pending_events,
7365
request_id_to_method_map: Mutex::new(HashMap::new()),
7466
lsps0_message_handler,
7567
config,
7668
}
7769
}
7870

79-
/// List the LSP protocols a node supports
80-
///
81-
/// Will receive the response via a ListProtocols event
82-
pub fn list_protocols(&self, counterparty_node_id: PublicKey) {
83-
self.lsps0_message_handler.list_protocols(counterparty_node_id)
84-
}
85-
86-
/// Needs to be polled regularly to surface events generated by the various message handlers
87-
pub fn get_and_clear_pending_events(&self) -> Vec<Event> {
88-
self.pending_events.lock().unwrap().drain(..).collect()
89-
}
90-
9171
fn handle_lsps_message(
9272
&self, msg: LSPSMessage, sender_node_id: &PublicKey,
9373
) -> Result<(), lightning::ln::msgs::LightningError> {

src/transport/protocol.rs

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use lightning::util::logger::Level;
55
use std::ops::Deref;
66
use std::sync::{Arc, Mutex};
77

8-
use crate::events::Event;
98
use crate::transport::message_handler::ProtocolMessageHandler;
109
use crate::transport::msgs::{
1110
LSPS0Message, LSPS0Request, LSPS0Response, LSPSMessage, ListProtocolsRequest,
@@ -19,7 +18,6 @@ where
1918
{
2019
entropy_source: ES,
2120
pending_messages: Arc<Mutex<Vec<(PublicKey, LSPSMessage)>>>,
22-
pending_events: Arc<Mutex<Vec<Event>>>,
2321
protocols: Vec<u16>,
2422
}
2523

@@ -30,9 +28,8 @@ where
3028
pub fn new(
3129
entropy_source: ES, protocols: Vec<u16>,
3230
pending_messages: Arc<Mutex<Vec<(PublicKey, LSPSMessage)>>>,
33-
pending_events: Arc<Mutex<Vec<Event>>>,
3431
) -> Self {
35-
Self { entropy_source, protocols, pending_messages, pending_events }
32+
Self { entropy_source, protocols, pending_messages }
3633
}
3734

3835
pub fn list_protocols(&self, counterparty_node_id: PublicKey) {
@@ -48,11 +45,6 @@ where
4845
self.pending_messages.lock().unwrap().push((counterparty_node_id, message.into()));
4946
}
5047

51-
fn enqueue_event(&self, event: Event) {
52-
let mut pending_events = self.pending_events.lock().unwrap();
53-
pending_events.push(event);
54-
}
55-
5648
fn handle_request(
5749
&self, request_id: RequestId, request: LSPS0Request, counterparty_node_id: &PublicKey,
5850
) -> Result<(), lightning::ln::msgs::LightningError> {
@@ -74,13 +66,7 @@ where
7466
&self, response: LSPS0Response, counterparty_node_id: &PublicKey,
7567
) -> Result<(), LightningError> {
7668
match response {
77-
LSPS0Response::ListProtocols(ListProtocolsResponse { protocols }) => {
78-
self.enqueue_event(Event::ListProtocols {
79-
counterparty_node_id: *counterparty_node_id,
80-
protocols,
81-
});
82-
Ok(())
83-
}
69+
LSPS0Response::ListProtocols(ListProtocolsResponse { protocols }) => Ok(()),
8470
LSPS0Response::ListProtocolsError(ResponseError { code, message, data, .. }) => {
8571
Err(LightningError {
8672
err: format!(
@@ -134,14 +120,9 @@ mod tests {
134120
let entropy = Arc::new(TestEntropy {});
135121
let protocols: Vec<u16> = vec![];
136122
let pending_messages = Arc::new(Mutex::new(vec![]));
137-
let pending_events = Arc::new(Mutex::new(vec![]));
138123

139-
let lsps0_handler = Arc::new(LSPS0MessageHandler::new(
140-
entropy,
141-
protocols,
142-
pending_messages.clone(),
143-
pending_events,
144-
));
124+
let lsps0_handler =
125+
Arc::new(LSPS0MessageHandler::new(entropy, protocols, pending_messages.clone()));
145126

146127
let list_protocols_request = LSPS0Message::Request(
147128
RequestId("xyz123".to_string()),
@@ -172,13 +153,11 @@ mod tests {
172153
#[test]
173154
fn test_list_protocols() {
174155
let pending_messages = Arc::new(Mutex::new(vec![]));
175-
let pending_events = Arc::new(Mutex::new(vec![]));
176156

177157
let lsps0_handler = Arc::new(LSPS0MessageHandler::new(
178158
Arc::new(TestEntropy {}),
179159
vec![1, 2, 3],
180160
pending_messages.clone(),
181-
pending_events,
182161
));
183162

184163
let counterparty_node_id = utils::parse_pubkey(
@@ -202,36 +181,4 @@ mod tests {
202181
))
203182
);
204183
}
205-
206-
#[test]
207-
fn test_handle_list_protocols_response() {
208-
let pending_messages = Arc::new(Mutex::new(vec![]));
209-
let pending_events = Arc::new(Mutex::new(vec![]));
210-
let protocols = vec![1, 2, 3];
211-
212-
let lsps0_handler = Arc::new(LSPS0MessageHandler::new(
213-
Arc::new(TestEntropy {}),
214-
protocols,
215-
pending_messages,
216-
pending_events.clone(),
217-
));
218-
219-
let list_protocols_response = LSPS0Message::Response(
220-
RequestId("00000000000000000000000000000000".to_string()),
221-
LSPS0Response::ListProtocols(ListProtocolsResponse { protocols: vec![1, 2, 3] }),
222-
);
223-
let counterparty_node_id = utils::parse_pubkey(
224-
"027100442c3b79f606f80f322d98d499eefcb060599efc5d4ecb00209c2cb54190",
225-
)
226-
.unwrap();
227-
228-
lsps0_handler.handle_message(list_protocols_response, &counterparty_node_id).unwrap();
229-
let pending_events = pending_events.lock().unwrap();
230-
231-
assert_eq!(pending_events.len(), 1);
232-
assert_eq!(
233-
pending_events[0],
234-
Event::ListProtocols { counterparty_node_id, protocols: vec![1, 2, 3] }
235-
);
236-
}
237184
}

0 commit comments

Comments
 (0)