Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Add WS filtering using WS pool strategy #6617

Closed
ishantiw opened this issue Aug 4, 2021 · 0 comments
Closed

Add WS filtering using WS pool strategy #6617

ishantiw opened this issue Aug 4, 2021 · 0 comments
Assignees
Labels
Milestone

Comments

@ishantiw
Copy link
Contributor

ishantiw commented Aug 4, 2021

Description

Add WS filtering using WS pool strategy. The idea is to support topic based communication over ws channel.

To achieve this, we need ws clients pooling mechanism where ws clients send subscribe message with the list of topics (ws.send({ type: 'subscribe', topic: 'app' })) and then the ws server adds these client sockets to corresponding topics as per the subscribe message sent by the client. Below is an idea for this strategy.

// At client
wsClientChannel.connect();
wsClientChannel.on('app', handler()); wsClientChannel.on('app:getNodeStatus', handler()); // will call ws.send({ type: 'subscribe', topics: ['app',’block']})


// Bus
const topicPool = {
   // all registered topics
  'app': [clientSocket1, clientSocket2],
  'dpos': [clientSocket2, clientSocket5],
}

wsServer.on('connection', sock => {
  // Broker registers the new client along with the topics subscribed and uses it to send 

  wsServer.on('message', msg => {
    if(message.type === 'subscribe') {
      for (const topic of msg.topics) {
         // subscribes the event for that client in broker
         topicPool[topic].push(sock);
      }
   }
  })
});

publish(event, data) {
  // iterate through peer Pool for the given event and send to clients
  const topic = event.split(':')[0];
  for (const client of topicPool[topic]) {
    client.send(data);
  }
}

Acceptance Criteria

  • Unit tests under test/unit/controller/ws should pass
  • Add additional functional/integration/unit tests to verify topic based ws API communication

Additional Information

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants