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.
IMPORTANT: This repository is un-maintained. The development of hopr-connect
has been integrated into https://github.com/hoprnet/hoprnet.
Disclaimer: support for libp2p test suite is still WIP, see KNOWN ISSUES
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.
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
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.
- libp2p >= 0.31
- Node.js 14.x, also tested with Node.js 12.x
- yarn
Start a bootstrapServer
const libp2p = require('libp2p')
const MPLEX = require('libp2p-mplex')
import { NOISE } from '@chainsafe/libp2p-noise'
const PeerId = require('peer-id')
import HoprConnect from 'hopr-connect'
import { Multiaddr } from 'multiaddr'
const peerId = await PeerId.create({ keyType: 'secp256k1' })
const node = await libp2p.create({
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: {
// Temporary fix
addressSorter: (ma: Multiaddr) => ma
}
})
Start another client
const libp2p = require('libp2p')
const MPLEX = require('libp2p-mplex')
import { NOISE } from '@chainsafe/libp2p-noise'
const PeerId = require('peer-id')
import HoprConnect from 'hopr-connect'
import { Multiaddr } from 'multiaddr'
const bootstrapId = '16Uiu2HAmCPgzWWQWNAn2E3UXx1G3CMzxbPfLr1SFzKqnFjDcbdwg' // Change this
const peerId = await PeerId.create({ keyType: 'secp256k1' })
const node = await libp2p.create({
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()}`)],
// Testing:
__noDirectConnections: false, // set to true to simulate NAT
__noWebRTCUpgrade: false // set to true to simulate bidirectional NAT
}
},
dialer: {
// Temporary fix
addressSorter: (ma: Multiaddr) => ma,
}
})
- IPv6 support disabled for the moment
- [WIP] libp2p test suite
and the rest of the HOPR team!