You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-55
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,11 @@ protocol before continuing too much further.
11
11
12
12
## Overview ##
13
13
14
-
Simple-Scuttle exports a class - soit `Gossip` - whose instances are
15
-
transform streams in objectMode. This stream maintains several data structures
16
-
with which it manages state (see [`Gossip.state`](#gossipstate)) and the
17
-
propagation of state changes (implemented with [`Gossip.digest`](#gossipdigest) and
18
-
[`Gossip.history`](#gossiphistory)).
14
+
Simple-Scuttle exports a class - soit `Gossip` - whose instances are transform
15
+
streams in objectMode. `Gossip` instances maintain several data structures with
16
+
which they manages state (see [`Gossip.state`](#gossipstate)) and the
17
+
propagation of state changes (implemented with [`Gossip.clock`](#gossipclock)
18
+
and [`Gossip.history`](#gossiphistory)).
19
19
20
20
Rather than implementing several parallel streams, `Gossip` instances choose
21
21
logical branches based on the semantics of the objects written to them-- the
@@ -29,26 +29,28 @@ documented in the [Expected Objects](#expected-objects) section.
29
29
```js
30
30
Gossip(
31
31
String id
32
-
, Integer mtu |false
33
-
, Integer max_history |false
34
-
, Functionsort(Update A, Update B) -> Bool |false
32
+
, Integer mtu |null
33
+
, Integer max_history |null
34
+
, Function should_apply |null
35
+
, Function sort |null
35
36
) -> gossip
36
37
```
37
38
38
39
-`id`: The unique identifier for each `Gossip` instance.
39
40
-`mtu`: How many messages the network can handle at once-- this is used to set
40
41
[opts.highWaterMark](http://nodejs.org/api/stream.html#stream_new_stream_readable_options). Defaults to 10 if falsey.
41
-
-`max_history`: How many deltas to store before we begin to forget old ones. Such concerns are absent from the paper, but they seem important to me. Defaults to 10 if falsey.
42
-
-`sort`: A function which describes how to resolve
43
-
versioning ties between when two deltas disagree on a key-value pair. It's
44
-
return value indicates whether its first argument should take primacy.
45
-
Defaults to sort by version and breaking ties with lexical ordering of IDs.
42
+
-`max_history`: How many updates to store before we begin to forget old ones. Such concerns are absent from the paper, but they seem important to me. Defaults to 10 if falsey.
43
+
-`should_apply``(gossip, update)` -> `Boolean`: A function which determines
44
+
whether or not a given update should be applied.
45
+
-`sort`: A function which describes how to order updates. Has the same
46
+
signature as javascripts
47
+
[Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort), and will be called by Array.sort under the hood.
46
48
47
49
## Expected Objects ##
48
50
49
-
Gossip instances expect objects written to them (with `gossip.write`) to either be `digest`s or `delta`s.
51
+
Gossip instances expect objects written to them (with `gossip.write`) to either be `digest`s or `delta`s. Note that `delta`s are also referred to as `updates`.
50
52
51
-
Digests look like:
53
+
####digests####
52
54
53
55
```js
54
56
var digest = {
@@ -78,43 +80,43 @@ from calling `delete Gossip.state[key]` at every node, and then handling
78
80
avoid designing a system in which the number of keys can grow without bound.
79
81
Implementing a safe delete method remains a [To Do](#todo)
80
82
83
+
####deltas####
81
84
The other kind of object, the delta, is an object that appears like the
82
85
following:
83
86
84
87
```js
85
88
86
89
var delta = {
87
-
key:any_obj_which_can_be_a_key
88
-
, value:some_serializable_value
89
-
, source_id:source_id
90
-
, version:version_number_for_this_update
90
+
key:'age'
91
+
, value:100
92
+
, source_id:'#A'
93
+
, version:10
91
94
}
92
95
```
93
96
94
97
This says: "source `source_id` thought `key` mapped to `value` at `version`."
95
-
There is still some ambiguity here about when to apply this update to the local
96
-
state, and indeed, [npm.im/scuttlebutt][] leaves this specification to the
97
-
client. At current, the update is always applied, so long as `version` is
98
-
greater than the current version for the key.
98
+
The `should_apply` argument allows the user to specify whether or not this
99
+
update should be applied.
99
100
100
101
## Methods ##
101
102
102
103
`Gossip` instances are [Transform
103
104
Streams](http://nodejs.org/api/stream.html#stream_class_stream_transform_1), so
104
105
they implement all of the methods and events as described in the node core
105
-
documentation.
106
+
documentation. In addition, there are a few methods specific to this purpose:
106
107
107
108
###`Gossip.set(key, value) -> null`###
108
109
109
110
This method applies a local delta, simply setting the given key to the given
110
-
value in the local instance, giving it the appropriate `version` number and
111
+
value in the local instance, and tacking on the appropriate `version` number and
0 commit comments