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 187
187
"@libp2p/mplex" : " ^1.0.2" ,
188
188
"@libp2p/peer-id" : " ^1.1.8" ,
189
189
"@libp2p/peer-id-factory" : " ^1.0.8" ,
190
- "@libp2p/peer-store" : " ^1.0.7" ,
191
190
"@libp2p/tcp" : " ^1.0.6" ,
192
191
"@nodeutils/defaults-deep" : " ^1.1.0" ,
193
192
"@types/debug" : " ^4.1.5" ,
202
201
"iso-random-stream" : " ^2.0.0" ,
203
202
"it-all" : " ^1.0.5" ,
204
203
"it-drain" : " ^1.0.4" ,
205
- "libp2p" : " next " ,
204
+ "libp2p" : " ^0.37.3 " ,
206
205
"lodash.difference" : " ^4.5.0" ,
207
206
"lodash.flatten" : " ^4.4.0" ,
208
207
"lodash.range" : " ^3.2.0" ,
Original file line number Diff line number Diff line change @@ -67,8 +67,8 @@ export class Network {
67
67
this . _registrarId = await this . _libp2p . registrar . register ( this . _protocols , topology )
68
68
69
69
// 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 )
72
72
} )
73
73
}
74
74
@@ -93,11 +93,14 @@ export class Network {
93
93
* @param {Stream } connection.stream - A duplex iterable stream
94
94
* @param {Connection } connection.connection - A libp2p Connection
95
95
*/
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 )
99
103
100
- try {
101
104
await pipe (
102
105
stream ,
103
106
lp . decode ( ) ,
@@ -113,9 +116,10 @@ export class Network {
113
116
}
114
117
}
115
118
)
116
- } catch ( err ) {
117
- this . _log ( err )
118
- }
119
+ } )
120
+ . catch ( err => {
121
+ this . _log ( err )
122
+ } )
119
123
}
120
124
121
125
/**
Original file line number Diff line number Diff line change @@ -37,9 +37,7 @@ describe('start/stop', () => {
37
37
registrar : {
38
38
register : ( ) => { }
39
39
} ,
40
- peerStore : {
41
- forEach : async ( ) => { }
42
- }
40
+ getConnections : ( ) => [ ]
43
41
}
44
42
// @ts -ignore not a full libp2p
45
43
const bitswap = new Bitswap ( libp2p , new MemoryBlockstore ( ) )
Original file line number Diff line number Diff line change @@ -307,10 +307,7 @@ describe('network', () => {
307
307
registrar : {
308
308
register : sinon . stub ( )
309
309
} ,
310
- // @ts -expect-error incomplete implementation
311
- peerStore : {
312
- forEach : async ( ) => { }
313
- } ,
310
+ getConnections : ( ) => [ ] ,
314
311
dial : mockDial ,
315
312
handle : sinon . stub ( )
316
313
}
Original file line number Diff line number Diff line change 1
- import { PersistentPeerStore } from '@libp2p/peer-store'
2
1
import { MemoryBlockstore } from 'blockstore-core/memory'
3
2
import { EventEmitter } from 'events'
4
- import { MemoryDatastore } from 'datastore-core/memory'
5
3
import { Bitswap } from '../../src/bitswap.js'
6
4
import { Network } from '../../src/network.js'
7
5
import { Stats } from '../../src/stats/index.js'
8
6
import { peerIdFromBytes } from '@libp2p/peer-id'
9
- import { Components } from '@libp2p/interfaces/components'
10
7
import { createLibp2pNode } from './create-libp2p-node.js'
11
8
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
12
9
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
@@ -56,13 +53,9 @@ export const mockLibp2pNode = () => {
56
53
swarm : {
57
54
setMaxListeners ( ) { }
58
55
} ,
59
- peerStore : new PersistentPeerStore ( {
60
- addressFilter : async ( ) => true
61
- } )
56
+ getConnections : ( ) => [ ]
62
57
} )
63
58
64
- libp2p . peerStore . init ( new Components ( { peerId, datastore : new MemoryDatastore ( ) } ) )
65
-
66
59
// @ts -expect-error not all libp2p fields are implemented
67
60
return libp2p
68
61
}
You can’t perform that action at this time.
0 commit comments