@leofcoin/peernet 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/codec-format-interface.js.html +637 -0
- package/coverage/lcov-report/dht-response.js.html +193 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +199 -0
- package/dist/browser/peernet.js +1288 -1385
- package/dist/commonjs/{client-bd0caeb7.js → client-1a1f75e6.js} +41 -41
- package/dist/commonjs/{codec-4a768e5e.js → codec-8c8c652f.js} +118 -118
- package/dist/commonjs/codec-format-interface.js +167 -167
- package/dist/commonjs/codec.js +2 -2
- package/dist/commonjs/dht-response.js +11 -11
- package/dist/commonjs/dht.js +2 -2
- package/dist/commonjs/hash.js +149 -149
- package/dist/commonjs/{http-2b0735ef.js → http-7bbac90a.js} +1 -1
- package/dist/commonjs/peernet-message.js +2 -2
- package/dist/commonjs/peernet.js +843 -934
- package/dist/commonjs/request.js +2 -2
- package/dist/commonjs/response.js +2 -2
- package/dist/module/peernet.js +1357 -1448
- package/package.json +2 -18
- package/src/client.js +75 -75
- package/src/codec/codec-format-interface.js +172 -172
- package/src/codec/codec.js +124 -124
- package/src/dht/dht.js +121 -121
- package/src/discovery/peer-discovery.js +75 -75
- package/src/hash/hash.js +155 -155
- package/src/http/client/http-client.js +44 -44
- package/src/messages/dht-response.js +14 -14
- package/src/peer.js +67 -67
- package/src/peernet.js +612 -612
- package/src/proto/chat-message.proto.js +7 -7
- package/src/utils/utils.js +78 -78
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default `
|
|
2
|
-
message ChatMessage {
|
|
3
|
-
required string value = 1;
|
|
4
|
-
required string author = 2;
|
|
5
|
-
required uint64 timestamp = 3;
|
|
6
|
-
repeated string files = 4;
|
|
7
|
-
}`
|
|
1
|
+
export default `
|
|
2
|
+
message ChatMessage {
|
|
3
|
+
required string value = 1;
|
|
4
|
+
required string author = 2;
|
|
5
|
+
required uint64 timestamp = 3;
|
|
6
|
+
repeated string files = 4;
|
|
7
|
+
}`
|
package/src/utils/utils.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import fetch from 'node-fetch'
|
|
2
|
-
import Codec from './../codec/codec.js'
|
|
3
|
-
|
|
4
|
-
export const expected = (expected, actual) => {
|
|
5
|
-
const rule = (entry) => {
|
|
6
|
-
return !entry ? `: undefined - ${entry} ` :`: ${typeof entry} - `
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const entries = Object.entries(actual)
|
|
10
|
-
.map((entry) => entry.join(rule(entry[1])));
|
|
11
|
-
|
|
12
|
-
return `\nExpected:
|
|
13
|
-
${expected.join('\n\t')}
|
|
14
|
-
|
|
15
|
-
actual:
|
|
16
|
-
${entries.join('\n\t')}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const debug = (log) => {
|
|
20
|
-
if (globalThis.DEBUG || globalThis.debug) console.log(`%c ${log}`, 'color: #0080ff;')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const protoFor = (data) => {
|
|
24
|
-
if (!Buffer.isBuffer(data)) data = Buffer.from(data)
|
|
25
|
-
const codec = new Codec(data)
|
|
26
|
-
if (!codec.name) throw new Error('proto not found')
|
|
27
|
-
const Proto = globalThis.peernet.protos[codec.name]
|
|
28
|
-
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
29
|
-
return new Proto(data)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* wether or not a peernet daemon is active
|
|
34
|
-
* @return {Boolean}
|
|
35
|
-
*/
|
|
36
|
-
export const hasDaemon = async () => {
|
|
37
|
-
try {
|
|
38
|
-
let response = await fetch('http://127.0.0.1:1000/api/version')
|
|
39
|
-
response = await response.json()
|
|
40
|
-
return Boolean(response.client === '@peernet/api/http')
|
|
41
|
-
} catch (e) {
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const https = () => {
|
|
47
|
-
if (!globalThis.location) return false;
|
|
48
|
-
return Boolean(globalThis.location.protocol === 'https:')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get current environment
|
|
53
|
-
* @return {String} current environment [node, electron, browser]
|
|
54
|
-
*/
|
|
55
|
-
export const environment = () => {
|
|
56
|
-
const _navigator = globalThis.navigator
|
|
57
|
-
if (!_navigator) {
|
|
58
|
-
return 'node'
|
|
59
|
-
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
60
|
-
return 'electron'
|
|
61
|
-
} else {
|
|
62
|
-
return 'browser'
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* * Get current environment
|
|
68
|
-
* @return {Object} result
|
|
69
|
-
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
70
|
-
* @property {Boolean} reult.environment Current environment
|
|
71
|
-
*/
|
|
72
|
-
export const target = async () => {
|
|
73
|
-
let daemon = false
|
|
74
|
-
const env = await environment()
|
|
75
|
-
if (!https()) daemon = await hasDaemon()
|
|
76
|
-
|
|
77
|
-
return {daemon, environment: env}
|
|
78
|
-
}
|
|
1
|
+
import fetch from 'node-fetch'
|
|
2
|
+
import Codec from './../codec/codec.js'
|
|
3
|
+
|
|
4
|
+
export const expected = (expected, actual) => {
|
|
5
|
+
const rule = (entry) => {
|
|
6
|
+
return !entry ? `: undefined - ${entry} ` :`: ${typeof entry} - `
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const entries = Object.entries(actual)
|
|
10
|
+
.map((entry) => entry.join(rule(entry[1])));
|
|
11
|
+
|
|
12
|
+
return `\nExpected:
|
|
13
|
+
${expected.join('\n\t')}
|
|
14
|
+
|
|
15
|
+
actual:
|
|
16
|
+
${entries.join('\n\t')}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const debug = (log) => {
|
|
20
|
+
if (globalThis.DEBUG || globalThis.debug) console.log(`%c ${log}`, 'color: #0080ff;')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const protoFor = (data) => {
|
|
24
|
+
if (!Buffer.isBuffer(data)) data = Buffer.from(data)
|
|
25
|
+
const codec = new Codec(data)
|
|
26
|
+
if (!codec.name) throw new Error('proto not found')
|
|
27
|
+
const Proto = globalThis.peernet.protos[codec.name]
|
|
28
|
+
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
29
|
+
return new Proto(data)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* wether or not a peernet daemon is active
|
|
34
|
+
* @return {Boolean}
|
|
35
|
+
*/
|
|
36
|
+
export const hasDaemon = async () => {
|
|
37
|
+
try {
|
|
38
|
+
let response = await fetch('http://127.0.0.1:1000/api/version')
|
|
39
|
+
response = await response.json()
|
|
40
|
+
return Boolean(response.client === '@peernet/api/http')
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const https = () => {
|
|
47
|
+
if (!globalThis.location) return false;
|
|
48
|
+
return Boolean(globalThis.location.protocol === 'https:')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get current environment
|
|
53
|
+
* @return {String} current environment [node, electron, browser]
|
|
54
|
+
*/
|
|
55
|
+
export const environment = () => {
|
|
56
|
+
const _navigator = globalThis.navigator
|
|
57
|
+
if (!_navigator) {
|
|
58
|
+
return 'node'
|
|
59
|
+
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
60
|
+
return 'electron'
|
|
61
|
+
} else {
|
|
62
|
+
return 'browser'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* * Get current environment
|
|
68
|
+
* @return {Object} result
|
|
69
|
+
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
70
|
+
* @property {Boolean} reult.environment Current environment
|
|
71
|
+
*/
|
|
72
|
+
export const target = async () => {
|
|
73
|
+
let daemon = false
|
|
74
|
+
const env = await environment()
|
|
75
|
+
if (!https()) daemon = await hasDaemon()
|
|
76
|
+
|
|
77
|
+
return {daemon, environment: env}
|
|
78
|
+
}
|