Documentation ¶
Overview ¶
Package treerequest block request protocol for ipfs
Each peer can provide a set of persistent root nodes and their children.
Other peers can ask for the CIDs of the trees and also any of the blocks.
Access can be restricted to a set of peers.
Known tree CIDs are stored in the data store you provide.
For convenience, there are http services to access the trees given a prefix you provide that handle GET and (for your own peer) PUT requests with optional encryption for a provided URL prefix:
unencrypted access: /PREFIX/PEERID/PATH encrypted access (only for your peer's files): /PREFIX/PATH
Before using the package, you must call InitTreeRequest().
IPFS-lite works well with TreeRequest and provides all of the required values for InitTreeRequest():
ipfslite.BadgerDatastore(PATH) returns a ds.Datastore (*ipfslite.Peer).BlockStore() returns a blockstore.Blockstore *ipfslite.Peer implements ipld.DAGService (*ipfslite.Peer).Session(CTX) returns an ipld.NodeGetter
Index ¶
- func ChangePeers(treeName string, add []peer.ID, remove []peer.ID)
- func Checkpoint() error
- func Decrypt(input io.ReadSeeker) ([]byte, peer.ID, error)
- func Encrypt(content []byte, certs ...*x509.Certificate) ([]byte, error)
- func Fetch(peerID peer.ID, name string) (done chan RequestResult)
- func GetFile(name string, aCid cid.Cid, encrypted bool) (io.ReadSeeker, time.Time, error)
- func HandlePeerFileRequests(prefix string, encrypted bool, published func(path string, treeCid cid.Cid))
- func InitTreeRequest(protocolName string, dstor ds.Datastore, inputHost host.Host, ...) error
- func PeerFileRequestHandler(prefix string, encrypted bool, published func(path string, treeCid cid.Cid)) func(http.ResponseWriter, *http.Request)
- func PeerTreeFromURL(urlPath string) (peer.ID, string, string, error)
- func SetTree(name string, root cid.Cid) error
- func TimeForBlock(blockCid cid.Cid) (time.Time, error)
- type CidTree
- type MsgBase
- type RequestResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangePeers ¶
ChangePeers add and/or remove peers
func Decrypt ¶
Decrypt decrypt a file (eventually switch to CMS standard: http://pike.lysator.liu.se/docs/ietf/rfc/60/rfc6032.xml) input: [keylen][key][iv][ciphertext] output: plaintext, signer, error
func Encrypt ¶
func Encrypt(content []byte, certs ...*x509.Certificate) ([]byte, error)
Encrypt encrypts content with multiple public keys output: [keylen][key][iv][ciphertext]
func Fetch ¶
func Fetch(peerID peer.ID, name string) (done chan RequestResult)
Fetch get the latest tree from a peer
func HandlePeerFileRequests ¶
func HandlePeerFileRequests(prefix string, encrypted bool, published func(path string, treeCid cid.Cid))
HandlePeerFileRequests install a PeerFileRequestHandler in the standard http server
func InitTreeRequest ¶
func InitTreeRequest(protocolName string, dstor ds.Datastore, inputHost host.Host, peerKey *rsa.PrivateKey, peerCert *x509.Certificate, bstor blockstore.Blockstore, getter ipld.NodeGetter, dagService ipld.DAGService, pin pinner.Pinner, cacheSize int, trees map[string]cid.Cid, ensureTrees map[string]bool, newConnection func(peer.ID)) error
InitTreeRequest ipfslite provides route (dht is a routing.ValueStore) and ds
func PeerFileRequestHandler ¶
func PeerFileRequestHandler(prefix string, encrypted bool, published func(path string, treeCid cid.Cid)) func(http.ResponseWriter, *http.Request)
PeerFileRequestHandler returns a handler for tree requests
GET paths are of the form TREE/PEER-ID/PATH
PUT paths are of the form TREE/PATH and are written to the peer's tree
Encrypted GET requests decrypt the file using the peer's private key ¶
Encrypted PUT requests encrypt the file using the peer's public key in addition to the peerids in the "PEERIDS" header.
Encrypted format uses a random 32-byte AES key encrypted by multiple public peer keys (including the encrypting peer):
(PLAINTEXT:) [# keys: int32] -- do we really need to allow for more than 65535 peer keys? [keylen: int16][key encrypted for peer 1] [keylen: int16][key encrypted for peer 2] ... [initialization vector: AES BLOCK SIZE] (CIPHERTEXT:) [keylen: int16][peer id 1] [keylen: int16][peer id 2] ... [content]
func PeerTreeFromURL ¶
PeerTreeFromURL get a peerID, treeName, and the remainder from a URL
func TimeForBlock ¶
TimeForBlock get the time a block was stored
Types ¶
type CidTree ¶
type CidTree struct { Nodes map[string]cid.Cid FileNodes []cid.Cid }
CidTree a CID tree for a peer
func NewCidTree ¶
NewCidTree make a new, initialized cidtree
type RequestResult ¶
RequestResult result for an asynchronous request