protected InboundMessageQueuer connectPeerWithoutVersionExchange(int id) throws Exception {
   Preconditions.checkArgument(id < PEER_SERVERS);
   InetSocketAddress remoteAddress = new InetSocketAddress("127.0.0.1", 2000 + id);
   Peer peer = peerGroup.connectTo(remoteAddress).getConnectionOpenFuture().get();
   InboundMessageQueuer writeTarget = newPeerWriteTargetQueue.take();
   writeTarget.peer = peer;
   return writeTarget;
 }
 private void stepThroughInit(VersionMessage versionMessage, InboundMessageQueuer writeTarget)
     throws InterruptedException {
   checkState(writeTarget.nextMessageBlocking() instanceof VersionMessage);
   checkState(writeTarget.nextMessageBlocking() instanceof VersionAck);
   if (versionMessage.isBloomFilteringSupported()) {
     checkState(writeTarget.nextMessageBlocking() instanceof BloomFilter);
     checkState(writeTarget.nextMessageBlocking() instanceof MemoryPoolMessage);
   }
 }
 // handle peer discovered by PeerGroup
 protected InboundMessageQueuer handleConnectToPeer(int id, VersionMessage versionMessage)
     throws Exception {
   InboundMessageQueuer writeTarget = newPeerWriteTargetQueue.take();
   checkArgument(versionMessage.hasBlockChain());
   // Complete handshake with the peer - send/receive version(ack)s, receive bloom filter
   writeTarget.sendMessage(versionMessage);
   writeTarget.sendMessage(new VersionAck());
   stepThroughInit(versionMessage, writeTarget);
   return writeTarget;
 }
 protected InboundMessageQueuer connectPeer(int id, VersionMessage versionMessage)
     throws Exception {
   checkArgument(versionMessage.hasBlockChain());
   InboundMessageQueuer writeTarget = connectPeerWithoutVersionExchange(id);
   // Complete handshake with the peer - send/receive version(ack)s, receive bloom filter
   writeTarget.sendMessage(versionMessage);
   writeTarget.sendMessage(new VersionAck());
   stepThroughInit(versionMessage, writeTarget);
   return writeTarget;
 }