@dxos/network-manager 2.33.7 → 2.33.8-dev.6bc74570

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.
@@ -8,8 +8,8 @@ import assert from 'assert';
8
8
  import debug from 'debug';
9
9
  import { EventEmitter } from 'events';
10
10
 
11
- import { keyToBuffer, keyToString } from '@dxos/crypto';
12
11
  import { Extension, Protocol } from '@dxos/mesh-protocol';
12
+ import { PublicKey } from '@dxos/protocols';
13
13
 
14
14
  import { protocolFactory } from '../protocol-factory';
15
15
 
@@ -20,7 +20,7 @@ const EXTENSION_NAME = 'test';
20
20
  // TODO(dboreham): This method should be added to Protocol (and one for "my ID"?).
21
21
  export const getPeerId = (protocol: Protocol) => {
22
22
  const { peerId } = protocol.getSession() ?? {};
23
- return keyToBuffer(peerId);
23
+ return PublicKey.bufferize(peerId);
24
24
  };
25
25
 
26
26
  /**
@@ -97,7 +97,7 @@ export class TestProtocolPlugin extends EventEmitter {
97
97
  */
98
98
  async send (peerId: Buffer, payload: string): Promise<string> {
99
99
  assert(Buffer.isBuffer(peerId));
100
- const peerIdStr = keyToString(peerId);
100
+ const peerIdStr = PublicKey.stringify(peerId);
101
101
  const peer = this._peers.get(peerIdStr);
102
102
  // TODO(dboreham): Throw fatal error if peer not found.
103
103
  const extension = peer.getExtension(EXTENSION_NAME);
@@ -111,7 +111,7 @@ export class TestProtocolPlugin extends EventEmitter {
111
111
  }
112
112
 
113
113
  async _receive (protocol: Protocol, data: any) {
114
- const peerIdStr = keyToString(getPeerId(protocol));
114
+ const peerIdStr = PublicKey.stringify(getPeerId(protocol));
115
115
  let payload = data.data.toString();
116
116
  if (this._uppercase) {
117
117
  payload = payload.toUpperCase();
@@ -125,7 +125,7 @@ export class TestProtocolPlugin extends EventEmitter {
125
125
  if (peerId === undefined) {
126
126
  return;
127
127
  }
128
- const peerIdStr = keyToString(peerId);
128
+ const peerIdStr = PublicKey.stringify(peerId);
129
129
  if (this._peers.has(peerIdStr)) {
130
130
  return;
131
131
  }
@@ -140,7 +140,7 @@ export class TestProtocolPlugin extends EventEmitter {
140
140
  return;
141
141
  }
142
142
 
143
- this._peers.delete(keyToString(peerId));
143
+ this._peers.delete(PublicKey.stringify(peerId));
144
144
  this.emit('disconnect', peerId);
145
145
  }
146
146
  }
@@ -151,6 +151,6 @@ export class TestProtocolPlugin extends EventEmitter {
151
151
  // TODO(dboreham): Try to encapsulate swarmKey, nodeId.
152
152
  export const testProtocolProvider = (swarmKey: Buffer, nodeId: Buffer, protocolPlugin: any) => protocolFactory({
153
153
  getTopics: () => [swarmKey],
154
- session: { peerId: keyToString(nodeId) },
154
+ session: { peerId: PublicKey.stringify(nodeId) },
155
155
  plugins: [protocolPlugin]
156
156
  });