New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hoprnet/hopr-connect

Package Overview
Dependencies
Maintainers
4
Versions
959
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hoprnet/hopr-connect

A libp2p-complaint transport module that handles NAT traversal by using WebRTC

  • 1.94.0-next.67
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
278
increased by3.35%
Maintainers
4
Weekly downloads
 
Created
Source

HOPR Logo

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: {
    // Temporary fix
    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' // Change this
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()}`)],
      // 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,
  }
})

Known issues

  • IPv6 support disabled for the moment
  • [WIP] libp2p test suite

Keywords

FAQs

Package last updated on 10 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc