Cover photo

Running DarkFi IRC on your phone

Motivation

Privacy Maximalist

DarkFi is a (hopefully soon) upcoming product from the @darkfisqaud team. It's ethos is lunar punk and I've become very interested in it, in the recent months following the Tornado Cash OFAC debacle. I believe the team is currently embodying the idea of maximalist privacy. They seem very talented in cryptography and the project is written in Rust (which doesn't matter, but it's nice)

Story (Skip to ‘How To’ if you don’t care)

I wanted to get more involved in the DarkFi code, as I'm also interested in privacy. Unfortunately I don't know anything about cryptography, I'm not that good at reading mathematical notation so the docs are pretty tough to get through, and I also don't know how to write rust (but I'm learning it). One of the products that have come out of the decentralisation priority for DarkFi is their IRC. Instead of running a discord server or Telegram group, you need to compile and run your own IRC connection instance. It can be somewhat complicated but their docs was pretty good and I got it up and running.

Sitting in meat space and reading the documentation, I had some questions, so I wanted to log into the IRC and ask them, I just didn't have my computer on me. I did have a Android phone with Termux on it, so I went to town. Installed rust with pkg install rustc installed git, jq etc etc. When compile time came, I needed to install wasm32-unknown-unknown I had to use rustup, which is how you would normally install rust on your pc. I hadn't done that, and according to the Termux reddit page, it wouldn't be possible. I had to build wasm32-unknown-unknown from scratch. It was surprisingly simple, using their documentation. But in the end everything broke on compile and I scrapped the idea for the rest of the day. Next day, doing some more research I read that I could just compile it on my computer to Android and then transfer it to my phone. I didn't even think of that as a possibility! For the next few days I tried to do just that. It took some time. The tutorials i followed seemed a bit outdated, but finally, it worked. The following describes how you can do it too.

How to

This guide is for Linux. Most of it will probably work on MacOS also, I have no idea about windows.

I've used the guide found on devpress.csdn.net to accomplish my goal. I've never visited the site before or know the author, but it was a nice starting point. I'll base this guide on that guide and try to go through what I did to make it work. Also I take no responsibility for what happens if you try this out. This is ‘do at your own risk’ (although none of the commands should be destructive)

Install android command line tools

Android development is a little weird so the directory names matter. To get this working; make a new directory in your $HOME folder that's called 'Android'. Enter the folder with cd Android.Next download the latest platform tools for android from this link: https://dl.google.com/android/repository/platform-tools-latest-linux.zip by using the command:

$> wget -O sdk-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-9123335_latest.zip 

Unzip with:$> unzip sdk-tools.zip

You a left with a directory looking like this:

~/Android/
    ├── cmdline-tools
    ├── sdk-tools.zip

usecd cmdline-toolsto go into our new folder. Create a new folder called ‘latest’ in the cmdline-tools folder and move the bin/ and lib/ folder into the cmdline-tools folder.

( Lines starting with ‘$>’ is the command to execute. The rest is just for explaining )

starting dir: ~/Android

$> cd cmdline-tools
~/Android/cmdline-tools

$> mkdir latest

TREE FOR: ~/Android
    ├── cmdline-tools
    │   ├── bin
    │   ├── latest
    │   ├── lib
    │   ├── ...
    └── sdk-tools.zip

$> mv bin latest && mv lib latest
TREE FOR: ~/Android
    ├── cmdline-tools
    │   ├── latest
    │   │   ├── bin
    │   │   └── lib
    │   ├── NOTICE.txt
    │   └── source.properties
    └── sdk-tools.zip

You need to do this, with the naming of folders and everything. Otherwise the sdkmanager will fail in the next steps, according to my experience.

Now we need to work with the sdkmanager. Navigate to the bin folder: cd ~/Android/cmdline-tools/latest/bin

run: yes | ./sdkmanager --licenses to accept the licenses.

Then run: ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29" "ndk-bundle"

Configure NDK for Rust

We are almost there. Now make a new directory in the ~/Android folder mkdir ~/Android/toolchains

Next go into ndk_bundle tools folder.

cd ~/Android/ndk_bundle/build/tools/

From here we will use the make_standalone_toolchain.py program to create our toolchains

From ~/Android/ndk_bundle/build/tools/ run:

$> ./make_standalone_toolchain.py --api 26 --arch arm64 --install-dir ~/Android/toolchains/arm64

$> ./make_standalone_toolchain.py --api 26 --arch arm --install-dir ~/Android/toolchains/arm

$> ./make_standalone_toolchain.py --api 26 --arch x86 --install-dir ~/Android/toolchains/x86

Your ~/Android/toolchains directory should look like this:

~/Android/toolchains
    ├── arm/
    ├── arm64/
    └── x86/

Rust cargo configs

Update the cargo config to tell cargo where to look for the toolchains like this:

run: vim ~/.cargo/config

Paste this into config:

[target.aarch64-linux-android]
ar = "~/Android/toolchains/arm64/bin/aarch64-linux-android-ar"
linker = "Android/toolchains/arm64/bin/aarch64-linux-android-clang"

[target.armv7-linux-androideabi]
ar = "~/Android/toolchains/arm/bin/arm-linux-androideabi-ar"
linker = "Android/toolchains/arm/bin/arm-linux-androideabi-clang"

[target.i686-linux-android]
ar = "~/Android/toolchains/x86/bin/i686-linux-android-ar"
linker = "Android/toolchains/x86/bin/i686-linux-android-clang"

press esc to exit insert mode and then type :x to save the file and close vim.

run: rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-androidto add our compilation targets for rust.

Compile ircd for android

Now we get the DarkFi project.

Navigate to the folder you want the DarkFi project in. Run:

$> git clone https://github.com/darkrenaissance/darkfi 
$> cd darkfi

Normally you would start building the rust project now, but we need to modify the build instructions

Open the Make file. vim Makefile

We need to modify the rust build. Find line 35 looking like this:

RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --all-features --release --package $@

Modify it to look like this:

RUSTFLAGS="$(RUSTFLAGS)" $(CARGO) build --frozen --target aarch64-linux-android --all-features --release --package $@

And do the same on line 49.

Compiling

And now simply make the ircd

$> make BINS=ircd

The release will be in: ../darkfi/target/aarch64-linux-android/release/ircd

ring error:

When I tried compiling I got an error with ring . This helped me solve it. I'll explain what worked: You need to set the TARGET_CC. To do this use this command:

$> export TARGET_AR=~/Android/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar

$> export TARGET_AR=~/Android/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang

note: these commands will only work this session. Export them to your PATH or run the command again next time to you need to compile the ircd.

And that should be it. You now need to transfer it to your device.

Transfer ircd to your device

In Termux

'Before opening the app go to 'Settings > Apps > Termux > Permissions > Storage' and enable storage' src

Run commands to make sure your repositories and packages are up to date. Then install net-tools (for ifconfig) and openssh (for sshd)

$> pkg update && pkg upgrade
$> pkg install net-tools openssh

Next I made a folder in the home directory of termux called binaries mkdir ~/binaries to hold the compiled programs.

Then:

  1. use whoami to get your phones user.

  2. use ifconfig and look for inet under wlan0 to get your phones IP address. It will look something like 192.168.x.xx

Then I shared my internet connection from my phone to my pc. I had huge problems to get sshd on the phone, and scp on the pc, working together. Sharing the internet connection made it easy.

Next create a password for your user, as sshd expects one, using the command: passwd

Then start the sshd server in termux: sshd -d

On PC

run this command:

In directory: .../darkfi/target/aarch64-linux-android/release/   

$> scp -vvvv -P 8022 ircd <whoami_username>@<ifconfig_ip>:/data/data/com.termux/files/home/binaries/

And that should do it.

In Termux

Check your ~/binaries directory. You should see the ircd program. Simply run it with ./ircd. Remember to aquire a wakelock or android will shut the whole operation down whenever it wants to, and enjoy.

Btw, you can use revolution irc client to connect to your server on your phone. I don't endorse it, it's just the only one I've tried so far.

Termux package

I'll update this section and start to (somewhat) maintain a termux community package if there is enough interest from people.

Conclusion

Yeah that's it. Have fun with it. If you need some help I'm available on private message on twitter. Or better yet, send me an email. I'll try to update the post whenever I get questions.

twitter: @cunningham_2nd email: samcryptoham@protonmail.com