@libp2p/gossipsub 17.2.1-ff95dc546 → 17.2.2
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/gossipsub.d.ts.map +1 -1
- package/dist/src/gossipsub.js +27 -11
- package/dist/src/gossipsub.js.map +1 -1
- package/dist/typedoc-urls.json +40 -0
- package/package.json +9 -9
- package/src/gossipsub.ts +29 -12
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"TopicValidatorResult": "https://libp2p.github.io/js-libp2p/enums/_libp2p_gossipsub.TopicValidatorResult.html",
|
|
3
|
+
".:TopicValidatorResult": "https://libp2p.github.io/js-libp2p/enums/_libp2p_gossipsub.TopicValidatorResult.html",
|
|
4
|
+
"GossipSub": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSub.html",
|
|
5
|
+
".:GossipSub": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSub.html",
|
|
6
|
+
"GossipSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSubComponents.html",
|
|
7
|
+
".:GossipSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSubComponents.html",
|
|
8
|
+
"GossipSubEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSubEvents.html",
|
|
9
|
+
".:GossipSubEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipSubEvents.html",
|
|
10
|
+
"GossipsubMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipsubMessage.html",
|
|
11
|
+
".:GossipsubMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipsubMessage.html",
|
|
12
|
+
"GossipsubOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipsubOpts.html",
|
|
13
|
+
".:GossipsubOpts": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.GossipsubOpts.html",
|
|
14
|
+
"MeshPeer": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.MeshPeer.html",
|
|
15
|
+
".:MeshPeer": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.MeshPeer.html",
|
|
16
|
+
"PublishResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.PublishResult.html",
|
|
17
|
+
".:PublishResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.PublishResult.html",
|
|
18
|
+
"SignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.SignedMessage.html",
|
|
19
|
+
".:SignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.SignedMessage.html",
|
|
20
|
+
"Subscription": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.Subscription.html",
|
|
21
|
+
".:Subscription": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.Subscription.html",
|
|
22
|
+
"SubscriptionChangeData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.SubscriptionChangeData.html",
|
|
23
|
+
".:SubscriptionChangeData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.SubscriptionChangeData.html",
|
|
24
|
+
"TopicValidatorFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.TopicValidatorFn.html",
|
|
25
|
+
".:TopicValidatorFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.TopicValidatorFn.html",
|
|
26
|
+
"UnsignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.UnsignedMessage.html",
|
|
27
|
+
".:UnsignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_gossipsub.UnsignedMessage.html",
|
|
28
|
+
"Message": "https://libp2p.github.io/js-libp2p/types/_libp2p_gossipsub.Message.html",
|
|
29
|
+
".:Message": "https://libp2p.github.io/js-libp2p/types/_libp2p_gossipsub.Message.html",
|
|
30
|
+
"SignaturePolicy": "https://libp2p.github.io/js-libp2p/types/_libp2p_gossipsub.SignaturePolicy.html",
|
|
31
|
+
".:SignaturePolicy": "https://libp2p.github.io/js-libp2p/types/_libp2p_gossipsub.SignaturePolicy.html",
|
|
32
|
+
"multicodec": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.multicodec.html",
|
|
33
|
+
".:multicodec": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.multicodec.html",
|
|
34
|
+
"StrictNoSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.StrictNoSign.html",
|
|
35
|
+
".:StrictNoSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.StrictNoSign.html",
|
|
36
|
+
"StrictSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.StrictSign.html",
|
|
37
|
+
".:StrictSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_gossipsub.StrictSign.html",
|
|
38
|
+
"gossipsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_gossipsub.gossipsub.html",
|
|
39
|
+
".:gossipsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_gossipsub.gossipsub.html"
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/gossipsub",
|
|
3
|
-
"version": "17.2.
|
|
3
|
+
"version": "17.2.2",
|
|
4
4
|
"description": "A typescript implementation of gossipsub",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
},
|
|
85
85
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/gossipsub#readme",
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@libp2p/crypto": "5.2.0
|
|
88
|
-
"@libp2p/interface": "3.4.0
|
|
89
|
-
"@libp2p/interface-internal": "3.2.
|
|
90
|
-
"@libp2p/peer-id": "6.0.18
|
|
91
|
-
"@libp2p/utils": "7.4.
|
|
87
|
+
"@libp2p/crypto": "^5.2.0",
|
|
88
|
+
"@libp2p/interface": "^3.4.0",
|
|
89
|
+
"@libp2p/interface-internal": "^3.2.3",
|
|
90
|
+
"@libp2p/peer-id": "^6.0.18",
|
|
91
|
+
"@libp2p/utils": "^7.4.6",
|
|
92
92
|
"@multiformats/multiaddr": "^13.0.3",
|
|
93
93
|
"denque": "^2.1.0",
|
|
94
94
|
"it-length-prefixed": "^11.0.1",
|
|
@@ -101,9 +101,9 @@
|
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
103
|
"@chainsafe/as-sha256": "^1.2.0",
|
|
104
|
-
"@libp2p/floodsub": "11.1.
|
|
105
|
-
"@libp2p/logger": "6.2.16
|
|
106
|
-
"@libp2p/peer-store": "12.0.
|
|
104
|
+
"@libp2p/floodsub": "^11.1.2",
|
|
105
|
+
"@libp2p/logger": "^6.2.16",
|
|
106
|
+
"@libp2p/peer-store": "^12.0.33",
|
|
107
107
|
"@types/benchmark": "^2.1.5",
|
|
108
108
|
"@types/sinon": "^22.0.0",
|
|
109
109
|
"abortable-iterator": "^5.1.0",
|
package/src/gossipsub.ts
CHANGED
|
@@ -1518,7 +1518,9 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1518
1518
|
* Handles Graft messages
|
|
1519
1519
|
*/
|
|
1520
1520
|
private async handleGraft (id: PeerIdStr, graft: RPC.ControlGraft[]): Promise<RPC.ControlPrune[]> {
|
|
1521
|
-
|
|
1521
|
+
// a single RPC can hold many GRAFTs for the same topic, only respond with
|
|
1522
|
+
// one PRUNE per topic
|
|
1523
|
+
const prune = new Set<TopicStr>()
|
|
1522
1524
|
const score = this.score.score(id)
|
|
1523
1525
|
const now = Date.now()
|
|
1524
1526
|
let doPX = this.opts.doPX
|
|
@@ -1550,7 +1552,7 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1550
1552
|
if (this.direct.has(id)) {
|
|
1551
1553
|
this.log('GRAFT: ignoring request from direct peer %s', id)
|
|
1552
1554
|
// this is possibly a bug from a non-reciprocal configuration; send a PRUNE
|
|
1553
|
-
prune.
|
|
1555
|
+
prune.add(topicID)
|
|
1554
1556
|
// but don't px
|
|
1555
1557
|
doPX = false
|
|
1556
1558
|
|
|
@@ -1569,14 +1571,14 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1569
1571
|
}
|
|
1570
1572
|
// refresh the backoff
|
|
1571
1573
|
this.addBackoff(id, topicID)
|
|
1572
|
-
prune.
|
|
1574
|
+
prune.add(topicID)
|
|
1573
1575
|
|
|
1574
1576
|
// check the score
|
|
1575
1577
|
} else if (score < 0) {
|
|
1576
1578
|
// we don't GRAFT peers with negative score
|
|
1577
1579
|
this.log('GRAFT: ignoring peer %s with negative score: score=%d, topic=%s', id, score, topicID)
|
|
1578
1580
|
// we do send them PRUNE however, because it's a matter of protocol correctness
|
|
1579
|
-
prune.
|
|
1581
|
+
prune.add(topicID)
|
|
1580
1582
|
// but we won't PX to them
|
|
1581
1583
|
doPX = false
|
|
1582
1584
|
// add/refresh backoff so that we don't reGRAFT too early even if the score decays
|
|
@@ -1586,24 +1588,27 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1586
1588
|
// from peers with outbound connections; this is a defensive check to restrict potential
|
|
1587
1589
|
// mesh takeover attacks combined with love bombing
|
|
1588
1590
|
} else if (peersInMesh.size >= this.opts.Dhi && !(this.outbound.get(id) ?? false)) {
|
|
1589
|
-
prune.
|
|
1591
|
+
prune.add(topicID)
|
|
1590
1592
|
this.addBackoff(id, topicID)
|
|
1591
1593
|
|
|
1592
1594
|
// valid graft
|
|
1593
1595
|
} else {
|
|
1594
1596
|
this.log('GRAFT: Add mesh link from %s in %s', id, topicID)
|
|
1595
1597
|
this.addToMesh(id, topicID, InclusionReason.Subscribed)
|
|
1596
|
-
}
|
|
1597
1598
|
|
|
1598
|
-
|
|
1599
|
+
// only notify when the peer was actually added to the mesh - rejected
|
|
1600
|
+
// GRAFTs do not change the mesh and listeners (e.g. peer tagging) can
|
|
1601
|
+
// be expensive
|
|
1602
|
+
this.safeDispatchEvent<MeshPeer>('gossipsub:graft', { detail: { peerId: id, topic: topicID, direction: 'inbound' } })
|
|
1603
|
+
}
|
|
1599
1604
|
})
|
|
1600
1605
|
|
|
1601
|
-
if (prune.
|
|
1606
|
+
if (prune.size === 0) {
|
|
1602
1607
|
return []
|
|
1603
1608
|
}
|
|
1604
1609
|
|
|
1605
1610
|
const onUnsubscribe = false
|
|
1606
|
-
return Promise.all(
|
|
1611
|
+
return Promise.all(Array.from(prune, async (topic) => this.makePrune(id, topic, doPX, onUnsubscribe)))
|
|
1607
1612
|
}
|
|
1608
1613
|
|
|
1609
1614
|
/**
|
|
@@ -1611,12 +1616,20 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1611
1616
|
*/
|
|
1612
1617
|
private async handlePrune (id: PeerIdStr, prune: RPC.ControlPrune[]): Promise<void> {
|
|
1613
1618
|
const score = this.score.score(id)
|
|
1619
|
+
// a single RPC can hold many PRUNEs for the same topic, only the first one
|
|
1620
|
+
// is processed so the work done is bounded by the number of topics
|
|
1621
|
+
const seenTopics = new Set<TopicStr>()
|
|
1614
1622
|
|
|
1615
1623
|
for (const { topicID, backoff, peers } of prune) {
|
|
1616
1624
|
if (topicID == null) {
|
|
1617
1625
|
continue
|
|
1618
1626
|
}
|
|
1619
1627
|
|
|
1628
|
+
if (seenTopics.has(topicID)) {
|
|
1629
|
+
continue
|
|
1630
|
+
}
|
|
1631
|
+
seenTopics.add(topicID)
|
|
1632
|
+
|
|
1620
1633
|
const peersInMesh = this.mesh.get(topicID)
|
|
1621
1634
|
if (peersInMesh == null) {
|
|
1622
1635
|
continue
|
|
@@ -1624,8 +1637,8 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1624
1637
|
|
|
1625
1638
|
this.log('PRUNE: Remove mesh link to %s in %s', id, topicID)
|
|
1626
1639
|
this.score.prune(id, topicID)
|
|
1627
|
-
|
|
1628
|
-
|
|
1640
|
+
const wasInMesh = peersInMesh.delete(id)
|
|
1641
|
+
if (wasInMesh) {
|
|
1629
1642
|
this.metrics?.onRemoveFromMesh(topicID, ChurnReason.Prune, 1)
|
|
1630
1643
|
}
|
|
1631
1644
|
|
|
@@ -1651,7 +1664,11 @@ export class GossipSub extends TypedEventEmitter<GossipSubEvents> implements Typ
|
|
|
1651
1664
|
}
|
|
1652
1665
|
}
|
|
1653
1666
|
|
|
1654
|
-
|
|
1667
|
+
// only notify when the peer was actually removed from the mesh -
|
|
1668
|
+
// listeners (e.g. peer untagging) can be expensive
|
|
1669
|
+
if (wasInMesh) {
|
|
1670
|
+
this.safeDispatchEvent<MeshPeer>('gossipsub:prune', { detail: { peerId: id, topic: topicID, direction: 'inbound' } })
|
|
1671
|
+
}
|
|
1655
1672
|
}
|
|
1656
1673
|
}
|
|
1657
1674
|
|