Dict.CN 在线词典, 英语学习, 在线翻译

IFSBrowser:一个老外的p2p软件

原文地址:
http://www.codeproject.com/webservices/ifs.asp

第一次翻译,还只是翻译了部分文章。

作者最近好像还有更新。


这是一个p2p软件,全称Internet File System,网络文件系统。是基于WebService实现的。实现的功能是:可以把自己的文件注册到网络上,让大家共享。
全文205k,我实在没有勇气去翻译。捡几个重要的部分介绍一下。

1:结构:
  peer 一个使用端,可以发布自己的文件让其网络共享,也可以获取一个声明为发布的文件到本地。
  Server 静态单一(singleton)的服务端,设有WebService。
  WebService:这个软件就是靠它实现p2p的了。定义?自己查吧。

2:使用方法:
  注册--〉登陆--〉可以查看获取网络文件/发布自己的文件。

3:Server是把每个使用端声明为发布的文件的(基本信息+发布用户端机器信息)注册到DB里面。诸如 文件名,文件所在文件夹名,大小,发布者信息(ip,port),虚拟目录名(好像是ifs自己的目录)

4:防火墙和“推”“拉”。
  事先定义:请求需要下载文件f的一端叫做p1,这个文件的所有者叫p2,服务器叫s。  考虑这四种情况:
  a:p1和p2都不在防火墙里面。也就是说p1和p2时可以互相看见的。这时候,下载文件的流程是这样的:p1登陆到s,获取f的基本信息。p1可以从这个信息里面获取f的所有者p2的一些基本信息,如ip,端口号,是否在火墙里等。既然p2部在火墙里面,p1就可以直接向p2(知道了他的endponit,that is ip+port)发送一个pull的命令.pull,简单的翻译为“拉”。即p1从p2的机器上直接找到文件,下载。
  b:p1不在火墙里,p2在火墙里面。这时候,p1是无法找到p2的。如何实现下载呢?方法叫做“Push”,简单的翻译为“推”。因为p1不在火墙里面,所以p2时可以访问到p1的。操作流程是这样的:p1登陆s,获取f的所有者p2的信息,发现在火墙里面,于是乎,p1向s发出请求,附加一个Push文件的Task给p2,p2的一个线程获取这个Task和p1的endpoint,然后p2主动向p1发送文件f。当然了,p1在发送了Push的请求之后,就准备接受文件了。
  c:p1在火墙里,p2不在火墙里。很容易,和第一种情况一样。
  d:p1和p2都在火墙里。这就意味着p1和p2都是不可见的。这时候,该s出马了。p1首先会像s发出一个请求Task,p2接受,但是发现p1也在墙里,so,p2把文件upload到s上面的一个空间上,上传结束后,通知p1(当然是通过s中转这个消息了),p1开始到s上找到这个空间,开始下载文件。



第一次看这么长的c++代码。我在看源码的时候,看到的一些重要的东东。

1:__gc*:声明为回收类型
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 'Connect' 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:'PublishFile','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?

posted @ 2010-11-02 15:07  无名-小卒  阅读(406)  评论(0编辑  收藏  举报