1

我开始使用 ttorrent(Turn 的 BitTorrent Java 库)来创建本地网络同步文件夹。

我的目标是使用 torrent 协议在节点硬盘中同步大文件。但我看不到如何使用 ttorrent 创建新的 torrent 文件。

我需要: 1) 一个新文件被添加到一个节点。2) 其他节点接收到 torent 文件并开始从第一个节点下载该文件或从其他节点下载该文件部分的片段,从而加快下载时间。这样我可以避免每个节点从服务器下载千兆字节(并等待一整天)。

如果不知道如何为该新添加的文件创建一个 torrent 文件(或者是否存在更好和更智能的方法),我将无法继续。

我可以有一个中心点作为跟踪器。

谢谢。

4

1 回答 1

2

感谢fujohnwang

public class Main {

    public static void main(String[] args) {
        // File parent = new File("d:/echo-insurance.backup");
        String sharedFile = "d:/echo-insurance.backup";

        try {
            Tracker tracker = new Tracker( InetAddress.getLocalHost() );
            tracker.start();
            System.out.println("Tracker running.");

            System.out.println( "create new .torrent metainfo file..." );
            Torrent torrent = Torrent.create(new File(sharedFile), tracker.getAnnounceUrl().toURI(), "createdByDarren");

            System.out.println("save .torrent to file...");

            FileOutputStream fos = new FileOutputStream("d:/seed.torrent");
            torrent.save( fos );            
            fos.close();

        } catch ( Exception e ) {
            e.printStackTrace();
        }

    }

}
于 2015-02-10T11:48:42.717 回答