實現基于P2P文件共享和同步的開源Java類庫:Hive2Hive

jopen 10年前發布 | 38K 次閱讀 Hive2Hive 網絡工具包

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
  • Users can use multiple clients (simulatenously)
  • Multiple users can use the same machine (simultaneously)

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

  • P2P Decentralization
    • Scalability
    • Heterogeneity
    • Reliability & Fault-Tolerance
  • 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

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

And there is even more to come:


項目主頁:http://www.baiduhome.net/lib/view/home/1415090978355

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!