@@ -1124,15 +1124,28 @@ mod tests {
1124
1124
1125
1125
use rand:: { thread_rng, Rng } ;
1126
1126
1127
- use std:: sync:: { Arc } ;
1127
+ use std:: sync:: { Arc , Mutex } ;
1128
1128
1129
- #[ derive( PartialEq , Eq , Clone , Hash ) ]
1129
+ #[ derive( Clone ) ]
1130
1130
struct FileDescriptor {
1131
1131
fd : u16 ,
1132
+ outbound_data : Arc < Mutex < Vec < u8 > > > ,
1133
+ }
1134
+ impl PartialEq for FileDescriptor {
1135
+ fn eq ( & self , other : & Self ) -> bool {
1136
+ self . fd == other. fd
1137
+ }
1138
+ }
1139
+ impl Eq for FileDescriptor { }
1140
+ impl std:: hash:: Hash for FileDescriptor {
1141
+ fn hash < H : std:: hash:: Hasher > ( & self , hasher : & mut H ) {
1142
+ self . fd . hash ( hasher)
1143
+ }
1132
1144
}
1133
1145
1134
1146
impl SocketDescriptor for FileDescriptor {
1135
1147
fn send_data ( & mut self , data : & [ u8 ] , _resume_read : bool ) -> usize {
1148
+ self . outbound_data . lock ( ) . unwrap ( ) . extend_from_slice ( data) ;
1136
1149
data. len ( )
1137
1150
}
1138
1151
@@ -1173,10 +1186,15 @@ mod tests {
1173
1186
1174
1187
fn establish_connection < ' a > ( peer_a : & PeerManager < FileDescriptor , & ' a test_utils:: TestChannelMessageHandler > , peer_b : & PeerManager < FileDescriptor , & ' a test_utils:: TestChannelMessageHandler > ) {
1175
1188
let secp_ctx = Secp256k1 :: new ( ) ;
1176
- let their_id = PublicKey :: from_secret_key ( & secp_ctx, & peer_b. our_node_secret ) ;
1177
- let fd = FileDescriptor { fd : 1 } ;
1178
- peer_a. new_inbound_connection ( fd. clone ( ) ) . unwrap ( ) ;
1179
- peer_a. peers . lock ( ) . unwrap ( ) . node_id_to_descriptor . insert ( their_id, fd. clone ( ) ) ;
1189
+ let a_id = PublicKey :: from_secret_key ( & secp_ctx, & peer_a. our_node_secret ) ;
1190
+ //let b_id = PublicKey::from_secret_key(&secp_ctx, &peer_b.our_node_secret);
1191
+ let mut fd_a = FileDescriptor { fd : 1 , outbound_data : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) } ;
1192
+ let mut fd_b = FileDescriptor { fd : 1 , outbound_data : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) } ;
1193
+ let initial_data = peer_b. new_outbound_connection ( a_id, fd_b. clone ( ) ) . unwrap ( ) ;
1194
+ peer_a. new_inbound_connection ( fd_a. clone ( ) ) . unwrap ( ) ;
1195
+ assert_eq ! ( peer_a. read_event( & mut fd_a, initial_data) . unwrap( ) , false ) ;
1196
+ assert_eq ! ( peer_b. read_event( & mut fd_b, fd_a. outbound_data. lock( ) . unwrap( ) . split_off( 0 ) ) . unwrap( ) , false ) ;
1197
+ assert_eq ! ( peer_a. read_event( & mut fd_a, fd_b. outbound_data. lock( ) . unwrap( ) . split_off( 0 ) ) . unwrap( ) , false ) ;
1180
1198
}
1181
1199
1182
1200
#[ test]
0 commit comments