-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorigin.js
69 lines (61 loc) · 1.28 KB
/
origin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { Node } = require('./node')
const extend = require('extend')
const hooks = require('./hooks')
const ram = require('random-access-memory')
/**
* The `Origin` class represents an extended `Node` that is
* is an origin node, non-ephemeral, only uploads, and does not look up
* peers.
* @public
* @class Origin
* @extends Node
*/
class Origin extends Node {
/**
* Default options for a `Origin` class instance.
* @public
* @static
* @param {?(Object)} defaults
* @param {...?(Object)} overrides
* @return {Object}
*/
static defaults(defaults, ...overrides) {
return Node.defaults({
ephemeral: false,
download: false,
lookup: false,
origin: true,
nonces: null,
hooks: [],
}, defaults, ...overrides)
}
/**
* @protected
*/
[Node.init](opts) {
super[Node.init](opts)
this.nonces = opts.nonces
}
[Node.options](opts) {
super[Node.options](opts)
if (opts.encryptionKey && opts.nonces) {
opts.hooks.push(hooks.xsalsa20)
}
}
[Node.codec](opts) {
return null
}
}
/**
* Factory for creating `Origin` instances.
* @public
*/
function createOrigin(...args) {
return new Origin(...args)
}
/**
* Module exports.
*/
module.exports = Object.assign(createOrigin, {
Origin,
})