TCP 打孔(NAT 穿越)库什么的? [英] TCP Hole Punch (NAT Traversal) Library or something?

查看:22
本文介绍了TCP 打孔(NAT 穿越)库什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 C# 中进行 TCP 打孔(NAT 遍历).如果需要,可以使用集合服务器来完成.我找到了 http://sharpstunt.codeplex.com/ 但无法让它工作.理想情况下,我需要一些方法,我将端口号(int)作为参数,在调用此方法后在 NAT 上可用(端口转发").如果该方法只返回一些端口号,然后在 NAT 上可用,那也是可以的.有没有人在 C# 中做过这个?你能给我一些关于尖锐特技或其他东西的例子吗?

I want to do TCP Hole Punching (NAT Traversal) in C#. It can be done with a rendezvous server if needed. I found http://sharpstunt.codeplex.com/ but can not get this to work. Ideally i need some method which i give a Port Number (int) as parameter that after a call to this method is available ("Port Forwarded") at the NAT. It would be also OK if the method just returns some port number which is then available at the NAT. Has anybody done this in C# ? Can you give me working examples for sharpstunt or something else?

推荐答案

在每个网络场景中,TCP 打孔的操作方式与 UDP 打孔的方式类似.例如,如果两个对等点 A 和 B 位于不同的 NAT 之后,则每个对等点发送到另一个对等点的第一个 SYN 数据包会在其各自的 NAT 中打开一个与其公共地址相关联的漏洞.如果 A 到 B 的第一个 SYN 数据包在 B 到 A 的第一个 SYN 数据包到达 B 的 NAT 之前到达 B 的 NAT,则 B 的 NAT 认为 A 的 SYN 数据包是未经请求的并丢弃它.但是,随后 B 的第一个 SYN 数据包可以成功通过 A 的 NAT,因为 A 的 NAT 将 B 的公共地址识别为 A 发起的传出会话的目的地.

In each network scenario, TCP hole punching operates in a similar way to UDP hole punching. For example, if two peers A and B are behind different NATs, each peer’s first SYN packet sent to the other peer opens up a hole associated with its public address in its respective NAT. If A’s first SYN packet to B reaches B’s NAT before B’s first SYN packet to A reaches B’s NAT, B’s NAT considers A’s SYN packet unsolicited and drops it. However, subsequently B’s first SYN packet can travel through A’s NAT successfully because A’s NAT recognises B’s public address as the destination of the outgoing session that A has initiated.

是的.TCP 打孔是可能的.我不明白为什么会有人不这么认为.

So yes. It's possible to TCP holepunch. I don't see why anyone would think otherwise.

另外,你不能手动创建这种类型的行为吗?它不需要依赖任何特定的协议,只要收集所有必需信息的步骤相同即可.

Also, could you not create this type of bahaviour manually? It doesn't need to depend on any specific protocol as long as the steps are the same to gather all of the required information.

一般来说,TCP 打孔(3.2.1)的过程如下:

In general, TCP hole punching (3.2.1) proceeds as follows:

客户:A、B服务器:S

Clients: A, B Server: S

• A 使用它与 S 的连接向 S 请求连接与 B.• S 用 B 的私有和公共地址回复 A,并同时将 A 的地址发送给 B.

• A uses its connection with S to ask S for a connection with B. • S replies to A with B’s private and public addresses, and simultaneously sends A’s addresses to B.

• A 和 B 在-处异步进行传出连接诱惑(发送 SYN 数据包)到彼此的公共和私有地址,来自他们使用的同一端口向 S 注册.同时,他们听取本地 TCP 上的 TCP 传入连接尝试端口.

• A and B asynchronously make outgoing connection at- tempts (send SYN packets) to each other’s public and private addresses, from the same port that they used to register with S. At the same time, they listen for TCP incoming connection attempts on their local TCP ports.

• A 和 B 等待对其输出的 SYN-ACK 响应正在发送 SYN 数据包,或传入的连接请求(SYN 包).如果连接失败,对等方可以重试最长超时期限.

• A and B wait for a SYN-ACK response to their out- going SYN packets, or an incoming connection request (SYN packet). If a connection fails, the peer can retry it up to a maximum timeout period.

• 三向握手过程完成后,对等体相互验证.如果真品——失败,对等方关闭该连接并等待另一个连接已成功通过身份验证.这将使用第一个成功通过身份验证的连接传输 TCP 数据.

• Once the three-way handshake process has completed, the peers authenticate each other. If the authentica- tion fails, the peers close that connection and wait until another connection is successfully authenticated. The first successfully authenticated connection will be used to transfer TCP data.

(我知道这不是一个很好的答案,但没有足够的空间发表评论).

(I know this isn't much of an answer but there wasn't enough room for a comment).

这篇关于TCP 打孔(NAT 穿越)库什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