go-ipfs

Go中的IPFS实现。(IPFS implementation in go.)

Github stars Tracking Chart

go-ipfs

在Go中执行IPFS

什么是IPFS?

IPFS是一个全局的、版本化的对等文件系统。 它结合了Git、BitTorrent、Kademlia、SFS和Web的好点子。 它就像一个bittorrent swarm,交换git对象。 IPFS提供了一个像HTTP Web一样简单的接口,但内置了永久性。您还可以将世界挂载到 /ipfs。

有关详细信息,请参阅:https://github.com/ipfs/ipfs。

请提出有关以下方面的所有问题:

安全问题

IPFS协议及其实现仍在大量开发中。这意味着我们的协议可能存在问题,或者我们的实施可能会出现错误。而且 - 虽然IPFS尚未准备好生产 - 但许多人已经在其机器中运行节点。所以我们非常重视安全漏洞。如果您发现安全问题,请立即将其提醒我们!

如果您发现可能影响实时部署的漏洞(例如,通过公开远程执行漏洞),请将您的报告私人发送至security@ipfs.io。请不要提交公开问题。 security@ipfs.io的GPG密钥为 4B9665FB 92636D17 7C7A86D3 50AAE8A9 59B13AF3

如果问题是无法立即被利用的协议弱点或尚未部署的问题,请公开讨论。

安装

IPFS的规范下载说明已在: http://ipfs.io/docs/install/。如果您对IPFS开发不感兴趣,强烈建议遵循这些说明。

系统要求

IPFS可以在大多数Linux、macOS和Windows系统上运行。 我们建议在具有至少2 GB RAM的机器上运行它(只有一个CPU内核可以正常运行),但只需1GB的内存即可正常运行。 在内存较少的系统上,它可能不完全稳定。

安装预编译软件包

我们在我们的发行版页面上托管预构建的二进制文件。

从那里:

  • 点击页面右侧的蓝色“下载go-ipfs”。
  • 打开/解压档案。
  • 将 ipfs 移动到您的路径( install.sh 可以为您完成)。

如果您无法访问ipfs.io,也可以从该项目的GitHub发布页面下载go-ipfs。

从Linux软件包管理器

Arch Linux

在Arch Linux中,go-ipfs可用 go-ipfs 包。

$ sudo pacman -S go-ipfs

go-ipfs的开发版本也在AUR下 go-ipfs-git 。 您可以使用您最喜爱的AUR Helper或AUR手动安装。

Nix

对于Linux和MacOSX,您可以使用纯功能包管理器 Nix

$ nix-env -i ipfs

您也可以使用它的属性名称(也是 ipfs )来安装Package。

Guix

GNU的功能包管理器Guix也提供了go-ipfs包:

Snap

在任何受支持的Linux发行版中使用捕捉:

$ sudo snap install ipfs

从源代码构建

安装Go

ipfs的构建过程需要Go 1.9或更高版本。如果您没有它:下载Go 1.9+

您需要将Go的bin目录添加到您的 $ PATH 环境变量中,例如,将这些行添加到/etc/profile 中(对于系统范围安装)或 $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin

(如果您遇到问题,请参阅 Go安装说明)。

下载并编译IPFS

$ go get -u -d github.com/ipfs/go-ipfs

$ cd $GOPATH/src/github.com/ipfs/go-ipfs
$ make install

如果您使用FreeBSD而不是 make install ,请使用 gmake install 。

不太常见的系统上构建

如果您的操作系统没有正式支持,但您仍然想尝试 无论如何建立ipfs(它应该在大多数情况下工作正常),你可以做的 以下代替 make install :

$ make install_unsupported

注意:如果 gx ,此过程可能会中断 (用于依赖管理)或其任何依赖项以去获取为例 将始终选择每个依赖项的最新代码,通常会导致 不匹配的API。

