the8472 / mldht

Bittorrent Mainline DHT implementation in java
Mozilla Public License 2.0
147 stars 45 forks source link

How to save the torrents not in disk ,but in database ? #12

Closed holicc closed 7 years ago

holicc commented 7 years ago
 public static void main(String[] args) throws SocketException {
        DHT dht = new DHT(DHT.DHTtype.IPV4_DHT);
        DHTConfiguration configuration = new DHTConfiguration() {
            @Override
            public boolean isPersistingID() {
                return false;
            }

            @Override
            public Path getStoragePath() {
                return Paths.get("");
            }

            @Override
            public int getListeningPort() {
                return 7892;
            }

            @Override
            public boolean noRouterBootstrap() {
                return false;
            }

            @Override
            public boolean allowMultiHoming() {
                return false;
            }
        };
        dht.setScheduler(Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors() * 2));
        dht.start(configuration);
        dht.bootstrap();

        List<DHT> dhts = new ArrayList<>();
        dhts.add(dht);
        Supplier<InputStream> configSchema = () -> Launcher.class.getResourceAsStream("config.xsd");
        Supplier<InputStream> configDefaults = () -> Launcher.class.getResourceAsStream("config-defaults.xml");
        ConfigReader reader = new ConfigReader(Paths.get(".", "config.xml"), configDefaults, configSchema);
        reader.registerFsNotifications(new FilesystemNotifications());

        TorrentDumper dumper = new TorrentDumper();
        dumper.start(dhts, reader);
    }
the8472 commented 7 years ago

TorrentDumper does not provide that customization. If you want to handle it differently you need to use TorrentFetcher instead which will provide its results as ByteBuffers.