IPFS is a decentralized file distributing system based on peer-to-peer protocol, adding any content on it is like broadcast a unique self-describe torrent file to every peer connected and start to seed the file.
Files will remain on the internet until there's no node seeding it.
IPFS could be seen as a single BitTorrent swarm, exchanging objects within one Git repository.
after running daemon, you can use web console
http://localhost:5001/webui
https://ipfs.io/ipfs/<ipfs-path>
https://ipfs.io/ipns/<nodeid>/[path-to-file]
The IPFS Protocol is divided into a stack of sub-protocols:
reference:
https://github.com/ipfs/specs
Nodes are identified by NodeId, which is a hashed public key(default RSA2048),
key generation 的計算
and required PoW while establishing it.(In order to prevent sybil attack)
p = count_preceding_zero_bits(hash(n.NodeId))
why?7/12討論
Upon first connecting, peers exchange public keys, and check:
hash(other.PublicKey) equals other.NodeId.
If not, the connection is terminated.
firewall 可以過嗎? ->多分おk
7/12討論
IPFS can use any network, it stores addresses as multiaddr formatted byte strings for the underlying network to use.
It can also connect to local network, and have local swarm peers.
For example :
SCTP/IPv4 connection
/ip4/10.20.30.40/sctp/1234/
SCTP/IPv4 connection proxied over TCP/IPv4
/ip4/5.6.7.8/tcp/5678/ip4/1.2.3.4/sctp/1234/
IPFS use a DSHT(Distributed Sloppy Hash Table) based on S/Kademlia and Coral.
Coral 的特性? V.S. bitTorrent DHT
routing 的意義? => Searching for node or data
7/12討論
DSHT:
A sloppy insert is akin to an append in which a replica pointer appended to
a “full” node spills over to the previous node in the lookup path.
A sloppy retrieve only returns some randomized subset
of the pointers stored under a given key.
http://iptps03.cs.berkeley.edu/final-papers/coral.pdf
IPFS DHT makes a distinction for values stored based on their size,
small values (equal to or less than 1KB) are stored directly on the DHT,
and for values larger, the DHT stores references, which are the NodeIds of
peers who can serve the block.
useful refs:https://github.com/ipfs/examples/blob/master/examples/data/readme.md
(1KB的小檔案快取目前並沒有實做)
1KB 是檔案大小還是 block? -> 檔案大小
一剛開始決定的 block 大小?
var BlockSizeLimit = 1048576 //1 MB
7/19會議
清楚的示意圖
7/12討論
IPFS use a Bittorrent inspired protocal: BitSwap to exchange blocks.
It use a credit-like system to incentivice nodes to seed and punish the leechers.
Let the debt ratio r between a node and its peer be:
and the probability of sending to a debtor be:
The relation between and :
So, the more bytes a peer send to you, the more probability you send bytes to him.
In the case that a node has nothing that its peers want (or nothing at all),
it seeks the pieces its peers want, with lower priority (cache) than what the node wants itself.
This incentivizes nodes to cache and disseminate rare pieces, even if they are not interested in them directly.
BitSwap nodes also keep ledgers accounting the transfers with other nodes.
懲罰機制?
7/12討論
Bitswap protocol specification :
上方 Peer 程式碼 interface & struct? -> 僅為示意,語法是錯的
7/19會議
Sketch of the lifetime of a peer connection:
IPFS builds a Merkle DAG[1], a directed acyclic graph where links between
objects are cryptographic hashes of the targets embedded in the sources.
This is a generalization of the Git data structure.
It provides some useful propoties, including:
After add file into IPFS, one can view the content by browsing gateway with
/ipfs/<hash-of-object>/<name-path-to-object>
/ipfs/XLYkgq61DYaQ8NhkcqyU7rLcnSa7dSHQ16x/foo.txt
/ipfs/<hash-of-foo>/bar/baz.txt
/ipfs/<hash-of-bar>/baz.txt
/ipfs/<hash-of-baz>
By using IPNS, one can access a mutable file with same link.
Example:
/ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/
/ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/docs
/ipns/XLF2ipQ4jD3UdeX5xp1KBgeHRhemUtaA8Vm/docs/ipfs
It also provide Peer link feature let users can link other users' objects directly into their own objects. [NOT implement]
Alice links to bob Bob
ipfs link /<alice-pk-hash>/friends/bob /<bob-pk-hash>
Eve links to Alice
ipfs link /<eve-pk-hash/friends/alice /<alice-pk-hash>
Eve also has access to Bob
/<eve-pk-hash/friends/alice/friends/bob
access Verisign certified domains
/<verisign-pk-hash>/foo.com
上傳的文件會存在多久?
有 url,有無可能完全存取不到?
7/19討論
確保交易的順序 ↩︎