d9e7381f commented on issue #435:
URL: https://github.com/apache/mina-sshd/issues/435#issuecomment-1857616177

   @tomaswolf 
   In my case, i will keep retrying to establish a connection to the server 
until it succeeds. so I overwrite some methods to do that, but I'm not sure if 
it will cause bad effect.
   
   ```
   import org.apache.sshd.client.SshClient;
   
   public class MySshClient extends SshClient {
   
     public static SshClient setUpDefaultClient() {
       ClientBuilder builder = ClientBuilder.builder();
       builder.factory(MySshClient::new);
       return builder.build();
     }
   
     protected InetSocketAddress pickSocketAddress(String host, int port) 
throws UnknownHostException {
       ThreadLocalRandom random = ThreadLocalRandom.current();
       final InetAddress[] inetAddresses = InetAddress.getAllByName(host);
       final InetAddress pickInetAddress = 
inetAddresses[random.nextInt(inetAddresses.length)];
       return new InetSocketAddress(pickInetAddress, port);
     }
   
     @Override
     protected ConnectFuture doConnect(
         HostConfigEntry hostConfig,
         List<HostConfigEntry> jumps,
         AttributeRepository context,
         SocketAddress localAddress)
         throws IOException {
       // some code
       String username = hostConfig.getUsername();
       if (GenericUtils.isNotEmpty(jumps)) {
         InetSocketAddress targetAddress =
             pickSocketAddress(hostConfig.getHostName(), hostConfig.getPort());
         ConnectFuture connectFuture = new DefaultConnectFuture(username + "@" 
+ targetAddress, null);
         HostConfigEntry jump = jumps.remove(0);
         ConnectFuture f1 = doConnect(jump, jumps, context, null);
         // some code
         return connectFuture;
       } else {
         return doConnect(
             hostConfig.getUsername(),
             pickSocketAddress(host, port),
             context,
             localAddress,
             keys,
             hostConfig.isIdentitiesOnly());
       }
     }
   }
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to