Home Reference Source
import TMan from 'tman-wrtc'
public class | source

TMan

Extends:

n2n-overlay-wrtc~N2N → TMan

Peer-sampling protocol running on top of WebRTC that builds network topologies using ranking functions.

Constructor Summary

Public Constructor
public

constructor(options: object, parent: IPSP)

Member Summary

Public Members
public

cache: *

public

parent: *

public
public
public
public

unicast: *

Method Summary

Public Methods
public

Get k neighbors from the partial view.

public

join(sender: callback): Promise

Joining a network.

Private Methods
private

_close(peerId: string)

private
private

_getSample(neighbor: object): object[]

private

_keep(peerId: string)

private

_onArcDown(peerId: string | null)

private

_onExchange(peerId: string, message: ISuggest)

private
private

_onJoin(peerId: string, message: MJoin)

private

_onPeerDown(peerId: string)

private
private

_onRequire(peerId: string, message: MRequire)

private

_open(peerId: string)

private
private

_receive(peerId: string, message: object | MExchange)

private
private

_sampleSize(flatten: string[]): number

private

_start(delay: *)

private

_stop()

private

Public Constructors

public constructor(options: object, parent: IPSP) source

Params:

NameTypeAttributeDescription
options object
  • optional

Options given to TMan to build the desired topology.

options.pid string
  • optional
  • default: 'tman-wrtc'

The identifier of this protocol.

options.delta number
  • optional
  • default: 60000

Every delta millisecond, exchange neighbors of the partial view.

options.timeout number
  • optional
  • default: 120000

WebRTC connections are expensive to establish, may fail, etc. Instead of immediately removing them, the protocol keep them warm during options.timeout milliseconds. Consequently, messages transiting through them can still be transmitted, and if the protocol requires such an arc, it can be reestablished at no cost.

options.descriptorTimeout number
  • optional
  • default: 10000

Peers regularly ask for descriptor and await an answer. If this answer does not come up in time, it throws an exception.

parent IPSP
  • optional

This module can depend of another peer-sampling protocol. If set, it will share the neighbors populating its inview and outview. Thus, the above options will be of no use. See neigbhorhood-wrtc module for more informations on the sharing process.

Public Members

public cache: * source

public parent: * source

public partialView: * source

public periodic: * source

public state: string source

public unicast: * source

Public Methods

public getPeers(k: number): string[] source

Get k neighbors from the partial view. If k is not reached, it tries to fill the gap with neighbors from the inview. It is worth noting that each peer controls its outview but not its inview. The more the neigbhors from the outview the better.

Params:

NameTypeAttributeDescription
k number

The number of neighbors requested. If k is not defined, it returns every known identifiers of the partial view.

Return:

string[]

Array of identifiers.

public join(sender: callback): Promise source

Joining a network.

Params:

NameTypeAttributeDescription
sender callback

Function that will be called each time an offer arrives to this peer. It is the responsability of the caller to send these offer (using sender) to the contact inside the network.

Return:

Promise

A promise that is resolved when the peer joins the network; rejected after a timeout, or already connected state.

Private Methods

private _close(peerId: string) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the removed arc.

private _exchange() source

private _getSample(neighbor: object): object[] source

Params:

NameTypeAttributeDescription
neighbor object

Object containing .peer for identifier of the peer to exchange with and .descriptor for the peer's descriptor.

Return:

object[]

Array of object containing .peer and .descriptor.

private _keep(peerId: string) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer to check.

private _onArcDown(peerId: string | null) source

Params:

NameTypeAttributeDescription
peerId string | null

The identifier of the peer with which we failed to create a connection. Null if it was yet to be known.

private _onExchange(peerId: string, message: ISuggest) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the initiating peer.

message ISuggest

The message containing the suggestions.

private _onExchangeBack(peerId: string, message: MSuggest | MSuggestBack) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer that sent the message.

message MSuggest | MSuggestBack

The message received.

private _onJoin(peerId: string, message: MJoin) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the newcomer.

message MJoin

The message sent by the newcomer.

private _onPeerDown(peerId: string) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer that seems left/crashed.

private _onRequestDescriptor(peerId: string, message: MRequestDescriptor) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the requester.

message MRequestDescriptor

The message received.

private _onRequire(peerId: string, message: MRequire) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer that requests connections.

message MRequire

The request message.

private _open(peerId: string) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the new neighbor.

private _partialViewSize(): number source

Return:

number

private _receive(peerId: string, message: object | MExchange) source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer that sent the message.

message object | MExchange

The message received.

private _requestDescriptor(peerId: string): Promise source

Params:

NameTypeAttributeDescription
peerId string

The identifier of the peer.

Return:

Promise

Resolved when the descriptor has been added to our cache; Rejected after a timeout or an error when sending the message.

private _sampleSize(flatten: string[]): number source

Params:

NameTypeAttributeDescription
flatten string[]

Array of identifiers.

Return:

number

The size of the sample to create.

private _start(delay: *) source

Params:

NameTypeAttributeDescription
delay *
  • optional

private _stop() source

private _updateState() source