Esframework extension-esfp2p-esframework-Based P2P implementation

Source: Internet
Author: User
I haven't written about esframework for a long time Article A long time ago, I promised to write an article about implementing napt P2P Based on esframework. Today, I can finally take the time to do this.
The basic theoretical knowledge of Network Address Translation NAT (or napt). There are a lot of related information on the Internet. If you are not very clear about what Nat is and why Nat is used. A very common use of NAT is P2P technology. It is not very simple to enable two machines hidden behind different local networks to communicate with each other, because, the two machines do not have a public IP address and cannot access each other directly through ipendpoint. Nat solves this problem. Although not all operating systems fully support NAT, most mainstream operating systems generally support NAT.
Generally, Nat supports UDP, And it is rare (or difficult to implement) to support TCP Nat ). Almost all of our existing P2P technologies are based on UDP.
The two machines that communicate with each other must first establish a P2P session through the server. This process must involve the participation of the server; otherwise, the session cannot be established. After the P2P session is established, the two machines can communicate with each other through P2P instead of passing through the server.

the esfp2p Extension Based on esframework is a P2P implementation of C #, which is used to assist in the establishment of P2P sessions. When esfp2p is used, we do not have to worry about setting up a P2P session when writing Program .
after a P2P session can be automatically created by esfp2p, the corresponding ip2pchannel can be used. Do you still remember imessagetransceiver? The intelligence of imessagetransceiver is that if p2pmessage can be directly sent through ip2pchannel, it is sent to ip2pchannel; otherwise, it is submitted to iserveragent for server forwarding. In this way, the application only needs to directly use imessagetransceiver to submit (send) messages, instead of caring about the underlying message routing path.
A review shows:
naptp2p, one of esframework extensions, is used to automatically build and make each ip2pchannel available. Once the ip2pchannel between Client1 and Client2 is successfully built, communication between them can be directly performed.

esfp2p has no perceptual knowledge of esfp2p for so long. Next we will introduce it in detail.
the main purpose of esfp2p is to assist in the construction of P2P sessions (that is, the construction of each ip2pchannel instance). This requires the client and the server to collaborate to complete this task.
for the theory that Nat's "hole" ("hole") process is used to establish P2P session, refer to other related documents (such as http://hwycheng.blogchina.com /). The esfp2p hole process is listed here:
(1) the server manages the UDP addresses of all online users
(2) clienta obtains the UDP address list of all online friends from the server upon logon.
(3) When clienta is initialized, p2pcheckmessage is sent to all online friends based on the address list.
(4) later, clienta regularly sends directp2pcheck messages to each channel managed by naptp2pchannelmanager.
(5) When a client receives p2pcheckmessage, it registers the corresponding user to naptp2pchannelmanager.
(6) when a client is online, the server notifies all other users. After receiving the notification, the user immediately sends p2pcheckmessage to the client.
(7) When a client is offline or offline, the server notifies all other users. After receiving the notification, the user cancels the deprecation from naptp2pchannelmanager.

Esfp2p ensures the correct establishment of P2P sessions by executing the preceding key points. When implementing these requirements, you need to introduce a series of types of messages. These message types can be displayed by p2psessionmessagetype attributes:

The askforfriendp2paddresses message is used by the client to request the P2P address of all friends from the server. The p2pcheckmessage is used to check whether the P2P session between two endpoints is successfully established. Once one endpoint receives the p2pcheckmessage from the other, it indicates that the P2P session between the two endpoints has been successfully established. P2plogon and p2plogout are messages sent to the server when the client logs in or out. Someonelogon and someonelogout are notifications sent to other users when a user goes online or offline.

Esfp2p provides support for the server (esfp2p. server space) and the client (esfp2p. Passive space. On the server side, it is mainly the p2psessiondealer component and the userp2paddressmanager component.
P2psessiondealer implements the idatadealer interface, which is a simple message processor used to process all messages related to p2psession creation, such as askforfriendp2paddresses, p2plogon, and p2plogout.
Userp2paddressmanager is used to manage the P2P addresses of all customers. When a user goes online/offline, it must send the someonelogon and someonelogout messages to notify the user's friends. The iuserp2paddressmanager class diagram of its interface is as follows:

Iuserp2paddressmanager can be used either on the server or on the client:
(1) The server is mainly filled with p2psessiondealer. In addition, the unregister call should also be triggered for user disconnection events.
(2) The client is mainly filled with p2psessionpassivedealer. In addition, the unregister call should be triggered for user offline events.

The following describes esfp2's support for the client.
The core interface of the client is inaptoutter, which encapsulates all the interactions with the server or other clients on the napt session.

When the client logs on, the inaptoutter. p2plogon method is called. When the client exits, the inaptoutter. p2plogout method is called. getfriendp2paddress is used to obtain the P2P address of all online friends.
Another important component of the client is p2psessionchecker, which is used to regularly send p2pcheckmessage to all online friends by calling inaptoutter. the sendp2pcheckmessage method), so that those customers who are going online can also use this p2pcheckmessage to determine the establishment of the P2P session.
There is also a client message processor p2psessionpassivedealer which implements the idatadealer interface and is also a simple message processor used to process all messages related to building P2P sessions on the client.

These are the main components of esfp2p. How can we use it to build P2P applications? (The premise of using esfp2p is that esframework is used)
(1) Configure p2psessionmessagetype in a public DLL, which will be used by the server and client.
(2) configure the p2psessiondealer component on the server end and assemble it into the processor factory.
(3) configure the userp2paddressmanager component on the server side, and bridge userp2paddressmanager and iusermanager through userp2paddressmanagerbridge.
(4) configure the naptoutter component on the client.
(5) configure the p2psessionpassivedealer component on the client and assemble it into the processor factory on the client.
(6) configure the naptp2pchannelmanager component on the client and assemble it into the imessagetransceiver component.
(7) configure the p2psessionchecker component on the client and call the initialize method when logging on.

Esfp2p. dll can be downloaded from the reusable application framework (sequence) of esframework for trial use.

Thanks for your attention!

Go to: esframework reusable application framework (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.