mokka
[![Build Status](https://travis-ci.org/ega-forever/mokka.svg?branch=master)](https://travis-ci.org/ega-forever/mokka)
Last updated 2 months ago by zuev.egor .
AGPLv3 · Original npm · Tarball · package.json
$ cnpm install mokka 
SYNC missed versions from official npm registry.

Mokka

Build Status

Mokka Consensus Algorithm implementation in Node.js.

Concept description (PDF)

consensus features

  • resistant to network splits
  • signature validation of each change in state (i.e. new logs and voting)
  • gossip protocol for transferring pending logs
  • non-anonymous voting

implementation features

  • Persists to LevelDB (or any database exposing a LevelDown interface).
  • Custom transport layer support: Mokka separate interface implementation and consensus.
  • Custom RSM implementation: you can create your own applier rules.

Installation

Via npm

$ npm install mokka --save

From repo

$ npm run build

Usage

Client example can be found under: src/demo/client.ts

The package.json already includes the script for running demo client. By default, the cluster has 4 members. So, you have to open 4 terminals and type in each terminal the appropriate command: terminal 1: npm run serve_client1 terminal 2: npm run serve_client2 terminal 3: npm run serve_client3 terminal 4: npm run serve_client4

In order to generate new random logs count (N), type:

generate N

To get RSM state, type:

get_info

API

new Mokka (options)

Returns a new mokka instance. As mokka is agnostic to protocol implementation, you have to create your own. Please check the Custom transport layer section.

Arguments:

  • address (string): an address in custom format. The only rule is that address should include the public key in the end (example: "tcp://127.0.0.1:2003/7b85cee8bf60035d1bbccff5c47635733b9818ddc8f34927d00df09c1da80b15")
  • electionMin (integer): minimum time required for voting
  • electionMax (integer): max time required for voting
  • heartbeat (integer): leader heartbeat timeout
  • gossipHeartbeat (integer): gossip heartbeat timeout
  • storage: levelDb compatible instance (can be leveldown, memdown and so on). Also be sure, that your instance satisfy the interface IStorageInterface.
  • logger (ILoggerInterface): logger instance. If omitted, then console.log will be used
  • privateKey: the 64 length private key. Please take a look at tweetnacl key pair generator

mokka.logApi.push (key: string, value: any): void

push new log and replicate it over the cluster.

await mokka.getDb().getState().getInfo(): Promise<StateModel>

Returns the current state of node (last log index, last committed log index, merkle root)

await mokka.getDb().getEntry().get(index: number): Promise<EntryModel>

Returns entry (i.e. structure with log), by provided index.

await mokka.getDb().getEntry().getAfterList (index: number, limit: number): Promise<Array<EntryModel>>

Returns N (specified in limit) logs after specified index.

Events

A Mokka instance emits the following events (available at /components/shared/EventTypes.ts):

  • join: once we add new peer
  • leave: once we remove peer
  • error: once error happens (for instance, bad voting)
  • heartbeat_timeout: once we can't receive the heartbeat from leader in certain time (specified in config)
  • state: once the state of node changed (i.e. leader, candidate, follower)
  • log: once node received new log
  • log_ack: once node acked the log

Also gossip expose events. To use them, you have to listen events from gossip instance: <mokka_instance>.gossip.on(<event_type>, ()=>{})

  • peer_new: once gossip connects to new peer
  • peer_update: once gossip update information about certain peer
  • peer_alive: once gossip checked that certain peer alive
  • peer_failed: once gossip can't receive any answer from certain peer

Custom transport layer

In order to communicate between nodes, you have to implement the interface by yourself. As an example you can take a look at TCP implementation: src/implementation/TCP. In order to write your own implementation you have to implement 2 methods:

  • The async initialize() function, which fires on mokka start. This method is useful, when you want to open the connection, for instance, tcp one, or connect to certain message broker like rabbitMQ.

  • The async write(address: string, packet: Buffer) function, which fires each time mokka wants to broadcast message to other peer (address param).

License

GNU AGPLv3

Copyright

Copyright (c) 2018-2019 Egor Zuev

Current Tags

  • 0.3.0                                ...           latest (2 months ago)

10 Versions

  • 0.3.0                                ...           2 months ago
  • 0.2.5                                ...           2 months ago
  • 0.2.4                                ...           2 months ago
  • 0.2.2                                ...           3 months ago
  • 0.2.1                                ...           3 months ago
  • 0.1.2                                ...           3 months ago
  • 0.1.1                                ...           3 months ago
  • 0.1.0                                ...           3 months ago
  • 0.0.2                                ...           5 months ago
  • 0.0.1                                ...           6 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 0
Last Month 11
Dependencies (10)
Dev Dependencies (23)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |