1
votes

I'm starting to use ttorrent (Turn's BitTorrent Java library) to create a local network synchronized folder.

My goal is to use the torrent protocol do sync large files in nodes hard drives. But I can't see how to create a new torrent file using ttorrent.

I need to: 1) A new file is added to one node. 2) Other nodes receive the torent file and start do download this file from the first node or pieces from other nodes that already downloaded that file part, speeding the downloading time. This way I can avoid each node to download gigabytes from a server (and wait all day).

I can't go ahead without knowing how to create a torrent file for that new added file (or if a better and smart way exists).

I can have a central point to serve as tracker.

Thanks.

1
I recommend using single file torrents, else you'll need to rehash all files if you want to stop sharing one. Or alternatively use BitComet's padding file hack, which isn't very popular among publicly available torrents, but should work for you.CodesInChaos

1 Answers

2
votes

Thanks to 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();
        }

    }

}