实现基于P2P文件共享和同步的开源Java类库:Hive2Hive

jopen 10年前

Hive2Hive 是一个开源的Java类库,用于安全、分布式、基于P2P文件同步和共享。它专注于最大的隐私与用户和数据的安全性。它构建在 TomP2P 之上(一个先进,高性能支持多键 - 值对的DHT)。

实现基于P2P文件共享和同步的开源Java类库:Hive2Hive

虽然存在很多知名的同步和共享服务,但其中大部分都是基于集中客户端 - 服务器的方法,因此将所有用户的数据存储在大容量的外部数据中心中。遗憾的是,这些私人数据往往是不加密的,只是以明文形式存储。其数据用户无法控制,因为它们无法检查还有谁可以访问它。此外,很容易受到有针对性的攻击。

该Hive2Hive库提供了一个免费的,分布式的解决方案,专注于用户和数据提供最大限度的安全和隐私来解决了这些问题。它支持类似Dropbox或Google Drive提供的大部分功能,都装在一个干净的API中。


网络管理

创建P2P网络
配置和设置新的P2P网络是很容易的。只要指定的配置和设置的初始节点。

  1. NetworkConfiguration 和 FileConfiguration 工厂类能够帮助指定你的配置
  2. 创建初始代码并连接至它
INetworkConfiguration netConfig = NetworkConfiguration.create("first");  IFileConfiguration fileConfig = FileConfiguration.createDefault();    IH2HNode node = H2HNode.createNode(netConfig, fileConfig);  node.connect();

加入现有的 P2P 网络
You may want to add other nodes to your created network. Any node can join by bootstrapping to another node that is already part of the network.

  1. specify the network configuration for the joining node (i.e., provide bootstrap address of another node)
  2. create the new node and connect it (it will bootstrap according to its network configuration)
INetworkConfiguration netConfig2 = NetworkConfiguration.create("second", InetAddress.getByName("192.168.1.100"));  IH2HNode node2 = H2HNode.createNode(netConfig2, fileConfig);  node2.connect();

用户管理

Once a node is connected to a network, users can interact with it. For this, each node provides a user management interface.

  1. user has to provide its credentials
  2. login user (if a user is new to the network, she has to register on her first visit)
  3. user can interact with the network (i.e., file management is enabled)
IUserManager userManager = node.getUserManager();    UserCredentials credentials = new UserCredentials("userId", "password", "pin");  Path rootDirectory = Paths.get("sample/path/to/rootDirectory");    if (!userManager.isRegistered(credentials.getUserId())) {      userManager.register(credentials).await();  }  userManager.login(credentials, rootDirectory).await();

文件管理

As soon as a user is logged in to the network, her files are automatically synchronized with the current node. Many further file operations are available. For this, each node provides a file management interface.

  • add / delete file
  • update / recover file
  • share file with another user
  • move file

IFileManager fileManager = node.getFileManager();    File folder = new File("folderpath");  File file = new File(folder, "filepath");    fileManager.add(file);    fileManager.update(file);    fileManager.share(folder, "other-userId", PermissionType.WRITE);    IVersionSelector versionSelector = new IVersionSelector() {      @Override      public IFileVersion selectVersion(List<IFileVersion> availableVersions) {          return availableVersions.get(0);      }  };  fileManager.recover(file, versionSelector);    fileManager.move(folder, new File("other-folder"));    fileManager.delete(file);

File Watchdog

In order to keep track of changes in the local file system, a file observer is needed. This observer then notifies its attached listeners on all file system events. You can either use the provided H2HFileObserver and H2HFileObserverListener or implement your own adhering to the IFileObserver and IFileObserverListener interfaces.
The H2HFileObserverListener automatically synchronizes the Hive2Hive root folder with the network.

IFileObserverListener listener = new H2HFileObserverListener(fileManager);    IFileObserver observer = new H2HFileObserver(rootDirectory.toFile());  observer.addFileObserverListener(listener);  observer.start();

特点与优势

Hive2Hive offers the same basic functionality known from popular synchronization services. (e.g., Dropbox)
On top of that, Hive2Hive provides additional features such as security and versioning.

  • File Synchronization
  • File Sharing (including user permissions (write, read-only))
  • File Versioning (including conflict detection)
  • File Watchdog / Change Detection (automated, configurable)
  • Security (configurable, see more)
    • Encryption of files
    • Encryption of messages
    • Authenticity of data and messages
    </li>
  • Users can use multiple clients (simulatenously)
  • Multiple users can use the same machine (simultaneously)
  • </ul>

    Using the Hive2Hive library is very simple and has several advantages:

    • P2P Decentralization
      • Scalability
      • Heterogeneity
      • Reliability & Fault-Tolerance
      </li>
    • no file size limits (configurable)
    • platform independent (JVM)
    • headless deployment possible* (e.g., on a Raspberry Pi)
    • free & open-source
    • generously configurable & customizable
    • highly extendable
    • detailed documentation
    • </ul>

      * Try our console-based org.hive2hive.client by just executing the library .jar.

      And there is even more to come:


      项目主页:http://www.open-open.com/lib/view/home/1415090978355