疑难解答

  • 单独的指令可用于在Windows上构建
  • 另请参阅 OpenBSD说明
  • 为了让 go get 获取所有的依赖关系, git 是必需的。
  • 包管理器通常包含过期的 golang 包。确保 go version 至少报告1.9。请参阅上文了解如何安装go。
  • 如果您对开发感兴趣,请安装开发依赖关系。
  • 警告:安装OSX FUSE(适用于Mac OS X)的旧版本可能会导致内核崩溃! 我们强烈建议您使用最新版本的OSX FUSE 。 (请参阅 https://github.com/ipfs/go-ipfs/issues/177
  • 有关设置FUSE(以便安装文件系统)的更多详细信息,请参阅docs文件夹。
  • Shell命令完成可在 misc/completion/ipfs-completion.bash 中找到。阅读 docs/command-completion.md 以了解如何安装它。
  • 请参阅初始示例,了解如何将IPFS连接到systemd或任何init系统您的发行版使用。

入门

另见: http://ipfs.io/docs/getting-started/

要开始使用IPFS,您必须首先在您的IPFS上初始化IPFS的配置文件 系统,这是通过 ipfs init 完成的。有关信息,请参阅 ipfs init --help 它需要的可选参数。初始化完成后,您可以使用 ipfs mount , ipfs add 以及任何其他要探索的命令!

一些要尝试的事情

本地'ipfs working'的基本证明:

echo "hello world" > hello
ipfs add hello
# This should output a hash string that looks something like:
# QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o
ipfs cat <that hash>

Docker使用情况

IPFS docker 映像托管于 hub.docker.com/r/ipfs/go-ipfs。 要在容器内部显示文件,您需要安装一个主机目录 使用docker的 -v 选项。选择一个你想用的目录 从IPFS导入/导出文件。你还应该选择一个目录来存储 IPFS文件将在您重新启动容器时保留。

export ipfs_staging=</absolute/path/to/somewhere/>
export ipfs_data=</absolute/path/to/somewhere_else/>

启动运行ipfs的容器并公开端口4001,5001和8080:

docker run -d --name ipfs_host -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

观看ipfs日志:

docker logs -f ipfs_host

等待ipfs启动。当您看到以下内容时,ipfs正在运行:

Gateway (readonly) server
listening on /ip4/0.0.0.0/tcp/8080

您现在可以停止观看日志。

运行ipfs命令:

docker exec ipfs_host ipfs <args...>

例如: 连接到对等方

docker exec ipfs_host ipfs swarm peers

添加文件:

cp -r <something> $ipfs_staging
docker exec ipfs_host ipfs add -r /export/<something>

停止正在运行的容器:

docker stop ipfs_host

疑难解答

如果您之前已经安装过IPFS并且正在运行 遇到问题需要更新版本才能使用,请尝试删除(或备份到某处) 否则)您的IPFS配置目录(默认为~/.ipfs)并重新运行 ipfs init 。 这会将配置文件重新初始化为默认值并清除本地 数据存储的任何不良条目。

