@@ -4,11 +4,11 @@ use crate::transport::protocol::LSPS0MessageHandler;
4
4
5
5
use bitcoin:: secp256k1:: PublicKey ;
6
6
use lightning:: ln:: features:: { InitFeatures , NodeFeatures } ;
7
+ use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
7
8
use lightning:: ln:: peer_handler:: CustomMessageHandler ;
8
9
use lightning:: ln:: wire:: CustomMessageReader ;
9
- use lightning:: log_info;
10
10
use lightning:: sign:: EntropySource ;
11
- use lightning:: util:: logger:: Logger ;
11
+ use lightning:: util:: logger:: Level ;
12
12
use lightning:: util:: ser:: Readable ;
13
13
use std:: collections:: HashMap ;
14
14
use std:: convert:: TryFrom ;
@@ -27,7 +27,7 @@ pub(crate) trait ProtocolMessageHandler {
27
27
28
28
fn handle_message (
29
29
& self , message : Self :: ProtocolMessage , counterparty_node_id : & PublicKey ,
30
- ) -> Result < ( ) , lightning :: ln :: msgs :: LightningError > ;
30
+ ) -> Result < ( ) , LightningError > ;
31
31
}
32
32
33
33
/// Configuration for the LSPManager
@@ -38,40 +38,36 @@ pub struct LSPConfig {
38
38
}
39
39
40
40
/// The main interface into LSP functionality
41
- pub struct LSPManager < L : Deref , ES : Deref >
41
+ pub struct LSPManager < ES : Deref >
42
42
where
43
- L :: Target : Logger ,
44
43
ES :: Target : EntropySource ,
45
44
{
46
- logger : L ,
47
45
pending_messages : Arc < Mutex < Vec < ( PublicKey , LSPSMessage ) > > > ,
48
46
pending_events : Arc < Mutex < Vec < Event > > > ,
49
47
request_id_to_method_map : Mutex < HashMap < String , String > > ,
50
48
lsps0_message_handler : LSPS0MessageHandler < ES > ,
51
49
config : LSPConfig ,
52
50
}
53
51
54
- impl < L : Deref , ES : Deref > LSPManager < L , ES >
52
+ impl < ES : Deref > LSPManager < ES >
55
53
where
56
- L :: Target : Logger ,
57
54
ES :: Target : EntropySource ,
58
55
{
59
56
/// Constructor for the LSPManager
60
57
///
61
58
/// Sets up all required protocol message handlers based on configuration passed in
62
- pub fn new ( logger : L , entropy_source : ES , config : LSPConfig ) -> Self {
59
+ pub fn new ( entropy_source : ES , config : LSPConfig ) -> Self {
63
60
let pending_messages = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
64
61
let pending_events = Arc :: new ( Mutex :: new ( vec ! [ ] ) ) ;
65
62
66
63
let lsps0_message_handler = LSPS0MessageHandler :: new (
67
64
entropy_source,
68
65
vec ! [ ] ,
69
- pending_messages . clone ( ) ,
70
- pending_events . clone ( ) ,
66
+ Arc :: clone ( & pending_messages ) ,
67
+ Arc :: clone ( & pending_events ) ,
71
68
) ;
72
69
73
70
Self {
74
- logger,
75
71
pending_messages,
76
72
pending_events,
77
73
request_id_to_method_map : Mutex :: new ( HashMap :: new ( ) ) ,
87
83
self . lsps0_message_handler . list_protocols ( counterparty_node_id)
88
84
}
89
85
90
- /// Needs to be polled regularly to surface events generated by the various protocols
86
+ /// Needs to be polled regularly to surface events generated by the various message handlers
91
87
pub fn get_and_clear_pending_events ( & self ) -> Vec < Event > {
92
88
self . pending_events . lock ( ) . unwrap ( ) . drain ( ..) . collect ( )
93
89
}
97
93
) -> Result < ( ) , lightning:: ln:: msgs:: LightningError > {
98
94
match msg {
99
95
LSPSMessage :: Invalid => {
100
- log_info ! ( self . logger , "Received invalid message from {:?} ", sender_node_id) ;
96
+ return Err ( LightningError { err : format ! ( "{} did not understand a message we previously sent, maybe they don't support a protocol we are trying to use? ", sender_node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Error ) } ) ;
101
97
}
102
98
LSPSMessage :: LSPS0 ( msg) => {
103
99
self . lsps0_message_handler . handle_message ( msg, sender_node_id) ?;
@@ -112,9 +108,8 @@ where
112
108
}
113
109
}
114
110
115
- impl < L : Deref , ES : Deref > CustomMessageReader for LSPManager < L , ES >
111
+ impl < ES : Deref > CustomMessageReader for LSPManager < ES >
116
112
where
117
- L :: Target : Logger ,
118
113
ES :: Target : EntropySource ,
119
114
{
120
115
type CustomMessage = RawLSPSMessage ;
@@ -129,9 +124,8 @@ where
129
124
}
130
125
}
131
126
132
- impl < L : Deref , ES : Deref > CustomMessageHandler for LSPManager < L , ES >
127
+ impl < ES : Deref > CustomMessageHandler for LSPManager < ES >
133
128
where
134
- L :: Target : Logger ,
135
129
ES :: Target : EntropySource ,
136
130
{
137
131
fn handle_custom_message (
0 commit comments