简体   繁体   English

用于 FAST 协议的 Node.JS 代理

[英]Node.JS proxy for FAST protocol

I'm trying to make a Node.JS proxy for FAST protocol over UDP multicast (PPTP connection).我正在尝试通过 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;
      }
    }

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.如果我在本地测试它(启动服务器并发送多播消息 - 它显示在客户端上),但我不能将它与 MOEX 流一起使用。 In logs nothing except of "UDP Client listening on 1.1.5.171:42009 [A]..." (for every stream in endpoints list).在日志中,除了“UDP 客户端侦听 1.1.5.171:42009 [A]...”(对于端点列表中的每个流)之外,什么都没有。

But according to netsh interface ip show joins client has successfully joined multicast groups.但是根据netsh interface ip show joins客户端已经成功加入多播组。

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安装并启动 smcroute 守护进程: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加入多播组并启用过滤(需要源 IP) 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然后应用程序开始获取多播数据包: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)附加信息:当我在寻找答案时,我发现了 UDP 到 TCP 代理工具: https : //github.com/MarkoPaul0/DatagramTunneler (它解决了多播加入参数不足的问题,因为我找不到源 ip 的多播加入参数在 Node.JS 中过滤)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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