Monday, October 15, 2012

Compiling RetroShare for the Raspberry Pi

The question is not if you are paranoid,
it is if you are paranoid enough.
I'm a fan of darknets. I've always been. I don't want this to turn into a political discussion - it is a "tech" blog - so it should be sufficient to say that I like and use RetroShare.

RetroShare is a decentralized sharing application/network that is, in my opinion, the best darknet software available right now. I've already tried WASTE, GnuNet and AllianceP2P, and they couldn't convince me for long.
Maybe I'll make an article about the pros and cons of RetroShare, but in this article I want to describe my attempts to get it running on my Raspberry Pi, so it can serve as a 24/7 node in the RetroShare network to forward connections without consuming that much power.

When I heard about the Raspberry Pi, the geek inside me wanted to have one. Fabian is still pissed that my Raspi arrived sooner than his, that is it arrived at all, although I ordered it much later. (I think he wants to go for Parallella now ...)

I've already managed to compile RetroShare 0.5.3 on and for my Raspi, but it segfaulted whenever I wanted to add a friend or open the settings menu. With the recent release of 0.5.4 I thought I could give it a try again.

Be warned: The compiling alone takes a few hours. I didn't write down exact times, but it's probably best if you have some other tasks to attend to for 2 hours while one subproject is compiling.

What we need to get started

Raspberry Pi and Raspbian Wheezy
I'm starting with my Raspberry Pi (Model B) with a sufficiently large SD card (4 GB should be enough) and a freshly installed Raspbian Wheezy (build 2012-09-18), which I've updated today (15th October) doing apt-get update && apt-get upgrade, and haven't modified so far besides putting my dotfiles under revision control using git.

In case that information changes on the Raspi website, I'll duplicate the links and information here, so we're all on the same page:
Torrent2012-09-18-wheezy-raspbian.zip.torrent
Direct download2012-09-18-wheezy-raspbian.zip
SHA-13bc788d447bc88feaae8382d61364eaba1088e78
Default loginUsername: pi Password: raspberry

RetroShare sources
The RetroShare version we need is 0.5.4b

Create a directory development in your home directory, cd there, download the sources and unpack them.
mkdir ~/development
mkdir ~/development/RetroShare-v0.5.4b
cd ~/development
wget http://sourceforge.net/projects/retroshare/files/RetroShare/0.5.4b/RetroShare-v0.5.4b.tar.gz
cd RetroShare-v0.5.4b
tar -xvf ../RetroShare-v0.5.4b.tar.gz

Required packages

My primary source for instructions is the RetroShare wiki page UnixCompile of today's version. It is a bit outdated because they've removed gnupg and introduced openpgp, but didn't update their instructions. Install the following packages with:
sudo apt-get install libqt4-dev g++ libupnp-dev libssl-dev libgnome-keyring-dev libbz2-dev libxss-dev

Then you need to compile the projects in the subdirectories, but there are still some modifications necessary to make it work under Debian. The first two subprojects should work fine:
cd ~/development/RetroShare-v0.5.4b/trunk/
cd libbitdht/src && qmake && make clean && make -j2
cd ../../openpgpsdk/src && qmake && make clean && make -j2
The problems start with libretroshare and there are two changes you need to make on it:

Firstly, because even though the preprocessor commands are there, you still need to tell the make process that you are on Debian and your libupnp is of a different version. You do this by editing the file libretroshare.pro in the libretroshare/src/ directory and after the line 221
DEFINES *= UBUNTU
you add (not replace) these lines
DEFINES *= DEBIAN
DEFINES *= UPNP_VERSION=10617
because we do in fact have version 1.6.17 of libupnp installed. (See this thread in the RetroShare forum.)

Secondly, someone hardcoded the location of glib-2.0 into that project file in a very system dependent way. You need to change this line (should be directly below the previous change, line 224 now)
INCLUDEPATH += /usr/include/glib-2.0/ /usr/lib/glib-2.0/include
to this
INCLUDEPATH += $$system(pkg-config --cflags glib-2.0 | sed -e "s/-I//g")
(Source)

cd ../../libretroshare/src && qmake && make clean && make -j2

And now the real fun starts. The Raspberry Pi has 256 MB RAM of which at least 16 MB need to be reserved for the video core, so only 240 MB RAM left. Unfortunately, this is not enough to compile retroshare-gui, it will quit with something like
virtual memory exhausted: Cannot allocate memory
g++: internal compiler error: Killed (program cc1plus)
when it tries to compile qrc_images.cpp.

Super hot update
The irony of situation is that just today an enhanced version of the Raspberry Pi was announced with 512 MB of RAM, which should make the following swap file part obsolete.

Now, I've heard that very, very bad things happen if you create a swap file on a flash storage device like the SD card your Raspi uses or USB sticks. But as a matter of fact, Raspbian wheezy already uses a swap file per default, so it can't be that bad. All you need to do is create another swap file of sufficient size, say 256 MB, which you delete afterwards just to be on the safe side:
sudo dd if=/dev/zero of=swapfile bs=1M count=256
sudo mkswap swapfile
sudo swapon swapfile
Then you can compile retroshare-gui
cd ../../retroshare-gui/src && qmake && make clean && make -j2
and deactivate the swap file again:
sudo swapoff swapfile
sudo rm swapfile
This is also a good opportunity to turn of the default swap file, too, as it really isn't that healthy for your SD card. (Hoping that actually running RetroShare is possible with only 256 MB RAM)

Done

And that's it, you've just compiled RetroShare. This article is already way too long, so I'll stop here and post about configuring and running it in a later post. Hopefully soon.

