Node.JS FAST 协议代理

Node.JS proxy for FAST protocol

我正在尝试为基于 UDP 多播(PPTP 连接)的 FAST 协议创建 Node.JS 代理。

    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;
      }
    }

如果我在本地测试它(启动服务器并发送多播消息 - 它显示在客户端上),但我不能将它与 MOEX 流一起使用。在日志中,除了“UDP Client listening on 1.1.5.171:42009 [A]...”(对于端点列表中的每个流)之外什么都没有。

但是根据netsh interface ip show joins客户端已经成功加入多播组。

看来我找到了问题的根源,其他解决方案也找到了。

仅仅加入多播组是不够的,还需要启用数据包的源过滤:

  1. 安装并启动 smcroute 守护进程: apt-get 安装 smcroute smcroute -d

  2. 加入启用过滤的多播组(需要源 IP) smcroute -j ppp0 91.203.253.235 239.195.9.9

  3. 然后应用程序开始获取组播数据包: tcpdump -i ppp0 -s 65534 主机 239.195.9.9

  • 附加信息:在寻找答案时,我发现了 UDP 到 TCP 代理工具:https://github.com/MarkoPaul0/DatagramTunneler(它解决了多播加入参数短缺问题,因为我找不到源 IP 过滤器的多播加入参数在 Node.JS)