簡體   English   中英

用於 FAST 協議的 Node.JS 代理

[英]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 客戶端偵聽 1.1.5.171:42009 [A]...”(對於端點列表中的每個流)之外,什么都沒有。

但是根據netsh interface ip show joins客戶端已經成功加入多播組。

看起來我已經找到了問題的根源,替代解決方案也是如此。

僅僅加入組播組是不夠的,還需要開啟數據包的源過濾:

  1. 安裝並啟動 smcroute 守護進程:apt-get install smcroute smcroute -d

  2. 加入多播組並啟用過濾(需要源 IP) smcroute -j ppp0 91.203.253.235 239.195.9.9

  3. 然后應用程序開始獲取多播數據包:tcpdump -i ppp0 -s 65534 host 239.195.9.9

  • 附加信息:當我在尋找答案時,我發現了 UDP 到 TCP 代理工具: https : //github.com/MarkoPaul0/DatagramTunneler (它解決了多播加入參數不足的問題,因為我找不到源 ip 的多播加入參數在 Node.JS 中過濾)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM