node.js - 在 STUN 服务器上实现 XOR-MAPPED-ADDRESS 属性

标签 node.js ip-address p2p xor stun

来自RFC 5389 Section 15.2 :

If the IP address family is IPv4, X-Address is computed by taking the mapped IP address in host byte order, XOR'ing it with the magic cookie, and converting the result to network byte order. If the IP address family is IPv6, X-Address is computed by taking the mapped IP address in host byte order, XOR'ing it with the concatenation of the magic cookie and the 96-bit transaction ID, and converting the result to network byte order.

我正在 Node.JS 中编写一个 STUN 服务器,我试图了解如何对 128 位值进行异或运算。我觉得好像需要使用 Buffer 中的这些函数之一模块,尽管它说最多只支持 48 位。关于如何为 IPv6 地址实现 128 位 XOR 运算符有什么建议吗?

最佳答案

这是我的 CryptoPals 代码中的 XOR 运算符:

var xor = function (b0, b1) {
  if (Buffer.isBuffer(b0)) {
    b0 = new Buffer(b0);
  }
  if (Buffer.isBuffer(b1)) {
    b1 = new Buffer(b1);
  }

  if (b0.length !== b1.length) {
    console.log(b0.length, b1.length);
    throw new Error('Tried to xor two buffers of differing length');
  }

  var arr = [];

  for (var i = 0; i < b0.length; i++) {
    arr.push(b0[i] ^ b1[i]);
  }

  return new Buffer(arr);
};

关于node.js - 在 STUN 服务器上实现 XOR-MAPPED-ADDRESS 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904407/

相关文章:

javascript - 使用 sailsjs Passport 身份验证本地策略既不会给出任何错误,也不会对用户进行身份验证

node.js - 如何使用 Braintree 从 webhook 获取客户 ID?

javascript - Polar accesslink API POST 用户无法工作

android - 如何使用 Android 的 Wi-Fi Direct 将 ArrayList<String> 对象从我在一部手机上的应用发送到另一部手机上的应用?

language-agnostic - 在对等网络中维护网络完整性

eclipse - 如何设置 Enide/Nodeclipse 的环境变量?

iphone - 如何从 NetService 获取 IP 地址

C# 引用的对象类型不支持尝试的操作

javascript - 在 Node 应用程序中使用restify时配置域名而不是IP地址

android - 将 android framebuffer 传输到其他设备