Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dht-iot

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dht-iot

The BitTorrent DHT for IoT communication

  • 1.5.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dht-iot

Using the BitTorrent DHT to store IoT data

I am using my forked version of the bitTorrent-dht module : https://github.com/EtienneV/bittorrent-dht

install

npm install dht-iot

Initialisation

var DHT_IOT = require('dht-iot')

var keypair = {publicKey:Buffer.from("xxxxxxxxxxxxxxxxxxxx", 'hex'),
			secretKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxx", 'hex')}
var dht_iot = new DHT_IOT({keypair: keypair})

Initiate a dht-iot instance with a specified keypair.

var DHT_IOT = require('dht-iot')

var dht_iot = new DHT_IOT()

Initiate a dht-iot instance with a random keypair.

Keypair generation

dht_iot.new_keypair()

It will display a new random keypair.

Put data

Send data over the DHT at the hash corresponding to the specified keypair.

dht_iot.put(val).then(function(hash) {})

IN val : Value to publish on the DHT

OUT hash : the hash corresponding to the value published

Example

var DHT_IOT = require('dht-iot')

var keypair = {publicKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxx", 'hex'),
			secretKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxx", 'hex')}
var dht_iot = new DHT_IOT({keypair: keypair})

dht_iot.put(50).then(function(hash) {
	console.log(hash)
	
	dht_iot.destroy()
})

Get data

Get data at the hash corresponding to the specified keypair.

dht_iot.get().then(function(val) {})

OUT val.v : the value val.t : the date of the value (UNIX timestamp in seconds)

Example

var DHT_IOT = require('dht-iot')

var keypair = {publicKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxxxx", 'hex'),
			secretKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'hex')}
var dht_iot = new DHT_IOT({keypair: keypair})

dht_iot.get().then(function(val) {
	console.log(val.value)
	
	dht_iot.destroy()
})

Get notified for new data

Get notified at every new message. The checking resolution is about 3 seconds.

dht_iot.get_notified() // Launch notification system

Everytime there is a new value an "new_value" event is fired

Example

var DHT_IOT = require('dht-iot')

var keypair = {publicKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'hex'),
			secretKey:Buffer.from("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 'hex')}
var dht_iot = new DHT_IOT({keypair: keypair})

var notif = dht_iot.get_notified()

dht_iot.on('new_value', function(hash, data){
	console.log('Hash : '+hash)
	console.log('Timestamp : '+data.timestamp)
	console.log('Value : '+data.value)
	console.log()
})

Keywords

FAQs

Package last updated on 13 Mar 2018

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