@libp2p/interop 0.0.0
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/LICENSE +4 -0
- package/README.md +60 -0
- package/dist/src/connect.d.ts +3 -0
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/src/connect.js +54 -0
- package/dist/src/connect.js.map +1 -0
- package/dist/src/dht/content-fetching.d.ts +3 -0
- package/dist/src/dht/content-fetching.d.ts.map +1 -0
- package/dist/src/dht/content-fetching.js +50 -0
- package/dist/src/dht/content-fetching.js.map +1 -0
- package/dist/src/dht/content-routing.d.ts +3 -0
- package/dist/src/dht/content-routing.d.ts.map +1 -0
- package/dist/src/dht/content-routing.js +50 -0
- package/dist/src/dht/content-routing.js.map +1 -0
- package/dist/src/dht/index.d.ts +3 -0
- package/dist/src/dht/index.d.ts.map +1 -0
- package/dist/src/dht/index.js +9 -0
- package/dist/src/dht/index.js.map +1 -0
- package/dist/src/dht/peer-routing.d.ts +3 -0
- package/dist/src/dht/peer-routing.d.ts.map +1 -0
- package/dist/src/dht/peer-routing.js +44 -0
- package/dist/src/dht/peer-routing.js.map +1 -0
- package/dist/src/index.d.ts +20 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/pubsub/floodsub.d.ts +3 -0
- package/dist/src/pubsub/floodsub.d.ts.map +1 -0
- package/dist/src/pubsub/floodsub.js +52 -0
- package/dist/src/pubsub/floodsub.js.map +1 -0
- package/dist/src/pubsub/gossipsub.d.ts +3 -0
- package/dist/src/pubsub/gossipsub.d.ts.map +1 -0
- package/dist/src/pubsub/gossipsub.js +52 -0
- package/dist/src/pubsub/gossipsub.js.map +1 -0
- package/dist/src/pubsub/hybrid.d.ts +3 -0
- package/dist/src/pubsub/hybrid.d.ts.map +1 -0
- package/dist/src/pubsub/hybrid.js +52 -0
- package/dist/src/pubsub/hybrid.js.map +1 -0
- package/dist/src/pubsub/index.d.ts +3 -0
- package/dist/src/pubsub/index.d.ts.map +1 -0
- package/dist/src/pubsub/index.js +9 -0
- package/dist/src/pubsub/index.js.map +1 -0
- package/dist/src/resources/keys/go.ed25519.key +1 -0
- package/dist/src/resources/keys/go.rsa.key +0 -0
- package/dist/src/resources/keys/go.secp256k1.key +1 -0
- package/dist/src/resources/keys/index.d.ts +5 -0
- package/dist/src/resources/keys/index.d.ts.map +1 -0
- package/dist/src/resources/keys/index.js +18 -0
- package/dist/src/resources/keys/index.js.map +1 -0
- package/dist/src/resources/keys/js.ed25519.key +1 -0
- package/dist/src/resources/keys/js.rsa.key +0 -0
- package/dist/src/resources/keys/js.secp256k1.key +1 -0
- package/dist/src/utils/dht-record.d.ts +6 -0
- package/dist/src/utils/dht-record.d.ts.map +1 -0
- package/dist/src/utils/dht-record.js +10 -0
- package/dist/src/utils/dht-record.js.map +1 -0
- package/package.json +151 -0
- package/src/connect.ts +75 -0
- package/src/dht/content-fetching.ts +70 -0
- package/src/dht/content-routing.ts +74 -0
- package/src/dht/index.ts +10 -0
- package/src/dht/peer-routing.ts +63 -0
- package/src/index.ts +31 -0
- package/src/pubsub/floodsub.ts +70 -0
- package/src/pubsub/gossipsub.ts +70 -0
- package/src/pubsub/hybrid.ts +70 -0
- package/src/pubsub/index.ts +10 -0
- package/src/resources/keys/go.ed25519.key +1 -0
- package/src/resources/keys/go.rsa.key +0 -0
- package/src/resources/keys/go.secp256k1.key +1 -0
- package/src/resources/keys/index.ts +24 -0
- package/src/resources/keys/js.ed25519.key +1 -0
- package/src/resources/keys/js.rsa.key +0 -0
- package/src/resources/keys/js.secp256k1.key +1 -0
- package/src/utils/dht-record.ts +10 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import { expect } from 'aegir/utils/chai.js'
|
|
4
|
+
import type { Daemon, DaemonFactory, NodeType, SpawnOptions } from '../index.js'
|
|
5
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
+
import first from 'it-first'
|
|
7
|
+
|
|
8
|
+
export function gossipsubTests (factory: DaemonFactory) {
|
|
9
|
+
const nodeTypes: NodeType[] = ['js', 'go']
|
|
10
|
+
|
|
11
|
+
for (const typeA of nodeTypes) {
|
|
12
|
+
for (const typeB of nodeTypes) {
|
|
13
|
+
runGossipsubTests(
|
|
14
|
+
factory,
|
|
15
|
+
{ type: typeA, pubsub: true, pubsubRouter: 'gossipsub' },
|
|
16
|
+
{ type: typeB, pubsub: true, pubsubRouter: 'gossipsub' }
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function runGossipsubTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions) {
|
|
23
|
+
describe('pubsub.gossipsub', () => {
|
|
24
|
+
let daemons: Daemon[]
|
|
25
|
+
|
|
26
|
+
// Start Daemons
|
|
27
|
+
before(async function () {
|
|
28
|
+
this.timeout(20 * 1000)
|
|
29
|
+
|
|
30
|
+
daemons = await Promise.all([
|
|
31
|
+
factory.spawn(optionsA),
|
|
32
|
+
factory.spawn(optionsB),
|
|
33
|
+
factory.spawn(optionsB)
|
|
34
|
+
])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Stop daemons
|
|
38
|
+
after(async function () {
|
|
39
|
+
if (daemons != null) {
|
|
40
|
+
await Promise.all(
|
|
41
|
+
daemons.map(async (daemon) => await daemon.stop())
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
47
|
+
const topic = 'test-topic'
|
|
48
|
+
const data = uint8ArrayFromString('test-data')
|
|
49
|
+
|
|
50
|
+
const subscribeIterator = await daemons[1].client.pubsub.subscribe(topic)
|
|
51
|
+
const subscriber = async () => {
|
|
52
|
+
const message = await first(subscribeIterator)
|
|
53
|
+
|
|
54
|
+
expect(message).to.exist()
|
|
55
|
+
expect(message).to.have.property('data').that.equalBytes(data)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const publisher = async () => {
|
|
59
|
+
// wait for subscription stream
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, 800))
|
|
61
|
+
await daemons[0].client.pubsub.publish(topic, data)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return await Promise.all([
|
|
65
|
+
subscriber(),
|
|
66
|
+
publisher()
|
|
67
|
+
])
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import { expect } from 'aegir/utils/chai.js'
|
|
4
|
+
import type { Daemon, DaemonFactory, NodeType, SpawnOptions } from '../index.js'
|
|
5
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
6
|
+
import first from 'it-first'
|
|
7
|
+
|
|
8
|
+
export function hybridTests (factory: DaemonFactory) {
|
|
9
|
+
const nodeTypes: NodeType[] = ['js', 'go']
|
|
10
|
+
|
|
11
|
+
for (const typeA of nodeTypes) {
|
|
12
|
+
for (const typeB of nodeTypes) {
|
|
13
|
+
runHybridTests(
|
|
14
|
+
factory,
|
|
15
|
+
{ type: typeA, pubsub: true, pubsubRouter: 'floodsub' },
|
|
16
|
+
{ type: typeB, pubsub: true, pubsubRouter: 'gossipsub' }
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function runHybridTests (factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions) {
|
|
23
|
+
describe('pubsub.hybrid', () => {
|
|
24
|
+
let daemons: Daemon[]
|
|
25
|
+
|
|
26
|
+
// Start Daemons
|
|
27
|
+
before(async function () {
|
|
28
|
+
this.timeout(20 * 1000)
|
|
29
|
+
|
|
30
|
+
daemons = await Promise.all([
|
|
31
|
+
factory.spawn(optionsA),
|
|
32
|
+
factory.spawn(optionsB),
|
|
33
|
+
factory.spawn(optionsB)
|
|
34
|
+
])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Stop daemons
|
|
38
|
+
after(async function () {
|
|
39
|
+
if (daemons != null) {
|
|
40
|
+
await Promise.all(
|
|
41
|
+
daemons.map(async (daemon) => await daemon.stop())
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
|
|
47
|
+
const topic = 'test-topic'
|
|
48
|
+
const data = uint8ArrayFromString('test-data')
|
|
49
|
+
|
|
50
|
+
const subscribeIterator = await daemons[1].client.pubsub.subscribe(topic)
|
|
51
|
+
const subscriber = async () => {
|
|
52
|
+
const message = await first(subscribeIterator)
|
|
53
|
+
|
|
54
|
+
expect(message).to.exist()
|
|
55
|
+
expect(message).to.have.property('data').that.equalBytes(data)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const publisher = async () => {
|
|
59
|
+
// wait for subscription stream
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, 800))
|
|
61
|
+
await daemons[0].client.pubsub.publish(topic, data)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return await Promise.all([
|
|
65
|
+
subscriber(),
|
|
66
|
+
publisher()
|
|
67
|
+
])
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DaemonFactory } from '../index.js'
|
|
2
|
+
import { floodsubTests } from './floodsub.js'
|
|
3
|
+
import { gossipsubTests } from './gossipsub.js'
|
|
4
|
+
import { hybridTests } from './hybrid.js'
|
|
5
|
+
|
|
6
|
+
export async function pubsubTests (factory: DaemonFactory) {
|
|
7
|
+
await floodsubTests(factory)
|
|
8
|
+
await gossipsubTests(factory)
|
|
9
|
+
await hybridTests(factory)
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`���W��ע���Fv=�E�O*bb��eJK"��Pk�a��W��bs��|��������8*�y+���Pk�a��W��bs��|��������8*�y+�
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{��ܥg�oT+.�\�L�Y��Jb���G�q7�
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
|
+
import type { NodeType, PeerIdType } from '../..'
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url)) // eslint-disable-line @typescript-eslint/naming-convention
|
|
6
|
+
|
|
7
|
+
type KeyCollection = Record<PeerIdType, string>
|
|
8
|
+
|
|
9
|
+
const goKeys: KeyCollection = {
|
|
10
|
+
ed25519: path.join(__dirname, 'go.ed25519.key'),
|
|
11
|
+
rsa: path.join(__dirname, 'go.rsa.key'),
|
|
12
|
+
secp256k1: path.join(__dirname, 'go.secp256k1.key')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const jsKeys: KeyCollection = {
|
|
16
|
+
ed25519: path.join(__dirname, 'js.ed25519.key'),
|
|
17
|
+
rsa: path.join(__dirname, 'js.rsa.key'),
|
|
18
|
+
secp256k1: path.join(__dirname, 'js.secp256k1.key')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const keys: Record<NodeType, KeyCollection> = {
|
|
22
|
+
go: goKeys,
|
|
23
|
+
js: jsKeys
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
`F́o��.ux��7f�v71��{�z���9*x7Ӟ�g��Q�g,�FhŒ�0������]3�7Ӟ�g��Q�g,�FhŒ�0������]3�
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
�z�m�/�kPa�ࡓ$�Z���p"�>v��
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: uint8ArrayConcat([
|
|
6
|
+
uint8ArrayFromString('/pk/'),
|
|
7
|
+
uint8ArrayFromString('muft89xjpybos8eas1vaq2xrbsx2vkll7is4ocy7pia5fsjlt3c2', 'base36')
|
|
8
|
+
]),
|
|
9
|
+
value: uint8ArrayFromString('080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100c2588f998971dac9e3eef76a311bf9159505aff69ea3b664c55a36aa28ee08de1127228a4d431bb9c0840240c75f6e98a0843a78d945491a3ea5e1f7cee2bc71383510db5290702383975b7bffae9fb40c84cc1220fb4a7db862fffb0de42f8fd8fb33a17deb20f30e2d0f194791fe69355a392f77df35f101e08a2fc95b2c018768938814fcb52482f899f5e90a1905e8abbcdbb1647ad80a5b0417e1ce8320d64197a6ba3848926375c63adebabdf6eb82109bcadfee13b62bf922bbb6f74c1a26c9bc6122d1436787e0e6de3c152b1959701092abef84599f73eaedb2fcef9f87293e1bbe8e0fef3f1a7fd2e8b94c7e633f88473644a63cb948e4d25c54490203010001', 'hex')
|
|
10
|
+
}
|