ipfs

package module
v0.0.0-...-ce94876 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2019 License: MIT Imports: 0 Imported by: 0

README

Ungx-ed fork of go-ipfs

GoDoc

This repository is an unofficial fork of github.com/ipfs/go-ipfs, converted from a gx based project to a plain Go project. The goal is to act as an IPFS library that can be imported and used from Go apps without the need of switching all dependency management over to gx. As a bonus, this fork is compatible with GoDoc!

For a rundown of why gx is not the best solution at the moment, please see the rationale section behind the ungx project.

Differences from upstream

Upstream go-ipfs is both a gx based project, as well as depends on many third party gx based packages. To use it in plain Go projects, all gx packages need to be resolved into their original canonical versions, or need to be converted into non-gx ones.

This fork uses the following logic to ungx go-ipfs:

  • If a dependency has a plain Go canonical version (e.g. golang.org/x/net), the dependency is converted from an IPFS multihash into its canonical path and vendored into the standard vendor folder. This ensures they play nice with the usual package managers.
  • If a dependency is only available as a gx project (e.g. github.com/libp2p/go-libp2p), the dependency is converted from an IPFS multihash into its canonical path, but is moved into the gxlibs folder within the main repository. This ensures external packages can import them.

Two caveats were also needed to enable this fork:

  • If multiple versions of the same plain Go dependency is found, these cannot be vendored in. In such cases, all clashing dependencies are embedded into the gxlibs/gx/ipfs folder with their original IPFS multihashes. This retains the original behavior whilst still permitting imports.
  • If an embedded dependency contains canonical path constraints (e.g. golang.org/x/sys/unix), these constraints are blindly deleted from the dependency sources. Unfortunately this is the only way to allow external code to import them without Go failing the build.

The ungx-ing process is done automatically for the master branch in a nightly Travis cron job from the ungx branch in this repository. Upstream releases (i.e. tags) are not yet ungx-ed to prevent having to re-tag versions if a bug in ungx is discovered. Those will be added and tagged when the process is deemed reliable enough.

Demo

The hello-world of IPFS is retrieving the official welcome page from the network. With the IPFS command line client this looks something like:

$ ipfs cat QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝
[...]

Doing the same thing from Go is a bit more involved as it entails creating an ephemeral in-process IPFS node and using that as a gateway to retrieve the welcome page:

package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"

	"github.com/ipsn/go-ipfs/core"
	"github.com/ipsn/go-ipfs/core/coreapi"
	"github.com/ipsn/go-ipfs/core/coreapi/interface"
)

func main() {
	// Create a new IPFS network node
	node, err := core.NewNode(context.TODO(), &core.BuildCfg{Online: true})
	if err != nil {
		log.Fatalf("Failed to start IPFS node: %v", err)
	}
	path, _ := iface.ParsePath("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB")

	// Resolve the IPFS welcome page
	reader, err := coreapi.NewCoreAPI(node).Unixfs().Get(context.TODO(), path)
	if err != nil {
		log.Fatalf("Failed to look up IPFS welcome page: %v", err)
	}
	// Retrieve and print the welcome page
	blob, err := ioutil.ReadAll(reader)
	if err != nil {
		log.Fatalf("Failed to retrieve IPFS welcome page: %v", err)
	}
	fmt.Println(string(blob))
}

However, after the dependencies are met, our pure Go IPFS code works flawlessly:

$ go get -v github.com/ipsn/go-ipfs/core
$ go run ipfs.go
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗  ███████╗
██║██╔═══╝ ██╔══╝  ╚════██║
██║██║     ██║     ███████║
╚═╝╚═╝     ╚═╝     ╚══════╝
[...]
Proper dependencies

Although the above demo works correctly, running go get -v github.com/ipsn/go-ipfs/core is not for the faint of heart. It will place about 1193 packages into you GOPATH 😱. A much better solution is to use your favorite dependency manager!

Demo with govendor:

$ go get -u github.com/kardianos/govendor
$ govendor init
$ govendor fetch -v +missing
$ go run ipfs.go
[...]

Credits

This repository is maintained by Péter Szilágyi (@karalabe), but authorship of all code contained inside belongs to the upstream go-ipfs project.

License

Same as upstream (MIT).

Documentation

Overview

IPFS is a global, versioned, peer-to-peer filesystem

There are sub-packages within the ipfs package for various low-level utilities, which are in turn assembled into:

core/...:

The low-level API that gives consumers all the knobs they need,
which we try hard to keep stable.

shell/...:

The high-level API that gives consumers easy access to common
operations (e.g. create a file node from a reader without wrapping
with metadata). We work really hard to keep this stable.

Then on top of the core/... and shell/... Go APIs, we have:

cmd/...:

Command-line executables

test/...:

Integration tests, etc.

To avoid cyclic imports, imports should never pull in higher-level APIs into a lower-level package. For example, you could import all of core and shell from cmd/... or test/..., but you couldn't import any of shell from core/....

Index

Constants

View Source
const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"
View Source
const CurrentVersionNumber = "0.4.19-dev"

CurrentVersionNumber is the current application's version literal

Variables

View Source
var CurrentCommit string

CurrentCommit is the current git commit, this is set as a ldflag in the Makefile

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
blocks
cmd
Package core implements the IpfsNode object and related methods.
Package core implements the IpfsNode object and related methods.
exchange
Package filestore implements a Blockstore which is able to read certain blocks of data directly from its original location in the filesystem.
Package filestore implements a Blockstore which is able to read certain blocks of data directly from its original location in the filesystem.
fuse
gxlibs
Package namesys implements resolvers and publishers for the IPFS naming system (IPNS).
Package namesys implements resolvers and publishers for the IPFS naming system (IPNS).
pin
Package pin implements structures and methods to keep track of which objects a user wants to keep stored locally.
Package pin implements structures and methods to keep track of which objects a user wants to keep stored locally.
test
thirdparty

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL