Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
fix: use unidirectional streams v0.20.x (#106)
Browse files Browse the repository at this point in the history
* fix: use-unidirectional-streams-v020x

* chore: use [email protected]
  • Loading branch information
vasco-santos authored Jun 4, 2020
1 parent 01a98f7 commit 8103e7a
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"debug": "^4.1.1",
"it-length-prefixed": "^3.0.0",
"it-pipe": "^1.0.1",
"libp2p-pubsub": "~0.4.0",
"libp2p-pubsub": "~0.4.5",
"p-map": "^3.0.0",
"protons": "^1.0.1",
"time-cache": "^0.3.0"
Expand Down
27 changes: 27 additions & 0 deletions test/2-nodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ describe('basics between 2 nodes', () => {
// Connect floodsub nodes
before(async () => {
const onConnectA = registrarRecordA[multicodec].onConnect
const onConnectB = registrarRecordB[multicodec].onConnect
const handleA = registrarRecordA[multicodec].handler
const handleB = registrarRecordB[multicodec].handler

// Notice peers of connection
const [c0, c1] = ConnectionPair()
await onConnectA(peerInfoB, c0)
await onConnectB(peerInfoA, c1)

await handleB({
protocol: multicodec,
Expand All @@ -72,6 +75,14 @@ describe('basics between 2 nodes', () => {
}
})

await handleA({
protocol: multicodec,
stream: c0.stream,
connection: {
remotePeer: peerInfoB.id
}
})

expect(fsA.peers.size).to.be.eql(1)
expect(fsB.peers.size).to.be.eql(1)
})
Expand Down Expand Up @@ -275,11 +286,27 @@ describe('basics between 2 nodes', () => {
const dial = async () => {
const onConnectA = registrarRecordA[multicodec].onConnect
const onConnectB = registrarRecordB[multicodec].onConnect
const handleA = registrarRecordA[multicodec].handler
const handleB = registrarRecordB[multicodec].handler

// Notice peers of connection
const [c0, c1] = ConnectionPair()
await onConnectA(peerInfoB, c0)
await handleB({
protocol: multicodec,
stream: c1.stream,
connection: {
remotePeer: peerInfoA.id
}
})
await onConnectB(peerInfoA, c1)
await handleA({
protocol: multicodec,
stream: c0.stream,
connection: {
remotePeer: peerInfoB.id
}
})
}

await Promise.all([
Expand Down
95 changes: 94 additions & 1 deletion test/multiple-nodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,46 @@ describe('multiple nodes (more than 2)', () => {
const onConnectA = registrarRecordA[multicodec].onConnect
const onConnectB = registrarRecordB[multicodec].onConnect
const onConnectC = registrarRecordC[multicodec].onConnect
const handleA = registrarRecordA[multicodec].handler
const handleB = registrarRecordB[multicodec].handler
const handleC = registrarRecordC[multicodec].handler

// Notice peers of connection
const [d0, d1] = ConnectionPair()
await onConnectA(peerInfoB, d0)
await handleB({
protocol: multicodec,
stream: d1.stream,
connection: {
remotePeer: peerInfoA.id
}
})
await onConnectB(peerInfoA, d1)
await handleA({
protocol: multicodec,
stream: d0.stream,
connection: {
remotePeer: peerInfoB.id
}
})

const [d2, d3] = ConnectionPair()
await onConnectB(peerInfoC, d2)
await handleC({
protocol: multicodec,
stream: d3.stream,
connection: {
remotePeer: peerInfoB.id
}
})
await onConnectC(peerInfoB, d3)
await handleB({
protocol: multicodec,
stream: d2.stream,
connection: {
remotePeer: peerInfoC.id
}
})
})

after(() => Promise.all([
Expand Down Expand Up @@ -267,23 +298,85 @@ describe('multiple nodes (more than 2)', () => {
const onConnectC = registrarRecordC[multicodec].onConnect
const onConnectD = registrarRecordD[multicodec].onConnect
const onConnectE = registrarRecordE[multicodec].onConnect
const handleA = registrarRecordA[multicodec].handler
const handleB = registrarRecordB[multicodec].handler
const handleC = registrarRecordC[multicodec].handler
const handleD = registrarRecordD[multicodec].handler
const handleE = registrarRecordE[multicodec].handler

// Notice peers of connection
const [d0, d1] = ConnectionPair() // A <-> B
await onConnectA(peerInfoB, d0)
await handleB({
protocol: multicodec,
stream: d1.stream,
connection: {
remotePeer: peerInfoA.id
}
})
await onConnectB(peerInfoA, d1)
await handleA({
protocol: multicodec,
stream: d0.stream,
connection: {
remotePeer: peerInfoB.id
}
})

const [d2, d3] = ConnectionPair() // B <-> C
await onConnectB(peerInfoC, d2)
await handleC({
protocol: multicodec,
stream: d3.stream,
connection: {
remotePeer: peerInfoB.id
}
})
await onConnectC(peerInfoB, d3)
await handleB({
protocol: multicodec,
stream: d2.stream,
connection: {
remotePeer: peerInfoC.id
}
})

const [d4, d5] = ConnectionPair() // C <-> D
await onConnectC(peerInfoD, d4)
await handleD({
protocol: multicodec,
stream: d5.stream,
connection: {
remotePeer: peerInfoC.id
}
})
await onConnectD(peerInfoC, d5)
await handleC({
protocol: multicodec,
stream: d4.stream,
connection: {
remotePeer: peerInfoD.id
}
})

const [d6, d7] = ConnectionPair() // C <-> D
const [d6, d7] = ConnectionPair() // D <-> E
await onConnectD(peerInfoE, d6)
await handleE({
protocol: multicodec,
stream: d7.stream,
connection: {
remotePeer: peerInfoD.id
}
})

await onConnectE(peerInfoD, d7)
await handleD({
protocol: multicodec,
stream: d6.stream,
connection: {
remotePeer: peerInfoE.id
}
})
})

after(() => Promise.all([
Expand Down

0 comments on commit 8103e7a

Please sign in to comment.