ping deadlock
This commit is contained in:
@@ -218,7 +218,7 @@ pub fn start_p2p_executor(
|
|||||||
sd.senders(),
|
sd.senders(),
|
||||||
sd.cryptopair(),
|
sd.cryptopair(),
|
||||||
sd.messages_list(),
|
sd.messages_list(),
|
||||||
sd.handshake_peers.username_k_peerinfo_v.clone(),
|
sd.handshake_peers.get_username_peerinfo_map(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let res =
|
let res =
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ pub fn parse_message(
|
|||||||
match msgtype {
|
match msgtype {
|
||||||
HELLO | HELLOREPLY => {
|
HELLO | HELLOREPLY => {
|
||||||
let ilength = u16::from_be_bytes(length_bytes);
|
let ilength = u16::from_be_bytes(length_bytes);
|
||||||
|
println!("hello");
|
||||||
println!("name received length: {}", ilength);
|
println!("name received length: {}", ilength);
|
||||||
let received_name = &received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
let received_name = &received_message[LENGTH + EXTENSIONS..LENGTH + ilength as usize];
|
||||||
let received_username = String::from_utf8(received_name.to_vec());
|
let received_username = String::from_utf8(received_name.to_vec());
|
||||||
@@ -147,12 +148,14 @@ pub fn parse_message(
|
|||||||
.block_on(get_peer_key(&username))
|
.block_on(get_peer_key(&username))
|
||||||
.expect("failed to retrieve public key"),
|
.expect("failed to retrieve public key"),
|
||||||
};
|
};
|
||||||
println!("handshake JULIUS added");
|
match msgtype {
|
||||||
|
HELLOREPLY => {
|
||||||
handhsake_history.add_new_handshake(peer_pubkey, "".to_string(), ip);
|
handhsake_history.add_new_handshake(peer_pubkey, "".to_string(), ip);
|
||||||
let signature: [u8; SIGNATURE] = received_message
|
}
|
||||||
[LENGTH + msg_length..LENGTH + msg_length + SIGNATURE]
|
_ => {
|
||||||
.try_into()
|
println!("no handshake added");
|
||||||
.expect("Taille incorrecte");
|
}
|
||||||
|
}
|
||||||
if !verify_signature(peer_pubkey, &received_message) {
|
if !verify_signature(peer_pubkey, &received_message) {
|
||||||
println!(
|
println!(
|
||||||
"incorrect signature from given peer: {}, ignoring message of type {} with id {}",
|
"incorrect signature from given peer: {}, ignoring message of type {} with id {}",
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ impl HandshakeHistory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_username_peerinfo_map(&self) -> Arc<Mutex<HashMap<String, PeerInfo>>> {
|
||||||
|
self.username_k_peerinfo_v.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_new_handshake(&self, hash: VerifyingKey, username: String, ip: SocketAddr) {
|
pub fn add_new_handshake(&self, hash: VerifyingKey, username: String, ip: SocketAddr) {
|
||||||
let peerinfo = PeerInfo {
|
let peerinfo = PeerInfo {
|
||||||
username: username.clone(),
|
username: username.clone(),
|
||||||
@@ -112,14 +116,11 @@ pub fn update_handshake(
|
|||||||
let map_for_thread = username_k_peerinfo_v.clone();
|
let map_for_thread = username_k_peerinfo_v.clone();
|
||||||
let handle = thread::spawn(move || {
|
let handle = thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
println!("loop boucle");
|
|
||||||
let guard = map_for_thread.lock().unwrap();
|
let guard = map_for_thread.lock().unwrap();
|
||||||
println!("len:{}", guard.len());
|
|
||||||
for (peer, peerinfo) in guard.iter() {
|
for (peer, peerinfo) in guard.iter() {
|
||||||
let id = generate_id();
|
let id = generate_id();
|
||||||
let mut map = messages_list.lock().unwrap();
|
let mut map = messages_list.lock().unwrap();
|
||||||
map.insert(id, EventType::Ping);
|
map.insert(id, EventType::Ping);
|
||||||
drop(map);
|
|
||||||
let pingrequest = construct_message(PING, Vec::new(), id, &crypto_pair);
|
let pingrequest = construct_message(PING, Vec::new(), id, &crypto_pair);
|
||||||
if let Some(ping) = pingrequest {
|
if let Some(ping) = pingrequest {
|
||||||
senders.add_message_to_retry_queue(
|
senders.add_message_to_retry_queue(
|
||||||
@@ -133,10 +134,10 @@ pub fn update_handshake(
|
|||||||
false,
|
false,
|
||||||
messages_list.clone(),
|
messages_list.clone(),
|
||||||
);
|
);
|
||||||
println!("ping envoye a {}", peer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread::sleep(Duration::from_secs(2));
|
drop(guard);
|
||||||
|
thread::sleep(Duration::from_secs(240));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Worker::spawn(handle, crate::threads_handling::WorkerType::PING)
|
Worker::spawn(handle, crate::threads_handling::WorkerType::PING)
|
||||||
|
|||||||
Reference in New Issue
Block a user