UNPKG

scc-broker-client

Version:

Client for SCC - For SocketCluster horizontal scalability.

24 lines (18 loc) 509 B
const Hasher = require('../hasher'); function SimpleMapper() { this.hasher = new Hasher(); this.sites = []; } SimpleMapper.prototype.setSites = function (sites) { this.sites = sites; }; SimpleMapper.prototype.getSites = function () { return this.sites; }; SimpleMapper.prototype.findSite = function (key) { key = this.hasher.hashToHex(key); let sites = this.sites; let targetIndex = this.hasher.hashToIndex(key, sites.length); return sites[targetIndex]; }; module.exports = SimpleMapper;