Esframework extension-esfp2p-reliable P2P Transfer

Source: Internet
Author: User

in the previous article, esframework extended esfp2p-esframework-Based P2P implementation mainly introduced how esfp2p helps build P2P sessions, that is only half of the story. The other half of esfp2p's main function is to ensure reliable delivery of P2P messages. We already know that the current implementation of esfp2p extension is UDP-based napt penetration (TCP-based napt penetration will be added later), while UDP is unreliable, packet Loss and wrong packets may occur during transmission. esfp2p extensions are enhanced over UDP to ensure reliable delivery of P2P messages. This reliability needs to solve three main problems, which will be described as follows.

1. Ensure that all P2P messages are received by the peer and processed correctly.
first, ensure that the received message is complete. When receiving a message, the esframework Network (TCP/UDP) component checks the integrity of the message. If the message is incomplete or does not meet the verification rules, it is discarded. This ensures that all messages processed by the message dispatcher are complete and correct.
second, esfp2p ensures that all messages are received by the other party by adding the ACK mechanism. When a P2P message is transmitted through p2pchannel, The transbyp2pchannel attribute in messageheader is set to true. Once the recipient receives a message and finds that this attribute is true, sends an ACK message to the sender of the P2P message. The one-to-one correspondence between ack messages and P2P messages is determined by the same correlationid in messageheader.
Each P2P message whose transbyp2pchannel attribute is set to true is stored in a hashtable after being sent. When Ack is received, the corresponding P2P message is deleted from the hashtable. Otherwise, the P2P message will be resold regularly. If the maximum number of resends is exceeded and the ACK corresponding to the message is not received, the p2pmessagelost event will be triggered, and the application can subscribe to this event, in the event processing function, you can use the server to forward the failed P2P message.
ip2packmanager is the component used to resend P2P messages at a scheduled time.
let's look at the receiver. We need to send an ACK message in another place. We can see from the esframework message flow diagram below that the best position is at igatewaymessagespy.

Therefore, esfp2p provides a p2packgatewaymessagespy component to complete this task.

 

2. if p2p messages are sequentially dependent, ensure that messages arrive at the peer end in the order of sending
Some P2P messages may be transmitted in the specified order. If the previous message is not successfully sent, the subsequent messages cannot be sent. For example, packet forwarding in a file must be delivered in sequence (of course, messages can be delivered in sequence, but messages must be sorted and reorganized on the receiver, which requires a high degree of implementation ). Esfp2p extends the messageheader and adds the dependentmessagecoreid attribute to the messageheader to indicate the correlationid of the message that the message depends on. If the dependentmessagecoreid is 0, it indicates that there is no dependency. Ip2pmessageheader is an extension of imessageheader in esframework.

Before sending a P2P message, p2pchannel checks the dependentmessagecoreid attribute to determine whether there is a sequential dependency. If there is an ordered dependency, p2pchannel queries whether the message on which ip2packmanager depends has been sent successfully. If the message has not been sent successfully, it will wait for a while to ask again, this P2P message is sent only when the dependent message is successfully sent or times out.

3. The recipient can identify and filter the received messages.Drop duplicate messages
The optimal location for identifying duplicate messages is still at igatewaymessagespy. Therefore, esfp2p implements the duplicate Message Identification and filtering function in the p2packgatewaymessagespy component. The method to identify duplicate messages is to use a fixed-size queue. Every time a message is sent, the flag (the flag of each message is unique) is pushed to the queue. When a new message is received, check the queue for the flag of the message. If yes, it indicates a duplicate message and discards it. The p2packgatewaymessagespy. checkrepeated attribute controls whether to enable duplicate Message check and filtering.

After reliable P2P communication, common file transfer in our IM system can also be done through P2P, without the need for server transfer, which further reduces the pressure on the server. With P2P, you can enable video and audio while chatting in text, and transmit multiple files, as shown in the demo:

Go to: esframework System (sequence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.