简体   繁体   English

如何使用 UDP 协议构建可靠的 P2P 数据传输

[英]how can I build reliable P2P data transfer using UDP protocol

as you can read in the title I have to build a reliable P2P data transfer Using UDP(I'm a student), so what I asking you guys is to not give me the code, actually, I hate copying and pasting so much, I feel pain in doing it, I'm asking for help to tell me what tool do I need, I'm familiar with Javascript and Java and Python, feel free to help me if you know any of these languages.正如您在标题中所读到的,我必须使用 UDP 构建可靠的 P2P 数据传输(我是一名学生),所以我要求你们不要给我代码,实际上,我非常讨厌复制和粘贴,我做起来很痛苦,我正在寻求帮助告诉我我需要什么工具,我熟悉 Javascript 和 Java 和 Python,如果你知道这些语言中的任何一种,请随时帮助我。

the reliability part will be achieved through checksum and ACKs(Acknowledgements), so I have to Implement them: -I know how checksum can be calculated.可靠性部分将通过校验和和 ACK(确认)来实现,因此我必须实现它们:-我知道如何计算校验和。 -ACKs can be Implemented in the way of Stop-and-wait protocol(I think it's the simplest one), if you know another protocol, that is okay. -ACK可以通过Stop-and-wait协议的方式来实现(我认为这是最简单的),如果你知道其他协议,那也没关系。

I'm really lost, I don't know from where I begin if you have some code examples, please share a link that would be helpful, so I can build an idea from where do I start.我真的迷路了,如果您有一些代码示例,我不知道从哪里开始,请分享一个有用的链接,这样我就可以从哪里开始建立一个想法。

thanks.谢谢。

Here are some reliable UDP examples in github like kcp, quic, utp.以下是 github 中一些可靠的 UDP 示例,例如 kcp、quic、utp。 You can read them and get the essential from them.您可以阅读它们并从中获取重要信息。

As for how to do it, there are some little suggestions:至于怎么做,有一些小建议:

  1. You need ACK to check if any packet/datagram lost, and then retransmit it您需要 ACK 来检查是否有任何数据包/数据报丢失,然后重新传输它
  2. You need to use FEC您需要使用 FEC
  3. Congestion algorithm can be considered later.拥塞算法可以在后面考虑。

When you try to build your own code, do a little goal in every step, don't build a complex protocol at the very begining.当你尝试构建自己的代码时,每一步都做一个小目标,不要在一开始就构建复杂的协议。

If you want an explanation - here is the resource如果你想要一个解释 - 这是资源

From one student to another - my.networking class used Kurose and Ross, and their Chapter 3, section 3.4 on reliable data transfer breaks this down in a really good manner.从一个学生到另一个学生——my.networking class 使用了 Kurose 和 Ross,他们关于可靠数据传输的第 3 章第 3.4 节以非常好的方式对此进行了分解。

They start by assuming Reliable Data Transfer through the.network, with an 'rdt 1.0' protocol to transfer through that.network, and slowly add in the different types of unreliability (such as packet loss or packet corruption).他们首先假设通过 .network 进行可靠的数据传输,使用“rdt 1.0”协议通过 .network 进行传输,然后慢慢添加不同类型的不可靠性(例如数据包丢失或数据包损坏)。 As you reach 'rdt 3.0', you should have what you want - reliable data transfer on top of UDP. Ofcourse, their approach is a bit more abstract, but it is a good explanation.当你到达“rdt 3.0”时,你应该拥有你想要的——在 UDP 之上的可靠数据传输。当然,他们的方法有点抽象,但它是一个很好的解释。 I can link in their final sender and receiver state machine, and the name of the textbook.我可以在他们的最终发送者和接收者state机器中链接,以及教科书的名称。

Here is a breakdown of what the textbook explains:以下是教科书解释的细目:

  1. Start by assuming a completely reliable.network.首先假设一个完全可靠的网络。 You just need to send the packets from the sender to the receiver.您只需要将数据包从发送方发送到接收方。

  2. Assume the.network now has bit corruption.假设 the.network 现在有位损坏。 You will need to transmit a checksum to allow for recovery incase the packet was corrupted.您将需要传输校验和以允许在数据包损坏的情况下进行恢复。 This also requires ACK (and initially NAK but this is eliminated with sequence numbers on the ACK).这也需要 ACK(并且最初需要 NAK,但这会被 ACK 上的序列号消除)。 Remember, your ACK are also packets going through the.network, and they can also get corrupted!请记住,您的 ACK 也是通过网络的数据包,它们也可能被损坏! (the solution was using sequence numbers with the ACK) (解决方案是使用带有 ACK 的序列号)

  3. Assume the.network can now lose packets.假设.network 现在可以丢失数据包。 The reliable data transfer now needs a timeout mechanism to retransmit a packet if it's ACK was not received.可靠的数据传输现在需要一种超时机制,以便在未收到 ACK 时重新传输数据包。

If you want just the implementation - Here is the resource如果您只想要实施 - 这是资源

Textbook - Kurose and Ross, Computer Networking, A Top-Down Approach Chapter - 3, Section - 3.4教科书 - Kurose 和 Ross,计算机网络,自上而下的方法第 3 章,第 3.4 节

Kurose & Ross rdt 3.0 状态机

The receiver state machine was left as an exercise to the reader, but should be easy to pick up from their explanation.接收器 state 机器留给读者作为练习,但从他们的解释中应该很容易理解。

Note - I am in no way affiliated with the textbook mentioned in this question.注意 - 我与这个问题中提到的教科书没有任何关系。 I just used it for a.networking class and I felt it had a good explanation for the question asked.我只是将它用于 a.networking class,我觉得它对所问的问题有很好的解释。

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

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