Commit f7c36eff authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] WS2P client testing was sometimes randomly failing

parent 7ac480f7
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -681,11 +681,11 @@ export class WS2PCluster {
      let uuids = Object.keys(this.ws2pClients)
      uuids = _.shuffle(uuids)
      let lowPriorityConnectionUUID:string = uuids[0]
      let minPriorityLevel = this.keyPriorityLevel(this.ws2pClients[lowPriorityConnectionUUID].connection.pubkey, preferedKeys)
      let minPriorityLevel = await this.keyPriorityLevel(this.ws2pClients[lowPriorityConnectionUUID].connection.pubkey, preferedKeys)
      for (const uuid of uuids) {
        const client = this.ws2pClients[uuid]
          if (uuid !== lowPriorityConnectionUUID) {
            let uuidPriorityLevel = this.keyPriorityLevel(client.connection.pubkey, preferedKeys)
            let uuidPriorityLevel = await this.keyPriorityLevel(client.connection.pubkey, preferedKeys)
            if (uuidPriorityLevel < minPriorityLevel) {
              lowPriorityConnectionUUID = uuid
              minPriorityLevel = uuidPriorityLevel
+2 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ import {WS2PConstants} from "./constants"
import {WS2PMessageHandler} from "./impl/WS2PMessageHandler"
import {WS2PStreamer} from "./WS2PStreamer"
import {WS2PSingleWriteStream} from "./WS2PSingleWriteStream"
import { WS2PCluster } from './WS2PCluster';

const WebSocketServer = require('ws').Server

@@ -159,10 +158,10 @@ export class WS2PServer extends events.EventEmitter {

  async removeLowPriorityConnection(privilegedKeys:string[]) {
    let lowPriorityConnection:WS2PConnection = this.connections[0]
    let minPriorityLevel = this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys)
    let minPriorityLevel = await this.keyPriorityLevel(lowPriorityConnection.pubkey, privilegedKeys)
    for (const c of this.connections) {
      if (c !== lowPriorityConnection) {
        let cPriorityLevel = this.keyPriorityLevel(c.pubkey, privilegedKeys)
        let cPriorityLevel = await this.keyPriorityLevel(c.pubkey, privilegedKeys)
        if (cPriorityLevel < minPriorityLevel) {
          lowPriorityConnection = c
          minPriorityLevel = cPriorityLevel