Skip to content

Commit

Permalink
fix: write correct ping message
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 30, 2024
1 parent 32c176f commit 35b4802
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/kad-dht/src/routing-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,15 @@ export class RoutingTable extends TypedEventEmitter<RoutingTableEvents> implemen
const connection = await this.components.connectionManager.openConnection(oldContact.peerId, options)
stream = await connection.newStream(this.protocol, options)

const pb = pbStream(stream)
const pb = pbStream(stream).pb(Message)
await pb.write({
type: MessageType.PING
}, Message, options)
const response = await pb.read(Message, options)
type: MessageType.PING,
closer: [],
providers: []
}, options)
const response = await pb.read(options)

await pb.unwrap().close(options)
await pb.unwrap().unwrap().close(options)

if (response.type !== MessageType.PING) {
throw new InvalidMessageError(`Incorrect message type received, expected PING got ${response.type}`)
Expand Down

0 comments on commit 35b4802

Please sign in to comment.