NKN client can be used to transparently tunnel any TCP based application in a purely decentralized way, and the application itself does not need any modification. Such tunnel does not require any side to have public IP address or port forwarding, and no centralized server is needed at all. Below is an instruction for Mozilla WebThings Gateway.
Both the client (user) and server (gateway) side needs to run nkn-tunnel. On the gateway device (or any device in the same local network), we start nkn-tunnel in server mode:
./nkn-tunnel -from nkn -to 127.0.0.1:8080 -s <seed>
127.0.0.1:8080 is the WebThings Gateway web server address, and
<seed> is the secret seed (similar to private key) used to create NKN client. The seed should be a 64-char hex string. If seed is omitted, a random seed will be used.
After nkn-tunnel is started, it will print out the listening address:
Listening at <server-listening-address>
<server-listening-address> is the NKN address of the tunnel.
Then on the user side, we start nkn-tunnel in client mode:
./nkn-tunnel -from 127.0.0.1:8081 -to <server-listening-address>
Now user can access the gateway interface by visiting http://127.0.0.1:8081
Embed nkn-tunnel in iOS/Android application
nkn-tunnel is written in Go and can be compiled to a native iOS/Android library using Go mobile.
Below is a simple iOS application that use nkn-tunnel + WebView as a minimal WebThings Gateway mobile client.
Using NKN client as p2p communication layer
About Mozilla WebThings
The Web of Things connects real-world objects to the World Wide Web.
The idea of the Web of Things is to create a decentralized Internet of Things by giving things URLs on the web to make them linkable and discoverable, and defining a standard data model and APIs to make them interoperable.
Mozilla WebThings is Mozilla’s open source implementation of the Web of Things, including the WebThings Gateway and the WebThings framework. For more information please check out: