Skip to content

Instantly share code, notes, and snippets.

@ryogrid
Last active June 3, 2024 22:47
Show Gist options
  • Save ryogrid/a8c585a7d229a666ff82369df1939058 to your computer and use it in GitHub Desktop.
Save ryogrid/a8c585a7d229a666ff82369df1939058 to your computer and use it in GitHub Desktop.
NostrP2P server on Android Smartphone

The other day, I wrote an articleshown below, and I was thinking about whether I could prepare or have a machine that can run the server continuously.

NostrP2P: Pure P2P Distributed Microblogging System - ryo_grid's tech articles

Then, I remembered that there is an app called Termux that creates a unique Linux environment within an Android device. So, I thought it would be a good idea to use an old Android smartphone to run the server, and when I tried it, it worked perfectly!

(The idea behind Termux is that since Android is a type of Linux, by changing the root location of the file system in the shell shown to the user with chroot and placing the necessary files, you can create a unique Linux userland.)

First, referring to the sites below, install Termux via the Fdroid app.

Installing from F-Droid - Termux Wiki

Once Termux is installed, you can follow the commands below to get the server running.

$ apt update
$ apt upgrade
$ apt install -y golang git
$ git clone https://github.com/ryogrid/nostrp2p
$ cd nostrp2p
$ go build -o nostrp2p main.go
$ ./nostrp2p server -l 0.0.0.0:20000 -p <npub format public key> -b ryogrid.net:8888

After that, find the IP address of the smartphone and specify it in the client. (If connected via WiFi, you can check the assigned IP address by following the network settings. If the IP address changes frequently, you can use a VPN app like Tailscale to use a fixed address on the VPN.)

The connection to the bootstrap server was successful.

To stop the server, terminate the server process with Ctrl + c, exit the shell with the exit command, and then close Termux like a regular app. If the environment built in Termux is no longer needed, uninstalling Termux will delete the environment and the files created within it.

Below are some screenshots.

Screenshot 1

Screenshot 2

Server address settings in the client (using a native client for Windows this time)

Screenshot 3

Tried posting

Screenshot 4

The data posted to the bootstrap server (also a trial server) was successfully transferred and displayed on the web client connected to the trial server.

Screenshot 5

Wow, Termux is amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment