message: Implement connection to new nodes after catch-up.
diff: @@ -128,17 +128,25 @@ enum Message {
  }
  impl PoolWorker {
  - fn connect_to_known_nodes(&mut self) {
  + fn restore_merkle_tree(&mut self) {
  let f = fs::File::open("pool_transactions_sandbox").expect("open file"); //FIXME use file for the pool
  let reader = io::BufReader::new(&f);
  for line in reader.lines() {
  let line: String = line.expect("read transaction line");
  - let mut rn: RemoteNode = RemoteNode::new(line.as_str());
  + self.merkle_tree.append(line);
  + }
  + }
  +
  + fn connect_to_known_nodes(&mut self) {
  + if self.merkle_tree.is_empty() {
  + self.restore_merkle_tree();
  + }
  let ctx: zmq::Context = zmq::Context::new();
  + for gen_txn in &self.merkle_tree {
  + let mut rn: RemoteNode = RemoteNode::new(gen_txn.as_str());
  rn.connect(&ctx);
  rn.zsock.as_ref().unwrap().send("pi".as_bytes(), 0).expect("send ping");
  self.nodes.push(rn);
  - self.merkle_tree.append(line);
  }
  self.f = self.merkle_tree.count(); //FIXME
  info!("merkle tree {:?}", self.merkle_tree);
  @@ -172,6 +180,7 @@ impl PoolWorker {
  fn process_catchup(&mut self, catchup: CatchupRep) {
  trace!("append {:?}", catchup);
  + let catchup_finished = {
  let mut process = self.pending_catchup.as_mut().unwrap();
  process.pending_reps.push(catchup);
  while !process.pending_reps.is_empty()
  @@ -186,8 +195,23 @@ impl PoolWorker {
  );
  }
  }
  - trace!("updated mt {:?}", process.merkle_tree);
  - trace!("updated mt hash {}", base64::encode(process.merkle_tree.root_hash()));
  + trace!("updated mt hash {}, tree {:?}", base64::encode(process.merkle_tree.root_hash()), process.merkle_tree);
  + if &process.merkle_tree.count() == &self.new_mt_size {
  + //TODO check also root hash?
  + true
  + } else {
  + false
  + }
  + };
  + if catchup_finished {
  + self.finish_catchup();
  + }
  + }
  +
  + fn finish_catchup(&mut self) {
  + self.merkle_tree = self.pending_catchup.take().unwrap().merkle_tree;
  + self.nodes.clear();
  + self.connect_to_known_nodes();
  }
  fn process_msg(&mut self, msg: &String, src_ind: usize) {
  