<commit_before>package bt.service;

import bt.data.DataAccessFactory;
import bt.data.DataDescriptor;
import bt.metainfo.IMetadataService;
import bt.metainfo.Torrent;
import bt.torrent.ITorrentDescriptor;
import bt.torrent.TorrentDescriptor;
import bt.tracker.ITrackerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class AdhocTorrentRegistry implements ITorrentRegistry {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdhocTorrentRegistry.class);

    private IMetadataService metadataService;
    private ITrackerService trackerService;
    private IConfigurationService configurationService;
    private DataAccessFactory dataAccessFactory;

    private ConcurrentMap<byte[], Torrent> torrents;
    private ConcurrentMap<Torrent, ITorrentDescriptor> descriptors;

    public AdhocTorrentRegistry(IMetadataService metadataService, ITrackerService trackerService,
                                IConfigurationService configurationService, DataAccessFactory dataAccessFactory) {

        this.metadataService = metadataService;
        this.trackerService = trackerService;
        this.configurationService = configurationService;
        this.dataAccessFactory = dataAccessFactory;

        torrents = new ConcurrentHashMap<>();
        descriptors = new ConcurrentHashMap<>();
    }

    @Override
    public Torrent getTorrent(byte[] infoHash) {
        return torrents.get(infoHash);
    }

    public Torrent createTorrentFromMetainfo(URL metainfoUrl) {

        Torrent torrent = metadataService.fromUrl(metainfoUrl);

        Torrent existing = torrents.putIfAbsent(torrent.getInfoHash(), torrent);
        if (existing != null) {
            LOGGER.warn("Received request to add an existing torrent: " + torrent.getName());
            torrent = existing;
        }
        return torrent;
    }

    @Override
    public ITorrentDescriptor getDescriptor(Torrent torrent) {

        ITorrentDescriptor descriptor = descriptors.get(torrent);
        if (descriptor == null) {
            descriptor = new TorrentDescriptor(trackerService, configurationService,
                    torrent, new DataDescriptor(dataAccessFactory, configurationService, torrent));
            ITorrentDescriptor existing = descriptors.putIfAbsent(torrent, descriptor);
            if (existing != null) {
                descriptor = existing;
            }
        }
        return descriptor;
    }
}<commit_msg>Queries for additional peers should be carried out by the peer registry<commit_after>package bt.service;

import bt.data.DataAccessFactory;
import bt.data.DataDescriptor;
import bt.metainfo.IMetadataService;
import bt.metainfo.Torrent;
import bt.torrent.ITorrentDescriptor;
import bt.torrent.TorrentDescriptor;
import bt.tracker.ITrackerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class AdhocTorrentRegistry implements ITorrentRegistry {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdhocTorrentRegistry.class);

    private IMetadataService metadataService;
    private ITrackerService trackerService;
    private IConfigurationService configurationService;
    private DataAccessFactory dataAccessFactory;

    private ConcurrentMap<byte[], Torrent> torrents;
    private ConcurrentMap<Torrent, ITorrentDescriptor> descriptors;

    public AdhocTorrentRegistry(IMetadataService metadataService, ITrackerService trackerService,
                                IConfigurationService configurationService, DataAccessFactory dataAccessFactory) {

        this.metadataService = metadataService;
        this.trackerService = trackerService;
        this.configurationService = configurationService;
        this.dataAccessFactory = dataAccessFactory;

        torrents = new ConcurrentHashMap<>();
        descriptors = new ConcurrentHashMap<>();
    }

    @Override
    public Torrent getTorrent(byte[] infoHash) {
        return torrents.get(infoHash);
    }

    public Torrent createTorrentFromMetainfo(URL metainfoUrl) {

        Torrent torrent = metadataService.fromUrl(metainfoUrl);

        Torrent existing = torrents.putIfAbsent(torrent.getInfoHash(), torrent);
        if (existing != null) {
            LOGGER.warn("Received request to add an existing torrent: " + torrent.getName());
            torrent = existing;
        }
        return torrent;
    }

    @Override
    public ITorrentDescriptor getDescriptor(Torrent torrent) {

        ITorrentDescriptor descriptor = descriptors.get(torrent);
        if (descriptor == null) {
            descriptor = new TorrentDescriptor(trackerService, torrent,
                    new DataDescriptor(dataAccessFactory, configurationService, torrent));
            ITorrentDescriptor existing = descriptors.putIfAbsent(torrent, descriptor);
            if (existing != null) {
                descriptor = existing;
            }
        }
        return descriptor;
    }
}
{'fraction_non_alphanumeric': 0.07234290147401086, 'fraction_numerical': 0.0007757951900698216, 'mean_word_length': 3.480451781059948, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2362362', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1283, 'n_words': 298}