[Recommended understanding] IPFS-point-to-point efficient transmission practice

IPFS-point-to-point efficient transmission practice

IPFS,有着远大的志向要成为“星际文件系统--InterPlanetary File System”。 
在我看来,它确实是一种具有代表性的点对点分布式文件系统,
与传统互联网规则不同之处在于,IPFS以内容进行寻址,而不是先找主机再找内容的方式。

This article made an attempt to transfer IPFS point-to-point files.
Please note that the premise of this file transfer is:
(1) Known file sender
(2) Obtain file index
(3) File sender data online

There are many online tutorials on the IPFS download and installation process, so I won’t repeat them here.
If you have any questions, you can leave a message and answer when you see it

One initialization

After installing IPFS, perform IPFS initialization on the receiving and sending nodes respectively.
In this practice, the sender is my laptop, and the recipient is the remote Alibaba Cloud host.

>ipfs init

The .ipfs directory structure generated by this command is as follows:
.ipfs file directory
Among them, keystore is used to store private keys.

Two start node

Perform separately on both the sender and receiver:

ipfs daemon

Examples of output information are as follows:

Initializing daemon...
go-ipfs version: 0.6.0
Repo version: 10
System version: amd64/linux
Golang version: go1.14.4
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/192.168.1.127/tcp/4001
Swarm listening on /ip4/192.168.1.127/udp/4001/quic
Swarm listening on /ip6/xxxxxxx人为匿了xxxxxxxxxx/tcp/4001
Swarm listening on /ip6/xxxxxxx人为匿了xxxxxxxxxx/udp/4001/quic
Swarm listening on /ip6/xxxxxxx人为匿了xxxxxxxxxx/tcp/4001
Swarm listening on /ip6/xxxxxxx人为匿了xxxxxxxxxx/udp/4001/quic
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/::1/udp/4001/quic
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/127.0.0.1/udp/4001/quic
Swarm announcing /ip4/192.168.1.127/tcp/4001
Swarm announcing /ip4/192.168.1.127/udp/4001/quic
Swarm announcing /ip6/xxxxxxx人为匿了xxxxxxxxxx/tcp/4001
Swarm announcing /ip6/xxxxxxx人为匿了xxxxxxxxxx/udp/4001/quic
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/::1/udp/4001/quic
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

The node now uses port 4001 to receive peer information and establish contact.
We can visit port 5001 to get the visualization page.
[Peers ID displayed on the page will be updated every time the node is initialized ( ipfs init )]
Visualization page

Three connection nodes

Both sender and receiver can initiate a link. There are two methods:
(1) Method 1: Page operation After
Connect node-page operation
clicking File, select "+Import" on the current page. Then select from IPFS in the candidate box .
Enter the node index provided by the other party, like:

/ip4/102.92.10.209/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw

Among them:
ip4 = ipv4 address type;
102.92.10.209 = ipv4 address;
4001 = peer listening port number
QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw = peer node ID

How to obtain the link: View it
through the ipfs id command on the host of the other party , and copy one at Addresses (it is recommended to copy the public IP).
Example:

>ipfs id
输出:
{
	"ID": "QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
	"PublicKey": "CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDZ/s+ocPZBJv4L5FEHhd3pty0GKC4wEOoHXAgRxwhjgO7ngmOXWsseG7hWjR7IAKpBZEXPnKDsZIYqsPt6cwQrqMWKPwzJaRzo4qmSTO774+mqOTE4daBfnG6nENb/fuZc/C6WHL4+SGyUu97TnzYqKGc/rDuTqzE9whV70wHY2K5eFZugvzm7iFqSHmAhpxjp7XfRCyN7x8af4HzidhyzZjSSfCbJJOKL55plgeqOV/YY1xBfM3xzEDAQXpvskNrem4KrG/XwSZHRr62YK7MUxjXsq1FkTh5YbGuhqu3Q7rsb6SIbTvGF37+o2V2gRC2KVzOfBWzISJRbKlQ8fSgRAgMBAAE=",
	"Addresses": [
		"/ip4/127.0.0.1/tcp/4001/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip4/172.17.55.9/tcp/4001/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip6/::1/tcp/4001/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip4/127.0.0.1/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip4/172.17.55.9/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip6/::1/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip4/102.92.10.209/tcp/4001/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw",
		"/ip4/102.92.10.209/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw"
	],
	"AgentVersion": "go-ipfs/0.6.0/",
	"ProtocolVersion": "ipfs/0.1.0"
}

(2) Method 2: Command line
The same as the above steps, use the command line to query the peers node connection index through ipfs id on the other host .
Then, enter on the command line:

ipfs bootstrap add  /ip4/102.92.10.209/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw

That is, the opposite node is designated as the seed node to be connected first. Due to network problems, this link may take a long time (about 3 minutes in this test).

Add a line of command ipfs ping to check connectivity and delay:

ipfs ping /ip4/102.92.10.209/udp/4001/quic/p2p/QmZ3DTrfPdahviV2xV9Ni4LXND8BALbykRC2zqNLonw

Four file upload

When the connection is established, that is, when ipfs ping can be pinged, the sender can start to upload files.
[The following codes are real data]

>ipfs add 20w_address.net 
added QmfN7mWDfChb9PMubEW9nC39mk6PXdX625wEtHz7kBTraP 20w_address.net
 1.45 GiB / 1.45 GiB [=================================================] 100.00%

The upload process is generally in seconds, because you only need to process the file hash locally and upload the final file hash (the root hash of the Merkel diagram) to the network.

Five file download

When the file is uploaded successfully, proceed to the receiving end:

>ipfs get QmfN7mWDfChb9PMubEW9nC39mk6PXdX625wEtHz7kBTraP
Saving file(s) to QmfN7mWDfChb9PMubEW9nC39mk6PXdX625wEtHz7kBTraP
 1.45 GiB / 1.45 GiB [============================================] 100.00% 8m4s

In practice, the transmission time is 8m4s, and the subsequent uploads and downloads maintain a high speed, and there is no need to perform node discovery again.

Six feelings

(1) Advantages:

a) Efficient transmission. Through the test, it is found that more time loss when IPFS performs peer-to-peer file transmission lies in the node discovery part.
From the perspective of information transmission between nodes, its performance is far better than Baidu W Disk (have never used members, don't know the member speed) .
b) Good privacy. Point-to-point sharing reduces third-party transfer links and has better data privacy.
c) Decentralization. Decentralized storage of data is convenient to avoid single point of failure, and multi-point storage can effectively increase the download speed.

(2) Insufficiency:

a) Node discovery is slower. The discovery process between nodes is time-consuming, uncertain, and user experience is poor.
b) The sender needs to be online. IPFS (especially in the early stage of document release) requires the sender to ensure that the data is online, but it is impossible to know when the recipient will use it.
c) Bad user experience. Currently, more functions of IPFS still rely on API calls, which is not conducive to non-professional users to get started quickly.

Conclusion:
Sometimes, defects represent hope.

Guess you like

Origin blog.csdn.net/weixin_43347204/article/details/107888269