<commit_before>package the8472.mldht.cli.commands;

import static the8472.bencode.Utils.buf2str;

import java.nio.ByteBuffer;
import java.time.Duration;
import java.time.Instant;
import java.util.Formatter;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import lbms.plugins.mldht.kad.DHT;
import lbms.plugins.mldht.kad.Key;
import lbms.plugins.mldht.kad.tasks.PeerLookupTask;
import lbms.plugins.mldht.utils.NIOConnectionManager;
import the8472.mldht.cli.CommandProcessor;

public class GetPeers extends CommandProcessor {
	
	NIOConnectionManager conMan;
	
	ScheduledThreadPoolExecutor timer;

	@Override
	protected void process() {
		
		List<Key> hashes = arguments.stream()
				.map(bytes -> buf2str(ByteBuffer.wrap(bytes)))
				.filter(Key.STRING_PATTERN.asPredicate())
				.map(st -> new Key(st))
				.collect(Collectors.toList());
		
		AtomicInteger counter = new AtomicInteger();
		Instant start = Instant.now();
		
		hashes.forEach(h -> {
			dhts.stream().filter(DHT::isRunning).map(DHT::getServerManager).map(m -> m.getRandomActiveServer(false)).filter(Objects::nonNull).forEach(d -> {
				DHT dht = d.getDHT();
				
				PeerLookupTask t = new PeerLookupTask(d, dht.getNode(), h);
				
				counter.incrementAndGet();
				
				t.addListener(unused -> {
					if(counter.decrementAndGet() == 0)
						exit(0);
				});
				
				t.setResultHandler(item -> {
					Formatter f = new Formatter();
					
					Duration elapsed = Duration.between(start, Instant.now());
					
					f.format("%-5dms %s %s", elapsed.toMillis(), h.toString(), item.toString());
					
					println(f.toString());
				});<commit_msg>small opt: CLI lookup doesn't want tokens<commit_after>package the8472.mldht.cli.commands;

import static the8472.bencode.Utils.buf2str;

import java.nio.ByteBuffer;
import java.time.Duration;
import java.time.Instant;
import java.util.Formatter;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import lbms.plugins.mldht.kad.DHT;
import lbms.plugins.mldht.kad.Key;
import lbms.plugins.mldht.kad.tasks.PeerLookupTask;
import lbms.plugins.mldht.utils.NIOConnectionManager;
import the8472.mldht.cli.CommandProcessor;

public class GetPeers extends CommandProcessor {
	
	NIOConnectionManager conMan;
	
	ScheduledThreadPoolExecutor timer;

	@Override
	protected void process() {
		
		List<Key> hashes = arguments.stream()
				.map(bytes -> buf2str(ByteBuffer.wrap(bytes)))
				.filter(Key.STRING_PATTERN.asPredicate())
				.map(st -> new Key(st))
				.collect(Collectors.toList());
		
		AtomicInteger counter = new AtomicInteger();
		Instant start = Instant.now();
		
		hashes.forEach(h -> {
			dhts.stream().filter(DHT::isRunning).map(DHT::getServerManager).map(m -> m.getRandomActiveServer(false)).filter(Objects::nonNull).forEach(d -> {
				DHT dht = d.getDHT();
				
				PeerLookupTask t = new PeerLookupTask(d, dht.getNode(), h);
				
				t.setNoAnnounce(true);
				
				counter.incrementAndGet();
				
				t.addListener(unused -> {
					if(counter.decrementAndGet() == 0)
						exit(0);
				});
				
				t.setResultHandler(item -> {
					Formatter f = new Formatter();
					
					Duration elapsed = Duration.between(start, Instant.now());
					
					f.format("%-5dms %s %s", elapsed.toMillis(), h.toString(), item.toString());
					
					println(f.toString());
				});
{'fraction_non_alphanumeric': 0.1367713004484305, 'fraction_numerical': 0.00952914798206278, 'mean_word_length': 3.9569444444444444, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6878898', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1152, 'n_words': 199}