简体   繁体   中英

Node.JS proxy for FAST protocol

I'm trying to make a Node.JS proxy for FAST protocol over UDP multicast (PPTP connection).

    const os = require('os');
    
    const osInterfaceName = 'VPN-подключение';
    const endpoints = {
      'FUT-TRADES': {
        A: {ip: '239.195.9.9', port: 42009},
        B: {ip: '239.195.137.9', port: 43009},
      },
      'OPT-TRADES': {
        A: {ip: '239.195.9.25', port: 42025},
        B: {ip: '239.195.137.25', port: 43025},
      }
    };
    
    const dgram = require('dgram');
    const osInterface = os.networkInterfaces()[osInterfaceName] !== undefined ? os.networkInterfaces()[osInterfaceName][0] : { address: '0.0.0.0' };
    
    const clients = {};
    for (let key in endpoints) {
      for (let serverId in endpoints[key]) {
        const client = dgram.createSocket('udp4');
        client.on('listening', function () {
          const address = client.address();
          console.log(`UDP Client listening on ${address.address}: ${address.port} [${serverId}]`);
          client.setBroadcast(true)
          client.setMulticastTTL(128);
          client.addMembership(endpoints[key][serverId].ip, osInterface.address);
        });
    
        client.on('message', function (message, remote) {
          console.log('Message from: ' + remote.address + ':' + remote.port +' - ' + message);
        });
    
        client.on('error', function (error) {
          console.log(`UDP error: ${error.stack}`);
        });
    
        client.bind(endpoints[key][serverId].port, osInterface.address);
    
        clients[`${key}:${serverId}`] = client;
      }
    }

If i test it locally (starting server and send a multicast message - it's shown on client), but i can't use it with MOEX stream. In logs nothing except of "UDP Client listening on 1.1.5.171:42009 [A]..." (for every stream in endpoints list).

But according to netsh interface ip show joins client has successfully joined multicast groups.

Looks like i have found the source of problem, so does alternate resolution.

It's not enough just to join multicast group, it's also required to enable source filtering of packets:

  1. install and start smcroute daemon: apt-get install smcroute smcroute -d

  2. join multicast group with enabled filtering (source IP required) smcroute -j ppp0 91.203.253.235 239.195.9.9

  3. then application starts to get multicast packets: tcpdump -i ppp0 -s 65534 host 239.195.9.9

  • Additional info: while i was searching for answer i've found UDP to TCP proxy tool: https://github.com/MarkoPaul0/DatagramTunneler (which solves multicast join params shortage, as i couldn't find multicast join param for source ip filter in Node.JS)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM