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>

Where 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>

where <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

nkn-tunnel is the easiest way to integrate with existing application, but might not be the most friendly way to users because it requires client side to run nkn-tunnel also. If you are able and willing to modify the server side application, you can use NKN client as the p2p communication layer and integrate NKN client to both the client and server side of your application. NKN client is currently available in Go, JavaScript, Java.

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:

iot.mozilla.org

About NKN

NKN is the new kind of P2P network connectivity protocol & ecosystem powered by a novel public blockchain. We use economic incentives to motivate Internet users to share network connection and utilize unused bandwidth. NKN’s open, efficient, and robust networking infrastructure enables application developers to build the decentralized Internet so everyone can enjoy secure, low cost, and universally accessible connectivity.


Home: https://nkn.org/

Email: contact@nkn.org

Telegram: https://t.me/nknorg

Twitter: https://twitter.com/NKN_ORG

Forum: https://forum.nkn.org

Medium: https://medium.com/nknetwork

Linkedin: https://www.linkedin.com/company/nknetwork/

Github: https://github.com/nknorg

Discord: https://discord.gg/yVCWmkC

YouTube: http://www.youtube.com/c/NKNORG