Ifsbrowser: A foreign P2P software

Source: Internet
Author: User

Original article address:
Http://www.codeproject.com/webservices/ifs.asp

For the first translation, I only translated some articles.

The author seems to have updated recently.

This is a P2P software, full name Internet file system, network file system. Is implemented based on WebService. The function is to register your files on the Internet for sharing.
The full text is 205 K, so I have no courage to translate it. Let's take a look at several important parts.

1: structure:
A peer can publish its own files to share the network, or obtain a file declared as published to the local device.
A single static server (Singleton) with a WebService.
WebService: This software relies on it to implement P2P. Definition? Check it by yourself.

2. Usage:
Register --> log on --> to view and obtain network files/publish your own files.

3: The server registers each user-side file (Basic Information + User-side machine information) declared as a published file to the DB. Such as file name, file folder name, size, Publisher Information (IP, port), virtual directory name (as if it is an IFS directory)

4: Firewall and push ".
Pre-defined: the end of the request to download the file F is called P1. The owner of this file is P2, and the server is called S. Consider these four situations:
A: Neither P1 nor P2 is in the firewall. That is to say, P1 and P2 can be seen each other. At this time, the process for downloading files is as follows: P1 logs on to S to obtain the basic information of F. P1 can obtain some basic information of the owner P2 of F from this information, such as IP address, port number, and whether the information is in the firewall. Since P2 is in the fire wall, P1 can directly send a pull command to p2 (knowing its endponit, that is IP + port. pull, which is simply translated as "pull ". That is, P1 directly finds and downloads the file from the P2 machine.
B: P1 is not in the fire wall, and P2 is in the fire wall. At this time, P1 cannot find P2. How can I download it? The method is called "push", which is simply translated as "push ". Because P1 is not in the fire wall, P1 can be accessed during P2. The operation procedure is as follows: P1 logs on to S and obtains P2 information of the owner of F. It is found in the fire wall. Therefore, P1 sends a request to S and attaches a task of pushing the file to P2, A P2 thread obtains the task and P1 endpoint, and P2 actively sends the file F to P1. Of course, after P1 sends a push request, it is ready to accept the file.
C: P1 is in the fire wall, and P2 is not in the fire wall. It's easy, just like in the first case.
D: P1 and P2 are both in the fire wall. This means that P1 and P2 are invisible. At this time, it's time to crash. P1 first sends a request task like S, which is accepted by P2, but it is found that P1 is also in the wall. So, P2 uploads the file to a space on S. After the upload is complete, notification p1 (of course, the message is transitioned through S). P1 starts to locate the space on S and starts to download the file.

The first time I saw such a long c ++ code. Some important things I see when I look at the source code.

1 :__ GC *: declared as the recycle type
2: pushcommand, pullcommand: For what?

3: Public _ value Enum tasktype: unsigned char
Pushfile = 1 ,//
Downloadfile = 2, // unimplemented
Uploadfile = 3 // Ditto

4: s "press enter to stop the server..." // to string type
5: Class p2pconfig. Use to manage the XML config file which log the very info for system. The file name is 'ifs. P2P. xml'
<? XML version = "1.0" encoding = "UTF-16"?>
<P2pconfig>
<Item key = "peerid"> 851966d6-35d0-4d08-b251-9641d3616b63 </item>
<Item key = "IPaddress"> 127.0.0.1 </item>
<Item key = "Port"> 12000 </item>
<Item key = "p2pfmknamespace"> internetfilesystem. p2pframework </item>
<Item key = "threadsleeptime"> 100 </item>
<Item key = "threadjointime"> 1000 </item>
<! -- Poll for tasks each 10 minutes -->
<Item key = "taskpollinterval"> 600000 </item>
</P2pconfig>
6: Class nethelper. use to manage all the net transport task. include 'connection' to a ipendpoint, 'close', 'writeline 'By buffersize = 1024, 'read/writearray', and so on.
7: works only if the remote peer is not behind Firewall
8: publishfile. There are several situation for publishfile: 'hhfile', 'publishfilehere '. Use virtualfolderpath
9: Properties of a peer
String _ GC * ID;
String _ GC * login;
String _ GC * password;
String _ GC * alias;
String _ GC * ipendpoint;
System: Boolean behindfirewall;
10: Use WebService. // a funny file 'ifswebservice. WSDL'
11: interface icommandexecutor (peercommand _ GC * command, nethelper _ GC * nethelper)
12: Like '3', What's meaning of 'pull 'and 'push', 'peer' and 'library '?
Peerpull = 0, // issued from a remote peer
Peerpush = 1, // Ditto
Librarypush = 2, // issued from the library
Librarypull = 3, // Ditto

Download = 4, // unsupported in this version
Upload = 5, // Ditto
13: Properties of server
Int port;
Serverstatus status;
Tcplistener _ GC * listener;
Thread _ GC * p2pthread;
Int threadsleeptime;
Int threadjointime;
String _ GC * namespacename;
Thread _ GC * taskthread;
// The "int" can handle about a month time
Int taskpollinterval;
String _ GC * peerid;
Ifswebservice _ GC * WebService;
14: Class servermanager have 3 method: sendpushcommand, sendpullcommand, sendmessage. Why send the two commands?

Related Article

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.