Write runtime libtorrent plugins with Java using frostwire-jlibtorrent #FrostWireLabs

We’ve just pushed upgrades to the frostwire-jlibtorrent API that will allow developers to extend and interact the Bittorrent protocol at a lower level through the implementation of libtorrent plugins.

Before today, a libtorrent plugin developer had to code plugins in C++ and rebuild the libtorrent library binaries for the architectures on which the plugin was meant to be used.

We think that non-bittorrent higher level abstractions (e.g. Bitcoin+Bittorrent integration) that need to occur near the core of the bittorrent protocol can be more easily coded, tested and debugged in a language like Java, without having to touch nor recompile the libtorrent libraries.

Today we’ve made available a new portion of the frostwire-jlibtorrent API that allows you to do this without all the C++ development headaches, you just focus on your plugin logic, and your code will also be available in all platforms with the same .class files.

Here’s an example of a dummy libtorrent Plugin implemented in Java using frostwire-jlibtorrent

To create a Plugin all you need to do is extend the AbstractPlugin class, whose newTorrent method will ask you to provide a TorrentPlugin interface implementation, this is meant to be a plugin instance that takes care of what happens when a torrent is added to the libtorrent session.

We provide an AbstractTorrentPlugin class for you to extend and as you do this you may or may not need to provide your own implementation of the TorrentPlugin::newPeerConnection method, which is meant to return a PeerPlugin, a plugin instance that takes care of what happens for every Peer connection, where probably most of your plugin logic will occur. We also provide an AbstractPeerPlugin implementation that you can extend.

Once you have your plugin ready to go, you can add it to the session with session.addExtension(myPlugin) and all torrents added to the session will invoke hooks that could be handled by your plugin implementations.

FrostWire for Desktop’s Lines of Code Count

    8724 text files.
    8237 unique files.                                          
    8917 files ignored.

http://cloc.sourceforge.net v 1.60  T=121.17 s (65.3 files/s, 14184.1 lines/s)
Language                      files          blank        comment           code
Java                           7591         300370         340020        1033777
HTML                            192           2811           2130          21190
C++                              12           1337            510           3207
XML                              17            178            101           1632
C/C++ Header                     20            562           1623           1188
Ant                              19            289            136           1124
Maven                            10             66             20           1073
JSP                              16             64            606            777
Objective C                       7            184            100            675
Objective C++                     1            138             71            583
Javascript                        5             58             25            361
SQL                               1             34              7            288
CSS                               2             63             13            274
Bourne Again Shell                3             45             25            229
XSD                               2             28             57            187
C                                 2             58             14            134
PHP                               1             18              0             73
Bourne Shell                      4             13              1             45
DOS Batch                         7              8              4             41
make                              1              9              0             21
SUM:                           7913         306333         345463        1066879

Help us over a million lines of code at https://github.com/frostwire