TMan
Extends:
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 |
partialView: * |
|
public |
periodic: * |
|
public |
|
|
public |
unicast: * |
Method Summary
Public Methods | ||
public |
Get k neighbors from the partial view. |
|
public |
Joining a network. |
Private Methods | ||
private |
|
|
private |
|
|
private |
_getSample(neighbor: object): object[] |
|
private |
|
|
private |
_onArcDown(peerId: string | null) |
|
private |
_onExchange(peerId: string, message: ISuggest) |
|
private |
_onExchangeBack(peerId: string, message: MSuggest | MSuggestBack) |
|
private |
|
|
private |
_onPeerDown(peerId: string) |
|
private |
_onRequestDescriptor(peerId: string, message: MRequestDescriptor) |
|
private |
_onRequire(peerId: string, message: MRequire) |
|
private |
|
|
private |
|
|
private |
|
|
private |
_requestDescriptor(peerId: string): Promise |
|
private |
_sampleSize(flatten: string[]): number |
|
private |
_start(delay: *) |
|
private |
_stop() |
|
private |
|
Public Constructors
public constructor(options: object, parent: IPSP) source
Params:
Name | Type | Attribute | Description |
options | object |
|
Options given to TMan to build the desired topology. |
options.pid | string |
|
The identifier of this protocol. |
options.delta | number |
|
Every delta millisecond, exchange neighbors of the partial view. |
options.timeout | number |
|
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 |
|
Peers regularly ask for descriptor and await an answer. If this answer does not come up in time, it throws an exception. |
parent | IPSP |
|
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 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:
Name | Type | Attribute | Description |
k | number | The number of neighbors requested. If k is not defined, it returns every known identifiers of the partial view. |
public join(sender: callback): Promise source
Joining a network.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
peerId | string | The identifier of the removed arc. |
private _exchange() source
private _getSample(neighbor: object): object[] source
Params:
Name | Type | Attribute | Description |
neighbor | object | Object containing .peer for identifier of the peer to exchange with and .descriptor for the peer's descriptor. |
private _keep(peerId: string) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the peer to check. |
private _onExchange(peerId: string, message: ISuggest) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the initiating peer. |
|
message | ISuggest | The message containing the suggestions. |
private _onExchangeBack(peerId: string, message: MSuggest | MSuggestBack) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the peer that sent the message. |
|
message | MSuggest | MSuggestBack | The message received. |
private _onPeerDown(peerId: string) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the peer that seems left/crashed. |
private _onRequestDescriptor(peerId: string, message: MRequestDescriptor) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the requester. |
|
message | MRequestDescriptor | The message received. |
private _open(peerId: string) source
Params:
Name | Type | Attribute | Description |
peerId | string | The identifier of the new neighbor. |
private _requestDescriptor(peerId: string): Promise source
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
flatten | string[] | Array of identifiers. |
private _start(delay: *) source
Params:
Name | Type | Attribute | Description |
delay | * |
|