@@ -10,14 +10,15 @@ import {
10
10
} from '@libp2p/daemon-protocol'
11
11
import { passThroughUpgrader } from '@libp2p/daemon-protocol/upgrader'
12
12
import { defaultLogger , logger } from '@libp2p/logger'
13
- import { peerIdFromBytes } from '@libp2p/peer-id'
13
+ import { peerIdFromMultihash } from '@libp2p/peer-id'
14
14
import { tcp } from '@libp2p/tcp'
15
15
import { multiaddr , protocols } from '@multiformats/multiaddr'
16
16
import * as lp from 'it-length-prefixed'
17
17
import { lpStream } from 'it-length-prefixed-stream'
18
18
import { pipe } from 'it-pipe'
19
19
import { pbStream } from 'it-protobuf-stream'
20
20
import { CID } from 'multiformats/cid'
21
+ import * as Digest from 'multiformats/hashes/digest'
21
22
import { DHTOperations } from './dht.js'
22
23
import { PubSubOperations } from './pubsub.js'
23
24
import { ErrorResponse , OkResponse } from './responses.js'
@@ -87,7 +88,7 @@ export class Server implements Libp2pServer {
87
88
88
89
const peer = request . connect . peer
89
90
const addrs = request . connect . addrs . map ( ( a ) => multiaddr ( a ) )
90
- const peerId = peerIdFromBytes ( peer )
91
+ const peerId = peerIdFromMultihash ( Digest . decode ( peer ) )
91
92
92
93
log ( 'connect - adding multiaddrs %a to peer %p' , addrs , peerId )
93
94
await this . libp2p . peerStore . merge ( peerId , {
@@ -107,21 +108,19 @@ export class Server implements Libp2pServer {
107
108
}
108
109
109
110
const { peer, proto } = request . streamOpen
110
- const peerId = peerIdFromBytes ( peer )
111
+ const peerId = peerIdFromMultihash ( Digest . decode ( peer ) )
111
112
112
113
log ( 'openStream - dial %p' , peerId )
113
114
const connection = await this . libp2p . dial ( peerId )
114
115
115
116
log ( 'openStream - open stream for protocol %s' , proto )
116
117
const stream = await connection . newStream ( proto , {
117
- runOnTransientConnection : true ,
118
- // @ts -expect-error this has not been released yet
119
118
runOnLimitedConnection : true
120
119
} )
121
120
122
121
return {
123
122
streamInfo : {
124
- peer : peerId . toBytes ( ) ,
123
+ peer : peerId . toMultihash ( ) . bytes ,
125
124
addr : connection . remoteAddr . bytes ,
126
125
proto : stream . protocol ?? ''
127
126
} ,
@@ -155,7 +154,7 @@ export class Server implements Libp2pServer {
155
154
} )
156
155
157
156
const message = StreamInfo . encode ( {
158
- peer : connection . remotePeer . toBytes ( ) ,
157
+ peer : connection . remotePeer . toMultihash ( ) . bytes ,
159
158
addr : connection . remoteAddr . bytes ,
160
159
proto : stream . protocol ?? ''
161
160
} )
@@ -194,8 +193,6 @@ export class Server implements Libp2pServer {
194
193
}
195
194
} )
196
195
} , {
197
- runOnTransientConnection : true ,
198
- // @ts -expect-error this has not been released yet
199
196
runOnLimitedConnection : true
200
197
} )
201
198
}
@@ -257,7 +254,7 @@ export class Server implements Libp2pServer {
257
254
throw new Error ( 'Invalid request' )
258
255
}
259
256
260
- const peerId = peerIdFromBytes ( request . id ) // eslint-disable-line no-case-declarations
257
+ const peerId = peerIdFromMultihash ( Digest . decode ( request . id ) ) // eslint-disable-line no-case-declarations
261
258
const peer = await this . libp2p . peerStore . get ( peerId ) // eslint-disable-line no-case-declarations
262
259
const protos = peer . protocols // eslint-disable-line no-case-declarations
263
260
yield OkResponse ( { peerStore : { protos } } )
@@ -331,7 +328,7 @@ export class Server implements Libp2pServer {
331
328
throw new Error ( 'Invalid request' )
332
329
}
333
330
334
- yield * this . dhtOperations . findPeer ( peerIdFromBytes ( request . peer ) )
331
+ yield * this . dhtOperations . findPeer ( peerIdFromMultihash ( Digest . decode ( request . peer ) ) )
335
332
return
336
333
case DHTRequest . Type . FIND_PROVIDERS :
337
334
if ( request . cid == null ) {
@@ -359,7 +356,7 @@ export class Server implements Libp2pServer {
359
356
throw new Error ( 'Invalid request' )
360
357
}
361
358
362
- yield * this . dhtOperations . getPublicKey ( peerIdFromBytes ( request . peer ) )
359
+ yield * this . dhtOperations . getPublicKey ( peerIdFromMultihash ( Digest . decode ( request . peer ) ) )
363
360
return
364
361
case DHTRequest . Type . GET_VALUE :
365
362
if ( request . key == null ) {
@@ -414,7 +411,7 @@ export class Server implements Libp2pServer {
414
411
await pb . write ( {
415
412
type : Response . Type . OK ,
416
413
identify : {
417
- id : daemon . libp2p . peerId . toBytes ( ) ,
414
+ id : daemon . libp2p . peerId . toMultihash ( ) . bytes ,
418
415
addrs : daemon . libp2p . getMultiaddrs ( ) . map ( ma => ma . decapsulateCode ( protocols ( 'p2p' ) . code ) ) . map ( m => m . bytes )
419
416
}
420
417
} , Response )
@@ -436,7 +433,7 @@ export class Server implements Libp2pServer {
436
433
seen . add ( peerId )
437
434
438
435
peers . push ( {
439
- id : connection . remotePeer . toBytes ( ) ,
436
+ id : connection . remotePeer . toMultihash ( ) . bytes ,
440
437
addrs : [ connection . remoteAddr . bytes ]
441
438
} )
442
439
}
0 commit comments