public ArrayList<TcpEndpoint> dhtGetPeers(Sha1Hash sha1, int timeout) {
        final ArrayList<TcpEndpoint> result = new ArrayList<>();
        if (session == null) {
            return result;
        }

        final sha1_hash target = sha1.swig();
        final CountDownLatch signal = new CountDownLatch(1);

        AlertListener listener = new AlertListener() {

            @Override
            public int[] types() {
                return DHT_GET_PEERS_REPLY_ALERT_TYPES;
            }

            @Override
            public void alert(Alert<?> alert) {
                DhtGetPeersReplyAlert a = (DhtGetPeersReplyAlert) alert;
                if (target.op_eq(a.swig().getInfo_hash())) {
                    result.addAll(a.peers());
                    signal.countDown();
                }
            }
        };

        addListener(listener);

        try {

            session.dht_get_peers(target);

            signal.await(timeout, TimeUnit.SECONDS);

        } catch (Throwable e) {
            LOG.error("Error getting peers from the dht", e);
        } finally {
            removeListener(listener);
        }

        return result;
    }
public ArrayList < TcpEndpoint > dhtGetPeers ( Sha1Hash sha1 , int timeout ) { final ArrayList < TcpEndpoint > result = new ArrayList < > ( ) ; if ( session == null ) { return result ; } final sha1_hash target = sha1 . swig ( ) ; final CountDownLatch signal = new CountDownLatch ( 1 ) ; AlertListener listener = new AlertListener ( ) { @ Override public int [ ] types ( ) { return DHT_GET_PEERS_REPLY_ALERT_TYPES ; } @ Override public void alert ( Alert < ? > alert ) { DhtGetPeersReplyAlert a = ( DhtGetPeersReplyAlert ) alert ; if ( target . op_eq ( a . swig ( ) . getInfo_hash ( ) ) ) { result . addAll ( a . peers ( ) ) ; signal . countDown ( ) ; } } } ; addListener ( listener ) ; try { session . dht_get_peers ( target ) ; signal . await ( timeout , TimeUnit . SECONDS ) ; } catch ( Throwable e ) { LOG . error ( "Error getting peers from the dht" , e ) ; } finally { removeListener ( listener ) ; } return result ; }
@param sha1
@param timeout in seconds
@return the peer list or an empty list