IPFS (InterPlanetary File System) is a globally oriented, peer-to-peer distributed version of the File System, is a decentralized nodes stored more important protocol, the goal of this agreement is to replace the traditional Internet protocols HTTP, let our Internet speed is faster, more secure, more open, but IPFS need through the implementation of incentive mechanism based on block chain, to encourage the nodes involved in IPFS network storage, providing services and get the return,
About IPFS had to mention FileCoin, people will often confuse IPFS and FileCoin, actually this is two different concepts, although is Juan Benet and his Protocal Lab, but IPFS is just an agreement, it will not be enough to build a platform for distributed storage, and FileCoin is based on the agreement on a file storage market, its implementation is to a block chain, through the chain block, and the chain on the issue of the tokens, FileCoin equivalent IPFS agreement on reward mechanism of added a file storage, with this mechanism, a storage requirements of users using tokens, provide storage space of the miners through competition to store files instead of money, so you will be willing to take out your spare hard disk storage of other people's files, to build a commercially available storage space of globalization, the future is it possible to replace IPFS HTTP protocol, to build a new Internet,
1. FileStorm
Based on IPFS agreement set up storage platform need to do the following things:
To ensure that the file is copied to multiple nodes,
Find and fix the defect file,
File storage providers can be rewarded,
File storage can be proved that two pieces:
Copy to prove (proof - of - the replication) - storage must be able to provide node documents have been stored in its physical hard disk,
Space-time prove (proof - of - spacetime) - storage node must be able to prove file is stored in a certain time,
Men is a born to decentralized application of multilevel block chain, the chain of each child will be used to support an application, but most of the applications have storage requirements, this is an integral part of chain block application, FileStorm is such a sliver chain, users can call intelligent contracts written and read the documents IPFS network,
FileStorm substring regular file validation to ensure that the documents are stored, and then to the storage nodes to pay benefits, because the underlying protocol is consistent, with main IPFS by FileStorm storage file is connected, so realizes the IPFS storage locations, will be a perfect decentralized application development platform,
And based on IPFS agreement set up storage platform need all of the conditions, can be easily through the substring locations:
Establish a composed of multiple nodes can provide storage function substring,
On substring own node updates, backup, and refresh the function implementation file repair,
Substring nodes through the piece reward,
FileStorm consensus mechanism from time and space to justifying the files to be copied,
2.
FileStorm consensus
FileStorm consensus, and similar ProcBlizzard consensus substring nodes in turn out in sequence, a piece of every n seconds, n can be set up, is now set to 10,
FileStorm the difference is that each FileStorm substring block head to have two parameters, one is a random number, one is the hash value, these two parameters are used for file verification, the certificate on each node are saved the remaining files, in the first edition FileStorm sub chain, all the files in each node must save a copy of every m blocks in a file verification, m can be set up, is now set to 10,
Validation method is that a piece of nodes to get a block on the random Numbers, and then calculated by the random number, find it in their own IPFS corresponding files, and find a file all subsections corresponding to the starting position, and then went back to take 256 bytes (number of bytes is not enough just to get the file the last byte), do a hash, and writes the hash value block head, generate a new random number written in block head at the same time, for the next block, and the other nodes after receiving the new blocks, also want to use the same method to validate the corresponding files in the local IPFS node, the verification results are consistent, it will be written into the local the block chain, if don't agree, just wait for the next block, so, FileStorm consensus son ensures that each node in the chain of save the save file,
3. FileStorm substring node
Run FileStorm substring need to install the following four modules
SCSServer - substring node scholars program,
Redis - a local database for storing documents of public and private hash hash,
IPFS Monkey - file management assistant, for file from IPFS Daemon in read, write, delete, and verify the
IPFS Daemon - files stored in the form of IPFS main platform,
IPFS Daemon generated by IPFS source code, there is no change, so FileStorm substring is a kind of open architecture, and other storage devices based on IPFS compatible,
4. FileStorm substring node security
In order to ensure the safety of the substring node locations, substring node is not exposed IP, all of the information transmission through the VNODE, however, IPFS can according to the specific node file hash value orientation of the IP address, so we will reduce the file hash encryption, however, if open the file, the file will ensure that there is a substring node to store with the original hash,
5. IPFS
IPFS contract must provide four basic functions:
Function a write (string fileHash, bool publicFile)
Can call this function writes the local file FileStorm substring node, if the input publicFile parameter is true, the file will be open, through the same fileHash can be read from the chain, if the input publicFile parameter is false, the open files will be closed, with fileHash can not read it out from the chain, can only call contract function for reading files,
The function of read (string fileHash)
Call this function can take FileStorm substring nodes files read local IPFS Daemon,
The function remove (string fileHash)
Call this function can delete documents from FileStorm a chain,
The function verify (string fileHash)
Call this function can verify node file exists,
Contract code (only for the use of test) :
` ` `
Pragma solidity ^ 0.4.18;
Contract Precompiled10 {
The function ipfsFile (string, uint, uint) public;
}
Contract IpfsSubChain {
Struct File {
String fileHash;
Bool publicFile;
}
Enum AccessType {read, write, remove, verify}
Enum AccessMode {isPublic, isPrivate}
String [] public fileHashes;
The File [] public files;
Precompiled10 constant PREC10=Precompiled10 (0 xa);
//constructor
The function IpfsSubChain () public {
}
The function list () public returns (uint count) {
Return fileHashes. Length;
}
Function a write (string fileHash, bool publicFile) public {
For (uint I=fileHashes. Length; I> 0; I -) {
If (compareStringsbyBytes (fileHash, fileHashes] [I - 1)) {
return;
}
}
FileHashes. Push (fileHash);
Files. Push (File (fileHash publicFile));
AccessMode AccessMode=AccessMode. IsPrivate;
If (publicFile)
AccessMode=accessMode. IsPublic;
PREC10. IpfsFile (fileHash, uint (AccessType. Write), uint (accessMode));
}
The function of read (string fileHash) public {
PREC10. IpfsFile (fileHash, uint (AccessType. Read), uint (AccessMode. IsPrivate));
}
The function remove (string fileHash) public {
For (uint I=fileHashes. Length; I> 0; I -) {
If (compareStringsbyBytes (fileHash, fileHashes] [I - 1)) {
For (uint j=I - 1; j
}
The delete fileHashes [fileHashes length - 1);
FileHashes. Length -- --;
}
}
PREC10. IpfsFile (fileHash, uint (AccessType. Remove), uint (AccessMode. IsPrivate));
}
The function verify (string fileHash) public {
PREC10. IpfsFile (fileHash, uint (AccessType. Verify), uint (AccessMode. IsPrivate));
}
The function compareStringsbyBytes (string s1, string s2) public pure returns (bool)
{
Bytes memory s1bytes=bytes (s1);
Bytes memory s2bytes=bytes (s2);
If (s1bytes length!=s2bytes. Length) {
return false;
}
The else {
For (uint I=0; i
If (s1bytes [I]!=s2bytes [I])
return false;
}
return true;
}
}
nullnullnullnull