File tree Expand file tree Collapse file tree 5 files changed +17
-26
lines changed Expand file tree Collapse file tree 5 files changed +17
-26
lines changed Original file line number Diff line number Diff line change 187187 "@libp2p/mplex" : " ^1.0.2" ,
188188 "@libp2p/peer-id" : " ^1.1.8" ,
189189 "@libp2p/peer-id-factory" : " ^1.0.8" ,
190- "@libp2p/peer-store" : " ^1.0.7" ,
191190 "@libp2p/tcp" : " ^1.0.6" ,
192191 "@nodeutils/defaults-deep" : " ^1.1.0" ,
193192 "@types/debug" : " ^4.1.5" ,
202201 "iso-random-stream" : " ^2.0.0" ,
203202 "it-all" : " ^1.0.5" ,
204203 "it-drain" : " ^1.0.4" ,
205- "libp2p" : " next " ,
204+ "libp2p" : " ^0.37.3 " ,
206205 "lodash.difference" : " ^4.5.0" ,
207206 "lodash.flatten" : " ^4.4.0" ,
208207 "lodash.range" : " ^3.2.0" ,
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ export class Network {
6767 this . _registrarId = await this . _libp2p . registrar . register ( this . _protocols , topology )
6868
6969 // All existing connections are like new ones for us
70- await this . _libp2p . peerStore . forEach ( peer => {
71- this . _libp2p . getConnections ( peer . id ) . forEach ( conn => this . _onPeerConnect ( conn . remotePeer ) )
70+ this . _libp2p . getConnections ( ) . forEach ( conn => {
71+ this . _onPeerConnect ( conn . remotePeer )
7272 } )
7373 }
7474
@@ -93,11 +93,14 @@ export class Network {
9393 * @param {Stream } connection.stream - A duplex iterable stream
9494 * @param {Connection } connection.connection - A libp2p Connection
9595 */
96- async _onConnection ( { protocol, stream, connection } ) {
97- if ( ! this . _running ) { return }
98- this . _log ( 'incoming new bitswap %s connection from %p' , protocol , connection . remotePeer )
96+ _onConnection ( { protocol, stream, connection } ) {
97+ if ( ! this . _running ) {
98+ return
99+ }
100+
101+ Promise . resolve ( ) . then ( async ( ) => {
102+ this . _log ( 'incoming new bitswap %s connection from %p' , protocol , connection . remotePeer )
99103
100- try {
101104 await pipe (
102105 stream ,
103106 lp . decode ( ) ,
@@ -113,9 +116,10 @@ export class Network {
113116 }
114117 }
115118 )
116- } catch ( err ) {
117- this . _log ( err )
118- }
119+ } )
120+ . catch ( err => {
121+ this . _log ( err )
122+ } )
119123 }
120124
121125 /**
Original file line number Diff line number Diff line change @@ -37,9 +37,7 @@ describe('start/stop', () => {
3737 registrar : {
3838 register : ( ) => { }
3939 } ,
40- peerStore : {
41- forEach : async ( ) => { }
42- }
40+ getConnections : ( ) => [ ]
4341 }
4442 // @ts -ignore not a full libp2p
4543 const bitswap = new Bitswap ( libp2p , new MemoryBlockstore ( ) )
Original file line number Diff line number Diff line change @@ -307,10 +307,7 @@ describe('network', () => {
307307 registrar : {
308308 register : sinon . stub ( )
309309 } ,
310- // @ts -expect-error incomplete implementation
311- peerStore : {
312- forEach : async ( ) => { }
313- } ,
310+ getConnections : ( ) => [ ] ,
314311 dial : mockDial ,
315312 handle : sinon . stub ( )
316313 }
Original file line number Diff line number Diff line change 1- import { PersistentPeerStore } from '@libp2p/peer-store'
21import { MemoryBlockstore } from 'blockstore-core/memory'
32import { EventEmitter } from 'events'
4- import { MemoryDatastore } from 'datastore-core/memory'
53import { Bitswap } from '../../src/bitswap.js'
64import { Network } from '../../src/network.js'
75import { Stats } from '../../src/stats/index.js'
86import { peerIdFromBytes } from '@libp2p/peer-id'
9- import { Components } from '@libp2p/interfaces/components'
107import { createLibp2pNode } from './create-libp2p-node.js'
118import { createEd25519PeerId } from '@libp2p/peer-id-factory'
129import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
@@ -56,13 +53,9 @@ export const mockLibp2pNode = () => {
5653 swarm : {
5754 setMaxListeners ( ) { }
5855 } ,
59- peerStore : new PersistentPeerStore ( {
60- addressFilter : async ( ) => true
61- } )
56+ getConnections : ( ) => [ ]
6257 } )
6358
64- libp2p . peerStore . init ( new Components ( { peerId, datastore : new MemoryDatastore ( ) } ) )
65-
6659 // @ts -expect-error not all libp2p fields are implemented
6760 return libp2p
6861}
You can’t perform that action at this time.
0 commit comments