top | item 14911372

Show HN: Bt – BitTorrent library in Java 8

254 points| atomashpolskiy | 8 years ago |github.com | reply

87 comments

order
[+] atomashpolskiy|8 years ago|reply
There are many great BitTorrent clients out there, yet I've made my own and willing to share and attract collaborators!
[+] atomashpolskiy|8 years ago|reply
Guys, I've added a code screenshot above the gif, is it better now?
[+] yodsanklai|8 years ago|reply
Just curious, how many hours do you think you've spent on this project?
[+] jph|8 years ago|reply
Thank you, your work is terrific! Good docs, good code, and I especially like the ability to create custom code to write to alternative storage.
[+] atomashpolskiy|8 years ago|reply
Thanks!! Yeah, I was pursuing such design that would allow to replace/customize most of the parts, including the internals. As a bonus, it makes it easier to continue working on the library as the codebase grows (now nearing 25K lines of code)
[+] gigatexal|8 years ago|reply
Man this looks slick, going to give it a shot. Love the ability to be able to download a magnet link from the CLI and not worry about what some fancy GUI is doing in the background cuz I am paranoid.
[+] atomashpolskiy|8 years ago|reply
Thank you! Make sure to install http://www.oracle.com/technetwork/java/javase/downloads/jce8... to allow 160-bit cryptography and use -e flag to be completely safe!

I also have a simple shell script locally, that wraps the java command, so I have to just type `btmagnet AF0D9AA01A9AE123A73802CFA58CCAF355EB19F8` to download to a pre-determined location (hardcoded in the script). I wonder if I should share it on the CLI README page

[+] rena-anju|8 years ago|reply
What things that makes you paranoid can a "fancy GUI" do in the background that an application with a CLI cannot also do in the background?
[+] pmatev|8 years ago|reply
Credit to OP, this looks like a really solid project. The CLI aspect of it reminds me of peerflix (https://github.com/mafintosh/peerflix), which I've been using for a while and am pretty happy with (no affiliation, promise)
[+] lotyrin|8 years ago|reply
I use rtorrent for exactly this.
[+] hobarrera|8 years ago|reply
Sounds like deluge (deluged) would have suited you fine.
[+] zitterbewegung|8 years ago|reply
It looks great but the top GIF makes it seem like you are offering a command line BT client. If I were you I would have it slowly scroll through the code of the client in the GIF or put a few frames of code of the client and or some compiling and then show the current top GIF.
[+] atomashpolskiy|8 years ago|reply
Oh, I didn't expect this :) Sounds good, but I'm not sure I have patience do this right, it's such a pain to record gifs - I always misspell or misclick something, and by take #47 go completely nuts
[+] yodsanklai|8 years ago|reply
Nice work. I'm wondering, how would you test/benchmark such an application. Besides manual testing on a variety of torrents, how would you do regression test there? same question for benchmarking. How to compare this work with another client?
[+] atomashpolskiy|8 years ago|reply
I have several hundred unit tests and also a bunch of integration tests. While UTs usually test API of individual classes, each of the ITs creates a swarm of local peers and launches a torrenting session with certain conditions: seeders to leechers ratio, downloading from .torrent file vs using a magnet link, PEX enabled/disabled, encrypted vs raw message streams, etc.

Benchmarks (like in libtorrent) is something I'm looking forward to, but the project is still in the early stage -- there's a lot to be done with regards to optimization, i.e. switching to using NIO selectors, adding a caching layer, etc. That's a lot of work, and that's why I'm looking for collaborators, before investing more time into performance-tuning.

[+] djhworld|8 years ago|reply
Really like the approach around using Guice as a central point for hooking your own code into the system.

Will look forward to reading through the code later!

[+] atomashpolskiy|8 years ago|reply
Thanks! God bless IoC, it saves my ass each time I make some silly design choice
[+] styfle|8 years ago|reply
I'm curious, it looks like the screenshot shows the author is using a Mac. But Mac OS hasn't shipped with Java in several years. So why Java? Is it simply familiarity, or are there other reasons?
[+] atomashpolskiy|8 years ago|reply
A mix of both, actually. I've been using uTorrent for years until 2016, when I've decided to switch to some new OS X release. After installing the system update, the old, ad-free version of uTorrent has stopped working. The new version seemed a bloated mess to me, so I've tried a few other clients, but was left unsatisfied. Finally, in despair I've decided to write my own client with simplistic command-line UI, with emphasis on streaming movies. The sheer amount of new information in BEPs was enough for me to decide to take the easiest route and use the language, that I'm most familiar with.
[+] jrs95|8 years ago|reply
This is a library for development. If you wanted to ship a client based on this, you could do that and package it with the Java runtime.
[+] pvg|8 years ago|reply
Most OS's don't ship with a C compiler, go, python 3, rust, arc, etc, what does that have to do with anything?
[+] segmondy|8 years ago|reply
Amazing work, how long did it take to build? Where you working on it full-time or part-time?
[+] atomashpolskiy|8 years ago|reply
Thank you! Calendar year, in the evenings and on weekends, with sprints of several weeks and a month or two of rest/AFK after each sprint to keep sanity (I have a full-time job, a wife and a 3 year old kid). Happy that I had the persistence to keep working on the project
[+] intellix|8 years ago|reply
I remember using Java based client Azureus and the memory usage was huge. Overnight it would leak to about 1Gb. Later uTorrent appeared and it used 2mb... Forever

I guess nothing to do with this but was triggered by two combined words: Torrent and Java

[+] amzans|8 years ago|reply
It's great to see projects like this on HN. Congrats man, well done!
[+] nunobrito|8 years ago|reply
Hello, thank you for writing the library.

On my context it is useful for downloading large files without depending on a single point of failure or fixed location.

Have a question in regards to the example syntax:

client.startAsync(state -> { if (state.getPiecesRemaining() == 0) { client.stop(); } }, 1000).join();

This is a feature from newer Java syntax that I'm not yet familiar enough with lambdas to understand in full what is happening.

Perhaps I can ask for an example that replaces the "->" into the older Java syntax? I know this would likely come at the cost of a few extra lines, it would certainly ease a lot for many developers looking at the example. Many thanks.

[+] train_robber|8 years ago|reply
In the older syntax, something like this:

  client.startAsync(new Consumer<TorrentSessionState> {
	void accept(TorrentSessionState state) {
		if (state.getPiecesRemaining() == 0) { 
			client.stop(); 
		}
	}
  }, 1000).join();
[+] tokenizerrr|8 years ago|reply
Just read the Java 8 docs.
[+] wodencafe|8 years ago|reply
Wow thanks man! This can be useful in a variety of circumstances!
[+] ikurei|8 years ago|reply
Not very familiar with the Java world yet. I've heard Android now supports at least some features from Java 8, but would this library work in an Android app?
[+] tonyrice|8 years ago|reply
It's amazing how this made it to the front page of HN and I had no idea until now. I actually discovered this by googling a couple hours ago :)
[+] alexanderbisc|8 years ago|reply
It's possible in Azureus, but it might be a lot of effort to turn the functionality into a library.