message: fix(test): communication that net reconnect a same node
diff: @@ -156,7 +156,7 @@ impl Net {
  .unwrap_or_else(|| panic!("not connected peer {}", node.p2p_address()));
  let net_message = receiver.recv_timeout(timeout)?;
  log::info!(
  - "received from peer-{}, message_name: {}",
  + "Net received from peer-{}, message_name: {}",
  peer_index,
  message_name(&net_message.2)
  );
  @@ -180,9 +180,9 @@ pub struct DummyProtocolHandler {
  // When a new peer connects, register to notice outside controller.
  register_tx: Sender<(String, PeerIndex, Receiver<NetMessage>)>,
  - // #{node_id => receiver}
  - // shared between multiple protocol handlers
  - senders: Arc<Mutex<HashMap<String, Sender<NetMessage>>>>,
  + // #{peer_id => receiver}
  + // It is shared between multiple protocol handlers.
  + senders: Arc<Mutex<HashMap<PeerIndex, Sender<NetMessage>>>>,
  }
  impl Clone for DummyProtocolHandler {
  @@ -216,17 +216,14 @@ impl CKBProtocolHandler for DummyProtocolHandler {
  let node_id = peer.peer_id.to_base58();
  let (sender, receiver) = unbounded();
  let mut senders = self.senders.lock();
  - if !senders.contains_key(&node_id) {
  - senders.insert(node_id.clone(), sender);
  + if !senders.contains_key(&peer_index) {
  + senders.insert(peer_index, sender);
  }
  let _ = self.register_tx.send((node_id, peer_index, receiver));
  }
  - fn disconnected(&mut self, nc: Arc<dyn CKBProtocolContext + Sync>, peer_index: PeerIndex) {
  - if let Some(peer) = nc.get_peer(peer_index) {
  - let node_id = peer.peer_id.to_base58();
  - self.senders.lock().remove(&node_id);
  - }
  + fn disconnected(&mut self, _nc: Arc<dyn CKBProtocolContext + Sync>, peer_index: PeerIndex) {
  + self.senders.lock().remove(&peer_index);
  }
  fn received(
  @@ -235,11 +232,8 @@ impl CKBProtocolHandler for DummyProtocolHandler {
  peer_index: PeerIndex,
  data: Bytes,
  ) {
  - if let Some(peer) = nc.get_peer(peer_index) {
  - let node_id = peer.peer_id.to_base58();
  - if let Some(sender) = self.senders.lock().get(&node_id) {
  - let _ = sender.send((peer_index, nc.protocol_id(), data));
  - }
  + if let Some(sender) = self.senders.lock().get(&peer_index) {
  + let _ = sender.send((peer_index, nc.protocol_id(), data)).unwrap();
  }
  }
  }
  