请直接提出一般性问题并向我们提供帮助 论坛或我们的IRC频道(freenode #ipfs)。

如果您认为您发现了一个错误,请检查单子列表 如果你没有在那里看到你的问题,或者来IRC上谈谈(freenode #ipfs)或者提出你自己的问题!

贡献

请参阅 Contribute.md

该存储库属于IPFS 行为准则

许可证

MIT

Overview

Name With Owneripfs/kubo
Primary LanguageGo
Program languageMakefile (Language Count: 6)
PlatformLinux, Mac, Windows
License:Other
Release Count171
Last Release Namev0.28.0 (Posted on 2024-04-15 09:25:50)
First Release Namev0.2.2-buildfails (Posted on )
Created At2014-06-26 08:14:34
Pushed At2024-04-27 13:05:00
Last Commit At2024-04-17 07:47:39
Stargazers Count15.8k
Watchers Count540
Fork Count3k
Commits Count15.1k
Has Issues Enabled
Issues Count4623
Issue Open Count1065
Pull Requests Count4199
Pull Requests Open Count105
Pull Requests Close Count1394
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

go-ipfs

banner


Matrix
IRC
Discord
GoDoc
standard-readme compliant
CircleCI

What is IPFS?

IPFS is a global, versioned, peer-to-peer filesystem. It combines good ideas from previous systems such Git, BitTorrent, Kademlia, SFS, and the Web. It is like a single bittorrent swarm, exchanging git objects. IPFS provides an interface as simple as the HTTP web, but with permanence built in. You can also mount the world at /ipfs.

For more info see: https://docs.ipfs.io/introduction/overview/

Before opening an issue, consider using one of the following locations to ensure you are opening your thread in the right place:

Table of Contents

Security Issues

The IPFS protocol and its implementations are still in heavy development. This means that there may be problems in our protocols, or there may be mistakes in our implementations. And -- though IPFS is not production-ready yet -- many people are already running nodes in their machines. So we take security vulnerabilities very seriously. If you discover a security issue, please bring it to our attention right away!

If you find a vulnerability that may affect live deployments -- for example, by exposing a remote execution exploit -- please send your report privately to security@ipfs.io. Please DO NOT file a public issue. The GPG key for security@ipfs.io is 4B9665FB 92636D17 7C7A86D3 50AAE8A9 59B13AF3.

If the issue is a protocol weakness that cannot be immediately exploited or something not yet deployed, just discuss it openly.

Install

The canonical download instructions for IPFS are over at: https://docs.ipfs.io/guides/guides/install/. It is highly suggested you follow those instructions if you are not interested in working on IPFS development.

System Requirements

IPFS can run on most Linux, macOS, and Windows systems. We recommend running it on a machine with at least 2 GB of RAM and 2 CPU cores (go-ipfs is highly parallel). On systems with less memory, it may not be completely stable.

If your system is resource constrained, we recommend:

  1. Installing OpenSSL and rebuilding go-ipfs manually with make build GOTAGS=openssl. See the download and compile section for more information on compiling go-ipfs.
  2. Initializing your daemon with ipfs init --profile=lowpower

Install prebuilt packages

We host prebuilt binaries over at our distributions page.

From there:

  • Click the blue "Download go-ipfs" on the right side of the page.
  • Open/extract the archive.
  • Move ipfs to your path (install.sh can do it for you).

You can also download go-ipfs from this project's GitHub releases page if you are unable to access ipfs.io.

From Linux package managers

Arch Linux

In Arch Linux go-ipfs is available as
go-ipfs package.

$ sudo pacman -S go-ipfs

Development version of go-ipfs is also on AUR under
go-ipfs-git.
You can install it using your favourite AUR Helper or manually from AUR.

Nix

For Linux and MacOSX you can use the purely functional package manager Nix:

$ nix-env -i ipfs

You can also install the Package by using it's attribute name, which is also ipfs.

Guix

GNU's functional package manager, Guix, also provides a go-ipfs package:

$ guix package -i go-ipfs

Solus

In solus, go-ipfs is available in the main repository as
go-ipfs.

$ sudo eopkg install go-ipfs

You can also install it trough the Solus software center.

Snap

With snap, in any of the supported Linux distributions:

$ sudo snap install ipfs

From Windows package managers

Chocolatey

The package ipfs currently points to go-ipfs and is being maintained.

PS> choco install ipfs

Scoop

Scoop provides go-ipfs in its 'extras' bucket.

PS> scoop bucket add extras
PS> scoop install go-ipfs

Build from Source

go-ipfs's build system requires Go 1.13 and some standard POSIX build tools:

  • GNU make
  • Git
  • GCC (or some other go compatible C Compiler) (optional)

To build without GCC, build with CGO_ENABLED=0 (e.g., make build CGO_ENABLED=0).

Install Go

The build process for ipfs requires Go 1.12 or higher. If you don't have it: Download Go 1.12+.

You'll need to add Go's bin directories to your $PATH environment variable e.g., by adding these lines to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin

(If you run into trouble, see the Go install instructions).

Download and Compile IPFS

$ git clone https://github.com/ipfs/go-ipfs.git

$ cd go-ipfs
$ make install

Alternatively, you can run make build to build the go-ipfs binary (storing it in cmd/ipfs/ipfs) without installing it.

NOTE: If you get an error along the lines of "fatal error: stdlib.h: No such file or directory", you're missing a C compiler. Either re-run make with CGO_ENABLED=0 or install GCC.

Cross Compiling

Compiling for a different platform is as simple as running:

make build GOOS=myTargetOS GOARCH=myTargetArchitecture
OpenSSL

To build go-ipfs with OpenSSL support, append GOTAGS=openssl to your make invocation. Building with OpenSSL should significantly reduce the background CPU usage on nodes that frequently make or receive new connections.

Note: OpenSSL requires CGO support and, by default, CGO is disabled when cross compiling. To cross compile with OpenSSL support, you must:

  1. Install a compiler toolchain for the target platform.
  2. Set the CGO_ENABLED=1 environment variable.

Troubleshooting

  • Separate instructions are available for building on Windows.
  • git is required in order for go get to fetch all dependencies.
  • Package managers often contain out-of-date golang packages.
    Ensure that go version reports at least 1.10. See above for how to install go.
  • If you are interested in development, please install the development
    dependencies as well.
  • WARNING: Older versions of OSX FUSE (for Mac OS X) can cause kernel panics when mounting!-
    We strongly recommend you use the latest version of OSX FUSE.
    (See https://github.com/ipfs/go-ipfs/issues/177)
  • For more details on setting up FUSE (so that you can mount the filesystem), see the docs folder.
  • Shell command completion is available in misc/completion/ipfs-completion.bash. Read docs/command-completion.md to learn how to install it.
  • See the init examples for how to connect IPFS to systemd or whatever init system your distro uses.

Updating go-ipfs

Using ipfs-update

IPFS has an updating tool that can be accessed through ipfs update. The tool is
not installed alongside IPFS in order to keep that logic independent of the main
codebase. To install ipfs update, download it here.

Downloading IPFS builds using IPFS

List the available versions of go-ipfs:

$ ipfs cat /ipns/dist.ipfs.io/go-ipfs/versions

Then, to view available builds for a version from the previous command ($VERSION):

$ ipfs ls /ipns/dist.ipfs.io/go-ipfs/$VERSION

To download a given build of a version:

$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_darwin-386.tar.gz # darwin 32-bit build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_darwin-amd64.tar.gz # darwin 64-bit build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_freebsd-amd64.tar.gz # freebsd 64-bit build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_linux-386.tar.gz # linux 32-bit build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_linux-amd64.tar.gz # linux 64-bit build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_linux-arm.tar.gz # linux arm build
$ ipfs get /ipns/dist.ipfs.io/go-ipfs/$VERSION/go-ipfs_$VERSION_windows-amd64.zip # windows 64-bit build

Getting Started

See also: https://docs.ipfs.io/introduction/usage/

To start using IPFS, you must first initialize IPFS's config files on your
system, this is done with ipfs init. See ipfs init --help for information on
the optional arguments it takes. After initialization is complete, you can use
ipfs mount, ipfs add and any of the other commands to explore!

Some things to try

Basic proof of 'ipfs working' locally:

echo "hello world" > hello
ipfs add hello
# This should output a hash string that looks something like:
# QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o
ipfs cat <that hash>

Usage

  ipfs - Global p2p merkle-dag filesystem.

  ipfs [<flags>] <command> [<arg>] ...

SUBCOMMANDS
  BASIC COMMANDS
    init          Initialize ipfs local configuration
    add <path>    Add a file to ipfs
    cat <ref>     Show ipfs object data
    get <ref>     Download ipfs objects
    ls <ref>      List links from an object
    refs <ref>    List hashes of links from an object

  DATA STRUCTURE COMMANDS
    block         Interact with raw blocks in the datastore
    object        Interact with raw dag nodes
    files         Interact with objects as if they were a unix filesystem

  ADVANCED COMMANDS
    daemon        Start a long-running daemon process
    mount         Mount an ipfs read-only mountpoint
    resolve       Resolve any type of name
    name          Publish or resolve IPNS names
    dns           Resolve DNS links
    pin           Pin objects to local storage
    repo          Manipulate an IPFS repository

  NETWORK COMMANDS
    id            Show info about ipfs peers
    bootstrap     Add or remove bootstrap peers
    swarm         Manage connections to the p2p network
    dht           Query the DHT for values or peers
    ping          Measure the latency of a connection
    diag          Print diagnostics

  TOOL COMMANDS
    config        Manage configuration
    version       Show ipfs version information
    update        Download and apply go-ipfs updates
    commands      List all available commands

  Use 'ipfs <command> --help' to learn more about each command.

  ipfs uses a repository in the local file system. By default, the repo is located
  at ~/.ipfs. To change the repo location, set the $IPFS_PATH environment variable:

    export IPFS_PATH=/path/to/ipfsrepo

Running IPFS inside Docker

An IPFS docker image is hosted at hub.docker.com/r/ipfs/go-ipfs.
To make files visible inside the container you need to mount a host directory
with the -v option to docker. Choose a directory that you want to use to
import/export files from IPFS. You should also choose a directory to store
IPFS files that will persist when you restart the container.

export ipfs_staging=</absolute/path/to/somewhere/>
export ipfs_data=</absolute/path/to/somewhere_else/>

Start a container running ipfs and expose ports 4001, 5001 and 8080:

docker run -d --name ipfs_host -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

Watch the ipfs log:

docker logs -f ipfs_host

Wait for ipfs to start. ipfs is running when you see:

Gateway (readonly) server
listening on /ip4/0.0.0.0/tcp/8080

You can now stop watching the log.

Run ipfs commands:

docker exec ipfs_host ipfs <args...>

For example: connect to peers

docker exec ipfs_host ipfs swarm peers

Add files:

cp -r <something> $ipfs_staging
docker exec ipfs_host ipfs add -r /export/<something>

Stop the running container:

docker stop ipfs_host

When starting a container running ipfs for the first time with an empty data directory, it will call ipfs init to initialize configuration files and generate a new keypair. At this time, you can choose which profile to apply using the IPFS_PROFILE environment variable:

docker run -d --name ipfs_host -e IPFS_PROFILE=server -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

It is possible to initialize the container with a swarm key file (/data/ipfs/swarm.key) using the variables IPFS_SWARM_KEY and IPFS_SWARM_KEY_FILE. The IPFS_SWARM_KEY creates swarm.key with the contents of the variable itself, whilst IPFS_SWARM_KEY_FILE copies the key from a path stored in the variable. The IPFS_SWARM_KEY_FILE overwrites the key generated by IPFS_SWARM_KEY.

docker run -d --name ipfs_host -e IPFS_SWARM_KEY=<your swarm key> -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

The swarm key initialization can also be done using docker secrets (requires docker swarm or docker-compose):

cat your_swarm.key, docker secret create swarm_key_secret -
docker run -d --name ipfs_host --secret swarm_key_secret -e IPFS_SWARM_KEY_FILE=/run/secrets/swarm_key_secret -v $ipfs_staging:/export -v $ipfs_data:/data/ipfs -p 4001:4001 -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/go-ipfs:latest

Troubleshooting

If you have previously installed IPFS before and you are running into problems getting a newer version to work, try deleting (or backing up somewhere else) your IPFS config directory (~/.ipfs by default) and rerunning ipfs init. This will reinitialize the config file to its defaults and clear out the local datastore of any bad entries.

Please direct general questions and help requests to our forum or our IRC channel (freenode #ipfs).

If you believe you've found a bug, check the issues list and, if you don't see your problem there, either come talk to us on IRC (freenode #ipfs) or file an issue of your own!

Packages

This table is generated using the module package-table with package-table --data=package-list.json.

Listing of the main packages used in the IPFS ecosystem. There are also three specifications worth linking here:, Name, CI/Travis, Coverage, Description, ---------, ---------, ---------, ---------, Files, go-unixfs, Travis CI, codecov, the core 'filesystem' logic, go-mfs, Travis CI, codecov, a mutable filesystem editor for unixfs, go-ipfs-posinfo, Travis CI, codecov, helper datatypes for the filestore, go-ipfs-chunker, Travis CI, codecov, file chunkers, Exchange, go-ipfs-exchange-interface, Travis CI, codecov, exchange service interface, go-ipfs-exchange-offline, Travis CI, codecov, (dummy) offline implementation of the exchange service, go-bitswap, Travis CI, codecov, bitswap protocol implementation, go-blockservice, Travis CI, codecov, service that plugs a blockstore and an exchange together, Datastores, go-datastore, Travis CI, codecov, datastore interfaces, adapters, and basic implementations, go-ipfs-ds-help, Travis CI, codecov, datastore utility functions, go-ds-flatfs, Travis CI, codecov, a filesystem-based datastore, go-ds-measure, Travis CI, codecov, a metric-collecting database adapter, go-ds-leveldb, Travis CI, codecov, a leveldb based datastore, go-ds-badger, Travis CI, codecov, a badgerdb based datastore, Namesys, go-ipns, Travis CI, codecov, IPNS datastructures and validation logic, Repo, go-ipfs-config, Travis CI, codecov, go-ipfs config file definitions, go-fs-lock, Travis CI, codecov, lockfile management functions, fs-repo-migrations, Travis CI, codecov, repo migrations, Blocks, go-block-format, Travis CI, codecov, block interfaces and implementations, go-ipfs-blockstore, Travis CI, codecov, blockstore interfaces and implementations, Commands, go-ipfs-cmds, Travis CI, codecov, CLI & HTTP commands library, go-ipfs-api, Travis CI, codecov, a shell for the IPFS HTTP API, Metrics & Logging, go-metrics-interface, Travis CI, codecov, metrics collection interfaces, go-metrics-prometheus, Travis CI, codecov, prometheus-backed metrics collector, go-log, Travis CI, codecov, logging framework, Generics/Utils, go-ipfs-routing, Travis CI, codecov, routing (content, peer, value) helpers, go-ipfs-util, Travis CI, codecov, the kitchen sink, go-ipfs-addr, Travis CI, codecov, utility functions for parsing IPFS multiaddrs, For brevity, we've omitted go-libp2p and go-ipld packages. These package tables can be found in their respective project's READMEs:

Development

Some places to get you started on the codebase:

Map of go-ipfs Subsystems

WIP: This is a high-level architecture diagram of the various sub-systems of go-ipfs. To be updated with how they interact. Anyone who has suggestions is welcome to comment here on how we can improve this!

CLI, HTTP-API, Architecture Diagram

Origin

Description: Dotted means "likely going away". The "Legacy" parts are thin wrappers around some commands to translate between the new system and the old system. The grayed-out parts on the "daemon" diagram are there to show that the code is all the same, it's just that we turn some pieces on and some pieces off depending on whether we're running on the client or the server.

Testing

make test

Development Dependencies

If you make changes to the protocol buffers, you will need to install the protoc compiler.

Developer Notes

Find more documentation for developers on docs

Contributing

We ❤️ all our contributors; this project wouldn’t be what it is without you! If you want to help out, please see CONTRIBUTING.md.

This repository falls under the IPFS Code of Conduct.

You can contact us on the freenode #ipfs-dev channel or attend one of our
weekly calls.

License

MIT

To the top