the8472 / mldht

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

Help,Is the right way to get the torrent file form infohash ? #11

Closed holicc closed 7 years ago

holicc commented 7 years ago

I ask a question on stackover , and i follow you comment . I'm a Java rookie , I try my best to understand you code . Please give me little help , the following code is correct ? Thank you .

` byte[] infoHash = {16, (byte) 190, (byte) 236, 84, 103, (byte) 129, (byte) 209, (byte) 161, (byte) 153, (byte) 148, (byte) 214, (byte) 188, 94, (byte) 200, 127, 70, (byte) 152, (byte) 193, 31, (byte) 128};

InetSocketAddress address = new InetSocketAddress("83.69.244.187", 63094);

PullMetaDataConnection metaDataConnection = new PullMetaDataConnection(infoHash, address);

metaDataConnection.canReadEvent();

ByteBuffer buffer = metaDataConnection.getMetaData().merge();

System.out.println(new String(buffer.array()));`

the8472 commented 7 years ago

That particular class is not really designed to be run in a stand-alone fashion, but with some extra initialization it might work anyway.

Take a look at the initialization in TorrentFetcher, which is the only class using PullMetaDataConnection . The most important ones would be the listener to get notified about completion and a NIOConnectionManager to get async network IO to work.

Alternatively you could look at atomashpolskiy/bt, which might provide cleaner APIs.

holicc commented 7 years ago

thanks :) 👍