@dxos/network-manager 2.28.6-dev.ca9d0e33 → 2.28.7-dev.1dc18bee

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.
@@ -13,24 +13,26 @@ const log = debug('dxos:network-manager:topology:star');
13
13
 
14
14
  export class StarTopology implements Topology {
15
15
  private _controller?: SwarmController;
16
-
17
16
  private _intervalId?: NodeJS.Timeout;
18
17
 
19
18
  constructor (
20
19
  private readonly _centralPeer: PublicKey
21
20
  ) {}
22
21
 
22
+ toString () {
23
+ return `StarTopology(${this._centralPeer})`;
24
+ }
25
+
23
26
  init (controller: SwarmController): void {
24
- assert(!this._controller, 'Already initialized');
27
+ assert(!this._controller, 'Already initialized.');
25
28
  this._controller = controller;
26
-
27
29
  this._intervalId = setInterval(() => {
28
30
  controller.lookup();
29
31
  }, 10_000);
30
32
  }
31
33
 
32
34
  update (): void {
33
- assert(this._controller, 'Not initialized');
35
+ assert(this._controller, 'Not initialized.');
34
36
  const { candidates, connected, ownPeerId } = this._controller.getState();
35
37
  if (!ownPeerId.equals(this._centralPeer)) {
36
38
  log('As leaf peer dropping all connections apart from central peer.');
@@ -42,6 +44,7 @@ export class StarTopology implements Topology {
42
44
  }
43
45
  }
44
46
  }
47
+
45
48
  for (const peer of candidates) {
46
49
  // Connect to central peer.
47
50
  if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
@@ -52,7 +55,7 @@ export class StarTopology implements Topology {
52
55
  }
53
56
 
54
57
  async onOffer (peer: PublicKey): Promise<boolean> {
55
- assert(this._controller, 'Not initialized');
58
+ assert(this._controller, 'Not initialized.');
56
59
  const { ownPeerId } = this._controller.getState();
57
60
  log(`Offer from ${peer} isCentral=${peer.equals(this._centralPeer)} isSelfCentral=${ownPeerId.equals(this._centralPeer)}`);
58
61
  return ownPeerId.equals(this._centralPeer) || peer.equals(this._centralPeer);
@@ -63,8 +66,4 @@ export class StarTopology implements Topology {
63
66
  clearInterval(this._intervalId);
64
67
  }
65
68
  }
66
-
67
- toString () {
68
- return `StarTopology(${this._centralPeer})`;
69
- }
70
69
  }