Federated Stellar addresses

A few days ago a nonprofit foundation, partly backed by Stripe, launched a new decentralized payment network (similar to Bitcoin) called Stellar. Unlike with Bitcoins Stellar doesn’t get mined (so maybe the vast amount of computing power of all this mining hardware could get used to sequence DNA or run SETI@home in the future) and Stellar supports transactions in arbitrary currencies via so called gateways. To learn more about Stellar, their launch blog post and Stripe’s blog post is probably a good starting point.

Another interesting feature of Stellar is federation.


What federation is about

Each Stellar user has both a wallet address (similar to Bitcoin) as well as a human readable username for that address (which is quite handy as sending a payment to e.g. watsi is a lot easier than sending one to gN4oHfh4iLRCSsrHVxVHzt6rZXs6EyTCe4). What’s nice about these usernames is that they are actually federated addresses and not just usernames. The username watsi is just the short version of watsi@stellar.org.

Stellars federation protocol makes it possible to set up federated addresses for your domain. That means, that if you control the domain example.org, you could receive payments under e.g. john.doe@example.org. Think about it like some kind of domain name system for wallet addresses. Stripe’s CTO Greg wrote a blog post with some more details about how federation works and also provides a link to his sample federation server there.

How a client figures out the recipients wallet address

Just to give you a rough idea, here’s a quick overview of how a Stellar client figures out the recipients wallet address.

Locate and parse stellar.txt

When you are trying to send Stellar to e.g. john.doe@example.org the client first tries to find a file called stellar.txt for the example.org domain by trying the following URLs in this order:

  • https://stellar.example.org/stellar.txt
  • https://example.org/stellar.txt
  • https://www.example.org/stellar.txt

If the file is found, the client parses it for the URL of the federation server that’s responsible for this domain. For this example the contents of that file might look something like this:

[federation_url]
https://federation-server.example.org

Query federation server

Now the client makes it’s final request and asks the responsible federation server for the wallet address of john.doe@example.org. If everything worked out as expected and the federation server actually knew that user, the client now knows the wallet address for john.doe@example.org and is able to send a payment.

Running your own federation server

To run your own federation server you’ll need a valid SSL certificate for both the server where your stellar.txt file is located as well as for the domain your federation server itself is running on (those two could of course be the same). If you are also curious about Stellar federation you can give my implementation (it’s on GitHub) a try.

Disclaimer

A quick word of warning: I put this together for fun and haven’t spent a lot of time with it, so please use it at your own risk and don’t sue me if you end up sending your life savings to /dev/null. :) The federation protocol itself also still seems to be evolving, so things might break when they change the protocol.

Let me know if you find bugs or have suggestions for improvement.


Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

PEAR on OS X 10.10 Yosemite

Like previous versions of OS X, 10.10 also ships with PEAR. Installing and activating it is easy. Once that’s done PEAR and PECL work as expected (if you also want to set up and install Apache, PHP and MySQL, check this post.


Installing PEAR

cd /usr/lib/php
sudo php install-pear-nozlib.phar

If that fails

autoconf may be missing. To install it just use Homebrew. Once Homebrew is installed, installing autoconf is as simple as:

brew install autoconf

After autoconf is installed, try running the pear installer above again.

Upgrade PEAR

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade-all

Xcode Command Line Developer Tools

You will run into problems installing pecl extensions, if you don’t have the Xcode Command Line Extensions installed, so we’ll also install them.

xcode-select --install

Configuring PHP

Open /etc/php.ini and add .:/usr/lib/php/pear to include_path (if /etc/php.ini does not exist, create it with the following content).

include_path = ".:/usr/lib/php/pear"

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

Apache, MySQL & PHP on OS X Yosemite

OS X 10.10 ships with both a recent version of Apache (2.4.x), as well as PHP (5.5.x), so you’ll just have to install MySQL and go through a few steps to get everything up and running.

Apache

First, you have to create a web root in your user account:

mkdir ~/Sites

Then add a configuration for your user:

sudo tee /etc/apache2/users/$USER.conf <<EOF
<Directory "$HOME/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Require all granted
</Directory>
EOF

Now we have to make sure that our user config above actually gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/users/*.conf
EOF

If you want to use vhosts, you’ll also have to make sure that the vhosts config gets loaded:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
Include /private/etc/apache2/extra/httpd-vhosts.conf
EOF

After that, configure vhosts as necessary in /etc/apache2/extra/httpd-vhosts.conf (don’t forget to remove the examples in there).

It seems that mod_rewrite no longer gets loaded by default, so we’ll also add that to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
EOF

PHP

PHP doesn’t get loaded by default. So we’ll also add it to our config:

sudo tee -a /etc/apache2/other/$USER-settings.conf <<EOF
LoadModule php5_module libexec/apache2/libphp5.so
EOF

You should also configure a few settings in /etc/php.ini:

sudo tee -a /etc/php.ini <<EOF
date.timezone = "`sudo systemsetup -gettimezone | awk '{print $3}'`"
display_errors = on
error_reporting = -1
EOF

To activate these settings you have to restart Apache:

sudo apachectl restart

If you also need PEAR/PECL, follow these instructions.

MySQL

MySQL is not shipped with OS X, so we’ll have to install that manually. Instead of going for an installer package, we’ll use Homebrew. Once Homebrew is installed, installing MySQL is as simple as:

brew install mysql

If you want to start MySQL automatically, the Caveats section from the output of the following command will show you how:

brew info mysql

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

NGINX with syslog support in Docker

If you haven’t heard about Docker, this post will be of little interest, but if you also have started dockering-all-the-things you might have run into the limited log handling capabilities for Docker containers (Docker v0.8.0 is the current version at the time of writing), too. I especially noticed this when trying to run NGINX inside a container.

Being able to attach /dev/log of the host system to /dev/log inside a container (by adding a -v /dev/log:/dev/log parameter to docker run) made it seem like a quick fix - but only until you notice this hint in the NGINX docs:

Logging to syslog is available as part of our commercial subscription only.

Luckily there is an open source syslog patch for NGINX on GitHub. Below is a quick and dirty Dockerfile for an Ubuntu 13.10 container with a patched NGINX version.

There are a few things missing (e.g. NGINX php-fpm config, adding your application, actually configuring NGINX to use syslog), but you’ll probably figure that out.


# VERSION 0.0.1
#
# BUILD: docker build -rm -t dominik/nginx-syslog .
# RUN:   docker run -p $PORT:80 dominik/nginx-syslog
#        (logging via: -v /dev/log:/dev/log)

FROM ubuntu:13.10

RUN export DEBIAN_FRONTEND=noninteractive

RUN apt-get -y -qq update
RUN apt-get -y -qq upgrade
RUN apt-get -y -qq dist-upgrade

RUN apt-get -y --force-yes -qq install nginx \
                                       php5-dev \
                                       php5-fpm \
                                       php5-cli \
                                       php5-curl \
                                       php5-json \
                                       php-apc

# Patch Syslog support into nginx
RUN echo "deb-src http://archive.ubuntu.com/ubuntu saucy main universe" >> /etc/apt/sources.list
RUN echo "deb-src http://archive.ubuntu.com/ubuntu saucy-updates main universe" >> /etc/apt/sources.list
RUN echo "deb-src http://archive.ubuntu.com/ubuntu saucy-security main universe" >> /etc/apt/sources.list
RUN apt-get -y -qq update
RUN apt-get -y --force-yes -qq install build-essential dpkg-dev
RUN apt-get -y --force-yes -qq build-dep nginx
RUN mkdir /tmp/nginx; \
    mkdir /tmp/nginx/mod; \
    cd /tmp/nginx; \
    apt-get -y --force-yes -qq source nginx
ADD https://raw2.github.com/yaoweibin/nginx_syslog_patch/master/syslog_1.4.0.patch /tmp/nginx/mod/syslog_1.4.0.patch
ADD https://raw2.github.com/yaoweibin/nginx_syslog_patch/master/config /tmp/nginx/mod/config
RUN cd /tmp/nginx/nginx-1.4.1; \
    patch -p1 < ../mod/syslog_1.4.0.patch; \
    mv ./debian/rules ./debian/rules.original; \
    awk '/\$\(CONFIGURE_OPTS\)/{print "--add-module=/tmp/nginx/mod \\"}1' ./debian/rules.original > ./debian/rules; \
    dpkg-buildpackage -us -uc -nc; \
    cd ..; \
    dpkg -i nginx-common_1.4.1-3ubuntu1.1_all.deb nginx-full_1.4.1-3ubuntu1.1_amd64.deb; \
    rm -rf /tmp/nginx

# Add App
RUN mkdir /opt/app

# Configure php
RUN echo "cgi.fix_pathinfo = 1" >> /etc/php5/fpm/php.ini
RUN echo "output_buffering off" >> /etc/php5/fpm/php.ini
RUN echo "always_populate_raw_post_data off" >> /etc/php5/fpm/php.ini
RUN echo "magic_quotes_gpc = Off" >> /etc/php5/fpm/php.ini
RUN echo "mbstring.func_overload off" >> /etc/php5/fpm/php.ini
RUN echo "expose_php = Off" >> /etc/php5/fpm/php.ini
RUN echo "date.timezone = 'UTC'" >> /etc/php5/fpm/php.ini
RUN echo "date.timezone = 'UTC'" >> /etc/php5/cli/php.ini

EXPOSE 80

CMD service php5-fpm start && nginx

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻

PEAR on OS X 10.9 Mavericks

Like previous versions of OS X, 10.9 also ships with PEAR. Installing and activating it is easy. Once that’s done PEAR and PECL work as expected (if you also want to set up and install Apache, PHP and MySQL, check this post.

Updated instructions for OS X 10.10 Yosemite are available here.


Installing PEAR

cd /usr/lib/php
sudo php install-pear-nozlib.phar

If that fails

autoconf may be missing. To install it just use Homebrew. Once Homebrew is installed, installing autoconf is as simple as:

brew install autoconf

After autoconf is installed, try running the pear installer above again.

Upgrade PEAR

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade-all

Xcode Command Line Developer Tools

You will run into problems installing pecl extensions, if you don’t have the Xcode Command Line Extensions installed, so we’ll also install them.

xcode-select --install

Configuring PHP

Open /etc/php.ini and add .:/usr/lib/php/pear to include_path (if /etc/php.ini does not exist, create it with the following content).

include_path = ".:/usr/lib/php/pear"

Any comments? Ping me on Twitter. 👉🏻 Get my newsletter for occasional updates. ✌🏻