HOPR
A project by the HOPR Association
HOPR is a privacy-preserving messaging protocol which enables the creation of a secure communication network via relay nodes powered by economic incentives using digital tokens.
hopr-connect
Disclaimer: support for libp2p test suite is still WIP, see KNOWN ISSUES
Description
A transport module for js-libp2p that handles NAT traversal automatically by using peers in the network and without requiring external resources such as public STUN or TURN servers.
Main features
See detailed architecture description for more information.
- fully compatible with js-libp2p, see KNOWN ISSUES
- automatic usage of WebRTC:
- try direct TCP connection, if not succesful
- use any other available peer in the network as signalling server
- perform WebRTC handshake(s)
- upgrade to direct connection if possible
- otherwise fallback to existing relayed connection
- use nodes in the network as STUN and TURN servers
- reconnect handling
Information for VPS / docker / firewalls
HoprConnect binds to a TCP socket as given by the configuration. It also bind to a UDP socket on the same port to perform and answer STUN requests from WebRTC and at startup to publish its own public IPv4 address.
Usage
Dependencies
- libp2p >= 0.31
- Node.js 14.x, also tested with Node.js 12.x
- yarn
Startup
Start a bootstrapServer
import { createLibp2p } from 'libp2p'
import { Mplex } from '@libp2p/mplex'
import { NOISE } from '@chainsafe/libp2p-noise'
import HoprConnect from 'hopr-connect'
import { Multiaddr } from '@multiformats/multiaddr'
import { createSecp256k1PeerId } from '@libp2p/peer-id-factory'
const peerId = await createSecp256k1PeerId()
const node = await createLibp2p({
peerId,
modules: {
transport: [HoprConnect],
streamMuxer: [Mplex],
connEncryption: [NOISE],
peerDiscovery: [HoprConnect.discovery]
},
addresses: {
listen: new Multiaddr(`/ip4/127.0.0.1/tcp/9091/p2p/${peerId.toB58String()}`)
},
dialer: {
addressSorter: (ma: Multiaddr) => ma
}
})
Start another client
import { createLibp2p } from 'libp2p'
import { Mplex } from '@libp2p/mplex'
import { NOISE } from '@chainsafe/libp2p-noise'
import HoprConnect from 'hopr-connect'
import { Multiaddr } from '@multiformats/multiaddr'
import { createSecp256k1PeerId } from '@libp2p/peer-id-factory'
const bootstrapId = '16Uiu2HAmCPgzWWQWNAn2E3UXx1G3CMzxbPfLr1SFzKqnFjDcbdwg'
const peerId = await createSecp256k1PeerId()
const node = await createLibp2p({
peerId
modules: {
transport: [HoprConnect],
streamMuxer: [Mplex],
connEncryption: [NOISE],
peerDiscovery: [HoprConnect.discovery]
},
addresses: {
listen: new Multiaddr(`/ip4/127.0.0.1/tcp/9092/p2p/${peerId.toB58String()}`)
},
config: {
HoprConnect: {
bootstrapServers: [new Multiaddr(`/ip4/127.0.0.1/tcp/9091/p2p/${bootstrapId.toB58String()}`)],
__noDirectConnections: false,
__noWebRTCUpgrade: false
}
},
dialer: {
addressSorter: (ma: Multiaddr) => ma,
}
})
Known issues
- IPv6 support disabled for the moment
- [WIP] libp2p test suite