13 comments:

  1. Big Thanks, florian!

    I will try it and post my progress.

    It would be nice for me to run the Raspberry Pi as RetroShare Server 24/7 with my NAS in the Back.

    BR cave

    ReplyDelete
  2. some other approach to combine RPi-Debian-RS

    http://www.loteks.de/index.php/retroshare-auf-dem-debian-server-debian-rasbberry-pi/

    ReplyDelete
    Replies
    1. That may actually work now. In one of the latest changes they fixed some of things that I had to work around.

      Delete
  3. Hi Florian,
    thanks for the instructions, everything went smoothly.
    I've compiled and installed ver. 0.5.4c

    G.

    ReplyDelete
    Replies
    1. Also for the ver. 0.5.4d everithing was fine.
      With my 512MB Raspy I had to stop most of the services in order not to use swap.
      Thanks again,

      G.

      -----BEGIN PGP PUBLIC KEY BLOCK-----
      Version: OpenPGP:SDK v0.9

      mQENBE+2dBYBCACpZZ0v/vhfhGgpc4s10b5P1hxx1W1+jxw4QNSgPi53PWhCxAcB
      1/T1OPgDj9KNdGzx28F7FXsOZNQcxZAEP7mxwAUJI1+jGSX7gjZ0eZa+SZIqVvRH
      9BwpjdHSf9Pci9qN5s5X/tjO3LFHJ1P7PtjNKKj9Dj2rotWMx4RPmUskTu3pPiLj
      mh6nPK5FGmGUcR7A7BJAgCvCd0iQuJ8exCBtNOYY3YXUsZdF/x332bTjXN4iVDyU
      ryKZ6fzVF1zuXiINHai9FS6COpmtV9YBEXXxDizczFiFKKB/CLbQgl8/q5bY4F6i
      12bdr7I4qdmOyeZkPnnkcF/jLLv5PeJWKsnTABEBAAG0K1RyZW1hbE5haWsgKGdl
      bmVyYXRlZCBieSBSZXRyb3NoYXJlKSA8bm9uZT6JATgEEwECACIFAk+2dBYCGy8G
      CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEBroMvE1M8NZBPUIAJbyhD4Yb+F6
      ZN1o3J5hBAcTuCVFXDyfQ/EbQSkF+bnOvBrs/zLJxEacRq2/G6UchgE1+P8mlPRA
      sXej8kPpbL6hIODoioJrQu8z8tyQj3kZfA7IMndomvjutOff1dpoKAMKsb1N5f/u
      PYWhkAYJeymXyquXrslTt4ye29LqV+iE9HgoG/P5sddmurJozSyZSwlxVoVNMspC
      IjdPkNHWhB8NRclNvHNebp4WLo5Os/vYKUDvjSoRBJD5lCGZW8QFge0DYWQyi7oa
      JKFLZN4kCfOE8I1WoB8vyuseXBkLw4Xj1PDctFIi0tK4D2UZTMRNd/M3zHhj1gPz
      DQC+Ogi9DgQ=
      =Ya3H
      -----END PGP PUBLIC KEY BLOCK-----
      --SSLID--891a5f254e27d7b85cdddb5ba02d42b5;--LOCATION--Raspy;
      --LOCAL--192.168.0.253:43769;--EXT--151.33.39.195:43769;

      Delete
  4. hi, i was yesterday successful to compile RetroShare v0.5.4c for my Raspberry Pi.
    Big thanks to your Guide!

    Now I Connected with TightVNCserver to my Raspi becaus i don't know how to configure and run it with CLI/SSH or no-Gui.

    After some search i found the file to start Retroshare.
    the path is something similar like "~/development/RetroShare_v0.5.4c/trunk/retroshare-gui/src/retroshare"
    I started it.
    created a new account and connected with my other PC and authenticated both.

    I am now working and trying on:
    silent auto start at re-boot
    (maybe as a daemon and no-Gui, or start it in the tightVNCserver:1)
    combine both RS Installations in one Account
    X-Forwarding of the Gui to openSuSe/Gnome, some-other-Linux, WinXP, Win7, Win-something.
    remote control it with Pyrs and Android or other tools

    anoter link to headless-RetroShare.
    http://lukas-pirl.de/spin-offs/how%20to%20run%20retroshare%20headless%20on%20a%20server

    I hope you will find some time to make a new post about configuring and running.
    Best regards
    cave

    ReplyDelete
  5. https://sourceforge.net/projects/pishare/ <-- now you can download the compiled binarys . please let me know, if you have any problems using it.

    If you can help me with autologin, it would be really nice!

    i start it with crontab and @reboot, but it stops at password input.

    ReplyDelete
    Replies
    1. Nice! Did you already contact the maintainers of the RetroShare debian packages? Maybe they can use your precompiled binaries to build .deb packages for raspbian.

      Delete
    2. http://www.raspberrypi.org/phpBB3/viewtopic.php?p=277726#p277726

      r6100 v0.5.4d is available as .deb on PiShare@SF

      linked with GCC 4.6
      r6095: gui, no-gui, plugins

      linked with GCC 4.7
      r6100: gui, no-gui, plugins

      in the next days, there will be a cross-compile-vm available for download.

      Delete
    3. I'm also currently writing an article on cross-compiling, let's see who gets it done first ;)

      Delete
  6. Hey all, just to let you know: I'm pretty stuck with work right now, but I'm planning on a new article to look at the newest changes of RetroShare, also maybe compiling it on your Linux machine to make it faster. Stay tuned!

    ReplyDelete
  7. Thanks for the swap tip, it made my day.

    ReplyDelete

Note: Only a member of this blog may post a comment.