Skip to content

diversario/node-disco

Repository files navigation

Disco

Network discovery, messaging and events.

Build Status Coverage Status Dependency Status NPM version

npm install disco

How it works

disco utilizes eventcast module to advertise themselves on the network. Advertisement messages may contain information that recipient would need to connect to sender through something other than UDP or anything else.

Messages can be of any (reasonable) size because eventcast fragments messages over 1KB in size and reassembles them. Of course, it's best to keep them short and sweet.

The goal of disco is to provide node discovery over the network and monitor discovered node's health. Use disco as a part of your project.

Usage

Create an instance of disco and start it:

var disco = Disco(9000) // port 9000

disco.on('discovery', function(msg){
  // handle message
})

disco.start()

By default, msg will contain sender's host, port and id.

disco maintains a list of discovered nodes. Each node provides host, port, id, hostname and the last received message. Nodes also have phi accrual failure detector attached to them that can be used to monitor node's availability.

REPL

disco creates a REPL that provides access to all instance methods and properties. REPL binds to a random port unless replPort is passed to the constructor.

$ telnet localhost 20001
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
disco> disco.stop()
true
disco>

Configuration

TODO

API

###start([callback]) Starts disco instance and calls callback, if provided.

###stop([callback]) Stops disco instance and calls callback, if provided.

###set(event, [message], [handler])

  • event String | Object If event is a string - default interval will be used, otherwise event.name and event.interval are required.
  • message * optional Message to pass with the event. Can be anything serializable.
  • handler Function optional Handler function for this event. If omitted, event will be emitted on disco instance.

Attach an event that will fire on interval with provided message. When received, message will be passed to handler or emitted on disco instance.

###unset(event)

  • event String event name

Removes event.

###discovery(message, handler)

  • message * Discovery message
  • handler Function Discovery message handler. Called with event name ("discovery") and the message.

Overrides the default discovery message and handler.

###getNodes Returns an array of known nodes.

##Nodes Nodes returned by Disco#getNodes represent instances of disco that this instance is aware of. Node object contains:

  • id Node ID.
  • host Node host
  • port Node port
  • info Last received discovery message
  • phi A function that returns suspicion level for this node.

About

Network discovery module.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published