├── assets ├── init-doc │ ├── ping │ ├── docs │ │ └── index │ ├── contact │ ├── help │ ├── readme │ └── security-notes └── README.md ├── core ├── .gitignore ├── coreunix │ ├── test_data │ │ ├── colors │ │ │ └── orange │ │ ├── corps │ │ │ └── apple │ │ └── fruits │ │ │ ├── apple │ │ │ └── orange │ ├── cat.go │ └── metadata.go ├── commands │ ├── diag.go │ ├── mount_windows.go │ ├── dht_test.go │ ├── mount_nofuse.go │ ├── shutdown.go │ ├── e │ │ └── error.go │ ├── helptext_test.go │ └── unixfs │ │ └── unixfs.go ├── corehttp │ ├── redirect.go │ ├── webui.go │ ├── ipns_hostname.go │ ├── logs.go │ └── gateway.go ├── coredag │ ├── cbor.go │ ├── raw.go │ └── dagpb.go ├── pathresolver_test.go ├── bootstrap_test.go └── corerepo │ └── stat.go ├── cmd ├── seccat │ ├── .gitignore │ └── util.go ├── ipfs │ ├── .gitignore │ ├── main_test.go │ ├── ulimit.go │ ├── dist │ │ ├── README.md │ │ ├── install.sh │ │ └── LICENSE │ ├── runmain_test.go │ ├── ulimit_unix.go │ └── ulimit_freebsd.go └── ipfswatch │ ├── README.md │ └── ipfswatch_test.go ├── test ├── 3nodetest │ ├── build │ │ ├── .gitkeep │ │ └── .gitignore │ ├── bin │ │ ├── .gitignore │ │ ├── clean.sh │ │ ├── save_logs.sh │ │ └── save_profiling_data.sh │ ├── data │ │ ├── .gitignore │ │ └── Dockerfile │ ├── bootstrap │ │ ├── README.md │ │ ├── Dockerfile │ │ └── config │ ├── server │ │ ├── README.md │ │ ├── Dockerfile │ │ ├── run.sh │ │ └── config │ ├── README.md │ ├── client │ │ ├── Dockerfile │ │ ├── run.sh │ │ └── config │ ├── fig.yml │ ├── Makefile │ └── run-test-on-img.sh ├── .gitignore ├── dependencies │ ├── go-sleep │ │ ├── .gitignore │ │ ├── go-sleep.go │ │ ├── README.md │ │ └── LICENSE │ ├── go-timeout │ │ ├── .gitignore │ │ ├── LICENSE │ │ └── main.go │ ├── Makefile │ └── ma-pipe-unidir │ │ └── LICENSE ├── sharness │ ├── t0110-gateway-data │ │ ├── foo.block │ │ └── foofoo.block │ ├── t0060-data │ │ └── mss-ls │ ├── t0051-object-data │ │ ├── testPut.pb │ │ ├── testPut.json │ │ ├── testPut.xml │ │ ├── expected_getOut │ │ ├── brokenPut.xml │ │ ├── brokenPut.json │ │ └── UTF-8-test.txt │ ├── .gitignore │ ├── t0053-dag-data │ │ └── non-canon.cbor │ ├── t0280-plugin-git-data │ │ └── git.tar.gz │ ├── Makefile │ ├── lib │ │ ├── test-lib-hashes.sh │ │ ├── random-dep.go │ │ ├── test-aggregate-results.sh │ │ └── iptb-lib.sh │ ├── t0018-indent.sh │ ├── t0025-datastores.sh │ ├── t0410-api-add.sh │ ├── t0070-user-config.sh │ ├── t0024-files │ │ ├── spec-newshardfun │ │ └── spec-nosync │ ├── t0024-datastore-config.sh │ ├── t0235-cli-request.sh │ ├── x0601-pin-fail-test.sh │ ├── t0023-shutdown.sh │ ├── t0088-repo-stat-symlink.sh │ ├── t0063-external.sh │ ├── t0150-clisuggest.sh │ ├── t0231-channel-streaming.sh │ ├── t0400-api-security.sh │ ├── t0151-sysdiag.sh │ ├── t0251-files-flushing.sh │ ├── t0101-iptb-name.sh │ ├── t0210-tar.sh │ ├── t0065-active-requests.sh │ ├── t0500-issues-and-regressions-offline.sh │ ├── t0022-init-default.sh │ ├── t0086-repo-verify.sh │ ├── t0063-daemon-init.sh │ └── t0280-plugin-git.sh ├── Rules.mk ├── bin │ ├── .gitignore │ ├── continueyn │ ├── verify-go-fmt.sh │ ├── checkflags │ └── Rules.mk ├── api-startup │ └── main.go ├── integration │ └── Makefile └── README.md ├── ci ├── jenkins └── Dockerfile.buildenv ├── plugin ├── plugins │ ├── .gitignore │ ├── gen_main.sh │ └── Rules.mk ├── Rules.mk ├── loader │ ├── Rules.mk │ ├── preload_list │ ├── preload.go │ ├── preload.sh │ ├── initializer.go │ └── load.go ├── plugin.go └── ipld.go ├── coverage └── .gitignore ├── .gx └── lastpubver ├── Godeps └── _workspace │ └── src │ └── github.com │ ├── jbenet │ ├── go-random │ │ ├── random │ │ │ ├── .gitignore │ │ │ └── random.go │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── lib.go │ │ └── LICENSE │ ├── go-random-files │ │ ├── random-files │ │ │ └── .gitignore │ │ ├── Makefile │ │ ├── ringreader │ │ │ ├── ringreader_test.go │ │ │ └── ringreader.go │ │ └── LICENSE │ └── go-detect-race │ │ ├── withrace.go │ │ ├── withoutrace.go │ │ ├── race.go │ │ ├── race_test.go │ │ ├── README.md │ │ └── LICENSE │ ├── whyrusleeping │ └── chunker │ │ ├── .travis.yml │ │ ├── README.md │ │ └── LICENSE │ ├── hashicorp │ └── golang-lru │ │ ├── .gitignore │ │ ├── README.md │ │ └── lru_test.go │ ├── mitchellh │ └── go-homedir │ │ ├── README.md │ │ └── LICENSE │ └── texttheater │ └── golang-levenshtein │ └── levenshtein │ └── levenshtein_test.go ├── .dockerignore ├── mk ├── footer.mk ├── header.mk ├── gx.mk └── util.mk ├── unixfs ├── io │ ├── doc.go │ ├── bufdagreader.go │ └── resolve.go ├── pb │ ├── Rules.mk │ └── unixfs.proto └── hamt │ └── util_test.go ├── fuse ├── readonly │ ├── doc.go │ └── mount_unix.go ├── node │ ├── mount_windows.go │ └── mount_nofuse.go └── ipns │ ├── link_unix.go │ ├── writerat.go │ ├── mount_unix.go │ └── common.go ├── repo ├── config │ ├── api.go │ ├── ipns.go │ ├── experiments.go │ ├── mounts.go │ ├── reprovider.go │ ├── discovery.go │ ├── gateway.go │ ├── version.go │ ├── swarm.go │ ├── addresses.go │ ├── identity.go │ └── datastore.go ├── fsrepo │ ├── doc.go │ ├── misc.go │ ├── serialize │ │ └── serialize_test.go │ └── migrations │ │ ├── mfsr_test.go │ │ └── mfsr.go ├── repo.go ├── mock.go └── common │ └── common.go ├── namesys ├── pb │ ├── Rules.mk │ └── namesys.proto ├── proquint.go └── base.go ├── thirdparty ├── math2 │ └── math2.go ├── README.md ├── posinfo │ └── posinfo.go ├── assert │ └── assert.go ├── unit │ ├── unit_test.go │ └── unit.go ├── dir │ └── dir.go ├── datastore2 │ ├── threadsafe.go │ ├── datastore_closer.go │ └── delayed.go └── ds-help │ └── key.go ├── filestore └── pb │ ├── Makefile │ └── dataobj.proto ├── merkledag ├── pb │ ├── Rules.mk │ └── merkledag.proto └── test │ └── utils.go ├── misc └── launchd │ ├── README.md │ ├── io.ipfs.ipfs-daemon.plist │ └── install.sh ├── pin └── internal │ └── pb │ ├── Rules.mk │ ├── doc.go │ └── header.proto ├── exchange ├── bitswap │ ├── message │ │ └── pb │ │ │ ├── Rules.mk │ │ │ ├── Makefile │ │ │ └── message.proto │ ├── testnet │ │ ├── interface.go │ │ └── peernet.go │ ├── decision │ │ └── bench_test.go │ └── stat.go └── interface.go ├── flags ├── flags.go └── flags_test.go ├── Makefile ├── .gitignore ├── codecov.yml ├── docs ├── generate-authors.sh ├── transports.md ├── openbsd.md ├── command-completion.md ├── plugins.md ├── releases.md └── developer-certificate-of-origin ├── .codeclimate.yml ├── bin ├── test-go-fmt ├── mkreleaselog ├── circle.sh ├── check_go_path ├── Rules.mk ├── graphmd ├── ipns-republish ├── gencmdref ├── check_go_version ├── container_daemon ├── check_gx_program └── archive-branches.sh ├── blocks ├── blocksutil │ ├── block_generator_test.go │ └── block_generator.go └── blockstore │ └── caching_test.go ├── .travis.yml ├── blockservice ├── test │ └── mock.go └── blockservice_test.go ├── commands └── channelmarshaler.go ├── doc.go ├── importer └── chunk │ └── rabin.go ├── LICENSE ├── ISSUE_TEMPLATE.md └── circle.yml /assets/init-doc/ping: -------------------------------------------------------------------------------- 1 | ipfs -------------------------------------------------------------------------------- /core/.gitignore: -------------------------------------------------------------------------------- 1 | .testdb 2 | -------------------------------------------------------------------------------- /cmd/seccat/.gitignore: -------------------------------------------------------------------------------- 1 | seccat 2 | -------------------------------------------------------------------------------- /test/3nodetest/build/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /assets/init-doc/docs/index: -------------------------------------------------------------------------------- 1 | Index 2 | -------------------------------------------------------------------------------- /ci/jenkins: -------------------------------------------------------------------------------- 1 | go-ipfs-jenkinsfile 2 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | IPFS-BUILD-OPTIONS 2 | -------------------------------------------------------------------------------- /test/3nodetest/bin/.gitignore: -------------------------------------------------------------------------------- 1 | random 2 | -------------------------------------------------------------------------------- /test/3nodetest/data/.gitignore: -------------------------------------------------------------------------------- 1 | file* 2 | -------------------------------------------------------------------------------- /core/coreunix/test_data/colors/orange: -------------------------------------------------------------------------------- 1 | orange 2 | -------------------------------------------------------------------------------- /core/coreunix/test_data/corps/apple: -------------------------------------------------------------------------------- 1 | apple 2 | -------------------------------------------------------------------------------- /core/coreunix/test_data/fruits/apple: -------------------------------------------------------------------------------- 1 | apple 2 | -------------------------------------------------------------------------------- /core/coreunix/test_data/fruits/orange: -------------------------------------------------------------------------------- 1 | orange 2 | -------------------------------------------------------------------------------- /plugin/plugins/.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | */main 3 | -------------------------------------------------------------------------------- /test/dependencies/go-sleep/.gitignore: -------------------------------------------------------------------------------- 1 | go-sleep 2 | -------------------------------------------------------------------------------- /test/dependencies/go-timeout/.gitignore: -------------------------------------------------------------------------------- 1 | go-timeout 2 | -------------------------------------------------------------------------------- /test/sharness/t0110-gateway-data/foo.block: -------------------------------------------------------------------------------- 1 | 2 | foo -------------------------------------------------------------------------------- /cmd/ipfs/.gitignore: -------------------------------------------------------------------------------- 1 | ipfs 2 | ipfs-test-cover 3 | ipfs.exe 4 | -------------------------------------------------------------------------------- /test/sharness/t0060-data/mss-ls: -------------------------------------------------------------------------------- 1 | /multistream/1.0.0 2 | ls 3 | -------------------------------------------------------------------------------- /coverage/.gitignore: -------------------------------------------------------------------------------- 1 | unitcover 2 | sharnesscover 3 | ipfs 4 | 5 | -------------------------------------------------------------------------------- /.gx/lastpubver: -------------------------------------------------------------------------------- 1 | 0.4.12: QmdKL1GVaUaDVt3JUWiYQSLYRsJMym2KRWxsiXAeEU6pzX 2 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/random/.gitignore: -------------------------------------------------------------------------------- 1 | random 2 | -------------------------------------------------------------------------------- /test/3nodetest/build/.gitignore: -------------------------------------------------------------------------------- 1 | .built_img 2 | *.log 3 | profiling_data* 4 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/testPut.pb: -------------------------------------------------------------------------------- 1 | 2 | test json for sharness test -------------------------------------------------------------------------------- /test/3nodetest/bin/clean.sh: -------------------------------------------------------------------------------- 1 | docker rm -f $( docker ps -q -a -f status=exited ) || true 2 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random-files/random-files/.gitignore: -------------------------------------------------------------------------------- 1 | random-files 2 | -------------------------------------------------------------------------------- /test/sharness/.gitignore: -------------------------------------------------------------------------------- 1 | lib/sharness/ 2 | test-results/ 3 | trash directory.*.sh/ 4 | plugins 5 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/testPut.json: -------------------------------------------------------------------------------- 1 | { 2 | "Data": "test json for sharness test" 3 | } 4 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/testPut.xml: -------------------------------------------------------------------------------- 1 | Test xml for sharness test 2 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/expected_getOut: -------------------------------------------------------------------------------- 1 | {"Links":[],"Data":"\u0008\u0002\u0012\nHello Mars\u0018\n"} 2 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/brokenPut.xml: -------------------------------------------------------------------------------- 1 | This is not a valid dag object fail 2 | -------------------------------------------------------------------------------- /test/3nodetest/bootstrap/README.md: -------------------------------------------------------------------------------- 1 | this is a bootstrap peer with an empty bootstrap list 2 | 3 | it listens on 4011 and 4012 4 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/brokenPut.json: -------------------------------------------------------------------------------- 1 | { 2 | "this": "should", 3 | "return": "an", 4 | "error":"not valid dag object" 5 | } -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | Dockerfile.fast 3 | .git/ 4 | !.git/HEAD 5 | !.git/refs/ 6 | !.git/packed-refs 7 | test/sharness/lib/sharness/ 8 | -------------------------------------------------------------------------------- /mk/footer.mk: -------------------------------------------------------------------------------- 1 | # standard NR-make boilerplate, to be included at the end of a file 2 | d := $(dirstack_$(sp)) 3 | sp := $(basename $(sp)) 4 | -------------------------------------------------------------------------------- /test/3nodetest/data/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | ADD filetiny /data/filetiny 4 | ADD filerand /data/filerand 5 | 6 | VOLUME ["/data"] 7 | -------------------------------------------------------------------------------- /test/sharness/t0053-dag-data/non-canon.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iosifpeterfi/go-ipfs/HEAD/test/sharness/t0053-dag-data/non-canon.cbor -------------------------------------------------------------------------------- /unixfs/io/doc.go: -------------------------------------------------------------------------------- 1 | // package unixfs/io implements convenience objects for working with the ipfs 2 | // unixfs data format. 3 | package io 4 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/withrace.go: -------------------------------------------------------------------------------- 1 | // +build race 2 | 3 | package detectrace 4 | 5 | const withRace = true 6 | -------------------------------------------------------------------------------- /fuse/readonly/doc.go: -------------------------------------------------------------------------------- 1 | // package fuse/readonly implements a fuse filesystem to access files 2 | // stored inside of ipfs. 3 | package readonly 4 | -------------------------------------------------------------------------------- /repo/config/api.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type API struct { 4 | HTTPHeaders map[string][]string // HTTP headers to return with the API. 5 | } 6 | -------------------------------------------------------------------------------- /test/sharness/t0051-object-data/UTF-8-test.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iosifpeterfi/go-ipfs/HEAD/test/sharness/t0051-object-data/UTF-8-test.txt -------------------------------------------------------------------------------- /test/sharness/t0110-gateway-data/foofoo.block: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iosifpeterfi/go-ipfs/HEAD/test/sharness/t0110-gateway-data/foofoo.block -------------------------------------------------------------------------------- /test/sharness/t0280-plugin-git-data/git.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iosifpeterfi/go-ipfs/HEAD/test/sharness/t0280-plugin-git-data/git.tar.gz -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/withoutrace.go: -------------------------------------------------------------------------------- 1 | // +build !race 2 | 3 | package detectrace 4 | 5 | const withRace = false 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random-files/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | cd random-files && go build 3 | 4 | install: 5 | cd random-files && go install 6 | -------------------------------------------------------------------------------- /repo/config/ipns.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type Ipns struct { 4 | RepublishPeriod string 5 | RecordLifetime string 6 | 7 | ResolveCacheSize int 8 | } 9 | -------------------------------------------------------------------------------- /mk/header.mk: -------------------------------------------------------------------------------- 1 | # keep track of dirs 2 | # standard NR-make boilerplate, to be included at the beginning of a file 3 | p := $(sp).x 4 | dirstack_$(sp) := $(d) 5 | d := $(dir) 6 | -------------------------------------------------------------------------------- /repo/config/experiments.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type Experiments struct { 4 | FilestoreEnabled bool 5 | ShardingEnabled bool 6 | Libp2pStreamMounting bool 7 | } 8 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/whyrusleeping/chunker/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | 4 | go: 5 | - 1.3.3 6 | - 1.4.2 7 | 8 | os: 9 | - linux 10 | - osx 11 | -------------------------------------------------------------------------------- /namesys/pb/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | PB_$(d) = $(wildcard $(d)/*.proto) 4 | TGTS_$(d) = $(PB_$(d):.proto=.pb.go) 5 | 6 | #DEPS_GO += $(TGTS_$(d)) 7 | 8 | include mk/footer.mk 9 | -------------------------------------------------------------------------------- /plugin/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | dir := $(d)/loader 4 | include $(dir)/Rules.mk 5 | 6 | dir := $(d)/plugins 7 | include $(dir)/Rules.mk 8 | 9 | include mk/footer.mk 10 | -------------------------------------------------------------------------------- /test/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | dir := $(d)/bin 4 | include $(dir)/Rules.mk 5 | 6 | dir := $(d)/sharness 7 | include $(dir)/Rules.mk 8 | 9 | include mk/footer.mk 10 | -------------------------------------------------------------------------------- /thirdparty/math2/math2.go: -------------------------------------------------------------------------------- 1 | package math2 2 | 3 | // IntMin returns the smaller of x or y. 4 | func IntMin(x, y int) int { 5 | if x < y { 6 | return x 7 | } 8 | return y 9 | } 10 | -------------------------------------------------------------------------------- /unixfs/pb/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | PB_$(d) = $(wildcard $(d)/*.proto) 4 | TGTS_$(d) = $(PB_$(d):.proto=.pb.go) 5 | 6 | #DEPS_GO += $(TGTS_$(d)) 7 | 8 | include mk/footer.mk 9 | -------------------------------------------------------------------------------- /cmd/ipfswatch/README.md: -------------------------------------------------------------------------------- 1 | IPFSWatch monitors a directory and adds changes to IPFS 2 | 3 | ``` 4 | λ. ipfswatch --help 5 | -path=".": the path to watch 6 | -repo="": IPFS_PATH to use 7 | ``` 8 | -------------------------------------------------------------------------------- /filestore/pb/Makefile: -------------------------------------------------------------------------------- 1 | PB = $(wildcard *.proto) 2 | GO = $(PB:.proto=.pb.go) 3 | 4 | all: $(GO) 5 | 6 | %.pb.go: %.proto 7 | protoc --gogo_out=. $< 8 | 9 | clean: 10 | rm *.pb.go 11 | -------------------------------------------------------------------------------- /merkledag/pb/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | PB_$(d) = $(wildcard $(d)/*.proto) 4 | TGTS_$(d) = $(PB_$(d):.proto=.pb.go) 5 | 6 | #DEPS_GO += $(TGTS_$(d)) 7 | 8 | include mk/footer.mk 9 | -------------------------------------------------------------------------------- /misc/launchd/README.md: -------------------------------------------------------------------------------- 1 | # ipfs launchd agent 2 | 3 | A bare-bones launchd agent file for ipfs. To have launchd automatically run the ipfs daemon for you, run `./misc/launchd/install.sh` 4 | 5 | -------------------------------------------------------------------------------- /pin/internal/pb/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | PB_$(d) = $(wildcard $(d)/*.proto) 4 | TGTS_$(d) = $(PB_$(d):.proto=.pb.go) 5 | 6 | #DEPS_GO += $(TGTS_$(d)) 7 | 8 | include mk/footer.mk 9 | -------------------------------------------------------------------------------- /repo/config/mounts.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // Mounts stores the (string) mount points 4 | type Mounts struct { 5 | IPFS string 6 | IPNS string 7 | FuseAllowOther bool 8 | } 9 | -------------------------------------------------------------------------------- /filestore/pb/dataobj.proto: -------------------------------------------------------------------------------- 1 | package datastore.pb; 2 | 3 | message DataObj { 4 | optional string FilePath = 1; 5 | optional uint64 Offset = 2; 6 | optional uint64 Size = 3; 7 | } 8 | -------------------------------------------------------------------------------- /exchange/bitswap/message/pb/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | PB_$(d) = $(wildcard $(d)/*.proto) 4 | TGTS_$(d) = $(PB_$(d):.proto=.pb.go) 5 | 6 | #DEPS_GO += $(TGTS_$(d)) 7 | 8 | include mk/footer.mk 9 | -------------------------------------------------------------------------------- /flags/flags.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "os" 5 | ) 6 | 7 | var LowMemMode bool 8 | 9 | func init() { 10 | if os.Getenv("IPFS_LOW_MEM") != "" { 11 | LowMemMode = true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /repo/config/reprovider.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type Reprovider struct { 4 | Interval string // Time period to reprovide locally stored objects to the network 5 | Strategy string // Which keys to announce 6 | } 7 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/race.go: -------------------------------------------------------------------------------- 1 | package detectrace 2 | 3 | // WithRace returns whether the binary was compiled 4 | // with the race flag on. 5 | func WithRace() bool { 6 | return withRace 7 | } 8 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/race_test.go: -------------------------------------------------------------------------------- 1 | package detectrace 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestWithRace(t *testing.T) { 8 | t.Logf("WithRace() is %v\n", WithRace()) 9 | } 10 | -------------------------------------------------------------------------------- /assets/init-doc/contact: -------------------------------------------------------------------------------- 1 | Come hang out in our IRC chat room if you have any questions. 2 | 3 | Contact the ipfs dev team: 4 | - Bugs: https://github.com/ipfs/go-ipfs/issues 5 | - Help: irc.freenode.org/#ipfs 6 | - Email: dev@ipfs.io 7 | -------------------------------------------------------------------------------- /repo/config/discovery.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type Discovery struct { 4 | MDNS MDNS 5 | } 6 | 7 | type MDNS struct { 8 | Enabled bool 9 | 10 | // Time in seconds between discovery rounds 11 | Interval int 12 | } 13 | -------------------------------------------------------------------------------- /test/3nodetest/server/README.md: -------------------------------------------------------------------------------- 1 | **requirements** 2 | 3 | * docker container with bootstrap node linked as "bootstrap" with ID QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE 4 | * file in data volume, internally mapped to /data/file 5 | -------------------------------------------------------------------------------- /mk/gx.mk: -------------------------------------------------------------------------------- 1 | gx-path = gx/ipfs/$(shell gx deps find $(1))/$(1) 2 | 3 | gx-deps: 4 | gx install --global 5 | .PHONY: gx-deps 6 | 7 | ifneq ($(IPFS_GX_USE_GLOBAL),1) 8 | gx-deps: bin/gx bin/gx-go 9 | endif 10 | 11 | DEPS_GO += gx-deps 12 | -------------------------------------------------------------------------------- /test/3nodetest/README.md: -------------------------------------------------------------------------------- 1 | this is an ipfs integration test 2 | 3 | **requirements** 4 | 5 | * Docker 6 | * fig 7 | * Go 8 | 9 | * ipfs image named "zaqwsx_ipfs-test-img" 10 | 11 | ``` 12 | make setup 13 | fig build 14 | fig up 15 | ``` 16 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.3 5 | - release 6 | - tip 7 | 8 | script: 9 | - go test -race -cpu=5 -v ./... 10 | - cd random && go build 11 | 12 | env: TEST_VERBOSE=1 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # General tools 2 | 3 | SHELL=PATH='$(PATH)' /bin/sh 4 | 5 | PROTOC = protoc --gogo_out=. --proto_path=.:/usr/local/opt/protobuf/include:$(dir $@) $< 6 | 7 | # enable second expansion 8 | .SECONDEXPANSION: 9 | 10 | include Rules.mk 11 | -------------------------------------------------------------------------------- /test/sharness/Makefile: -------------------------------------------------------------------------------- 1 | # default target is to run all tests 2 | all: aggregate 3 | 4 | SH := $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) 5 | 6 | .DEFAULT $(SH): ALWAYS 7 | $(MAKE) -C ../.. test/sharness/$@ 8 | 9 | ALWAYS: 10 | .PHONY: ALWAYS 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ipfs can generate profiling dump files 2 | *.cpuprof 3 | *.memprof 4 | 5 | *.swp 6 | .ipfsconfig 7 | *.out 8 | *.coverprofile 9 | *.test 10 | *.orig 11 | *~ 12 | 13 | coverage.txt 14 | 15 | .ipfs 16 | bin/gx 17 | bin/gx* 18 | bin/tmp 19 | -------------------------------------------------------------------------------- /exchange/bitswap/message/pb/Makefile: -------------------------------------------------------------------------------- 1 | # TODO(brian): add proto tasks 2 | all: message.pb.go 3 | 4 | message.pb.go: message.proto 5 | protoc --gogo_out=. --proto_path=../../../../../:/usr/local/opt/protobuf/include:. $< 6 | 7 | clean: 8 | rm message.pb.go 9 | -------------------------------------------------------------------------------- /pin/internal/pb/doc.go: -------------------------------------------------------------------------------- 1 | package pb 2 | 3 | //go:generate protoc --gogo_out=. header.proto 4 | 5 | // kludge to get vendoring right in protobuf output 6 | //go:generate sed -i s,github.com/,github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/,g header.pb.go 7 | -------------------------------------------------------------------------------- /plugin/loader/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | $(d)/preload.go: d:=$(d) 4 | $(d)/preload.go: $(d)/preload_list $(d)/preload.sh 5 | $(d)/preload.sh > $@ 6 | go fmt $@ >/dev/null 7 | 8 | DEPS_GO += $(d)/preload.go 9 | 10 | include mk/footer.mk 11 | -------------------------------------------------------------------------------- /plugin/loader/preload_list: -------------------------------------------------------------------------------- 1 | # this file contains plugins to be preloaded 2 | # empty lines or starting with '#' are ignored 3 | # 4 | # name go-path number of the sub-plugin 5 | 6 | #ipldgit github.com/ipfs/go-ipfs/plugin/plugins/git 0 7 | -------------------------------------------------------------------------------- /test/bin/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory by default 2 | /** 3 | 4 | # Do not ignore this file itself 5 | !.gitignore 6 | 7 | # Do not ignore the following special scripts 8 | !checkflags 9 | !continueyn 10 | !verify-go-fmt.sh 11 | !Rules.mk 12 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | ci: 3 | - "ci/circle-ci" 4 | - "!travis-ci.org" 5 | - "!ci.ipfs.team:8111" 6 | - "!ci.ipfs.team" 7 | notify: 8 | require_ci_to_pass: no 9 | after_n_builds: 2 10 | coverage: 11 | range: "50...100" 12 | comment: off 13 | -------------------------------------------------------------------------------- /test/3nodetest/bootstrap/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zaqwsx_ipfs-test-img 2 | 3 | RUN ipfs init -b=1024 4 | ADD . /tmp/id 5 | RUN mv -f /tmp/id/config /root/.ipfs/config 6 | RUN ipfs id 7 | 8 | ENV IPFS_PROF true 9 | ENV IPFS_LOGGING_FMT nocolor 10 | 11 | EXPOSE 4011 4012/udp 12 | -------------------------------------------------------------------------------- /fuse/node/mount_windows.go: -------------------------------------------------------------------------------- 1 | package node 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/core" 5 | ) 6 | 7 | func Mount(node *core.IpfsNode, fsdir, nsdir string) error { 8 | // TODO 9 | // currently a no-op, but we don't want to return an error 10 | return nil 11 | } 12 | -------------------------------------------------------------------------------- /thirdparty/README.md: -------------------------------------------------------------------------------- 1 | thirdparty consists of Golang packages that contain no go-ipfs dependencies and 2 | may be vendored ipfs/go-ipfs at a later date. 3 | 4 | packages in under this directory _must not_ import packages under 5 | `ipfs/go-ipfs` that are not also under `thirdparty`. 6 | -------------------------------------------------------------------------------- /repo/config/gateway.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // Gateway contains options for the HTTP gateway server. 4 | type Gateway struct { 5 | HTTPHeaders map[string][]string // HTTP headers to return with the gateway 6 | RootRedirect string 7 | Writable bool 8 | PathPrefixes []string 9 | } 10 | -------------------------------------------------------------------------------- /test/bin/continueyn: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Author: Juan Batiz-Benet 3 | # MIT LICENSED 4 | 5 | # if not a terminal, exit 0 (yes!) 6 | test -t 1 || exit 0 7 | 8 | read -p "continue? [y/N] " REPLY 9 | echo 10 | case "$REPLY" in 11 | [Yy]*) exit 0 ;; 12 | *) exit 1 ;; 13 | esac 14 | -------------------------------------------------------------------------------- /test/sharness/lib/test-lib-hashes.sh: -------------------------------------------------------------------------------- 1 | # this file defines several useful hashes used across the test codebase. 2 | # thus they can be defined + changed in one place 3 | 4 | HASH_WELCOME_DOCS="QmS4ustL54uo8FzR9455qaxZwuMiUhyvMcX9Ba8nUH4uVv" 5 | HASH_EMPTY_DIR="QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" 6 | -------------------------------------------------------------------------------- /assets/README.md: -------------------------------------------------------------------------------- 1 | # Assets loaded in with IPFS 2 | 3 | ## Generating docs 4 | 5 | Do not edit the .go files directly. 6 | 7 | Instead, edit the source files and use `go generate` from within the 8 | assets directory: 9 | 10 | ``` 11 | go get -u github.com/jteeuwen/go-bindata/... 12 | go generate 13 | ``` 14 | -------------------------------------------------------------------------------- /plugin/loader/preload.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/plugin" 5 | ) 6 | 7 | // DO NOT EDIT THIS FILE 8 | // This file is being generated as part of plugin build process 9 | // To change it, modify the plugin/loader/preload.sh 10 | 11 | var preloadPlugins = []plugin.Plugin{} 12 | -------------------------------------------------------------------------------- /fuse/node/mount_nofuse.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd netbsd openbsd 2 | // +build nofuse 3 | 4 | package node 5 | 6 | import ( 7 | "errors" 8 | 9 | core "github.com/ipfs/go-ipfs/core" 10 | ) 11 | 12 | func Mount(node *core.IpfsNode, fsdir, nsdir string) error { 13 | return errors.New("not compiled in") 14 | } 15 | -------------------------------------------------------------------------------- /test/3nodetest/client/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zaqwsx_ipfs-test-img 2 | 3 | RUN ipfs init -b=1024 4 | ADD . /tmp/id 5 | RUN mv -f /tmp/id/config /root/.ipfs/config 6 | RUN ipfs id 7 | 8 | EXPOSE 4031 4032/udp 9 | 10 | ENV IPFS_PROF true 11 | ENV IPFS_LOGGING_FMT nocolor 12 | 13 | ENTRYPOINT ["/bin/bash"] 14 | CMD ["/tmp/id/run.sh"] 15 | -------------------------------------------------------------------------------- /test/dependencies/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: restore 3 | 4 | restore: 5 | @echo "*** $@ ***" 6 | which godep 7 | mkdir -p tmp_gopath 8 | OLD_GOPATH="$$GOPATH" 9 | export GOPATH=$$(pwd)/tmp_gopath 10 | cd ../.. 11 | godep restore 12 | cd - 13 | rm -rf tmp_gopath 14 | export GOPATH="$$OLD_GOPATH" 15 | 16 | .PHONY: all restore 17 | -------------------------------------------------------------------------------- /test/sharness/t0018-indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Test sharness test indent" 4 | 5 | . lib/test-lib.sh 6 | 7 | for file in $(find .. -name 't*.sh' -type f); do 8 | test_expect_success "indent in $file is not using tabs" ' 9 | test_must_fail grep -P "^ *\t" $file 10 | ' 11 | done 12 | 13 | test_done 14 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/whyrusleeping/chunker/README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/restic/chunker.svg?branch=master)](https://travis-ci.org/restic/chunker) 2 | 3 | Content Defined Chunking (CDC) based on a rolling Rabin Checksum. 4 | 5 | Part of https://github.com/restic/restic. 6 | 7 | Better README will follow soon. 8 | -------------------------------------------------------------------------------- /assets/init-doc/help: -------------------------------------------------------------------------------- 1 | Some helpful resources for finding your way around ipfs: 2 | 3 | - quick-start: a quick show of various ipfs features. 4 | - ipfs commands: a list of all commands 5 | - ipfs --help: every command describes itself 6 | - https://github.com/ipfs/go-ipfs -- the src repository 7 | - #ipfs on irc.freenode.org -- the community irc channel 8 | -------------------------------------------------------------------------------- /cmd/ipfs/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | 6 | "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 7 | ) 8 | 9 | func TestIsCientErr(t *testing.T) { 10 | t.Log("Only catch pointers") 11 | if !isClientError(&cmdkit.Error{Code: cmdkit.ErrClient}) { 12 | t.Errorf("misidentified error") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /repo/config/version.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // CurrentCommit is the current git commit, this is set as a ldflag in the Makefile 4 | var CurrentCommit string 5 | 6 | // CurrentVersionNumber is the current application's version literal 7 | const CurrentVersionNumber = "0.4.14-dev" 8 | 9 | const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/" 10 | -------------------------------------------------------------------------------- /test/3nodetest/server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zaqwsx_ipfs-test-img 2 | 3 | RUN ipfs init -b=1024 4 | ADD . /tmp/test 5 | RUN mv -f /tmp/test/config /root/.ipfs/config 6 | RUN ipfs id 7 | RUN chmod +x /tmp/test/run.sh 8 | 9 | EXPOSE 4021 4022/udp 10 | 11 | ENV IPFS_PROF true 12 | ENV IPFS_LOGGING_FMT nocolor 13 | 14 | ENTRYPOINT ["/bin/bash"] 15 | CMD ["/tmp/test/run.sh"] 16 | -------------------------------------------------------------------------------- /thirdparty/posinfo/posinfo.go: -------------------------------------------------------------------------------- 1 | package posinfo 2 | 3 | import ( 4 | "os" 5 | 6 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 7 | ) 8 | 9 | type PosInfo struct { 10 | Offset uint64 11 | FullPath string 12 | Stat os.FileInfo // can be nil 13 | } 14 | 15 | type FilestoreNode struct { 16 | node.Node 17 | PosInfo *PosInfo 18 | } 19 | -------------------------------------------------------------------------------- /cmd/ipfs/ulimit.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "strconv" 6 | ) 7 | 8 | var ipfsFileDescNum = uint64(2048) 9 | 10 | func init() { 11 | if val := os.Getenv("IPFS_FD_MAX"); val != "" { 12 | n, err := strconv.Atoi(val) 13 | if err != nil { 14 | log.Errorf("bad value for IPFS_FD_MAX: %s", err) 15 | } else { 16 | ipfsFileDescNum = uint64(n) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /docs/generate-authors.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # see also ".mailmap" for how email addresses and names are deduplicated 5 | 6 | 7 | cat >AUTHORS <<-'EOF' 8 | # This file lists all individuals having contributed content to the repository. 9 | # For how it is generated, see `docs/generate-authors.sh`. 10 | 11 | EOF 12 | git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf >>AUTHORS 13 | -------------------------------------------------------------------------------- /test/sharness/t0025-datastores.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Test non-standard datastores" 4 | 5 | . lib/test-lib.sh 6 | 7 | test_expect_success "'ipfs init --profile=badgerds' succeeds" ' 8 | BITS="1024" && 9 | ipfs init --bits="$BITS" --profile=badgerds 10 | ' 11 | 12 | test_expect_success "'ipfs pin ls' works" ' 13 | ipfs pin ls | wc -l | grep 9 14 | ' 15 | 16 | test_done 17 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | ratings: 2 | paths: 3 | - "**/*.go" 4 | 5 | exclude_paths: 6 | - test/ 7 | - Godeps/ 8 | - thirdparty/ 9 | - "**/*.pb.go" 10 | 11 | engines: 12 | fixme: 13 | enabled: true 14 | config: 15 | strings: 16 | - FIXME 17 | - HACK 18 | - XXX 19 | - BUG 20 | golint: 21 | enabled: true 22 | govet: 23 | enabled: true 24 | gofmt: 25 | enabled: true 26 | -------------------------------------------------------------------------------- /exchange/bitswap/testnet/interface.go: -------------------------------------------------------------------------------- 1 | package bitswap 2 | 3 | import ( 4 | bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" 5 | "gx/ipfs/QmQgLZP9haZheimMHqqAjJh2LhRmNfEoZDfbtkpeMhi9xK/go-testutil" 6 | peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" 7 | ) 8 | 9 | type Network interface { 10 | Adapter(testutil.Identity) bsnet.BitSwapNetwork 11 | 12 | HasPeer(peer.ID) bool 13 | } 14 | -------------------------------------------------------------------------------- /namesys/pb/namesys.proto: -------------------------------------------------------------------------------- 1 | package namesys.pb; 2 | 3 | message IpnsEntry { 4 | enum ValidityType { 5 | // setting an EOL says "this record is valid until..." 6 | EOL = 0; 7 | } 8 | required bytes value = 1; 9 | required bytes signature = 2; 10 | 11 | optional ValidityType validityType = 3; 12 | optional bytes validity = 4; 13 | 14 | optional uint64 sequence = 5; 15 | 16 | optional uint64 ttl = 6; 17 | } 18 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/golang-lru/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /plugin/plugin.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | // Plugin is base interface for all kinds of go-ipfs plugins 4 | // It will be included in interfaces of different Plugins 5 | type Plugin interface { 6 | // Name should return uniqe name of the plugin 7 | Name() string 8 | // Version returns current version of the plugin 9 | Version() string 10 | // Init is called once when the Plugin is being loaded 11 | Init() error 12 | } 13 | -------------------------------------------------------------------------------- /bin/test-go-fmt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | T="$(mktemp)" 4 | find . -name '*.go' | xargs gofmt -l > "$T" 5 | 6 | if [ -n "$(cat $T)" ]; then 7 | echo "Following Go code is not formatted." 8 | echo "-----------------------------------" 9 | cat "$T" 10 | echo "-----------------------------------" 11 | echo "Run 'go fmt ./...' in your source directory" 12 | rm -f "$T" 13 | exit 1 14 | fi 15 | rm -f "$T" 16 | -------------------------------------------------------------------------------- /pin/internal/pb/header.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package ipfs.pin; 4 | 5 | option go_package = "pb"; 6 | 7 | message Set { 8 | // 1 for now, library will refuse to handle entries with an unrecognized version. 9 | optional uint32 version = 1; 10 | // how many of the links are subtrees 11 | optional uint32 fanout = 2; 12 | // hash seed for subtree selection, a random number 13 | optional fixed32 seed = 3; 14 | } 15 | -------------------------------------------------------------------------------- /core/commands/diag.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | cmds "github.com/ipfs/go-ipfs/commands" 5 | 6 | "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 7 | ) 8 | 9 | var DiagCmd = &cmds.Command{ 10 | Helptext: cmdkit.HelpText{ 11 | Tagline: "Generate diagnostic reports.", 12 | }, 13 | 14 | Subcommands: map[string]*cmds.Command{ 15 | "sys": sysDiagCmd, 16 | "cmds": ActiveReqsCmd, 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /blocks/blocksutil/block_generator_test.go: -------------------------------------------------------------------------------- 1 | package blocksutil 2 | 3 | import "testing" 4 | 5 | func TestBlocksAreDifferent(t *testing.T) { 6 | gen := NewBlockGenerator() 7 | 8 | blocks := gen.Blocks(100) 9 | 10 | for i, block1 := range blocks { 11 | for j, block2 := range blocks { 12 | if i != j { 13 | if block1.String() == block2.String() { 14 | t.Error("Found duplicate blocks") 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/3nodetest/bin/save_logs.sh: -------------------------------------------------------------------------------- 1 | # STRIP strips color from terminal output 2 | STRIP="perl -pe 's/\e\[?.*?[\@-~]//g'" 3 | 4 | # TODO use a for loop like a grownup 5 | docker logs 3nodetest_bootstrap_1 2>&1 | eval $STRIP > ./build/bootstrap.log 6 | docker logs 3nodetest_client_1 2>&1 | eval $STRIP > ./build/client.log 7 | docker logs 3nodetest_data_1 2>&1 | eval $STRIP > ./build/data.log 8 | docker logs 3nodetest_server_1 2>&1 | eval $STRIP > ./build/server.log 9 | -------------------------------------------------------------------------------- /cmd/ipfswatch/ipfswatch_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/ipfs/go-ipfs/thirdparty/assert" 7 | ) 8 | 9 | func TestIsHidden(t *testing.T) { 10 | assert.True(IsHidden("bar/.git"), t, "dirs beginning with . should be recognized as hidden") 11 | assert.False(IsHidden("."), t, ". for current dir should not be considered hidden") 12 | assert.False(IsHidden("bar/baz"), t, "normal dirs should not be hidden") 13 | } 14 | -------------------------------------------------------------------------------- /test/bin/verify-go-fmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #TODO add go lint and go vet 4 | 5 | verify_gofmt() { 6 | GOFMT="gofmt -s" 7 | cd "$(git rev-parse --show-toplevel)" 8 | bad_files=$($GOFMT -l . | grep -v Godeps) 9 | cd - 10 | if [[ -n $bad_files ]]; then 11 | echo "You have to run '$GOFMT' on these files:" 12 | echo "$bad_files" 13 | false 14 | else 15 | true 16 | fi 17 | } 18 | 19 | verify_gofmt 20 | -------------------------------------------------------------------------------- /test/sharness/lib/random-dep.go: -------------------------------------------------------------------------------- 1 | // package randomdep is here to introduce a dependency in random for godep to 2 | // function properly. this way we can keep go-random vendored and not 3 | // accidentally break our tests when we change it. 4 | package randomdep 5 | 6 | import ( 7 | _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random" 8 | _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random-files" 9 | ) 10 | -------------------------------------------------------------------------------- /flags/flags_test.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | ) 7 | 8 | // This variable is initialized before flags init(), so we export the ENV variable here. 9 | var _lowMemOn = lowMemOn() 10 | 11 | func lowMemOn() error { 12 | os.Setenv("IPFS_LOW_MEM", "true") 13 | return nil 14 | } 15 | 16 | func TestLowMemMode(t *testing.T) { 17 | if !LowMemMode { 18 | t.Fatal("LowMemMode does not turn on even with 'IPFS_LOW_MEM' ENV variable set.") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /plugin/ipld.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/core/coredag" 5 | 6 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 7 | ) 8 | 9 | // PluginIPLD is an interface that can be implemented to add handlers for 10 | // for different IPLD formats 11 | type PluginIPLD interface { 12 | Plugin 13 | 14 | RegisterBlockDecoders(dec node.BlockDecoder) error 15 | RegisterInputEncParsers(iec coredag.InputEncParsers) error 16 | } 17 | -------------------------------------------------------------------------------- /repo/config/swarm.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | type SwarmConfig struct { 4 | AddrFilters []string 5 | DisableBandwidthMetrics bool 6 | DisableNatPortMap bool 7 | DisableRelay bool 8 | EnableRelayHop bool 9 | 10 | ConnMgr ConnMgr 11 | } 12 | 13 | // ConnMgr defines configuration options for the libp2p connection manager 14 | type ConnMgr struct { 15 | Type string 16 | LowWater int 17 | HighWater int 18 | GracePeriod string 19 | } 20 | -------------------------------------------------------------------------------- /bin/mkreleaselog: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LAST_TAG=$(git tag -l | sort -V | grep -v -- '-rc' | grep 'v'| tail -n1) 4 | 5 | git log --oneline --merges --reverse $LAST_TAG...master | 6 | while read MERGE 7 | do 8 | commit=$(echo $MERGE | awk '{ print $1 }') 9 | prnum=$(echo $MERGE | awk '{ print $5 }' | tr -d '#') 10 | desc=$(git show $commit | sed '8q;d' | sed 's/^ //g') 11 | printf " - %s ([ipfs/go-ipfs#%s](https://github.com/ipfs/go-ipfs/pull/%s))\n" "$desc" "$prnum" "$prnum" 12 | done 13 | -------------------------------------------------------------------------------- /repo/config/addresses.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | // Addresses stores the (string) multiaddr addresses for the node. 4 | type Addresses struct { 5 | Swarm []string // addresses for the swarm to listen on 6 | Announce []string // swarm addresses to announce to the network 7 | NoAnnounce []string // swarm addresses not to announce to the network 8 | API string // address for the local API (RPC) 9 | Gateway string // address to listen on for IPFS HTTP object gateway 10 | } 11 | -------------------------------------------------------------------------------- /unixfs/pb/unixfs.proto: -------------------------------------------------------------------------------- 1 | package unixfs.pb; 2 | 3 | message Data { 4 | enum DataType { 5 | Raw = 0; 6 | Directory = 1; 7 | File = 2; 8 | Metadata = 3; 9 | Symlink = 4; 10 | HAMTShard = 5; 11 | } 12 | 13 | required DataType Type = 1; 14 | optional bytes Data = 2; 15 | optional uint64 filesize = 3; 16 | repeated uint64 blocksizes = 4; 17 | 18 | optional uint64 hashType = 5; 19 | optional uint64 fanout = 6; 20 | } 21 | 22 | message Metadata { 23 | optional string MimeType = 1; 24 | } 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # dist: trusty # KVM Setup 2 | 3 | notifications: 4 | email: false 5 | 6 | os: 7 | - linux 8 | - osx 9 | 10 | language: go 11 | 12 | go: 13 | - 1.8 14 | 15 | env: 16 | - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_go_expensive 17 | - TEST_NO_FUSE=1 TEST_VERBOSE=1 TEST_SUITE=test_sharness_expensive 18 | 19 | install: 20 | - make install 21 | 22 | script: 23 | - make $TEST_SUITE 24 | 25 | # For docker containers 26 | 27 | sudo: required 28 | 29 | services: 30 | - docker 31 | -------------------------------------------------------------------------------- /bin/circle.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # the CircleCI build line got a bit out of hands 3 | # thus we have sparate file for it 4 | 5 | curl -s https://codecov.io/bash > codecov 6 | 7 | case $CIRCLE_NODE_INDEX in 8 | 0) make -j 1 coverage/unit_tests.coverprofile && 9 | bash codecov -cF unittests -X search -f coverage/unit_tests.coverprofile 10 | ;; 11 | 1) make -j 1 coverage/sharness_tests.coverprofile && 12 | bash codecov -cF sharness -X search -f coverage/sharness_tests.coverprofile 13 | ;; 14 | esac 15 | -------------------------------------------------------------------------------- /docs/transports.md: -------------------------------------------------------------------------------- 1 | ## /ws and /wss -- websockets 2 | 3 | If you want browsers to connect to e.g. `/dns4/example.com/tcp/443/wss/ipfs/QmFoo` 4 | 5 | - [ ] An SSL cert matching the `/dns4` or `/dns6` name 6 | - [ ] go-ipfs listening on `/ip4/127.0.0.1/tcp/8081/ws` 7 | - 8081 is just an example 8 | - note that it's `/ws` here, not `/wss` -- go-ipfs can't currently do SSL, see the next point 9 | - [ ] nginx 10 | - configured with the SSL cert 11 | - listening on port 443 12 | - forwarding to 127.0.0.1:8081 13 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random-files/ringreader/ringreader_test.go: -------------------------------------------------------------------------------- 1 | package ringreader 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestRingReader(t *testing.T) { 8 | r, _ := NewReader(256) 9 | t.Log("buffer:", r.Buf) 10 | 11 | for i := 1; i < 1048576; i = i * 2 { 12 | buf := make([]byte, i) 13 | n, err := r.Read(buf) 14 | if err != nil { 15 | t.Error(err) 16 | } 17 | if n != len(buf) { 18 | t.Error("did not read %d bytes", n) 19 | } 20 | t.Log("read:", buf) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/sharness/lib/test-aggregate-results.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Script to aggregate results using Sharness 4 | # 5 | # Copyright (c) 2014 Christian Couder 6 | # MIT Licensed; see the LICENSE file in this repository. 7 | # 8 | 9 | SHARNESS_AGGREGATE="lib/sharness/aggregate-results.sh" 10 | 11 | test -f "$SHARNESS_AGGREGATE" || { 12 | echo >&2 "Cannot find: $SHARNESS_AGGREGATE" 13 | echo >&2 "Please check Sharness installation." 14 | exit 1 15 | } 16 | 17 | ls test-results/t*-*.sh.*.counts | "$SHARNESS_AGGREGATE" 18 | -------------------------------------------------------------------------------- /mk/util.mk: -------------------------------------------------------------------------------- 1 | # util functions 2 | OS ?= $(shell sh -c 'uname -s 2>/dev/null || echo not') 3 | ifeq ($(OS),Windows_NT) 4 | WINDOWS :=1 5 | ?exe :=.exe # windows compat 6 | PATH_SEP :=; 7 | else 8 | ?exe := 9 | PATH_SEP :=: 10 | endif 11 | 12 | space:= 13 | space+= 14 | comma:=, 15 | join-with=$(subst $(space),$1,$(strip $2)) 16 | 17 | # debug target, prints varaible. Example: `make print-GOFLAGS` 18 | print-%: 19 | @echo $*=$($*) 20 | 21 | # phony target that will mean that recipe is always exectued 22 | ALWAYS: 23 | .PHONY: ALWAYS 24 | -------------------------------------------------------------------------------- /thirdparty/assert/assert.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import "testing" 4 | 5 | func Nil(err error, t *testing.T, msgs ...string) { 6 | if err != nil { 7 | t.Fatal(msgs, "error:", err) 8 | } 9 | } 10 | 11 | func True(v bool, t *testing.T, msgs ...string) { 12 | if !v { 13 | t.Fatal(msgs) 14 | } 15 | } 16 | 17 | func False(v bool, t *testing.T, msgs ...string) { 18 | True(!v, t, msgs...) 19 | } 20 | 21 | func Err(err error, t *testing.T, msgs ...string) { 22 | if err == nil { 23 | t.Fatal(msgs, "error:", err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bin/check_go_path: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PWD=$1 4 | 5 | if [ -z "$PWD" ]; then 6 | echo "must pass in your current working directory" 7 | exit 1 8 | fi 9 | 10 | if [ -z "$GOPATH" ]; then 11 | echo "GOPATH not set, you must have go configured properly to install ipfs" 12 | exit 1 13 | fi 14 | 15 | while [ ${#} -gt 1 ]; do 16 | if [ "$PWD" = "$2" ]; then 17 | exit 0 18 | fi 19 | shift 20 | done 21 | 22 | echo "go-ipfs must be built from within your \$GOPATH directory." 23 | echo "expected within '$GOPATH' but got '$PWD'" 24 | exit 1 25 | -------------------------------------------------------------------------------- /plugin/plugins/gen_main.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dir=${1:?first paramater with dir to work in is required} 4 | pkg=${2:?second parameter with full name of the package is required} 5 | main_pkg="$dir/main" 6 | 7 | shortpkg="uniquepkgname" 8 | 9 | mkdir -p "$main_pkg" 10 | 11 | cat > "$main_pkg/main.go" <expected && 17 | ipfs config Foo.Bar >actual && 18 | test_cmp expected actual 19 | ' 20 | 21 | test_done 22 | -------------------------------------------------------------------------------- /test/bin/checkflags: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Author: Christian Couder 3 | # MIT LICENSED 4 | 5 | if test "$#" -lt 3 6 | then 7 | echo >&2 "usage $0 FILE VALUES MSG..." 8 | exit 1 9 | fi 10 | 11 | FLAG_FILE="$1" 12 | FLAG_VALS="$2" 13 | shift 14 | shift 15 | FLAG_MSGS="$@" 16 | 17 | test -f $FLAG_FILE || touch $FLAG_FILE 18 | 19 | # Use x in front of tested values as flags could be 20 | # interpreted by "test" to be for itself. 21 | if test x"$FLAG_VALS" != x"$(cat "$FLAG_FILE")" 22 | then 23 | echo "$FLAG_MSGS" 24 | echo "$FLAG_VALS" >"$FLAG_FILE" 25 | fi 26 | -------------------------------------------------------------------------------- /core/commands/mount_windows.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "errors" 5 | 6 | cmds "github.com/ipfs/go-ipfs/commands" 7 | 8 | cmdkit "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 9 | ) 10 | 11 | var MountCmd = &cmds.Command{ 12 | Helptext: cmdkit.HelpText{ 13 | Tagline: "Not yet implemented on Windows.", 14 | ShortDescription: "Not yet implemented on Windows. :(", 15 | }, 16 | 17 | Run: func(req cmds.Request, res cmds.Response) { 18 | res.SetError(errors.New("Mount isn't compatible with Windows yet"), cmdkit.ErrNormal) 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /core/coreunix/cat.go: -------------------------------------------------------------------------------- 1 | package coreunix 2 | 3 | import ( 4 | "context" 5 | 6 | core "github.com/ipfs/go-ipfs/core" 7 | path "github.com/ipfs/go-ipfs/path" 8 | uio "github.com/ipfs/go-ipfs/unixfs/io" 9 | ) 10 | 11 | func Cat(ctx context.Context, n *core.IpfsNode, pstr string) (uio.DagReader, error) { 12 | r := &path.Resolver{ 13 | DAG: n.DAG, 14 | ResolveOnce: uio.ResolveUnixfsOnce, 15 | } 16 | 17 | dagNode, err := core.Resolve(ctx, n.Namesys, r, path.Path(pstr)) 18 | if err != nil { 19 | return nil, err 20 | } 21 | 22 | return uio.NewDagReader(ctx, dagNode, n.DAG) 23 | } 24 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/golang-lru/README.md: -------------------------------------------------------------------------------- 1 | golang-lru 2 | ========== 3 | 4 | This provides the `lru` package which implements a fixed-size 5 | thread safe LRU cache. It is based on the cache in Groupcache. 6 | 7 | Documentation 8 | ============= 9 | 10 | Full docs are available on [Godoc](http://godoc.org/github.com/hashicorp/golang-lru) 11 | 12 | Example 13 | ======= 14 | 15 | Using the LRU is very simple: 16 | 17 | ```go 18 | l, _ := New(128) 19 | for i := 0; i < 256; i++ { 20 | l.Add(i, nil) 21 | } 22 | if l.Len() != 128 { 23 | panic("bad len: %v", l.Len()) 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /cmd/ipfs/dist/README.md: -------------------------------------------------------------------------------- 1 | # ipfs commandline tool 2 | 3 | This is the [ipfs](http://ipfs.io) commandline tool. It contains a full ipfs node. 4 | 5 | ## Install 6 | 7 | To install it, move the binary somewhere in your `$PATH`: 8 | 9 | ```sh 10 | sudo mv ipfs /usr/local/bin/ipfs 11 | ``` 12 | 13 | Or run `sudo install.sh` which does this for you. 14 | 15 | ## Usage 16 | 17 | First, you must initialize your local ipfs node: 18 | 19 | ```sh 20 | ipfs init 21 | ``` 22 | 23 | This will give you directions to get started with ipfs. 24 | You can always get help with: 25 | 26 | ```sh 27 | ipfs --help 28 | ``` 29 | -------------------------------------------------------------------------------- /core/corehttp/redirect.go: -------------------------------------------------------------------------------- 1 | package corehttp 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | 7 | core "github.com/ipfs/go-ipfs/core" 8 | ) 9 | 10 | func RedirectOption(path string, redirect string) ServeOption { 11 | handler := &redirectHandler{redirect} 12 | return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 13 | mux.Handle("/"+path+"/", handler) 14 | return mux, nil 15 | } 16 | } 17 | 18 | type redirectHandler struct { 19 | path string 20 | } 21 | 22 | func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 23 | http.Redirect(w, r, i.path, 302) 24 | } 25 | -------------------------------------------------------------------------------- /thirdparty/dir/dir.go: -------------------------------------------------------------------------------- 1 | package dir 2 | 3 | // TODO move somewhere generic 4 | 5 | import ( 6 | "errors" 7 | "os" 8 | "path/filepath" 9 | ) 10 | 11 | // Writable ensures the directory exists and is writable 12 | func Writable(path string) error { 13 | // Construct the path if missing 14 | if err := os.MkdirAll(path, os.ModePerm); err != nil { 15 | return err 16 | } 17 | // Check the directory is writeable 18 | if f, err := os.Create(filepath.Join(path, "._check_writeable")); err == nil { 19 | f.Close() 20 | os.Remove(f.Name()) 21 | } else { 22 | return errors.New("'" + path + "' is not writeable") 23 | } 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /fuse/readonly/mount_unix.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd netbsd openbsd 2 | // +build !nofuse 3 | 4 | package readonly 5 | 6 | import ( 7 | core "github.com/ipfs/go-ipfs/core" 8 | mount "github.com/ipfs/go-ipfs/fuse/mount" 9 | ) 10 | 11 | // Mount mounts IPFS at a given location, and returns a mount.Mount instance. 12 | func Mount(ipfs *core.IpfsNode, mountpoint string) (mount.Mount, error) { 13 | cfg, err := ipfs.Repo.Config() 14 | if err != nil { 15 | return nil, err 16 | } 17 | allow_other := cfg.Mounts.FuseAllowOther 18 | fsys := NewFileSystem(ipfs) 19 | return mount.NewMount(ipfs.Process(), fsys, mountpoint, allow_other) 20 | } 21 | -------------------------------------------------------------------------------- /thirdparty/datastore2/threadsafe.go: -------------------------------------------------------------------------------- 1 | package datastore2 2 | 3 | import ( 4 | "io" 5 | 6 | "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 7 | ) 8 | 9 | // ClaimThreadSafe claims that a Datastore is threadsafe, even when 10 | // it's type does not guarantee this. Use carefully. 11 | type ClaimThreadSafe struct { 12 | datastore.Batching 13 | } 14 | 15 | var _ datastore.ThreadSafeDatastore = ClaimThreadSafe{} 16 | 17 | func (ClaimThreadSafe) IsThreadSafe() {} 18 | 19 | // TEMP UNTIL dev0.4.0 merges and solves this ugly interface stuff 20 | func (c ClaimThreadSafe) Close() error { 21 | return c.Batching.(io.Closer).Close() 22 | } 23 | -------------------------------------------------------------------------------- /test/sharness/t0024-files/spec-newshardfun: -------------------------------------------------------------------------------- 1 | { 2 | "mounts": [ 3 | { 4 | "child": { 5 | "path": "blocks", 6 | "shardFunc": "/repo/flatfs/shard/v1/next-to-last/3", 7 | "sync": true, 8 | "type": "flatfs" 9 | }, 10 | "mountpoint": "/blocks", 11 | "prefix": "flatfs.datastore", 12 | "type": "measure" 13 | }, 14 | { 15 | "child": { 16 | "compression": "none", 17 | "path": "datastore", 18 | "type": "levelds" 19 | }, 20 | "mountpoint": "/", 21 | "prefix": "leveldb.datastore", 22 | "type": "measure" 23 | } 24 | ], 25 | "type": "mount" 26 | } 27 | -------------------------------------------------------------------------------- /test/sharness/t0024-files/spec-nosync: -------------------------------------------------------------------------------- 1 | { 2 | "mounts": [ 3 | { 4 | "child": { 5 | "path": "blocks", 6 | "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2", 7 | "sync": false, 8 | "type": "flatfs" 9 | }, 10 | "mountpoint": "/blocks", 11 | "prefix": "flatfs.datastore", 12 | "type": "measure" 13 | }, 14 | { 15 | "child": { 16 | "compression": "none", 17 | "path": "datastore", 18 | "type": "levelds" 19 | }, 20 | "mountpoint": "/", 21 | "prefix": "leveldb.datastore", 22 | "type": "measure" 23 | } 24 | ], 25 | "type": "mount" 26 | } 27 | -------------------------------------------------------------------------------- /test/dependencies/go-sleep/go-sleep.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | ) 8 | 9 | func main() { 10 | if len(os.Args) != 2 { 11 | usageError() 12 | } 13 | d, err := time.ParseDuration(os.Args[1]) 14 | if err != nil { 15 | fmt.Fprintf(os.Stderr, "Could not parse duration: %s\n", err) 16 | usageError() 17 | } 18 | 19 | time.Sleep(d) 20 | } 21 | 22 | func usageError() { 23 | fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args[0]) 24 | fmt.Fprintln(os.Stderr, `Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`) 25 | fmt.Fprintln(os.Stderr, "See https://godoc.org/time#ParseDuration for more.") 26 | os.Exit(-1) 27 | } 28 | -------------------------------------------------------------------------------- /merkledag/test/utils.go: -------------------------------------------------------------------------------- 1 | package mdutils 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/blocks/blockstore" 5 | bsrv "github.com/ipfs/go-ipfs/blockservice" 6 | "github.com/ipfs/go-ipfs/exchange/offline" 7 | dag "github.com/ipfs/go-ipfs/merkledag" 8 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 9 | dssync "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync" 10 | ) 11 | 12 | func Mock() dag.DAGService { 13 | return dag.NewDAGService(Bserv()) 14 | } 15 | 16 | func Bserv() bsrv.BlockService { 17 | bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) 18 | return bsrv.New(bstore, offline.Exchange(bstore)) 19 | } 20 | -------------------------------------------------------------------------------- /core/commands/dht_test.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/ipfs/go-ipfs/namesys" 7 | tu "gx/ipfs/QmQgLZP9haZheimMHqqAjJh2LhRmNfEoZDfbtkpeMhi9xK/go-testutil" 8 | ) 9 | 10 | func TestKeyTranslation(t *testing.T) { 11 | pid := tu.RandPeerIDFatal(t) 12 | a, b := namesys.IpnsKeysForID(pid) 13 | 14 | pkk, err := escapeDhtKey("/pk/" + pid.Pretty()) 15 | if err != nil { 16 | t.Fatal(err) 17 | } 18 | 19 | ipnsk, err := escapeDhtKey("/ipns/" + pid.Pretty()) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | 24 | if pkk != a { 25 | t.Fatal("keys didnt match!") 26 | } 27 | 28 | if ipnsk != b { 29 | t.Fatal("keys didnt match!") 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /repo/fsrepo/doc.go: -------------------------------------------------------------------------------- 1 | // package fsrepo 2 | // 3 | // TODO explain the package roadmap... 4 | // 5 | // .ipfs/ 6 | // ├── client/ 7 | // | ├── client.lock <------ protects client/ + signals its own pid 8 | // │ ├── ipfs-client.cpuprof 9 | // │ └── ipfs-client.memprof 10 | // ├── config 11 | // ├── daemon/ 12 | // │ ├── daemon.lock <------ protects daemon/ + signals its own address 13 | // │ ├── ipfs-daemon.cpuprof 14 | // │ └── ipfs-daemon.memprof 15 | // ├── datastore/ 16 | // ├── repo.lock <------ protects datastore/ and config 17 | // └── version 18 | package fsrepo 19 | 20 | // TODO prevent multiple daemons from running 21 | -------------------------------------------------------------------------------- /fuse/ipns/link_unix.go: -------------------------------------------------------------------------------- 1 | // +build !nofuse 2 | 3 | package ipns 4 | 5 | import ( 6 | "context" 7 | "os" 8 | 9 | "gx/ipfs/QmaFNtBAXX4nVMQWbUqNysXyhevUj1k4B1y5uS45LC7Vw9/fuse" 10 | "gx/ipfs/QmaFNtBAXX4nVMQWbUqNysXyhevUj1k4B1y5uS45LC7Vw9/fuse/fs" 11 | ) 12 | 13 | type Link struct { 14 | Target string 15 | } 16 | 17 | func (l *Link) Attr(ctx context.Context, a *fuse.Attr) error { 18 | log.Debug("Link attr.") 19 | a.Mode = os.ModeSymlink | 0555 20 | return nil 21 | } 22 | 23 | func (l *Link) Readlink(ctx context.Context, req *fuse.ReadlinkRequest) (string, error) { 24 | log.Debugf("ReadLink: %s", l.Target) 25 | return l.Target, nil 26 | } 27 | 28 | var _ fs.NodeReadlinker = (*Link)(nil) 29 | -------------------------------------------------------------------------------- /fuse/ipns/writerat.go: -------------------------------------------------------------------------------- 1 | package ipns 2 | 3 | import "io" 4 | 5 | type WriteAtBuf interface { 6 | io.WriterAt 7 | Bytes() []byte 8 | } 9 | 10 | type writerAt struct { 11 | buf []byte 12 | } 13 | 14 | func NewWriterAtFromBytes(b []byte) WriteAtBuf { 15 | return &writerAt{b} 16 | } 17 | 18 | // TODO: make this better in the future, this is just a quick hack for now 19 | func (wa *writerAt) WriteAt(p []byte, off int64) (int, error) { 20 | if off+int64(len(p)) > int64(len(wa.buf)) { 21 | wa.buf = append(wa.buf, make([]byte, (int(off)+len(p))-len(wa.buf))...) 22 | } 23 | copy(wa.buf[off:], p) 24 | return len(p), nil 25 | } 26 | 27 | func (wa *writerAt) Bytes() []byte { 28 | return wa.buf 29 | } 30 | -------------------------------------------------------------------------------- /repo/fsrepo/misc.go: -------------------------------------------------------------------------------- 1 | package fsrepo 2 | 3 | import ( 4 | "os" 5 | 6 | homedir "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir" 7 | "github.com/ipfs/go-ipfs/repo/config" 8 | ) 9 | 10 | // BestKnownPath returns the best known fsrepo path. If the ENV override is 11 | // present, this function returns that value. Otherwise, it returns the default 12 | // repo path. 13 | func BestKnownPath() (string, error) { 14 | ipfsPath := config.DefaultPathRoot 15 | if os.Getenv(config.EnvDir) != "" { 16 | ipfsPath = os.Getenv(config.EnvDir) 17 | } 18 | ipfsPath, err := homedir.Expand(ipfsPath) 19 | if err != nil { 20 | return "", err 21 | } 22 | return ipfsPath, nil 23 | } 24 | -------------------------------------------------------------------------------- /misc/launchd/io.ipfs.ipfs-daemon.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | KeepAlive 6 | 7 | Label 8 | io.ipfs.ipfs-daemon 9 | ProgramArguments 10 | 11 | {{IPFS_BIN}} 12 | daemon 13 | 14 | EnvironmentVariables 15 | 16 | IPFS_PATH 17 | {{IPFS_PATH}} 18 | 19 | RunAtLoad 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/api-startup/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "sync" 8 | "time" 9 | ) 10 | 11 | func main() { 12 | when := make(chan (time.Time), 2) 13 | var wg sync.WaitGroup 14 | wg.Add(2) 15 | for _, port := range []string{"5001", "8080"} { 16 | go func(port string) { 17 | defer wg.Done() 18 | for { 19 | r, err := http.Get(fmt.Sprintf("http://127.0.0.1:%s", port)) 20 | if err != nil { 21 | continue 22 | } 23 | t := time.Now() 24 | when <- t 25 | log.Println(port, t, r.StatusCode) 26 | break 27 | } 28 | }(port) 29 | } 30 | wg.Wait() 31 | first := <-when 32 | second := <-when 33 | log.Println(second.Sub(first)) 34 | } 35 | -------------------------------------------------------------------------------- /bin/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | dist_root_$(d)=/ipfs/QmR27Do9gqx9VmuQTEX1UGXETSWYJTQzPzxS5FNUnySCv1 4 | 5 | $(d)/gx: $(d)/gx-v0.12.0 6 | $(d)/gx-go: $(d)/gx-go-v1.5.0 7 | 8 | TGTS_$(d) := $(d)/gx $(d)/gx-go 9 | DISTCLEAN += $(wildcard $(d)/gx-v*) $(wildcard $(d)/gx-go-v*) $(d)/tmp 10 | 11 | PATH := $(realpath $(d)):$(PATH) 12 | 13 | $(TGTS_$(d)): 14 | rm -f $@ 15 | ln -s $(notdir $^) $@ 16 | 17 | bin/gx-v%: 18 | @echo "installing gx $(@:bin/gx-%=%)" 19 | bin/dist_get $(dist_root_bin) gx $@ $(@:bin/gx-%=%) 20 | 21 | bin/gx-go-v%: 22 | @echo "installing gx-go $(@:bin/gx-go-%=%)" 23 | @bin/dist_get $(dist_root_bin) gx-go $@ $(@:bin/gx-go-%=%) 24 | 25 | CLEAN += $(TGTS_$(d)) 26 | include mk/footer.mk 27 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/README.md: -------------------------------------------------------------------------------- 1 | # go-random outputs randomness 2 | 3 | This is a unix util that outputs randomness. 4 | It is a thin wrapper around `crypto/rand`. 5 | It aims to be portable (though it may not yet be). 6 | 7 | ### Install 8 | 9 | ```sh 10 | go install github.com/jbenet/go-random/random 11 | ``` 12 | 13 | (The extra /random is there because go get is stupidly too proscriptive about 14 | package/repository names and I don't yet know how to change the default binary 15 | output name) 16 | 17 | ### Usage: 18 | 19 | ``` 20 | > random 21 | Usage: random 22 | Print random bytes (from Go's crypto/rand) 23 | > random 6 24 | 2q���# 25 | ``` 26 | 27 | ### License 28 | 29 | MIT 30 | -------------------------------------------------------------------------------- /fuse/ipns/mount_unix.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd netbsd openbsd 2 | // +build !nofuse 3 | 4 | package ipns 5 | 6 | import ( 7 | core "github.com/ipfs/go-ipfs/core" 8 | mount "github.com/ipfs/go-ipfs/fuse/mount" 9 | ) 10 | 11 | // Mount mounts ipns at a given location, and returns a mount.Mount instance. 12 | func Mount(ipfs *core.IpfsNode, ipnsmp, ipfsmp string) (mount.Mount, error) { 13 | cfg, err := ipfs.Repo.Config() 14 | if err != nil { 15 | return nil, err 16 | } 17 | 18 | allow_other := cfg.Mounts.FuseAllowOther 19 | 20 | fsys, err := NewFileSystem(ipfs, ipfs.PrivateKey, ipfsmp, ipnsmp) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | return mount.NewMount(ipfs.Process(), fsys, ipnsmp, allow_other) 26 | } 27 | -------------------------------------------------------------------------------- /core/commands/mount_nofuse.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd netbsd openbsd 2 | // +build nofuse 3 | 4 | package commands 5 | 6 | import ( 7 | cmds "github.com/ipfs/go-ipfs/commands" 8 | 9 | "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 10 | ) 11 | 12 | var MountCmd = &cmds.Command{ 13 | Helptext: cmdkit.HelpText{ 14 | Tagline: "Mounts ipfs to the filesystem (disabled).", 15 | ShortDescription: ` 16 | This version of ipfs is compiled without fuse support, which is required 17 | for mounting. If you'd like to be able to mount, please use a version of 18 | ipfs compiled with fuse. 19 | 20 | For the latest instructions, please check the project's repository: 21 | http://github.com/ipfs/go-ipfs 22 | `, 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /blockservice/test/mock.go: -------------------------------------------------------------------------------- 1 | package bstest 2 | 3 | import ( 4 | . "github.com/ipfs/go-ipfs/blockservice" 5 | bitswap "github.com/ipfs/go-ipfs/exchange/bitswap" 6 | tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet" 7 | mockrouting "github.com/ipfs/go-ipfs/routing/mock" 8 | delay "github.com/ipfs/go-ipfs/thirdparty/delay" 9 | ) 10 | 11 | // Mocks returns |n| connected mock Blockservices 12 | func Mocks(n int) []BlockService { 13 | net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0)) 14 | sg := bitswap.NewTestSessionGenerator(net) 15 | 16 | instances := sg.Instances(n) 17 | 18 | var servs []BlockService 19 | for _, i := range instances { 20 | servs = append(servs, New(i.Blockstore(), i.Exchange)) 21 | } 22 | return servs 23 | } 24 | -------------------------------------------------------------------------------- /plugin/loader/preload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 4 | 5 | to_preload() { 6 | awk 'NF' "$DIR/preload_list" | sed '/^#/d' 7 | } 8 | 9 | cat < go-sleep 20 | Usage: go-sleep 21 | Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". 22 | See https://godoc.org/time#ParseDuration for more. 23 | > time go-sleep 100ms 24 | 25 | real 0m0.104s 26 | user 0m0.000s 27 | sys 0m0.007s 28 | ``` 29 | 30 | ### License 31 | 32 | MIT 33 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/mitchellh/go-homedir/README.md: -------------------------------------------------------------------------------- 1 | # go-homedir 2 | 3 | This is a Go library for detecting the user's home directory without 4 | the use of cgo, so the library can be used in cross-compilation environments. 5 | 6 | Usage is incredibly simple, just call `homedir.Dir()` to get the home directory 7 | for a user, and `homedir.Expand()` to expand the `~` in a path to the home 8 | directory. 9 | 10 | **Why not just use `os/user`?** The built-in `os/user` package requires 11 | cgo on Darwin systems. This means that any Go code that uses that package 12 | cannot cross compile. But 99% of the time the use for `os/user` is just to 13 | retrieve the home directory, which we can do for the current user without 14 | cgo. This library does that, enabling cross-compilation. 15 | -------------------------------------------------------------------------------- /cmd/ipfs/runmain_test.go: -------------------------------------------------------------------------------- 1 | // +build testrunmain 2 | 3 | package main 4 | 5 | import ( 6 | "flag" 7 | "fmt" 8 | "io/ioutil" 9 | "os" 10 | "testing" 11 | ) 12 | 13 | // this abuses go so much that I felt dirty writing this code 14 | // but it is the only way to do it without writing custom compiler that would 15 | // be a clone of go-build with go-test 16 | func TestRunMain(t *testing.T) { 17 | args := flag.Args() 18 | os.Args = append([]string{os.Args[0]}, args...) 19 | ret := mainRet() 20 | 21 | p := os.Getenv("IPFS_COVER_RET_FILE") 22 | if len(p) != 0 { 23 | ioutil.WriteFile(p, []byte(fmt.Sprintf("%d\n", ret)), 0777) 24 | } 25 | 26 | // close outputs so go testing doesn't print anything 27 | null, _ := os.Open(os.DevNull) 28 | os.Stderr = null 29 | os.Stdout = null 30 | } 31 | -------------------------------------------------------------------------------- /test/sharness/t0024-datastore-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Test datastore config" 4 | 5 | . lib/test-lib.sh 6 | 7 | test_init_ipfs 8 | 9 | test_launch_ipfs_daemon 10 | test_kill_ipfs_daemon 11 | 12 | SPEC_NOSYNC=$(cat ../t0024-files/spec-nosync) 13 | 14 | SPEC_NEWSHARDFUN=$(cat ../t0024-files/spec-newshardfun) 15 | 16 | test_expect_success "change runtime value in spec config" ' 17 | ipfs config --json Datastore.Spec "$SPEC_NOSYNC" 18 | ' 19 | 20 | test_launch_ipfs_daemon 21 | test_kill_ipfs_daemon 22 | 23 | test_expect_success "change on-disk value in spec config" ' 24 | ipfs config --json Datastore.Spec "$SPEC_NEWSHARDFUN" 25 | ' 26 | 27 | test_expect_success "can not launch daemon after on-disk value change" ' 28 | test_must_fail ipfs daemon 29 | ' 30 | 31 | test_done 32 | -------------------------------------------------------------------------------- /test/3nodetest/fig.yml: -------------------------------------------------------------------------------- 1 | data: 2 | build: ./data 3 | volumes: 4 | - /data 5 | command: sleep 1000000 6 | 7 | bootstrap: 8 | build: ./bootstrap 9 | command: daemon --debug --init 10 | expose: 11 | - "4011" 12 | - "4012/udp" 13 | environment: 14 | IPFS_LOGGING: debug 15 | 16 | server: 17 | build: ./server 18 | links: 19 | - bootstrap 20 | volumes_from: 21 | - data 22 | expose: 23 | - "4021" 24 | - "4022/udp" 25 | environment: 26 | IPFS_LOGGING: debug 27 | 28 | client: 29 | build: ./client 30 | links: 31 | - bootstrap 32 | volumes_from: 33 | - data 34 | expose: 35 | - "4031" 36 | - "4032/udp" 37 | environment: 38 | IPFS_LOGGING: debug 39 | -------------------------------------------------------------------------------- /plugin/plugins/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | $(d)_plugins:=$(d)/git 4 | $(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins)) 5 | $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins)) 6 | 7 | 8 | $($(d)_plugins_main): d:=$(d) 9 | $($(d)_plugins_main): 10 | $(d)/gen_main.sh "$(dir $@).." "$(call go-pkg-name,$(dir $@)/..)" 11 | $(GOCC) fmt $@ >/dev/null 12 | 13 | $($(d)_plugins_so): %.so : %/main/main.go 14 | $($(d)_plugins_so): $$(DEPS_GO) ALWAYS 15 | $(GOCC) build -buildmode=plugin -i -pkgdir "$(GOPATH)/pkg/linux_amd64_dynlink" $(go-flags-with-tags) -o "$@" "$(call go-pkg-name,$(basename $@))/main" 16 | chmod +x "$@" 17 | 18 | CLEAN += $($(d)_plugins_so) 19 | CLEAN += $(foreach main_dir,$($(d)_plugins_main),$(dir $(main_dir))) 20 | 21 | build_plugins: $($(d)_plugins_so) 22 | 23 | 24 | include mk/footer.mk 25 | -------------------------------------------------------------------------------- /core/commands/shutdown.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "fmt" 5 | 6 | "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 7 | 8 | cmds "github.com/ipfs/go-ipfs/commands" 9 | ) 10 | 11 | var daemonShutdownCmd = &cmds.Command{ 12 | Helptext: cmdkit.HelpText{ 13 | Tagline: "Shut down the ipfs daemon", 14 | }, 15 | Run: func(req cmds.Request, res cmds.Response) { 16 | nd, err := req.InvocContext().GetNode() 17 | if err != nil { 18 | res.SetError(err, cmdkit.ErrNormal) 19 | return 20 | } 21 | 22 | if nd.LocalMode() { 23 | res.SetError(fmt.Errorf("daemon not running"), cmdkit.ErrClient) 24 | return 25 | } 26 | 27 | if err := nd.Process().Close(); err != nil { 28 | log.Error("error while shutting down ipfs daemon:", err) 29 | } 30 | 31 | res.SetOutput(nil) 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /core/coredag/cbor.go: -------------------------------------------------------------------------------- 1 | package coredag 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | 7 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 8 | ipldcbor "gx/ipfs/QmWCs8kMecJwCPK8JThue8TjgM2ieJ2HjTLDu7Cv2NEmZi/go-ipld-cbor" 9 | ) 10 | 11 | func cborJSONParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { 12 | nd, err := ipldcbor.FromJson(r, mhType, mhLen) 13 | if err != nil { 14 | return nil, err 15 | } 16 | 17 | return []node.Node{nd}, nil 18 | } 19 | 20 | func cborRawParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { 21 | data, err := ioutil.ReadAll(r) 22 | if err != nil { 23 | return nil, err 24 | } 25 | 26 | nd, err := ipldcbor.Decode(data, mhType, mhLen) 27 | if err != nil { 28 | return nil, err 29 | } 30 | 31 | return []node.Node{nd}, nil 32 | } 33 | -------------------------------------------------------------------------------- /bin/graphmd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$#" -ne 1 ]; then 4 | echo "usage: $0 ..." 5 | echo "output merkledag links in graphviz dot" 6 | echo "" 7 | echo "use it with dot:" 8 | echo " $0 QmZPAMWUfLD95GsdorXt9hH7aVrarb2SuLDMVVe6gABYmx | dot -Tsvg" 9 | echo " $0 QmZPAMWUfLD95GsdorXt9hH7aVrarb2SuLDMVVe6gABYmx | dot -Tpng" 10 | echo " $0 QmZPAMWUfLD95GsdorXt9hH7aVrarb2SuLDMVVe6gABYmx | dot -Tpdf" 11 | echo "" 12 | exit 1 13 | fi 14 | 15 | src=' [fontsize=8 shape=box];' 16 | dst=' [fontsize=8 shape=box];' 17 | edge=' -> [label=""];' 18 | fmt="$src 19 | $dst 20 | $edge" 21 | 22 | echo "digraph {" 23 | echo " graph [rankdir=LR];" 24 | ipfs refs -r --format="$fmt" "$@" | awk '{ print "\t" $0 }' 25 | # ipfs refs -r --format="$fmt" "$@" | awk '{ print "\t" $0 }' | unflatten -l3 26 | echo "}" 27 | -------------------------------------------------------------------------------- /bin/ipns-republish: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -ne 1 ]; then 4 | echo "usage: $0 " 5 | echo "republishes an ipns name every 20 minutes" 6 | echo "(this is an icky stop-gap until ipfs nodes do it for you)" 7 | echo "" 8 | echo "example:" 9 | echo " > $0 QmSYCpuKPbPQ2iFr2swJj2hvz7wQUXfPBXPiuVsQdL5FEs" 10 | echo "" 11 | exit 1 12 | fi 13 | 14 | # must be run online. 15 | ipfs swarm peers >/dev/null 16 | if [ $? -ne 0 ]; then 17 | echo "error: ipfs daemon must be online and connected to peers " 18 | exit 1 19 | fi 20 | 21 | # check the object is there 22 | ipfs object stat "$1" >/dev/null 23 | if [ $? -ne 0 ]; then 24 | echo "error: ipfs cannot find $1" 25 | exit 1 26 | fi 27 | 28 | echo "republishing $1 every 20 minutes" 29 | while : 30 | do 31 | ipfs name publish $1 32 | sleep 1200 33 | done 34 | -------------------------------------------------------------------------------- /docs/openbsd.md: -------------------------------------------------------------------------------- 1 | # Building on OpenBSD 2 | 3 | ## Prepare your system 4 | 5 | Make sure you have `git`, `go` and `gmake` installed on your system. 6 | 7 | ``` 8 | $ doas pkg_add -v git go gmake 9 | ``` 10 | 11 | ## Prepare go environment 12 | 13 | Make sure your gopath is set: 14 | 15 | ``` 16 | $ export GOPATH=~/go 17 | $ echo "$GOPATH" 18 | $ export PATH="$PATH:$GOPATH/bin" 19 | ``` 20 | 21 | ## Build 22 | 23 | The `install_unsupported` target works nicely for openbsd. This will install 24 | `gx`, `gx-go` and run `go install -tags nofuse ./cmd/ipfs`. 25 | 26 | ``` 27 | $ go get -v -u -d github.com/ipfs/go-ipfs 28 | 29 | $ cd $GOPATH/src/github.com/ipfs/go-ipfs 30 | $ gmake install_unsupported 31 | ``` 32 | 33 | if everything went well, your ipfs binary should be ready at `$GOPATH/bin/ipfs`. 34 | 35 | ``` 36 | $ ipfs version 37 | ``` 38 | -------------------------------------------------------------------------------- /thirdparty/unit/unit.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import "fmt" 4 | 5 | type Information int64 6 | 7 | const ( 8 | _ Information = iota // ignore first value by assigning to blank identifier 9 | KB = 1 << (10 * iota) 10 | MB 11 | GB 12 | TB 13 | PB 14 | EB 15 | ) 16 | 17 | func (i Information) String() string { 18 | 19 | tmp := int64(i) 20 | 21 | // default 22 | var d = tmp 23 | symbol := "B" 24 | 25 | switch { 26 | case i > EB: 27 | d = tmp / EB 28 | symbol = "EB" 29 | case i > PB: 30 | d = tmp / PB 31 | symbol = "PB" 32 | case i > TB: 33 | d = tmp / TB 34 | symbol = "TB" 35 | case i > GB: 36 | d = tmp / GB 37 | symbol = "GB" 38 | case i > MB: 39 | d = tmp / MB 40 | symbol = "MB" 41 | case i > KB: 42 | d = tmp / KB 43 | symbol = "KB" 44 | } 45 | return fmt.Sprintf("%d %s", d, symbol) 46 | } 47 | -------------------------------------------------------------------------------- /core/corehttp/webui.go: -------------------------------------------------------------------------------- 1 | package corehttp 2 | 3 | // TODO: move to IPNS 4 | const WebUIPath = "/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ" 5 | 6 | // this is a list of all past webUI paths. 7 | var WebUIPaths = []string{ 8 | WebUIPath, 9 | "/ipfs/QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R", 10 | "/ipfs/QmXdu7HWdV6CUaUabd9q2ZeA4iHZLVyDRj3Gi4dsJsWjbr", 11 | "/ipfs/QmaaqrHyAQm7gALkRW8DcfGX3u8q9rWKnxEMmf7m9z515w", 12 | "/ipfs/QmSHDxWsMPuJQKWmVA1rB5a3NX2Eme5fPqNb63qwaqiqSp", 13 | "/ipfs/QmctngrQAt9fjpQUZr7Bx3BsXUcif52eZGTizWhvcShsjz", 14 | "/ipfs/QmS2HL9v5YeKgQkkWMvs1EMnFtUowTEdFfSSeMT4pos1e6", 15 | "/ipfs/QmR9MzChjp1MdFWik7NjEjqKQMzVmBkdK3dz14A6B5Cupm", 16 | "/ipfs/QmRyWyKWmphamkMRnJVjUTzSFSAAZowYP4rnbgnfMXC9Mr", 17 | "/ipfs/QmU3o9bvfenhTKhxUakbYrLDnZU7HezAVxPM6Ehjw9Xjqy", 18 | } 19 | 20 | var WebUIOption = RedirectOption("webui", WebUIPath) 21 | -------------------------------------------------------------------------------- /repo/fsrepo/serialize/serialize_test.go: -------------------------------------------------------------------------------- 1 | package fsrepo 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | config "github.com/ipfs/go-ipfs/repo/config" 8 | ) 9 | 10 | func TestConfig(t *testing.T) { 11 | const filename = ".ipfsconfig" 12 | cfgWritten := new(config.Config) 13 | cfgWritten.Identity.PeerID = "faketest" 14 | 15 | err := WriteConfigFile(filename, cfgWritten) 16 | if err != nil { 17 | t.Fatal(err) 18 | } 19 | cfgRead, err := Load(filename) 20 | if err != nil { 21 | t.Fatal(err) 22 | } 23 | if cfgWritten.Identity.PeerID != cfgRead.Identity.PeerID { 24 | t.Fatal() 25 | } 26 | st, err := os.Stat(filename) 27 | if err != nil { 28 | t.Fatalf("cannot stat config file: %v", err) 29 | } 30 | if g := st.Mode().Perm(); g&0117 != 0 { 31 | t.Fatalf("config file should not be executable or accessible to world: %v", g) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/3nodetest/bin/save_profiling_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for container in 3nodetest_bootstrap_1 3nodetest_client_1 3nodetest_server_1; do 4 | # ipfs binary is required by `go tool pprof` 5 | docker cp $container:/go/bin/ipfs build/profiling_data_$container 6 | done 7 | 8 | # since the nodes are executed with the --debug flag, profiling data is written 9 | # to the the working dir. by default, the working dir is /go. 10 | 11 | for container in 3nodetest_bootstrap_1 3nodetest_client_1 3nodetest_server_1; do 12 | docker cp $container:/go/ipfs.cpuprof build/profiling_data_$container 13 | done 14 | 15 | # TODO get memprof from client (client daemon isn't terminated, so memprof isn't retrieved) 16 | for container in 3nodetest_bootstrap_1 3nodetest_server_1; do 17 | docker cp $container:/go/ipfs.memprof build/profiling_data_$container 18 | done 19 | -------------------------------------------------------------------------------- /test/sharness/t0235-cli-request.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2015 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="test http requests made by cli" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | test_expect_success "can make http request against nc server" ' 14 | nc -ld 5005 > nc_out & 15 | NCPID=$! 16 | go-sleep 0.5s && kill "$NCPID" & 17 | ipfs cat /ipfs/Qmabcdef --api /ip4/127.0.0.1/tcp/5005 || true 18 | ' 19 | 20 | test_expect_success "output does not contain multipart info" ' 21 | test_expect_code 1 grep multipart nc_out 22 | ' 23 | 24 | test_expect_success "request looks good" ' 25 | grep "POST /api/v0/cat" nc_out 26 | ' 27 | 28 | test_expect_success "api flag does not appear in request" ' 29 | test_expect_code 1 grep "api=/ip4" nc_out 30 | ' 31 | 32 | test_done 33 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/README.md: -------------------------------------------------------------------------------- 1 | # go-detect-race 2 | 3 | Check if the race detector is running. 4 | 5 | I didnt find a variable to check quickly enough so I made this. 6 | 7 | 8 | ## Usage 9 | 10 | ```go 11 | import ( 12 | detectrace "github.com/jbenet/go-detect-race" 13 | ) 14 | 15 | func main() { 16 | if detectrace.WithRace() { 17 | // running with -race 18 | } else { 19 | // running without -race 20 | } 21 | } 22 | ``` 23 | 24 | ## Why? 25 | 26 | Because the race detector doesnt like massive stress tests. Example: 27 | https://groups.google.com/forum/#!topic/golang-nuts/XDPHUt2LE70 28 | 29 | ## Why didn't you just use... 30 | 31 | Please tell me about a better way of doing this. It wasn't 32 | readily apparent to me, so I made this. But i would much prefer 33 | an env var or some already existing var from the stdlib :) 34 | -------------------------------------------------------------------------------- /core/commands/e/error.go: -------------------------------------------------------------------------------- 1 | package e 2 | 3 | import ( 4 | "fmt" 5 | "runtime/debug" 6 | ) 7 | 8 | // TypeErr returns an error with a string that explains what error was expected and what was received. 9 | func TypeErr(expected, actual interface{}) error { 10 | return fmt.Errorf("expected type %T, got %T", expected, actual) 11 | } 12 | 13 | // compile time type check that HandlerError is an error 14 | var _ error = New(nil) 15 | 16 | // HandlerError is adds a stack trace to an error 17 | type HandlerError struct { 18 | Err error 19 | Stack []byte 20 | } 21 | 22 | // Error makes HandlerError implement error 23 | func (err HandlerError) Error() string { 24 | return fmt.Sprintf("%s in:\n%s", err.Err.Error(), err.Stack) 25 | } 26 | 27 | // New returns a new HandlerError 28 | func New(err error) HandlerError { 29 | return HandlerError{Err: err, Stack: debug.Stack()} 30 | } 31 | -------------------------------------------------------------------------------- /test/sharness/x0601-pin-fail-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test very large number of pins" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | test_launch_ipfs_daemon 14 | 15 | test_expect_success "pre-test setup" ' 16 | printf "" > pins && 17 | ipfs pin ls --type=recursive -q > rec_pins_before 18 | ' 19 | 20 | 21 | for i in `seq 9000` 22 | do 23 | test_expect_success "ipfs add (and pin) a file" ' 24 | echo $i | ipfs add -q >> pins 25 | ' 26 | done 27 | 28 | test_expect_success "get pinset afterwards" ' 29 | ipfs pin ls --type=recursive -q | sort > rec_pins_after && 30 | cat pins rec_pins_before | sort | uniq > exp_pins_after && 31 | test_cmp rec_pins_after exp_pins_after 32 | ' 33 | 34 | test_kill_ipfs_daemon 35 | 36 | test_done 37 | 38 | -------------------------------------------------------------------------------- /unixfs/io/bufdagreader.go: -------------------------------------------------------------------------------- 1 | package io 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io" 7 | ) 8 | 9 | type bufDagReader struct { 10 | *bytes.Reader 11 | } 12 | 13 | func NewBufDagReader(b []byte) *bufDagReader { 14 | return &bufDagReader{bytes.NewReader(b)} 15 | } 16 | 17 | var _ DagReader = (*bufDagReader)(nil) 18 | 19 | func (*bufDagReader) Close() error { 20 | return nil 21 | } 22 | 23 | func (rd *bufDagReader) CtxReadFull(ctx context.Context, b []byte) (int, error) { 24 | return rd.Read(b) 25 | } 26 | 27 | func (rd *bufDagReader) Offset() int64 { 28 | of, err := rd.Seek(0, io.SeekCurrent) 29 | if err != nil { 30 | panic("this should never happen " + err.Error()) 31 | } 32 | return of 33 | } 34 | 35 | func (rd *bufDagReader) Size() uint64 { 36 | s := rd.Reader.Size() 37 | if s < 0 { 38 | panic("size smaller than 0 (impossible!!)") 39 | } 40 | return uint64(s) 41 | } 42 | -------------------------------------------------------------------------------- /repo/config/identity.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/base64" 5 | 6 | ic "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" 7 | ) 8 | 9 | const IdentityTag = "Identity" 10 | const PrivKeyTag = "PrivKey" 11 | const PrivKeySelector = IdentityTag + "." + PrivKeyTag 12 | 13 | // Identity tracks the configuration of the local node's identity. 14 | type Identity struct { 15 | PeerID string 16 | PrivKey string `json:",omitempty"` 17 | } 18 | 19 | // DecodePrivateKey is a helper to decode the users PrivateKey 20 | func (i *Identity) DecodePrivateKey(passphrase string) (ic.PrivKey, error) { 21 | pkb, err := base64.StdEncoding.DecodeString(i.PrivKey) 22 | if err != nil { 23 | return nil, err 24 | } 25 | 26 | // currently storing key unencrypted. in the future we need to encrypt it. 27 | // TODO(security) 28 | return ic.UnmarshalPrivateKey(pkb) 29 | } 30 | -------------------------------------------------------------------------------- /test/sharness/t0023-shutdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test shutdown command" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | test_launch_ipfs_daemon 14 | 15 | test_expect_success "shutdown succeeds" ' 16 | ipfs shutdown 17 | ' 18 | 19 | test_expect_success "daemon no longer running" ' 20 | for i in $(test_seq 1 100) 21 | do 22 | go-sleep 100ms 23 | ! kill -0 $IPFS_PID 2>/dev/null && return 24 | done 25 | ' 26 | 27 | test_launch_ipfs_daemon --offline 28 | 29 | test_expect_success "shutdown succeeds" ' 30 | ipfs shutdown 31 | ' 32 | 33 | test_expect_success "daemon no longer running" ' 34 | for i in $(test_seq 1 100) 35 | do 36 | go-sleep 100ms 37 | ! kill -0 $IPFS_PID 2>/dev/null && return 38 | done 39 | ' 40 | test_done 41 | -------------------------------------------------------------------------------- /commands/channelmarshaler.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | type ChannelMarshaler struct { 8 | Channel <-chan interface{} 9 | Marshaler func(interface{}) (io.Reader, error) 10 | Res Response 11 | 12 | reader io.Reader 13 | } 14 | 15 | func (cr *ChannelMarshaler) Read(p []byte) (int, error) { 16 | if cr.reader == nil { 17 | val, more := <-cr.Channel 18 | if !more { 19 | //check error in response 20 | if cr.Res.Error() != nil { 21 | return 0, cr.Res.Error() 22 | } 23 | return 0, io.EOF 24 | } 25 | 26 | r, err := cr.Marshaler(val) 27 | if err != nil { 28 | return 0, err 29 | } 30 | if r == nil { 31 | return 0, nil 32 | } 33 | cr.reader = r 34 | } 35 | 36 | n, err := cr.reader.Read(p) 37 | if err != nil && err != io.EOF { 38 | return n, err 39 | } 40 | if n == 0 { 41 | cr.reader = nil 42 | } 43 | return n, nil 44 | } 45 | -------------------------------------------------------------------------------- /test/sharness/t0088-repo-stat-symlink.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017 John Reed 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test 'ipfs repo stat' where IPFS_PATH is a symbolic link" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_expect_success "create symbolic link for IPFS_PATH" ' 12 | mkdir sym_link_target && 13 | ln -s sym_link_target .ipfs 14 | ' 15 | 16 | test_init_ipfs 17 | 18 | # compare RepoSize when getting it directly vs via symbolic link 19 | test_expect_success "'ipfs repo stat' RepoSize is correct with sym link" ' 20 | export IPFS_PATH="sym_link_target" && 21 | reposize_direct=$(ipfs repo stat | grep RepoSize | awk '\''{ print $2 }'\'') && 22 | export IPFS_PATH=".ipfs" && 23 | reposize_symlink=$(ipfs repo stat | grep RepoSize | awk '\''{ print $2 }'\'') && 24 | test $reposize_symlink -ge $reposize_direct 25 | ' 26 | 27 | test_done 28 | -------------------------------------------------------------------------------- /test/sharness/t0063-external.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2015 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="test external command functionality" 8 | 9 | . lib/test-lib.sh 10 | 11 | 12 | # set here so daemon launches with it 13 | PATH=`pwd`/bin:$PATH 14 | 15 | test_init_ipfs 16 | 17 | test_launch_ipfs_daemon 18 | 19 | test_expect_success "create fake ipfs-update bin" ' 20 | mkdir bin && 21 | echo "#!/bin/sh" > bin/ipfs-update && 22 | echo "pwd" >> bin/ipfs-update && 23 | chmod +x bin/ipfs-update 24 | ' 25 | 26 | test_expect_success "external command runs from current user directory" ' 27 | mkdir just_for_test && 28 | (cd just_for_test && ipfs update) > actual 29 | ' 30 | 31 | test_expect_success "output looks good" ' 32 | echo `pwd`/just_for_test > exp && 33 | test_cmp exp actual 34 | ' 35 | 36 | test_kill_ipfs_daemon 37 | 38 | test_done 39 | -------------------------------------------------------------------------------- /test/sharness/t0150-clisuggest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Test ipfs cli cmd suggest" 4 | 5 | . lib/test-lib.sh 6 | 7 | test_suggest() { 8 | 9 | 10 | test_expect_success "test command fails" ' 11 | test_must_fail ipfs kog 2>actual 12 | ' 13 | 14 | test_expect_success "test one command is suggested" ' 15 | grep "Did you mean this?" actual && 16 | grep "log" actual || 17 | test_fsh cat actual 18 | ' 19 | 20 | test_expect_success "test command fails" ' 21 | test_must_fail ipfs lis 2>actual 22 | ' 23 | 24 | test_expect_success "test multiple commands are suggested" ' 25 | grep "Did you mean any of these?" actual && 26 | grep "ls" actual && 27 | grep "id" actual || 28 | test_fsh cat actual 29 | ' 30 | 31 | } 32 | 33 | test_init_ipfs 34 | 35 | test_suggest 36 | 37 | test_launch_ipfs_daemon 38 | 39 | test_suggest 40 | 41 | test_kill_ipfs_daemon 42 | 43 | test_done 44 | -------------------------------------------------------------------------------- /assets/init-doc/readme: -------------------------------------------------------------------------------- 1 | Hello and Welcome to IPFS! 2 | 3 | ██╗██████╗ ███████╗███████╗ 4 | ██║██╔══██╗██╔════╝██╔════╝ 5 | ██║██████╔╝█████╗ ███████╗ 6 | ██║██╔═══╝ ██╔══╝ ╚════██║ 7 | ██║██║ ██║ ███████║ 8 | ╚═╝╚═╝ ╚═╝ ╚══════╝ 9 | 10 | If you're seeing this, you have successfully installed 11 | IPFS and are now interfacing with the ipfs merkledag! 12 | 13 | ------------------------------------------------------- 14 | | Warning: | 15 | | This is alpha software. Use at your own discretion! | 16 | | Much is missing or lacking polish. There are bugs. | 17 | | Not yet secure. Read the security notes for more. | 18 | ------------------------------------------------------- 19 | 20 | Check out some of the other files in this directory: 21 | 22 | ./about 23 | ./help 24 | ./quick-start <-- usage examples 25 | ./readme <-- this file 26 | ./security-notes 27 | -------------------------------------------------------------------------------- /bin/gencmdref: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import datetime 6 | import subprocess 7 | 8 | from subprocess import check_output 9 | 10 | def run(cmd): 11 | return check_output(cmd) 12 | 13 | def main(): 14 | lines = [l.strip() for l in sys.stdin] 15 | 16 | print '# ipfs command reference' 17 | print '' 18 | print 'generated on', datetime.datetime.now() 19 | print '' 20 | for line in lines: 21 | print '- [%s](#%s)' % (line, line.replace(' ', '-')) 22 | print '' 23 | 24 | for line in lines: 25 | print '## %s' % line 26 | print '' 27 | print '```' 28 | print run((line + ' --help').split(' ')).strip() 29 | print '```' 30 | print '' 31 | 32 | if __name__ == '__main__': 33 | if '-h' in sys.argv or '--help' in sys.argv: 34 | print 'usage: ipfs commands | %s >cmdref.md' % sys.argv[0] 35 | print 'outputs all commands with --help to a markdown file' 36 | exit(0) 37 | 38 | main() 39 | -------------------------------------------------------------------------------- /exchange/bitswap/message/pb/message.proto: -------------------------------------------------------------------------------- 1 | package bitswap.message.pb; 2 | 3 | message Message { 4 | 5 | message Wantlist { 6 | 7 | message Entry { 8 | optional string block = 1; // the block cid (cidV0 in bitswap 1.0.0, cidV1 in bitswap 1.1.0) 9 | optional int32 priority = 2; // the priority (normalized). default to 1 10 | optional bool cancel = 3; // whether this revokes an entry 11 | } 12 | 13 | repeated Entry entries = 1; // a list of wantlist entries 14 | optional bool full = 2; // whether this is the full wantlist. default to false 15 | } 16 | 17 | message Block { 18 | optional bytes prefix = 1; // CID prefix (cid version, multicodec and multihash prefix (type + length) 19 | optional bytes data = 2; 20 | } 21 | 22 | optional Wantlist wantlist = 1; 23 | repeated bytes blocks = 2; // used to send Blocks in bitswap 1.0.0 24 | repeated Block payload = 3; // used to send Blocks in bitswap 1.1.0 25 | } 26 | -------------------------------------------------------------------------------- /cmd/ipfs/dist/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Installation script for ipfs. It tries to move $bin in one of the 4 | # directories stored in $binpaths. 5 | 6 | bin=ipfs 7 | binpaths="/usr/local/bin /usr/bin" 8 | 9 | # This variable contains a nonzero length string in case the script fails 10 | # because of missing write permissions. 11 | is_write_perm_missing="" 12 | 13 | for binpath in $binpaths; do 14 | if mv "$bin" "$binpath/$bin" 2> /dev/null; then 15 | echo "Moved $bin to $binpath" 16 | exit 0 17 | else 18 | if [ -d "$binpath" -a ! -w "$binpath" ]; then 19 | is_write_perm_missing=1 20 | fi 21 | fi 22 | done 23 | 24 | echo "We cannot install $bin in one of the directories $binpaths" 25 | 26 | if [ -n "$is_write_perm_missing" ]; then 27 | echo "It seems that we do not have the necessary write permissions." 28 | echo "Perhaps try running this script as a privileged user:" 29 | echo 30 | echo " sudo $0" 31 | echo 32 | fi 33 | 34 | exit 1 35 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | IPFS is a global, versioned, peer-to-peer filesystem 3 | 4 | There are sub-packages within the ipfs package for various low-level 5 | utilities, which are in turn assembled into: 6 | 7 | core/...: 8 | The low-level API that gives consumers all the knobs they need, 9 | which we try hard to keep stable. 10 | shell/...: 11 | The high-level API that gives consumers easy access to common 12 | operations (e.g. create a file node from a reader without wrapping 13 | with metadata). We work really hard to keep this stable. 14 | 15 | Then on top of the core/... and shell/... Go APIs, we have: 16 | 17 | cmd/...: 18 | Command-line executables 19 | test/...: 20 | Integration tests, etc. 21 | 22 | To avoid cyclic imports, imports should never pull in higher-level 23 | APIs into a lower-level package. For example, you could import all of 24 | core and shell from cmd/... or test/..., but you couldn't import any 25 | of shell from core/.... 26 | */ 27 | package ipfs 28 | -------------------------------------------------------------------------------- /plugin/loader/initializer.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/core/coredag" 5 | "github.com/ipfs/go-ipfs/plugin" 6 | 7 | format "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 8 | ) 9 | 10 | func initialize(plugins []plugin.Plugin) error { 11 | for _, p := range plugins { 12 | err := p.Init() 13 | if err != nil { 14 | return err 15 | } 16 | } 17 | 18 | return nil 19 | } 20 | 21 | func run(plugins []plugin.Plugin) error { 22 | for _, pl := range plugins { 23 | err := runIPLDPlugin(pl) 24 | if err != nil { 25 | return err 26 | } 27 | } 28 | return nil 29 | } 30 | 31 | func runIPLDPlugin(pl plugin.Plugin) error { 32 | ipldpl, ok := pl.(plugin.PluginIPLD) 33 | if !ok { 34 | return nil 35 | } 36 | 37 | err := ipldpl.RegisterBlockDecoders(format.DefaultBlockDecoder) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | return ipldpl.RegisterInputEncParsers(coredag.DefaultInputEncParsers) 43 | } 44 | -------------------------------------------------------------------------------- /test/sharness/t0231-channel-streaming.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2015 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test output of streaming json commands" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | get_api_port() { 14 | cat "$IPFS_PATH/api" | awk -F/ '{ print $5 }' 15 | } 16 | 17 | test_ls_cmd() { 18 | test_expect_success "make a file with multiple refs" ' 19 | HASH=$(random 1000000 | ipfs add -q) 20 | ' 21 | 22 | test_expect_success "can get refs through curl" ' 23 | PORT=$(get_api_port) && 24 | curl http://localhost:$PORT/api/v0/refs/$HASH > output 25 | ' 26 | 27 | # make sure newlines are printed between each object 28 | test_expect_success "output looks good" ' 29 | test_expect_code 1 grep "}{" output > /dev/null 30 | ' 31 | } 32 | 33 | # should work online (only) 34 | test_launch_ipfs_daemon 35 | test_ls_cmd 36 | test_kill_ipfs_daemon 37 | 38 | test_done 39 | -------------------------------------------------------------------------------- /thirdparty/ds-help/key.go: -------------------------------------------------------------------------------- 1 | package dshelp 2 | 3 | import ( 4 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 5 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 6 | base32 "gx/ipfs/QmfVj3x4D6Jkq9SEoi5n2NmoUomLwoeiwnYz2KQa15wRw6/base32" 7 | ) 8 | 9 | // TODO: put this code into the go-datastore itself 10 | 11 | func NewKeyFromBinary(rawKey []byte) ds.Key { 12 | buf := make([]byte, 1+base32.RawStdEncoding.EncodedLen(len(rawKey))) 13 | buf[0] = '/' 14 | base32.RawStdEncoding.Encode(buf[1:], rawKey) 15 | return ds.RawKey(string(buf)) 16 | } 17 | 18 | func BinaryFromDsKey(k ds.Key) ([]byte, error) { 19 | return base32.RawStdEncoding.DecodeString(k.String()[1:]) 20 | } 21 | 22 | func CidToDsKey(k *cid.Cid) ds.Key { 23 | return NewKeyFromBinary(k.Bytes()) 24 | } 25 | 26 | func DsKeyToCid(dsKey ds.Key) (*cid.Cid, error) { 27 | kb, err := BinaryFromDsKey(dsKey) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return cid.Cast(kb) 32 | } 33 | -------------------------------------------------------------------------------- /core/pathresolver_test.go: -------------------------------------------------------------------------------- 1 | package core_test 2 | 3 | import ( 4 | "testing" 5 | 6 | core "github.com/ipfs/go-ipfs/core" 7 | coremock "github.com/ipfs/go-ipfs/core/mock" 8 | path "github.com/ipfs/go-ipfs/path" 9 | ) 10 | 11 | func TestResolveNoComponents(t *testing.T) { 12 | n, err := coremock.NewMockNode() 13 | if n == nil || err != nil { 14 | t.Fatal("Should have constructed a mock node", err) 15 | } 16 | 17 | _, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipns/")) 18 | if err != path.ErrNoComponents { 19 | t.Fatal("Should error with no components (/ipns/).", err) 20 | } 21 | 22 | _, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipfs/")) 23 | if err != path.ErrNoComponents { 24 | t.Fatal("Should error with no components (/ipfs/).", err) 25 | } 26 | 27 | _, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/../..")) 28 | if err != path.ErrBadPath { 29 | t.Fatal("Should error with invalid path.", err) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /exchange/interface.go: -------------------------------------------------------------------------------- 1 | // package exchange defines the IPFS exchange interface 2 | package exchange 3 | 4 | import ( 5 | "context" 6 | "io" 7 | 8 | blocks "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format" 9 | 10 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 11 | ) 12 | 13 | // Any type that implements exchange.Interface may be used as an IPFS block 14 | // exchange protocol. 15 | type Interface interface { // type Exchanger interface 16 | Fetcher 17 | 18 | // TODO Should callers be concerned with whether the block was made 19 | // available on the network? 20 | HasBlock(blocks.Block) error 21 | 22 | IsOnline() bool 23 | 24 | io.Closer 25 | } 26 | 27 | // Fetcher is an object that can be used to retrieve blocks 28 | type Fetcher interface { 29 | // GetBlock returns the block associated with a given key. 30 | GetBlock(context.Context, *cid.Cid) (blocks.Block, error) 31 | GetBlocks(context.Context, []*cid.Cid) (<-chan blocks.Block, error) 32 | } 33 | -------------------------------------------------------------------------------- /importer/chunk/rabin.go: -------------------------------------------------------------------------------- 1 | package chunk 2 | 3 | import ( 4 | "hash/fnv" 5 | "io" 6 | 7 | "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/chunker" 8 | ) 9 | 10 | var IpfsRabinPoly = chunker.Pol(17437180132763653) 11 | 12 | type Rabin struct { 13 | r *chunker.Chunker 14 | reader io.Reader 15 | } 16 | 17 | func NewRabin(r io.Reader, avgBlkSize uint64) *Rabin { 18 | min := avgBlkSize / 3 19 | max := avgBlkSize + (avgBlkSize / 2) 20 | 21 | return NewRabinMinMax(r, min, avgBlkSize, max) 22 | } 23 | 24 | func NewRabinMinMax(r io.Reader, min, avg, max uint64) *Rabin { 25 | h := fnv.New32a() 26 | ch := chunker.New(r, IpfsRabinPoly, h, avg, min, max) 27 | 28 | return &Rabin{ 29 | r: ch, 30 | reader: r, 31 | } 32 | } 33 | 34 | func (r *Rabin) NextBytes() ([]byte, error) { 35 | ch, err := r.r.Next() 36 | if err != nil { 37 | return nil, err 38 | } 39 | 40 | return ch.Data, nil 41 | } 42 | 43 | func (r *Rabin) Reader() io.Reader { 44 | return r.reader 45 | } 46 | -------------------------------------------------------------------------------- /exchange/bitswap/decision/bench_test.go: -------------------------------------------------------------------------------- 1 | package decision 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "testing" 7 | 8 | "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist" 9 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 10 | "gx/ipfs/QmQgLZP9haZheimMHqqAjJh2LhRmNfEoZDfbtkpeMhi9xK/go-testutil" 11 | u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util" 12 | "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" 13 | ) 14 | 15 | // FWIW: At the time of this commit, including a timestamp in task increases 16 | // time cost of Push by 3%. 17 | func BenchmarkTaskQueuePush(b *testing.B) { 18 | q := newPRQ() 19 | peers := []peer.ID{ 20 | testutil.RandPeerIDFatal(b), 21 | testutil.RandPeerIDFatal(b), 22 | testutil.RandPeerIDFatal(b), 23 | } 24 | b.ResetTimer() 25 | for i := 0; i < b.N; i++ { 26 | c := cid.NewCidV0(u.Hash([]byte(fmt.Sprint(i)))) 27 | 28 | q.Push(&wantlist.Entry{Cid: c, Priority: math.MaxInt32}, peers[i%len(peers)]) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /fuse/ipns/common.go: -------------------------------------------------------------------------------- 1 | package ipns 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/ipfs/go-ipfs/core" 7 | nsys "github.com/ipfs/go-ipfs/namesys" 8 | path "github.com/ipfs/go-ipfs/path" 9 | ft "github.com/ipfs/go-ipfs/unixfs" 10 | ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto" 11 | ) 12 | 13 | // InitializeKeyspace sets the ipns record for the given key to 14 | // point to an empty directory. 15 | func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error { 16 | emptyDir := ft.EmptyDirNode() 17 | nodek, err := n.DAG.Add(emptyDir) 18 | if err != nil { 19 | return err 20 | } 21 | 22 | ctx, cancel := context.WithCancel(n.Context()) 23 | defer cancel() 24 | 25 | err = n.Pinning.Pin(ctx, emptyDir, false) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | err = n.Pinning.Flush() 31 | if err != nil { 32 | return err 33 | } 34 | 35 | pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore()) 36 | 37 | return pub.Publish(ctx, key, path.FromCid(nodek)) 38 | } 39 | -------------------------------------------------------------------------------- /core/commands/helptext_test.go: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | 7 | cmds "gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds" 8 | ) 9 | 10 | func checkHelptextRecursive(t *testing.T, name []string, c *cmds.Command) { 11 | if c.Helptext.Tagline == "" { 12 | t.Errorf("%s has no tagline!", strings.Join(name, " ")) 13 | } 14 | 15 | if c.Helptext.LongDescription == "" { 16 | t.Errorf("%s has no long description!", strings.Join(name, " ")) 17 | } 18 | 19 | if c.Helptext.ShortDescription == "" { 20 | t.Errorf("%s has no short description!", strings.Join(name, " ")) 21 | } 22 | 23 | if c.Helptext.Synopsis == "" { 24 | t.Errorf("%s has no synopsis!", strings.Join(name, " ")) 25 | } 26 | 27 | for subname, sub := range c.Subcommands { 28 | checkHelptextRecursive(t, append(name, subname), sub) 29 | } 30 | } 31 | 32 | func TestHelptexts(t *testing.T) { 33 | t.Skip("sill isn't 100%") 34 | Root.ProcessHelp() 35 | checkHelptextRecursive(t, []string{"ipfs"}, Root) 36 | } 37 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random-files/ringreader/ringreader.go: -------------------------------------------------------------------------------- 1 | package ringreader 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "math/rand" 7 | 8 | random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random" 9 | ) 10 | 11 | type Reader struct { 12 | Buf []byte 13 | } 14 | 15 | func NewReader(bufsize int) (*Reader, error) { 16 | buf := bytes.NewBuffer(nil) 17 | err := random.WritePseudoRandomBytes(int64(bufsize), buf, rand.Int63()) 18 | return &Reader{Buf: buf.Bytes()}, err 19 | } 20 | 21 | func (r *Reader) Read(buf []byte) (n int, err error) { 22 | ibufl := len(r.Buf) 23 | left := len(buf) 24 | copied := 0 25 | 26 | for copied < left { 27 | pos1 := rand.Intn(len(r.Buf)) 28 | pos2 := pos1 + left 29 | if pos2 > ibufl { 30 | pos2 = ibufl 31 | } 32 | copied += copy(buf[copied:], r.Buf[pos1:pos2]) 33 | } 34 | 35 | if copied != left { 36 | err := fmt.Errorf("copied a different ammount: %d != %d", copied, left) 37 | panic(err.Error()) 38 | } 39 | return copied, nil 40 | } 41 | -------------------------------------------------------------------------------- /core/coredag/raw.go: -------------------------------------------------------------------------------- 1 | package coredag 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | "math" 7 | 8 | "github.com/ipfs/go-ipfs/merkledag" 9 | 10 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 11 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 12 | block "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format" 13 | mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash" 14 | ) 15 | 16 | func rawRawParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { 17 | if mhType == math.MaxUint64 { 18 | mhType = mh.SHA2_256 19 | } 20 | 21 | data, err := ioutil.ReadAll(r) 22 | if err != nil { 23 | return nil, err 24 | } 25 | 26 | h, err := mh.Sum(data, mhType, mhLen) 27 | if err != nil { 28 | return nil, err 29 | } 30 | c := cid.NewCidV1(cid.Raw, h) 31 | blk, err := block.NewBlockWithCid(data, c) 32 | if err != nil { 33 | return nil, err 34 | } 35 | nd := &merkledag.RawNode{Block: blk} 36 | return []node.Node{nd}, nil 37 | } 38 | -------------------------------------------------------------------------------- /misc/launchd/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | src_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 4 | plist=io.ipfs.ipfs-daemon.plist 5 | dest_dir="$HOME/Library/LaunchAgents" 6 | IPFS_PATH="${IPFS_PATH:-$HOME/.ipfs}" 7 | escaped_ipfs_path=$(echo $IPFS_PATH|sed 's/\//\\\//g') 8 | 9 | IPFS_BIN=$(which ipfs || echo ipfs) 10 | escaped_ipfs_bin=$(echo $IPFS_BIN|sed 's/\//\\\//g') 11 | 12 | mkdir -p "$dest_dir" 13 | 14 | sed -e 's/{{IPFS_PATH}}/'"$escaped_ipfs_path"'/g' \ 15 | -e 's/{{IPFS_BIN}}/'"$escaped_ipfs_bin"'/g' \ 16 | "$src_dir/$plist" \ 17 | > "$dest_dir/$plist" 18 | 19 | launchctl list | grep ipfs-daemon >/dev/null 20 | if [ $? ]; then 21 | echo Unloading existing ipfs-daemon 22 | launchctl unload "$dest_dir/$plist" 23 | fi 24 | 25 | echo Loading ipfs-daemon 26 | if (( `sw_vers -productVersion | cut -d'.' -f2` > 9 )); then 27 | sudo chown root "$dest_dir/$plist" 28 | sudo launchctl bootstrap system "$dest_dir/$plist" 29 | else 30 | launchctl load "$dest_dir/$plist" 31 | fi 32 | launchctl list | grep ipfs-daemon 33 | -------------------------------------------------------------------------------- /namesys/proquint.go: -------------------------------------------------------------------------------- 1 | package namesys 2 | 3 | import ( 4 | "errors" 5 | 6 | context "context" 7 | 8 | path "github.com/ipfs/go-ipfs/path" 9 | proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint" 10 | ) 11 | 12 | type ProquintResolver struct{} 13 | 14 | // Resolve implements Resolver. 15 | func (r *ProquintResolver) Resolve(ctx context.Context, name string) (path.Path, error) { 16 | return r.ResolveN(ctx, name, DefaultDepthLimit) 17 | } 18 | 19 | // ResolveN implements Resolver. 20 | func (r *ProquintResolver) ResolveN(ctx context.Context, name string, depth int) (path.Path, error) { 21 | return resolve(ctx, r, name, depth, "/ipns/") 22 | } 23 | 24 | // resolveOnce implements resolver. Decodes the proquint string. 25 | func (r *ProquintResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) { 26 | ok, err := proquint.IsProquint(name) 27 | if err != nil || !ok { 28 | return "", errors.New("not a valid proquint string") 29 | } 30 | return path.FromString(string(proquint.Decode(name))), nil 31 | } 32 | -------------------------------------------------------------------------------- /exchange/bitswap/stat.go: -------------------------------------------------------------------------------- 1 | package bitswap 2 | 3 | import ( 4 | "sort" 5 | 6 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 7 | ) 8 | 9 | type Stat struct { 10 | ProvideBufLen int 11 | Wantlist []*cid.Cid 12 | Peers []string 13 | BlocksReceived uint64 14 | DataReceived uint64 15 | BlocksSent uint64 16 | DataSent uint64 17 | DupBlksReceived uint64 18 | DupDataReceived uint64 19 | } 20 | 21 | func (bs *Bitswap) Stat() (*Stat, error) { 22 | st := new(Stat) 23 | st.ProvideBufLen = len(bs.newBlocks) 24 | st.Wantlist = bs.GetWantlist() 25 | bs.counterLk.Lock() 26 | c := bs.counters 27 | st.BlocksReceived = c.blocksRecvd 28 | st.DupBlksReceived = c.dupBlocksRecvd 29 | st.DupDataReceived = c.dupDataRecvd 30 | st.BlocksSent = c.blocksSent 31 | st.DataSent = c.dataSent 32 | st.DataReceived = c.dataRecvd 33 | bs.counterLk.Unlock() 34 | 35 | for _, p := range bs.engine.Peers() { 36 | st.Peers = append(st.Peers, p.Pretty()) 37 | } 38 | sort.Strings(st.Peers) 39 | 40 | return st, nil 41 | } 42 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/golang-lru/lru_test.go: -------------------------------------------------------------------------------- 1 | package lru 2 | 3 | import "testing" 4 | 5 | func TestLRU(t *testing.T) { 6 | l, err := New(128) 7 | if err != nil { 8 | t.Fatalf("err: %v", err) 9 | } 10 | for i := 0; i < 256; i++ { 11 | l.Add(i, i) 12 | } 13 | if l.Len() != 128 { 14 | t.Fatalf("bad len: %v", l.Len()) 15 | } 16 | for _, k := range l.Keys() { 17 | if v, ok := l.Get(k); !ok || v != k { 18 | t.Fatalf("bad key: %v", k) 19 | } 20 | } 21 | for i := 0; i < 128; i++ { 22 | _, ok := l.Get(i) 23 | if ok { 24 | t.Fatalf("should be evicted") 25 | } 26 | } 27 | for i := 128; i < 256; i++ { 28 | _, ok := l.Get(i) 29 | if !ok { 30 | t.Fatalf("should not be evicted") 31 | } 32 | } 33 | for i := 128; i < 192; i++ { 34 | l.Remove(i) 35 | _, ok := l.Get(i) 36 | if ok { 37 | t.Fatalf("should be deleted") 38 | } 39 | } 40 | 41 | l.Purge() 42 | if l.Len() != 0 { 43 | t.Fatalf("bad len: %v", l.Len()) 44 | } 45 | if _, ok := l.Get(200); ok { 46 | t.Fatalf("should contain nothing") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/lib.go: -------------------------------------------------------------------------------- 1 | package random 2 | 3 | import ( 4 | "bytes" 5 | randcrypto "crypto/rand" 6 | "io" 7 | randmath "math/rand" 8 | ) 9 | 10 | func WriteRandomBytes(count int64, w io.Writer) error { 11 | r := &io.LimitedReader{R: randcrypto.Reader, N: count} 12 | _, err := io.Copy(w, r) 13 | return err 14 | } 15 | 16 | func WritePseudoRandomBytes(count int64, w io.Writer, seed int64) error { 17 | randmath.Seed(seed) 18 | 19 | // Configurable buffer size 20 | bufsize := int64(1024 * 1024 * 4) 21 | b := make([]byte, bufsize) 22 | 23 | for count > 0 { 24 | if bufsize > count { 25 | bufsize = count 26 | b = b[:bufsize] 27 | } 28 | 29 | var n uint32 30 | for i := int64(0); i < bufsize; { 31 | n = randmath.Uint32() 32 | for j := 0; j < 4 && i < bufsize; j++ { 33 | b[i] = byte(n & 0xff) 34 | n >>= 8 35 | i++ 36 | } 37 | } 38 | count = count - bufsize 39 | 40 | r := bytes.NewReader(b) 41 | _, err := io.Copy(w, r) 42 | if err != nil { 43 | return err 44 | } 45 | } 46 | return nil 47 | } 48 | -------------------------------------------------------------------------------- /test/sharness/t0400-api-security.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Lars Gierth 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test API security" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | # by default, we don't let you load arbitrary ipfs objects through the api, 14 | # because this would open up the api to scripting vulnerabilities. 15 | # only the webui objects are allowed. 16 | # if you know what you're doing, go ahead and pass --unrestricted-api. 17 | 18 | test_launch_ipfs_daemon 19 | test_expect_success "Gateway on API unavailable" ' 20 | HASH=$(echo "testing" | ipfs add -q) 21 | test_curl_resp_http_code "http://127.0.0.1:$API_PORT/ipfs/$HASH" "HTTP/1.1 404 Not Found" 22 | ' 23 | test_kill_ipfs_daemon 24 | 25 | test_launch_ipfs_daemon --unrestricted-api 26 | test_expect_success "Gateway on --unrestricted-api API available" ' 27 | HASH=$(echo "testing" | ipfs add -q) 28 | test_curl_resp_http_code "http://127.0.0.1:$API_PORT/ipfs/$HASH" "HTTP/1.1 200 OK" 29 | ' 30 | test_kill_ipfs_daemon 31 | 32 | test_done 33 | -------------------------------------------------------------------------------- /blocks/blockstore/caching_test.go: -------------------------------------------------------------------------------- 1 | package blockstore 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | ) 7 | 8 | func TestCachingOptsLessThanZero(t *testing.T) { 9 | opts := DefaultCacheOpts() 10 | opts.HasARCCacheSize = -1 11 | 12 | if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil { 13 | t.Error("wrong ARC setting was not detected") 14 | } 15 | 16 | opts = DefaultCacheOpts() 17 | opts.HasBloomFilterSize = -1 18 | 19 | if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil { 20 | t.Error("negative bloom size was not detected") 21 | } 22 | 23 | opts = DefaultCacheOpts() 24 | opts.HasBloomFilterHashes = -1 25 | 26 | if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil { 27 | t.Error("negative hashes setting was not detected") 28 | } 29 | } 30 | 31 | func TestBloomHashesAtZero(t *testing.T) { 32 | opts := DefaultCacheOpts() 33 | opts.HasBloomFilterHashes = 0 34 | 35 | if _, err := CachedBlockstore(context.TODO(), nil, opts); err == nil { 36 | t.Error("zero hashes setting with positive size was not detected") 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /cmd/seccat/util.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | 8 | logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" 9 | ) 10 | 11 | var log = logging.Logger("seccat") 12 | 13 | func exit(format string, vals ...interface{}) { 14 | if format != "" { 15 | fmt.Fprintf(os.Stderr, "seccat: error: "+format+"\n", vals...) 16 | } 17 | Usage() 18 | os.Exit(1) 19 | } 20 | 21 | func out(format string, vals ...interface{}) { 22 | if verbose { 23 | fmt.Fprintf(os.Stderr, "seccat: "+format+"\n", vals...) 24 | } 25 | } 26 | 27 | type logRW struct { 28 | n string 29 | rw io.ReadWriter 30 | } 31 | 32 | func (r *logRW) Read(buf []byte) (int, error) { 33 | n, err := r.rw.Read(buf) 34 | if err == nil { 35 | log.Debugf("%s read: %v", r.n, buf) 36 | } 37 | return n, err 38 | } 39 | 40 | func (r *logRW) Write(buf []byte) (int, error) { 41 | log.Debugf("%s write: %v", r.n, buf) 42 | return r.rw.Write(buf) 43 | } 44 | 45 | func (r *logRW) Close() error { 46 | c, ok := r.rw.(io.Closer) 47 | if ok { 48 | return c.Close() 49 | } 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /test/integration/Makefile: -------------------------------------------------------------------------------- 1 | # This Makefile provides a way to really simple way to run benchmarks in a 2 | # docker environment. 3 | 4 | IPFS_ROOT = ../.. 5 | CONTAINER = go-ipfs-bench 6 | PACKAGE = integrationtest 7 | PACKAGE_DIR = test/integration 8 | BUILD_DIR = ./build/bench 9 | CONTAINER_WORKING_DIR = /go 10 | CPU_PROF_NAME = cpu.out 11 | EXTRA_TEST_ARGS = 12 | 13 | all: collect 14 | 15 | collect: clean build_image run_profiler cp_pprof_from_container 16 | 17 | cp_pprof_from_container: 18 | docker cp $(CONTAINER):$(CONTAINER_WORKING_DIR)/$(CPU_PROF_NAME) $(BUILD_DIR) 19 | docker cp $(CONTAINER):$(CONTAINER_WORKING_DIR)/$(PACKAGE).test $(BUILD_DIR) 20 | 21 | build_image: 22 | cd $(IPFS_ROOT) && docker build -t $(IMAGE) . 23 | 24 | run_profiler: 25 | docker run --name $(CONTAINER) -it --entrypoint go $(IMAGE) test ./src/github.com/ipfs/go-ipfs/$(PACKAGE_DIR) --cpuprofile=$(CPU_PROF_NAME) $(EXTRA_TEST_ARGS) 26 | 27 | 28 | clean: 29 | docker rm $(CONTAINER) || true 30 | rm -rf $(BUILD_DIR) 31 | 32 | analyze: 33 | go tool pprof $(BUILD_DIR)/$(PACKAGE).test $(BUILD_DIR)/$(CPU_PROF_NAME) 34 | -------------------------------------------------------------------------------- /cmd/ipfs/ulimit_unix.go: -------------------------------------------------------------------------------- 1 | // +build darwin linux netbsd openbsd 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | 8 | unix "gx/ipfs/QmPXvegq26x982cQjSfbTvSzZXn7GiaMwhhVPHkeTEhrPT/sys/unix" 9 | ) 10 | 11 | func init() { 12 | fileDescriptorCheck = checkAndSetUlimit 13 | } 14 | 15 | func checkAndSetUlimit() error { 16 | var rLimit unix.Rlimit 17 | err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit) 18 | if err != nil { 19 | return fmt.Errorf("error getting rlimit: %s", err) 20 | } 21 | 22 | var setting bool 23 | if rLimit.Cur < ipfsFileDescNum { 24 | if rLimit.Max < ipfsFileDescNum { 25 | log.Error("adjusting max") 26 | rLimit.Max = ipfsFileDescNum 27 | } 28 | fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum) 29 | rLimit.Cur = ipfsFileDescNum 30 | setting = true 31 | } 32 | 33 | err = unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit) 34 | if err != nil { 35 | return fmt.Errorf("error setting ulimit: %s", err) 36 | } 37 | 38 | if setting { 39 | fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum) 40 | } 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /test/sharness/t0151-sysdiag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2015 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="test output of sysdiag command" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | test_expect_success "ipfs diag sys succeeds" ' 14 | ipfs diag sys > output 15 | ' 16 | 17 | test_expect_success "output contains some expected keys" ' 18 | grep "virt" output && 19 | grep "interface_addresses" output && 20 | grep "arch" output && 21 | grep "online" output 22 | ' 23 | 24 | test_expect_success "uname succeeds" ' 25 | UOUT=$(uname) 26 | ' 27 | 28 | test_expect_success "output is similar to uname" ' 29 | case $UOUT in 30 | Linux) 31 | grep linux output > /dev/null 32 | ;; 33 | Darwin) 34 | grep darwin output > /dev/null 35 | ;; 36 | FreeBSD) 37 | grep freebsd output > /dev/null 38 | ;; 39 | CYGWIN*) 40 | grep windows output > /dev/null 41 | ;; 42 | *) 43 | test_fsh echo system check for $UOUT failed, unsupported system? 44 | ;; 45 | esac 46 | ' 47 | 48 | test_done 49 | -------------------------------------------------------------------------------- /test/3nodetest/Makefile: -------------------------------------------------------------------------------- 1 | RANDOMSRC = ../../Godeps/_workspace/src/github.com/jbenet/go-random 2 | IMAGE_NAME = ipfs-test-latest 3 | IPFS_ROOT = ../.. 4 | 5 | test: clean setup 6 | ./run-test-on-img.sh $(IMAGE_NAME) 7 | 8 | setup: docker_ipfs_image data/filetiny data/filerand 9 | 10 | save_logs: 11 | sh bin/save_logs.sh 12 | 13 | save_profiling_data: 14 | sh bin/save_profiling_data.sh 15 | 16 | data/filetiny: Makefile 17 | cp Makefile ./data/filetiny # simple 18 | 19 | data/filerand: bin/random 20 | ./bin/random 50000000 > ./data/filerand 21 | 22 | bin/random: $(RANDOMSRC)/**/*.go 23 | go build -o ./bin/random $(RANDOMSRC)/random 24 | 25 | # just build it every time... this part isn't 26 | # even the lengthy part, and it decreases pain. 27 | docker_ipfs_image: 28 | docker build -t $(IMAGE_NAME) -f Dockerfile.fast . 29 | docker images | grep $(IMAGE_NAME) 30 | 31 | clean: 32 | sh bin/clean.sh 33 | fig stop 34 | fig rm -v --force 35 | rm -f bin/random 36 | rm -f data/filetiny 37 | rm -f data/filerand 38 | rm -rf build/* 39 | docker rmi $(docker images | grep "^" | awk "{print \$3}") -f || true 40 | -------------------------------------------------------------------------------- /docs/command-completion.md: -------------------------------------------------------------------------------- 1 | Command Completion 2 | ================== 3 | 4 | Shell command completion is provided by the script at 5 | [/misc/completion/ipfs-completion.bash](../misc/completion/ipfs-completion.bash). 6 | 7 | 8 | Installation 9 | ------------ 10 | The simplest way to see it working is to run 11 | `source misc/completion/ipfs-completion.bash` straight from your shell. This 12 | is only temporary and to fully enable it, you'll have to follow one of the steps 13 | below. 14 | 15 | ### Bash on Linux 16 | For bash, completion can be enabled in a couple of ways. One is to copy the 17 | completion script to the directory `~/.ipfs/` and then in the file 18 | `~/.bash_completion` add 19 | ```bash 20 | source ~/.ipfs/ipfs-completion.bash 21 | ``` 22 | It will automatically be loaded the next time bash is loaded. 23 | To enable ipfs command completion globally on your system you may also 24 | copy the completion script to `/etc/bash_completion.d/`. 25 | 26 | 27 | Additional References 28 | --------------------- 29 | * https://www.debian-administration.org/article/316/An_introduction_to_bash_completion_part_1 30 | -------------------------------------------------------------------------------- /repo/config/datastore.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // DefaultDataStoreDirectory is the directory to store all the local IPFS data. 8 | const DefaultDataStoreDirectory = "datastore" 9 | 10 | // Datastore tracks the configuration of the datastore. 11 | type Datastore struct { 12 | StorageMax string // in B, kB, kiB, MB, ... 13 | StorageGCWatermark int64 // in percentage to multiply on StorageMax 14 | GCPeriod string // in ns, us, ms, s, m, h 15 | 16 | // deprecated fields, use Spec 17 | Type string `json:",omitempty"` 18 | Path string `json:",omitempty"` 19 | NoSync bool `json:",omitempty"` 20 | Params *json.RawMessage `json:",omitempty"` 21 | 22 | Spec map[string]interface{} 23 | 24 | HashOnRead bool 25 | BloomFilterSize int 26 | } 27 | 28 | // DataStorePath returns the default data store path given a configuration root 29 | // (set an empty string to have the default configuration root) 30 | func DataStorePath(configroot string) (string, error) { 31 | return Path(configroot, DefaultDataStoreDirectory) 32 | } 33 | -------------------------------------------------------------------------------- /thirdparty/datastore2/datastore_closer.go: -------------------------------------------------------------------------------- 1 | package datastore2 2 | 3 | import ( 4 | "io" 5 | 6 | "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 7 | syncds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync" 8 | ) 9 | 10 | type ThreadSafeDatastoreCloser interface { 11 | datastore.ThreadSafeDatastore 12 | io.Closer 13 | 14 | Batch() (datastore.Batch, error) 15 | } 16 | 17 | func CloserWrap(ds datastore.ThreadSafeDatastore) ThreadSafeDatastoreCloser { 18 | return &datastoreCloserWrapper{ds} 19 | } 20 | 21 | func ThreadSafeCloserMapDatastore() ThreadSafeDatastoreCloser { 22 | return CloserWrap(syncds.MutexWrap(datastore.NewMapDatastore())) 23 | } 24 | 25 | type datastoreCloserWrapper struct { 26 | datastore.ThreadSafeDatastore 27 | } 28 | 29 | func (w *datastoreCloserWrapper) Close() error { 30 | return nil // no-op 31 | } 32 | 33 | func (w *datastoreCloserWrapper) Batch() (datastore.Batch, error) { 34 | bds, ok := w.ThreadSafeDatastore.(datastore.Batching) 35 | if !ok { 36 | return nil, datastore.ErrBatchUnsupported 37 | } 38 | 39 | return bds.Batch() 40 | } 41 | -------------------------------------------------------------------------------- /blocks/blocksutil/block_generator.go: -------------------------------------------------------------------------------- 1 | // Package blocksutil provides utility functions for working 2 | // with Blocks. 3 | package blocksutil 4 | 5 | import "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format" 6 | 7 | // NewBlockGenerator returns an object capable of 8 | // producing blocks. 9 | func NewBlockGenerator() BlockGenerator { 10 | return BlockGenerator{} 11 | } 12 | 13 | // BlockGenerator generates BasicBlocks on demand. 14 | // For each instace of BlockGenerator, 15 | // each new block is different from the previous, 16 | // although two different instances will produce the same. 17 | type BlockGenerator struct { 18 | seq int 19 | } 20 | 21 | // Next generates a new BasicBlock. 22 | func (bg *BlockGenerator) Next() *blocks.BasicBlock { 23 | bg.seq++ 24 | return blocks.NewBlock([]byte(string(bg.seq))) 25 | } 26 | 27 | // Blocks generates as many BasicBlocks as specified by n. 28 | func (bg *BlockGenerator) Blocks(n int) []blocks.Block { 29 | blocks := make([]blocks.Block, 0, n) 30 | for i := 0; i < n; i++ { 31 | b := bg.Next() 32 | blocks = append(blocks, b) 33 | } 34 | return blocks 35 | } 36 | -------------------------------------------------------------------------------- /merkledag/pb/merkledag.proto: -------------------------------------------------------------------------------- 1 | package merkledag.pb; 2 | 3 | import "code.google.com/p/gogoprotobuf/gogoproto/gogo.proto"; 4 | 5 | option (gogoproto.gostring_all) = true; 6 | option (gogoproto.equal_all) = true; 7 | option (gogoproto.verbose_equal_all) = true; 8 | option (gogoproto.goproto_stringer_all) = false; 9 | option (gogoproto.stringer_all) = true; 10 | option (gogoproto.populate_all) = true; 11 | option (gogoproto.testgen_all) = true; 12 | option (gogoproto.benchgen_all) = true; 13 | option (gogoproto.marshaler_all) = true; 14 | option (gogoproto.sizer_all) = true; 15 | option (gogoproto.unmarshaler_all) = true; 16 | 17 | 18 | // An IPFS MerkleDAG Link 19 | message PBLink { 20 | 21 | // multihash of the target object 22 | optional bytes Hash = 1; 23 | 24 | // utf string name. should be unique per object 25 | optional string Name = 2; 26 | 27 | // cumulative size of target object 28 | optional uint64 Tsize = 3; 29 | } 30 | 31 | // An IPFS MerkleDAG Node 32 | message PBNode { 33 | 34 | // refs to other objects 35 | repeated PBLink Links = 2; 36 | 37 | // opaque user data 38 | optional bytes Data = 1; 39 | } 40 | -------------------------------------------------------------------------------- /cmd/ipfs/ulimit_freebsd.go: -------------------------------------------------------------------------------- 1 | // +build freebsd 2 | 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | 8 | unix "gx/ipfs/QmPXvegq26x982cQjSfbTvSzZXn7GiaMwhhVPHkeTEhrPT/sys/unix" 9 | ) 10 | 11 | func init() { 12 | fileDescriptorCheck = checkAndSetUlimit 13 | } 14 | 15 | func checkAndSetUlimit() error { 16 | var rLimit unix.Rlimit 17 | err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit) 18 | if err != nil { 19 | return fmt.Errorf("error getting rlimit: %s", err) 20 | } 21 | 22 | ipfsFileDescNum := int64(ipfsFileDescNum) 23 | 24 | var setting bool 25 | if rLimit.Cur < ipfsFileDescNum { 26 | if rLimit.Max < ipfsFileDescNum { 27 | log.Error("adjusting max") 28 | rLimit.Max = ipfsFileDescNum 29 | } 30 | fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum) 31 | rLimit.Cur = ipfsFileDescNum 32 | setting = true 33 | } 34 | 35 | err = unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit) 36 | if err != nil { 37 | return fmt.Errorf("error setting ulimit: %s", err) 38 | } 39 | 40 | if setting { 41 | fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum) 42 | } 43 | 44 | return nil 45 | } 46 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/texttheater/golang-levenshtein/levenshtein/levenshtein_test.go: -------------------------------------------------------------------------------- 1 | package levenshtein_test 2 | 3 | import ( 4 | "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/texttheater/golang-levenshtein/levenshtein" 5 | "testing" 6 | ) 7 | 8 | var testCases = []struct { 9 | source string 10 | target string 11 | distance int 12 | }{ 13 | {"", "a", 1}, 14 | {"a", "aa", 1}, 15 | {"a", "aaa", 2}, 16 | {"", "", 0}, 17 | {"a", "b", 2}, 18 | {"aaa", "aba", 2}, 19 | {"aaa", "ab", 3}, 20 | {"a", "a", 0}, 21 | {"ab", "ab", 0}, 22 | {"a", "", 1}, 23 | {"aa", "a", 1}, 24 | {"aaa", "a", 2}, 25 | } 26 | 27 | func TestLevenshtein(t *testing.T) { 28 | for _, testCase := range testCases { 29 | distance := levenshtein.DistanceForStrings( 30 | []rune(testCase.source), 31 | []rune(testCase.target), 32 | levenshtein.DefaultOptions) 33 | if distance != testCase.distance { 34 | t.Log( 35 | "Distance between", 36 | testCase.source, 37 | "and", 38 | testCase.target, 39 | "computed as", 40 | distance, 41 | ", should be", 42 | testCase.distance) 43 | t.Fail() 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/sharness/t0251-files-flushing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="test the unix files api flushing" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | verify_path_exists() { 14 | # simply running ls on a file should be a good 'check' 15 | ipfs files ls $1 16 | } 17 | 18 | verify_dir_contents() { 19 | dir=$1 20 | shift 21 | rm -f expected 22 | touch expected 23 | for e in $@ 24 | do 25 | echo $e >> expected 26 | done 27 | 28 | test_expect_success "can list dir" ' 29 | ipfs files ls $dir > output 30 | ' 31 | 32 | test_expect_success "dir entries look good" ' 33 | test_sort_cmp output expected 34 | ' 35 | } 36 | 37 | test_launch_ipfs_daemon 38 | 39 | test_expect_success "can copy a file in" ' 40 | HASH=$(echo "foo" | ipfs add -q) && 41 | ipfs files cp /ipfs/$HASH /file 42 | ' 43 | 44 | test_kill_ipfs_daemon 45 | test_launch_ipfs_daemon 46 | 47 | test_expect_success "file is still there" ' 48 | verify_path_exists /file 49 | ' 50 | 51 | test_kill_ipfs_daemon 52 | 53 | test_done 54 | -------------------------------------------------------------------------------- /repo/fsrepo/migrations/mfsr_test.go: -------------------------------------------------------------------------------- 1 | package mfsr 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "strconv" 7 | "testing" 8 | 9 | "github.com/ipfs/go-ipfs/thirdparty/assert" 10 | ) 11 | 12 | func testVersionFile(v string, t *testing.T) (rp RepoPath) { 13 | name, err := ioutil.TempDir("", v) 14 | if err != nil { 15 | t.Fatal(err) 16 | } 17 | rp = RepoPath(name) 18 | return rp 19 | } 20 | 21 | func TestVersion(t *testing.T) { 22 | rp := RepoPath("") 23 | _, err := rp.Version() 24 | assert.Err(err, t, "Should throw an error when path is bad,") 25 | 26 | rp = RepoPath("/path/to/nowhere") 27 | _, err = rp.Version() 28 | if !os.IsNotExist(err) { 29 | t.Fatalf("Should throw an `IsNotExist` error when file doesn't exist: %v", err) 30 | } 31 | 32 | fsrepoV := 5 33 | 34 | rp = testVersionFile(strconv.Itoa(fsrepoV), t) 35 | _, err = rp.Version() 36 | assert.Err(err, t, "Bad VersionFile") 37 | 38 | assert.Nil(rp.WriteVersion(fsrepoV), t, "Trouble writing version") 39 | 40 | assert.Nil(rp.CheckVersion(fsrepoV), t, "Trouble checking the verion") 41 | 42 | assert.Err(rp.CheckVersion(1), t, "Should throw an error for the wrong version.") 43 | } 44 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Sharness test command coverage 3 | 4 | Module | Online Test | Offline Test | 5 | -----------|-----------------|-----------------| 6 | object | t0051 | t0051 7 | ls | t0045 | t0045 8 | cat | t0040 | 9 | dht | | 10 | bitswap | | 11 | block | | t0050 12 | daemon | t0030 | N/A 13 | init | N/A | t0020 14 | add | t0040 | 15 | config | t0021 | t0021 16 | version | t0060 | t0010 17 | ping | | 18 | diag | | 19 | mount | t0030 | 20 | name | t0110 | t0100 21 | pin | t0080 | 22 | get | t0090 | t0090 23 | refs | t0080 | 24 | repo gc | t0080 | 25 | id | | 26 | bootstrap | t0120 | t0120 27 | swarm | | 28 | update | | 29 | commands | | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmd/ipfs/dist/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /core/corehttp/ipns_hostname.go: -------------------------------------------------------------------------------- 1 | package corehttp 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "net/http" 7 | "strings" 8 | 9 | "github.com/ipfs/go-ipfs/core" 10 | 11 | isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain" 12 | ) 13 | 14 | // IPNSHostnameOption rewrites an incoming request if its Host: header contains 15 | // an IPNS name. 16 | // The rewritten request points at the resolved name on the gateway handler. 17 | func IPNSHostnameOption() ServeOption { 18 | return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 19 | childMux := http.NewServeMux() 20 | mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 21 | ctx, cancel := context.WithCancel(n.Context()) 22 | defer cancel() 23 | 24 | host := strings.SplitN(r.Host, ":", 2)[0] 25 | if len(host) > 0 && isd.IsDomain(host) { 26 | name := "/ipns/" + host 27 | if _, err := n.Namesys.Resolve(ctx, name); err == nil { 28 | r.Header["X-Ipns-Original-Path"] = []string{r.URL.Path} 29 | r.URL.Path = name + r.URL.Path 30 | } 31 | } 32 | childMux.ServeHTTP(w, r) 33 | }) 34 | return childMux, nil 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/sharness/t0101-iptb-name.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2014 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test ipfs repo operations" 8 | 9 | . lib/test-lib.sh 10 | 11 | num_nodes=4 12 | 13 | test_expect_success "set up an iptb cluster" ' 14 | iptb init -n $num_nodes -p 0 -f --bootstrap=none 15 | ' 16 | 17 | startup_cluster $num_nodes 18 | 19 | test_expect_success "add an obect on one node" ' 20 | echo "ipns is super fun" > file && 21 | HASH_FILE=$(ipfsi 1 add -q file) 22 | ' 23 | 24 | test_expect_success "publish that object as an ipns entry" ' 25 | ipfsi 1 name publish $HASH_FILE 26 | ' 27 | 28 | test_expect_success "add an entry on another node pointing to that one" ' 29 | NODE1_ID=$(iptb get id 1) && 30 | ipfsi 2 name publish /ipns/$NODE1_ID 31 | ' 32 | 33 | test_expect_success "cat that entry on a third node" ' 34 | NODE2_ID=$(iptb get id 2) && 35 | ipfsi 3 cat /ipns/$NODE2_ID > output 36 | ' 37 | 38 | test_expect_success "ensure output was the same" ' 39 | test_cmp file output 40 | ' 41 | 42 | test_expect_success "shut down iptb" ' 43 | iptb stop 44 | ' 45 | 46 | test_done 47 | -------------------------------------------------------------------------------- /test/sharness/lib/iptb-lib.sh: -------------------------------------------------------------------------------- 1 | # iptb test framework 2 | # 3 | # Copyright (c) 2014, 2016 Jeromy Johnson, Christian Couder 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | 6 | export IPTB_ROOT="$(pwd)/.iptb" 7 | 8 | ipfsi() { 9 | dir="$1" 10 | shift 11 | IPFS_PATH="$IPTB_ROOT/$dir" ipfs "$@" 12 | } 13 | 14 | check_has_connection() { 15 | node="$1" 16 | ipfsi "$node" swarm peers >"swarm_peers_$node" && 17 | grep "ipfs" "swarm_peers_$node" >/dev/null 18 | } 19 | 20 | startup_cluster() { 21 | num_nodes="$1" 22 | shift 23 | other_args="$@" 24 | bound=$(expr "$num_nodes" - 1) 25 | 26 | if test -n "$other_args"; then 27 | test_expect_success "start up nodes with additional args" ' 28 | iptb start --args $other_args 29 | ' 30 | else 31 | test_expect_success "start up nodes" ' 32 | iptb start 33 | ' 34 | fi 35 | 36 | test_expect_success "connect nodes to eachother" ' 37 | iptb connect [1-$bound] 0 38 | ' 39 | 40 | for i in $(test_seq 0 "$bound") 41 | do 42 | test_expect_success "node $i is connected" ' 43 | check_has_connection "$i" || 44 | test_fsh cat "swarm_peers_$i" 45 | ' 46 | done 47 | } 48 | -------------------------------------------------------------------------------- /test/3nodetest/run-test-on-img.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ "$#" -ne 1 ]; then 3 | echo "usage: $0 " 4 | echo "runs this test on image matching " 5 | exit 1 6 | fi 7 | 8 | # this tag is used by the dockerfiles in 9 | # {data, server, client, bootstrap} 10 | tag=zaqwsx_ipfs-test-img 11 | 12 | # could use set -v, but i dont want to see the comments... 13 | 14 | img=$(docker images | grep $1 | awk '{print $3}') 15 | echo "using docker image: $img ($1)" 16 | 17 | echo docker tag -f $img $tag 18 | docker tag -f $img $tag 19 | 20 | echo "fig build --no-cache" 21 | fig build --no-cache 22 | 23 | echo "fig up --no-color | tee build/fig.log" 24 | fig up --no-color | tee build/fig.log 25 | 26 | # save the ipfs logs for inspection 27 | echo "make save_logs" 28 | make save_logs || true # don't fail 29 | 30 | # save the ipfs logs for inspection 31 | echo "make save_profiling_data" 32 | make save_profiling_data || true # don't fail 33 | 34 | # fig up won't report the error using an error code, so we grep the 35 | # fig.log file to find out whether the call succeeded 36 | echo 'tail build/fig.log | grep "exited with code 0"' 37 | tail build/fig.log | grep "exited with code 0" 38 | -------------------------------------------------------------------------------- /repo/fsrepo/migrations/mfsr.go: -------------------------------------------------------------------------------- 1 | package mfsr 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "path" 8 | "strconv" 9 | "strings" 10 | ) 11 | 12 | const VersionFile = "version" 13 | 14 | type RepoPath string 15 | 16 | func (rp RepoPath) VersionFile() string { 17 | return path.Join(string(rp), VersionFile) 18 | } 19 | 20 | func (rp RepoPath) Version() (int, error) { 21 | if rp == "" { 22 | return 0, fmt.Errorf("invalid repo path \"%s\"", rp) 23 | } 24 | 25 | fn := rp.VersionFile() 26 | if _, err := os.Stat(fn); err != nil { 27 | return 0, err 28 | } 29 | 30 | c, err := ioutil.ReadFile(fn) 31 | if err != nil { 32 | return 0, err 33 | } 34 | 35 | s := strings.TrimSpace(string(c)) 36 | return strconv.Atoi(s) 37 | } 38 | 39 | func (rp RepoPath) CheckVersion(version int) error { 40 | v, err := rp.Version() 41 | if err != nil { 42 | return err 43 | } 44 | 45 | if v != version { 46 | return fmt.Errorf("versions differ (expected: %d, actual:%d)", version, v) 47 | } 48 | 49 | return nil 50 | } 51 | 52 | func (rp RepoPath) WriteVersion(version int) error { 53 | fn := rp.VersionFile() 54 | return ioutil.WriteFile(fn, []byte(fmt.Sprintf("%d\n", version)), 0644) 55 | } 56 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-detect-race/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random-files/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/mitchellh/go-homedir/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/dependencies/ma-pipe-unidir/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Łukasz Magiera 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /core/commands/unixfs/unixfs.go: -------------------------------------------------------------------------------- 1 | package unixfs 2 | 3 | import ( 4 | cmds "github.com/ipfs/go-ipfs/commands" 5 | e "github.com/ipfs/go-ipfs/core/commands/e" 6 | 7 | "gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit" 8 | ) 9 | 10 | var UnixFSCmd = &cmds.Command{ 11 | Helptext: cmdkit.HelpText{ 12 | Tagline: "Interact with IPFS objects representing Unix filesystems.", 13 | ShortDescription: ` 14 | 'ipfs file' provides a familiar interface to file systems represented 15 | by IPFS objects, which hides ipfs implementation details like layout 16 | objects (e.g. fanout and chunking). 17 | `, 18 | LongDescription: ` 19 | 'ipfs file' provides a familiar interface to file systems represented 20 | by IPFS objects, which hides ipfs implementation details like layout 21 | objects (e.g. fanout and chunking). 22 | `, 23 | }, 24 | 25 | Subcommands: map[string]*cmds.Command{ 26 | "ls": LsCmd, 27 | }, 28 | } 29 | 30 | // copy+pasted from ../commands.go 31 | func unwrapOutput(i interface{}) (interface{}, error) { 32 | var ( 33 | ch <-chan interface{} 34 | ok bool 35 | ) 36 | 37 | if ch, ok = i.(<-chan interface{}); !ok { 38 | return nil, e.TypeErr(ch, i) 39 | } 40 | 41 | return <-ch, nil 42 | } 43 | -------------------------------------------------------------------------------- /repo/repo.go: -------------------------------------------------------------------------------- 1 | package repo 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | 7 | filestore "github.com/ipfs/go-ipfs/filestore" 8 | keystore "github.com/ipfs/go-ipfs/keystore" 9 | config "github.com/ipfs/go-ipfs/repo/config" 10 | 11 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 12 | ma "gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr" 13 | ) 14 | 15 | var ( 16 | ErrApiNotRunning = errors.New("api not running") 17 | ) 18 | 19 | type Repo interface { 20 | Config() (*config.Config, error) 21 | SetConfig(*config.Config) error 22 | 23 | SetConfigKey(key string, value interface{}) error 24 | GetConfigKey(key string) (interface{}, error) 25 | 26 | Datastore() Datastore 27 | GetStorageUsage() (uint64, error) 28 | 29 | Keystore() keystore.Keystore 30 | 31 | FileManager() *filestore.FileManager 32 | 33 | // SetAPIAddr sets the API address in the repo. 34 | SetAPIAddr(addr ma.Multiaddr) error 35 | 36 | SwarmKey() ([]byte, error) 37 | 38 | io.Closer 39 | } 40 | 41 | // Datastore is the interface required from a datastore to be 42 | // acceptable to FSRepo. 43 | type Datastore interface { 44 | ds.Batching // should be threadsafe, just be careful 45 | io.Closer 46 | } 47 | -------------------------------------------------------------------------------- /test/3nodetest/server/run.sh: -------------------------------------------------------------------------------- 1 | # must be connected to bootstrap node 2 | ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE 3 | ipfs bootstrap # list bootstrap nodes for debugging 4 | 5 | # wait for daemon to start/bootstrap 6 | # alternatively use ipfs swarm connect 7 | echo "3nodetest> starting server daemon" 8 | 9 | # run daemon in debug mode to collect profiling data 10 | ipfs daemon --debug & 11 | sleep 3 12 | # TODO instead of bootrapping: ipfs swarm connect /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE 13 | 14 | # change dir before running add commands so ipfs client profiling data doesn't 15 | # overwrite the daemon profiling data 16 | cd /tmp 17 | 18 | # must mount this volume from data container 19 | ipfs add -q /data/filetiny > tmptiny 20 | mv tmptiny /data/idtiny 21 | echo "3nodetest> added tiny file. hash is" $(cat /data/idtiny) 22 | 23 | ipfs add -q /data/filerand > tmprand 24 | mv tmprand /data/idrand 25 | echo "3nodetest> added rand file. hash is" $(cat /data/idrand) 26 | 27 | # allow ample time for the client to pull the data 28 | sleep 10000000 29 | -------------------------------------------------------------------------------- /test/sharness/t0210-tar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2015 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test tar commands" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | test_expect_success "create some random files" ' 14 | mkdir foo && 15 | random 10000 > foo/a && 16 | random 12345 > foo/b && 17 | mkdir foo/bar && 18 | random 5432 > foo/bar/baz && 19 | ln -s ../a foo/bar/link && 20 | echo "exit" > foo/script && 21 | chmod +x foo/script 22 | ' 23 | 24 | test_expect_success "tar those random files up" ' 25 | tar cf files.tar foo/ 26 | ' 27 | 28 | test_expect_success "'ipfs tar add' succeeds" ' 29 | TAR_HASH=$(ipfs tar add files.tar) 30 | ' 31 | 32 | test_expect_success "'ipfs tar cat' succeeds" ' 33 | mkdir output && 34 | ipfs tar cat $TAR_HASH > output/out.tar 35 | ' 36 | 37 | test_expect_success "can extract tar" ' 38 | tar xf output/out.tar -C output/ 39 | ' 40 | 41 | test_expect_success "files look right" ' 42 | diff foo/a output/foo/a && 43 | diff foo/b output/foo/b && 44 | diff foo/bar/baz output/foo/bar/baz && 45 | [ -L output/foo/bar/link ] && 46 | [ -x foo/script ] 47 | ' 48 | 49 | test_done 50 | -------------------------------------------------------------------------------- /test/dependencies/go-sleep/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Juan Batiz-Benet 4 | Copyright (c) 2015 Christian Couder 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /test/dependencies/go-timeout/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Jakub "Kubuxu" Sztandera 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /test/sharness/t0065-active-requests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test active request commands" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | test_launch_ipfs_daemon 13 | 14 | test_expect_success "command works" ' 15 | ipfs diag cmds > cmd_out 16 | ' 17 | 18 | test_expect_success "invoc shows up in output" ' 19 | grep "diag/cmds" cmd_out > /dev/null 20 | ' 21 | 22 | test_expect_success "start longer running command" ' 23 | ipfs log tail & 24 | LOGPID=$! 25 | go-sleep 100ms 26 | ' 27 | 28 | test_expect_success "long running command shows up" ' 29 | ipfs diag cmds > cmd_out2 30 | ' 31 | 32 | test_expect_success "output looks good" ' 33 | grep "log/tail" cmd_out2 | grep "true" > /dev/null 34 | ' 35 | 36 | test_expect_success "kill log cmd" ' 37 | kill $LOGPID 38 | go-sleep 0.5s 39 | kill $LOGPID 40 | 41 | wait $LOGPID || true 42 | ' 43 | 44 | test_expect_success "long running command inactive" ' 45 | ipfs diag cmds > cmd_out3 46 | ' 47 | 48 | test_expect_success "command shows up as inactive" ' 49 | grep "log/tail" cmd_out3 | grep "false" 50 | ' 51 | 52 | test_kill_ipfs_daemon 53 | test_done 54 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | #### Version information: 8 | 9 | 10 | #### Type: 11 | 12 | 18 | #### Severity: 19 | 20 | #### Description: 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | -------------------------------------------------------------------------------- /assets/init-doc/security-notes: -------------------------------------------------------------------------------- 1 | IPFS Alpha Security Notes 2 | 3 | We try hard to ensure our system is safe and robust, but all software 4 | has bugs, especially new software. This distribution is meant to be an 5 | alpha preview, don't use it for anything mission critical. 6 | 7 | Please note the following: 8 | 9 | - This is alpha software and has not been audited. It is our goal 10 | to conduct a proper security audit once we close in on a 1.0 release. 11 | 12 | - ipfs is a networked program, and may have serious undiscovered 13 | vulnerabilities. It is written in Go, and we do not execute any 14 | user provided data. But please point any problems out to us in a 15 | github issue, or email security@ipfs.io privately. 16 | 17 | - security@ipfs.io GPG key: 18 | - 4B9665FB 92636D17 7C7A86D3 50AAE8A9 59B13AF3 19 | - https://pgp.mit.edu/pks/lookup?op=get&search=0x50AAE8A959B13AF3 20 | 21 | - ipfs uses encryption for all communication, but it's NOT PROVEN SECURE 22 | YET! It may be totally broken. For now, the code is included to make 23 | sure we benchmark our operations with encryption in mind. In the future, 24 | there will be an "unsafe" mode for high performance intranet apps. 25 | If this is a blocking feature for you, please contact us. 26 | -------------------------------------------------------------------------------- /bin/check_go_version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Check that the go version is at least equal to a minimum version 4 | # number. 5 | # 6 | # Call it for example like this: 7 | # 8 | # $ check_go_version "1.5.2" 9 | # 10 | 11 | USAGE="$0 GO_MIN_VERSION" 12 | 13 | die() { 14 | printf >&2 "fatal: %s\n" "$@" 15 | exit 1 16 | } 17 | 18 | # Get arguments 19 | 20 | test "$#" -eq "1" || die "This program must be passed exactly 1 arguments" "Usage: $USAGE" 21 | 22 | GO_MIN_VERSION="$1" 23 | 24 | UPGRADE_MSG="Please take a look at https://golang.org/doc/install to install or upgrade go." 25 | 26 | # Get path to the directory containing this file 27 | # If $0 has no slashes, uses "./" 28 | PREFIX=$(expr "$0" : "\(.*\/\)") || PREFIX='./' 29 | # Include the 'check_at_least_version' function 30 | . ${PREFIX}check_version 31 | 32 | # Check that the go binary exist and is in the path 33 | 34 | type go >/dev/null 2>&1 || die_upgrade "go is not installed or not in the PATH!" 35 | 36 | # Check the go binary version 37 | 38 | VERS_STR=$(go version 2>&1) || die "'go version' failed with output: $VERS_STR" 39 | 40 | GO_CUR_VERSION=$(expr "$VERS_STR" : ".*go version go\([^ ]*\) .*") || die "Invalid 'go version' output: $VERS_STR" 41 | 42 | check_at_least_version "$GO_MIN_VERSION" "$GO_CUR_VERSION" "go" 43 | -------------------------------------------------------------------------------- /docs/plugins.md: -------------------------------------------------------------------------------- 1 | # Plugins 2 | 3 | Since 0.4.11 go-ipfs has an experimental plugin system that allows augmenting 4 | the daemons functionality without recompiling. 5 | 6 | When an IPFS node is created, it will load plugins from the `$IPFS_PATH/plugins` 7 | directory (by default `~/.ipfs/plugins`). 8 | 9 | ### Plugin types 10 | 11 | #### IPLD 12 | IPLD plugins add support for additional formats to `ipfs dag` and other IPLD 13 | related commands. 14 | 15 | ### Supported plugins 16 | 17 | | Name | Type | 18 | |------|------| 19 | | git | IPLD | 20 | 21 | #### Installation 22 | 23 | ##### Linux 24 | 25 | 1. Build included plugins: 26 | ```bash 27 | go-ipfs$ make build_plugins 28 | go-ipfs$ ls plugin/plugins/*.so 29 | ``` 30 | 31 | 3. Copy desired plugins to `$IPFS_PATH/plugins` 32 | ```bash 33 | go-ipfs$ mkdir -p ~/.ipfs/plugins/ 34 | go-ipfs$ cp plugin/plugins/git.so ~/.ipfs/plugins/ 35 | go-ipfs$ chmod +x ~/.ipfs/plugins/git.so # ensure plugin is executable 36 | ``` 37 | 38 | 4. Restart daemon if it is running 39 | 40 | ##### Other 41 | 42 | Go currently only supports plugins on Linux, for other platforms you will need 43 | to compile them into IPFS binary. 44 | 45 | 1. Uncomment plugin entries in `plugin/loader/preload_list` 46 | 2. Build ipfs 47 | ```bash 48 | go-ipfs$ make build 49 | ``` 50 | -------------------------------------------------------------------------------- /unixfs/hamt/util_test.go: -------------------------------------------------------------------------------- 1 | package hamt 2 | 3 | import ( 4 | "math/big" 5 | "testing" 6 | ) 7 | 8 | func TestPopCount(t *testing.T) { 9 | x := big.NewInt(0) 10 | 11 | for i := 0; i < 50; i++ { 12 | x.SetBit(x, i, 1) 13 | } 14 | 15 | if popCount(x) != 50 { 16 | t.Fatal("expected popcount to be 50") 17 | } 18 | } 19 | 20 | func TestHashBitsEvenSizes(t *testing.T) { 21 | buf := []byte{255, 127, 79, 45, 116, 99, 35, 17} 22 | hb := hashBits{b: buf} 23 | 24 | for _, v := range buf { 25 | if hb.Next(8) != int(v) { 26 | t.Fatal("got wrong numbers back") 27 | } 28 | } 29 | } 30 | 31 | func TestHashBitsUneven(t *testing.T) { 32 | buf := []byte{255, 127, 79, 45, 116, 99, 35, 17} 33 | hb := hashBits{b: buf} 34 | 35 | v := hb.Next(4) 36 | if v != 15 { 37 | t.Fatal("should have gotten 15: ", v) 38 | } 39 | 40 | v = hb.Next(4) 41 | if v != 15 { 42 | t.Fatal("should have gotten 15: ", v) 43 | } 44 | 45 | if v := hb.Next(3); v != 3 { 46 | t.Fatalf("expected 3, but got %b", v) 47 | } 48 | if v := hb.Next(3); v != 7 { 49 | t.Fatalf("expected 7, but got %b", v) 50 | } 51 | if v := hb.Next(3); v != 6 { 52 | t.Fatalf("expected 6, but got %b", v) 53 | } 54 | 55 | if v := hb.Next(15); v != 20269 { 56 | t.Fatalf("expected 20269, but got %b (%d)", v, v) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /circle.yml: -------------------------------------------------------------------------------- 1 | machine: 2 | environment: 3 | TEST_NO_FUSE: 1 4 | TEST_VERBOSE: 1 5 | TEST_NO_DOCKER: 1 6 | TRAVIS: 1 7 | CIRCLE: 1 8 | IMPORT_PATH: "github.com/ipfs/go-ipfs" 9 | GOPATH: "$HOME/.go_workspace" 10 | GOBIN: "$GOPATH/bin" 11 | SERVICE: "circle-ci" 12 | 13 | post: 14 | - sudo rm -rf /usr/local/go 15 | - if [ ! -e go1.8.3.linux-amd64.tar.gz ]; then curl -o go1.8.3.linux-amd64.tar.gz https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz; fi 16 | - sudo tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz 17 | 18 | services: 19 | - docker 20 | 21 | dependencies: 22 | pre: 23 | # setup ipv6 24 | - sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.all.disable_ipv6=0 25 | 26 | override: 27 | - rm -rf "$HOME/.go_workspace/src/$IMPORT_PATH" 28 | - mkdir -p "$HOME/.go_workspace/src/$IMPORT_PATH" 29 | - cp -aT . "$HOME/.go_workspace/src/$IMPORT_PATH" 30 | - cd "$HOME/.go_workspace/src/$IMPORT_PATH" && make deps 31 | 32 | cache_directories: 33 | - ~/go1.8.3.linux-amd64.tar.gz 34 | - "$HOME/.go_workspace/src/gx/ipfs" 35 | 36 | test: 37 | override: 38 | - bin/circle.sh: 39 | pwd: "../.go_workspace/src/$IMPORT_PATH" 40 | parallel: true 41 | -------------------------------------------------------------------------------- /thirdparty/datastore2/delayed.go: -------------------------------------------------------------------------------- 1 | package datastore2 2 | 3 | import ( 4 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 5 | dsq "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/query" 6 | 7 | delay "github.com/ipfs/go-ipfs/thirdparty/delay" 8 | ) 9 | 10 | func WithDelay(ds ds.Datastore, delay delay.D) ds.Datastore { 11 | return &delayed{ds: ds, delay: delay} 12 | } 13 | 14 | type delayed struct { 15 | ds ds.Datastore 16 | delay delay.D 17 | } 18 | 19 | func (dds *delayed) Put(key ds.Key, value interface{}) (err error) { 20 | dds.delay.Wait() 21 | return dds.ds.Put(key, value) 22 | } 23 | 24 | func (dds *delayed) Get(key ds.Key) (value interface{}, err error) { 25 | dds.delay.Wait() 26 | return dds.ds.Get(key) 27 | } 28 | 29 | func (dds *delayed) Has(key ds.Key) (exists bool, err error) { 30 | dds.delay.Wait() 31 | return dds.ds.Has(key) 32 | } 33 | 34 | func (dds *delayed) Delete(key ds.Key) (err error) { 35 | dds.delay.Wait() 36 | return dds.ds.Delete(key) 37 | } 38 | 39 | func (dds *delayed) Query(q dsq.Query) (dsq.Results, error) { 40 | dds.delay.Wait() 41 | return dds.ds.Query(q) 42 | } 43 | 44 | func (dds *delayed) Batch() (ds.Batch, error) { 45 | return ds.NewBasicBatch(dds), nil 46 | } 47 | 48 | var _ ds.Datastore = &delayed{} 49 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/jbenet/go-random/random/random.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | 8 | random "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-random" 9 | "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" 10 | ) 11 | 12 | func main() { 13 | l := len(os.Args) 14 | if l != 2 && l != 3 { 15 | usageError() 16 | } 17 | 18 | countuint64, err := humanize.ParseBytes(os.Args[1]) 19 | if err != nil { 20 | usageError() 21 | } 22 | count := int64(countuint64) 23 | 24 | if l == 2 { 25 | err = random.WriteRandomBytes(count, os.Stdout) 26 | } else { 27 | seed, err2 := strconv.ParseInt(os.Args[2], 10, 64) 28 | if err2 != nil { 29 | usageError() 30 | } 31 | err = random.WritePseudoRandomBytes(count, os.Stdout, seed) 32 | } 33 | 34 | if err != nil { 35 | die(err) 36 | } 37 | } 38 | 39 | func usageError() { 40 | fmt.Fprintf(os.Stderr, "Usage: %s []\n", os.Args[0]) 41 | fmt.Fprintf(os.Stderr, "If is given, output pseudo random bytes made from (from Go's math/rand)\n") 42 | fmt.Fprintf(os.Stderr, "Otherwise, output random bytes (from Go's crypto/rand)\n") 43 | os.Exit(-1) 44 | } 45 | 46 | func die(err error) { 47 | fmt.Fprintf(os.Stderr, "Error: %v", err) 48 | os.Exit(-1) 49 | } 50 | -------------------------------------------------------------------------------- /ci/Dockerfile.buildenv: -------------------------------------------------------------------------------- 1 | FROM golang:1.8 2 | MAINTAINER Jakub Sztandera 3 | 4 | 5 | RUN apt-get update && apt-get install -y --no-install-recommends \ 6 | netcat-openbsd bash curl \ 7 | sudo \ 8 | && rm -rf /var/lib/apt/lists/* 9 | 10 | ENV GOBIN $GOPATH/bin 11 | ENV SRC_PATH /go/src/github.com/ipfs/go-ipfs 12 | 13 | RUN curl -s https://codecov.io/bash > /usr/bin/codecov && chmod +x /usr/bin/codecov \ 14 | && go get -u github.com/Kubuxu/gocovmerge && go get -u golang.org/x/tools/cmd/cover 15 | ENV IPFS_SKIP_COVER_BINS 1 16 | 17 | 18 | RUN useradd user 19 | RUN chown -R user $GOPATH 20 | 21 | WORKDIR $SRC_PATH 22 | 23 | COPY ./bin $SRC_PATH/bin/ 24 | COPY ./mk $SRC_PATH/mk/ 25 | RUN chown -R user $GOPATH 26 | 27 | USER user 28 | # install gx and gx-go 29 | RUN make -j 4 -f bin/Rules.mk d=bin bin/gx bin/gx-go && cp bin/gx bin/gx-go $GOBIN 30 | USER root 31 | ENV IPFS_GX_USE_GLOBAL 1 32 | 33 | COPY package.json $SRC_PATH/ 34 | ENV PATH $SRC_PATH/bin:$PATH 35 | 36 | USER user 37 | RUN make -f mk/gx.mk gx-deps 38 | USER root 39 | 40 | COPY . $SRC_PATH 41 | RUN chown -R user:user $GOPATH 42 | USER user 43 | # mkdir .git/objects is required for git to detect repo 44 | RUN mkdir .git/objects && make cmd/ipfs/ipfs #populate go cache 45 | 46 | CMD ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"] 47 | -------------------------------------------------------------------------------- /test/dependencies/go-timeout/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | "os/exec" 8 | "strconv" 9 | "syscall" 10 | "time" 11 | ) 12 | 13 | func main() { 14 | if len(os.Args) < 3 { 15 | fmt.Fprintf(os.Stderr, 16 | "Usage: %s \n", os.Args[0]) 17 | os.Exit(1) 18 | } 19 | timeout, err := strconv.ParseUint(os.Args[1], 10, 32) 20 | if err != nil { 21 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) 22 | os.Exit(1) 23 | } 24 | ctx, _ := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second) 25 | 26 | cmd := exec.CommandContext(ctx, os.Args[2], os.Args[3:]...) 27 | cmd.Stdin = os.Stdin 28 | cmd.Stdout = os.Stdout 29 | cmd.Stderr = os.Stderr 30 | err = cmd.Start() 31 | if err != nil { 32 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) 33 | } 34 | err = cmd.Wait() 35 | 36 | if err != nil { 37 | if ctx.Err() != nil { 38 | os.Exit(124) 39 | } else { 40 | exitErr, ok := err.(*exec.ExitError) 41 | if !ok { 42 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) 43 | os.Exit(255) 44 | } 45 | waits, ok := exitErr.Sys().(syscall.WaitStatus) 46 | if !ok { 47 | fmt.Fprintf(os.Stderr, "Error: %v\n", err) 48 | os.Exit(255) 49 | } 50 | os.Exit(waits.ExitStatus()) 51 | } 52 | } else { 53 | os.Exit(0) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /namesys/base.go: -------------------------------------------------------------------------------- 1 | package namesys 2 | 3 | import ( 4 | "strings" 5 | 6 | context "context" 7 | 8 | path "github.com/ipfs/go-ipfs/path" 9 | ) 10 | 11 | type resolver interface { 12 | // resolveOnce looks up a name once (without recursion). 13 | resolveOnce(ctx context.Context, name string) (value path.Path, err error) 14 | } 15 | 16 | // resolve is a helper for implementing Resolver.ResolveN using resolveOnce. 17 | func resolve(ctx context.Context, r resolver, name string, depth int, prefixes ...string) (path.Path, error) { 18 | for { 19 | p, err := r.resolveOnce(ctx, name) 20 | if err != nil { 21 | log.Warningf("Could not resolve %s", name) 22 | return "", err 23 | } 24 | log.Debugf("Resolved %s to %s", name, p.String()) 25 | 26 | if strings.HasPrefix(p.String(), "/ipfs/") { 27 | // we've bottomed out with an IPFS path 28 | return p, nil 29 | } 30 | 31 | if depth == 1 { 32 | return p, ErrResolveRecursion 33 | } 34 | 35 | matched := false 36 | for _, prefix := range prefixes { 37 | if strings.HasPrefix(p.String(), prefix) { 38 | matched = true 39 | if len(prefixes) == 1 { 40 | name = strings.TrimPrefix(p.String(), prefix) 41 | } 42 | break 43 | } 44 | } 45 | 46 | if !matched { 47 | return p, nil 48 | } 49 | 50 | if depth > 1 { 51 | depth-- 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /test/bin/Rules.mk: -------------------------------------------------------------------------------- 1 | include mk/header.mk 2 | 3 | TGTS_$(d) := 4 | 5 | $(d)/random: Godeps/_workspace/src/github.com/jbenet/go-random/random 6 | $(go-build) 7 | TGTS_$(d) += $(d)/random 8 | 9 | $(d)/random-files: Godeps/_workspace/src/github.com/jbenet/go-random-files/random-files 10 | $(go-build) 11 | TGTS_$(d) += $(d)/random-files 12 | 13 | $(d)/pollEndpoint: thirdparty/pollEndpoint 14 | $(go-build) 15 | TGTS_$(d) += $(d)/pollEndpoint 16 | 17 | $(d)/go-sleep: test/dependencies/go-sleep 18 | $(go-build) 19 | TGTS_$(d) += $(d)/go-sleep 20 | 21 | $(d)/go-timeout: test/dependencies/go-timeout 22 | $(go-build) 23 | TGTS_$(d) += $(d)/go-timeout 24 | 25 | $(d)/ma-pipe-unidir: test/dependencies/ma-pipe-unidir 26 | $(go-build) 27 | TGTS_$(d) += $(d)/ma-pipe-unidir 28 | 29 | TGTS_GX_$(d) := hang-fds iptb 30 | TGTS_GX_$(d) := $(addprefix $(d)/,$(TGTS_GX_$(d))) 31 | 32 | $(TGTS_GX_$(d)): 33 | go build -i $(go-flags-with-tags) -o "$@" "$(call gx-path,$(notdir $@))" 34 | 35 | TGTS_$(d) += $(TGTS_GX_$(d)) 36 | 37 | # multihash is special 38 | $(d)/multihash: 39 | go build -i $(go-flags-with-tags) -o "$@" "gx/ipfs/$(shell gx deps find go-multihash)/go-multihash/multihash" 40 | TGTS_$(d) += $(d)/multihash 41 | 42 | $(TGTS_$(d)): $$(DEPS_GO) 43 | 44 | CLEAN += $(TGTS_$(d)) 45 | 46 | PATH := $(realpath $(d)):$(PATH) 47 | 48 | include mk/footer.mk 49 | -------------------------------------------------------------------------------- /core/coreunix/metadata.go: -------------------------------------------------------------------------------- 1 | package coreunix 2 | 3 | import ( 4 | core "github.com/ipfs/go-ipfs/core" 5 | dag "github.com/ipfs/go-ipfs/merkledag" 6 | ft "github.com/ipfs/go-ipfs/unixfs" 7 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 8 | ) 9 | 10 | func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) { 11 | c, err := cid.Decode(skey) 12 | if err != nil { 13 | return "", err 14 | } 15 | 16 | nd, err := n.DAG.Get(n.Context(), c) 17 | if err != nil { 18 | return "", err 19 | } 20 | 21 | mdnode := new(dag.ProtoNode) 22 | mdata, err := ft.BytesForMetadata(m) 23 | if err != nil { 24 | return "", err 25 | } 26 | 27 | mdnode.SetData(mdata) 28 | if err := mdnode.AddNodeLinkClean("file", nd); err != nil { 29 | return "", err 30 | } 31 | 32 | nk, err := n.DAG.Add(mdnode) 33 | if err != nil { 34 | return "", err 35 | } 36 | 37 | return nk.String(), nil 38 | } 39 | 40 | func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) { 41 | c, err := cid.Decode(skey) 42 | if err != nil { 43 | return nil, err 44 | } 45 | 46 | nd, err := n.DAG.Get(n.Context(), c) 47 | if err != nil { 48 | return nil, err 49 | } 50 | 51 | pbnd, ok := nd.(*dag.ProtoNode) 52 | if !ok { 53 | return nil, dag.ErrNotProtobuf 54 | } 55 | 56 | return ft.MetadataFromBytes(pbnd.Data()) 57 | } 58 | -------------------------------------------------------------------------------- /test/sharness/t0500-issues-and-regressions-offline.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Tests for various fixed issues and regressions." 4 | 5 | . lib/test-lib.sh 6 | 7 | # Tests go here 8 | 9 | test_expect_success "ipfs init with occupied input works - #2748" ' 10 | export IPFS_PATH="ipfs_path" 11 | echo "" | go-timeout 10 ipfs init && 12 | rm -rf ipfs_path 13 | ' 14 | test_init_ipfs 15 | 16 | test_expect_success "ipfs cat --help succeeds when input remains open" ' 17 | yes | go-timeout 1 ipfs cat --help 18 | ' 19 | 20 | test_expect_success "ipfs pin ls --help succeeds when input remains open" ' 21 | yes | go-timeout 1 ipfs pin ls --help 22 | ' 23 | 24 | test_expect_success "ipfs add on 1MB from stdin woks" ' 25 | random 1048576 42 | ipfs add -q > 1MB.hash 26 | ' 27 | 28 | test_expect_success "'ipfs refs -r -e \$(cat 1MB.hash)' succeeds" ' 29 | ipfs refs -r -e $(cat 1MB.hash) > refs-e.out 30 | ' 31 | 32 | test_expect_success "output of 'ipfs refs -e' links to separate blocks" ' 33 | grep "$(cat 1MB.hash) ->" refs-e.out 34 | ' 35 | 36 | test_expect_success "output of 'ipfs refs -e' contains all first level links" ' 37 | grep "$(cat 1MB.hash) ->" refs-e.out | sed -e '\''s/.* -> //'\'' | sort > refs-s.out && 38 | ipfs refs "$(cat 1MB.hash)" | sort > refs-one.out && 39 | test_cmp refs-s.out refs-one.out 40 | ' 41 | 42 | test_done 43 | -------------------------------------------------------------------------------- /core/corehttp/logs.go: -------------------------------------------------------------------------------- 1 | package corehttp 2 | 3 | import ( 4 | "io" 5 | "net" 6 | "net/http" 7 | 8 | core "github.com/ipfs/go-ipfs/core" 9 | logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" 10 | ) 11 | 12 | type writeErrNotifier struct { 13 | w io.Writer 14 | errs chan error 15 | } 16 | 17 | func newWriteErrNotifier(w io.Writer) (io.WriteCloser, <-chan error) { 18 | ch := make(chan error, 1) 19 | return &writeErrNotifier{ 20 | w: w, 21 | errs: ch, 22 | }, ch 23 | } 24 | 25 | func (w *writeErrNotifier) Write(b []byte) (int, error) { 26 | n, err := w.w.Write(b) 27 | if err != nil { 28 | select { 29 | case w.errs <- err: 30 | default: 31 | } 32 | } 33 | if f, ok := w.w.(http.Flusher); ok { 34 | f.Flush() 35 | } 36 | return n, err 37 | } 38 | 39 | func (w *writeErrNotifier) Close() error { 40 | select { 41 | case w.errs <- io.EOF: 42 | default: 43 | } 44 | return nil 45 | } 46 | 47 | func LogOption() ServeOption { 48 | return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 49 | mux.HandleFunc("/logs", func(w http.ResponseWriter, r *http.Request) { 50 | w.WriteHeader(200) 51 | wnf, errs := newWriteErrNotifier(w) 52 | logging.WriterGroup.AddWriter(wnf) 53 | log.Event(n.Context(), "log API client connected") 54 | <-errs 55 | }) 56 | return mux, nil 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /exchange/bitswap/testnet/peernet.go: -------------------------------------------------------------------------------- 1 | package bitswap 2 | 3 | import ( 4 | "context" 5 | 6 | bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network" 7 | mockrouting "github.com/ipfs/go-ipfs/routing/mock" 8 | testutil "gx/ipfs/QmQgLZP9haZheimMHqqAjJh2LhRmNfEoZDfbtkpeMhi9xK/go-testutil" 9 | mockpeernet "gx/ipfs/QmTzs3Gp2rU3HuNayjBVG7qBgbaKWE8bgtwJ7faRxAe9UP/go-libp2p/p2p/net/mock" 10 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 11 | peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer" 12 | ) 13 | 14 | type peernet struct { 15 | mockpeernet.Mocknet 16 | routingserver mockrouting.Server 17 | } 18 | 19 | func StreamNet(ctx context.Context, net mockpeernet.Mocknet, rs mockrouting.Server) (Network, error) { 20 | return &peernet{net, rs}, nil 21 | } 22 | 23 | func (pn *peernet) Adapter(p testutil.Identity) bsnet.BitSwapNetwork { 24 | client, err := pn.Mocknet.AddPeer(p.PrivateKey(), p.Address()) 25 | if err != nil { 26 | panic(err.Error()) 27 | } 28 | routing := pn.routingserver.ClientWithDatastore(context.TODO(), p, ds.NewMapDatastore()) 29 | return bsnet.NewFromIpfsHost(client, routing) 30 | } 31 | 32 | func (pn *peernet) HasPeer(p peer.ID) bool { 33 | for _, member := range pn.Mocknet.Peers() { 34 | if p == member { 35 | return true 36 | } 37 | } 38 | return false 39 | } 40 | 41 | var _ Network = (*peernet)(nil) 42 | -------------------------------------------------------------------------------- /test/sharness/t0022-init-default.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2014 Christian Couder 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test init command with default config" 8 | 9 | . lib/test-lib.sh 10 | 11 | cfg_key="Addresses.API" 12 | cfg_val="/ip4/0.0.0.0/tcp/5001" 13 | 14 | # test that init succeeds 15 | test_expect_success "ipfs init succeeds" ' 16 | export IPFS_PATH="$(pwd)/.ipfs" && 17 | echo "IPFS_PATH: \"$IPFS_PATH\"" && 18 | BITS="2048" && 19 | ipfs init --bits="$BITS" >actual_init || 20 | test_fsh cat actual_init 21 | ' 22 | 23 | test_expect_success ".ipfs/config has been created" ' 24 | test -f "$IPFS_PATH"/config || 25 | test_fsh ls -al .ipfs 26 | ' 27 | 28 | test_expect_success "ipfs config succeeds" ' 29 | ipfs config $cfg_flags "$cfg_key" "$cfg_val" 30 | ' 31 | 32 | test_expect_success "ipfs read config succeeds" ' 33 | IPFS_DEFAULT_CONFIG=$(cat "$IPFS_PATH"/config) 34 | ' 35 | 36 | test_expect_success "clean up ipfs dir" ' 37 | rm -rf "$IPFS_PATH" 38 | ' 39 | 40 | test_expect_success "ipfs init default config succeeds" ' 41 | echo $IPFS_DEFAULT_CONFIG | ipfs init - >actual_init || 42 | test_fsh cat actual_init 43 | ' 44 | 45 | test_expect_success "ipfs config output looks good" ' 46 | echo "$cfg_val" >expected && 47 | ipfs config "$cfg_key" >actual && 48 | test_cmp expected actual 49 | ' 50 | 51 | test_done 52 | -------------------------------------------------------------------------------- /test/3nodetest/client/run.sh: -------------------------------------------------------------------------------- 1 | ipfs bootstrap add /ip4/$BOOTSTRAP_PORT_4011_TCP_ADDR/tcp/$BOOTSTRAP_PORT_4011_TCP_PORT/ipfs/QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE 2 | ipfs bootstrap # list bootstrap nodes for debugging 3 | 4 | echo "3nodetest> starting client daemon" 5 | 6 | ipfs daemon --debug & 7 | sleep 3 8 | 9 | # switch dirs so ipfs client profiling data doesn't overwrite the ipfs daemon 10 | # profiling data 11 | cd /tmp 12 | 13 | while [ ! -f /data/idtiny ] 14 | do 15 | echo "3nodetest> waiting for server to add the file..." 16 | sleep 1 17 | done 18 | echo "3nodetest> client found file with hash:" $(cat /data/idtiny) 19 | 20 | ipfs cat $(cat /data/idtiny) > filetiny 21 | 22 | cat filetiny 23 | 24 | diff -u filetiny /data/filetiny 25 | 26 | if (($? > 0)); then 27 | printf '%s\n' 'files did not match' >&2 28 | exit 1 29 | fi 30 | 31 | while [ ! -f /data/idrand ] 32 | do 33 | echo "3nodetest> waiting for server to add the file..." 34 | sleep 1 35 | done 36 | echo "3nodetest> client found file with hash:" $(cat /data/idrand) 37 | 38 | cat /data/idrand 39 | 40 | ipfs cat $(cat /data/idrand) > filerand 41 | 42 | if (($? > 0)); then 43 | printf '%s\n' 'ipfs cat failed' >&2 44 | exit 1 45 | fi 46 | 47 | diff -u filerand /data/filerand 48 | 49 | if (($? > 0)); then 50 | printf '%s\n' 'files did not match' >&2 51 | exit 1 52 | fi 53 | 54 | echo "3nodetest> success" 55 | -------------------------------------------------------------------------------- /repo/mock.go: -------------------------------------------------------------------------------- 1 | package repo 2 | 3 | import ( 4 | "errors" 5 | 6 | filestore "github.com/ipfs/go-ipfs/filestore" 7 | keystore "github.com/ipfs/go-ipfs/keystore" 8 | "github.com/ipfs/go-ipfs/repo/config" 9 | 10 | ma "gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr" 11 | ) 12 | 13 | var errTODO = errors.New("TODO: mock repo") 14 | 15 | // Mock is not thread-safe 16 | type Mock struct { 17 | C config.Config 18 | D Datastore 19 | K keystore.Keystore 20 | } 21 | 22 | func (m *Mock) Config() (*config.Config, error) { 23 | return &m.C, nil // FIXME threadsafety 24 | } 25 | 26 | func (m *Mock) SetConfig(updated *config.Config) error { 27 | m.C = *updated // FIXME threadsafety 28 | return nil 29 | } 30 | 31 | func (m *Mock) SetConfigKey(key string, value interface{}) error { 32 | return errTODO 33 | } 34 | 35 | func (m *Mock) GetConfigKey(key string) (interface{}, error) { 36 | return nil, errTODO 37 | } 38 | 39 | func (m *Mock) Datastore() Datastore { return m.D } 40 | 41 | func (m *Mock) GetStorageUsage() (uint64, error) { return 0, nil } 42 | 43 | func (m *Mock) Close() error { return errTODO } 44 | 45 | func (m *Mock) SetAPIAddr(addr ma.Multiaddr) error { return errTODO } 46 | 47 | func (m *Mock) Keystore() keystore.Keystore { return nil } 48 | 49 | func (m *Mock) SwarmKey() ([]byte, error) { 50 | return nil, nil 51 | } 52 | 53 | func (m *Mock) FileManager() *filestore.FileManager { return nil } 54 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/whyrusleeping/chunker/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Alexander Neumann 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /test/sharness/t0086-repo-verify.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2016 Jeromy Johnson 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test ipfs repo fsck" 8 | 9 | . lib/test-lib.sh 10 | 11 | test_init_ipfs 12 | 13 | sort_rand() { 14 | case `uname` in 15 | Linux) 16 | sort -R 17 | ;; 18 | Darwin) 19 | ruby -e 'puts STDIN.readlines.shuffle' 20 | ;; 21 | *) 22 | echo "unsupported system: $(uname)" 23 | esac 24 | } 25 | 26 | check_random_corruption() { 27 | to_break=$(find "$IPFS_PATH/blocks" -type f | grep -v README | grep -v SHARDING | sort_rand | head -n 1) 28 | 29 | test_expect_success "back up file and overwrite it" ' 30 | cp "$to_break" backup_file && 31 | echo "this is super broken" > "$to_break" 32 | ' 33 | 34 | test_expect_success "repo verify detects failure" ' 35 | test_expect_code 1 ipfs repo verify 36 | ' 37 | 38 | test_expect_success "replace the object" ' 39 | cp backup_file "$to_break" 40 | ' 41 | 42 | test_expect_success "ipfs repo verify passes just fine now" ' 43 | ipfs repo verify 44 | ' 45 | } 46 | 47 | test_expect_success "create some files" ' 48 | random-files -depth=3 -dirs=4 -files=10 foobar > /dev/null 49 | ' 50 | 51 | test_expect_success "add them all" ' 52 | ipfs add -r -q foobar > /dev/null 53 | ' 54 | 55 | for i in `seq 20` 56 | do 57 | check_random_corruption 58 | done 59 | 60 | test_done 61 | -------------------------------------------------------------------------------- /repo/common/common.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func MapGetKV(v map[string]interface{}, key string) (interface{}, error) { 9 | var ok bool 10 | var mcursor map[string]interface{} 11 | var cursor interface{} = v 12 | 13 | parts := strings.Split(key, ".") 14 | for i, part := range parts { 15 | sofar := strings.Join(parts[:i], ".") 16 | 17 | mcursor, ok = cursor.(map[string]interface{}) 18 | if !ok { 19 | return nil, fmt.Errorf("%s key is not a map", sofar) 20 | } 21 | 22 | cursor, ok = mcursor[part] 23 | if !ok { 24 | return nil, fmt.Errorf("%s key has no attributes", sofar) 25 | } 26 | } 27 | return cursor, nil 28 | } 29 | 30 | func MapSetKV(v map[string]interface{}, key string, value interface{}) error { 31 | var ok bool 32 | var mcursor map[string]interface{} 33 | var cursor interface{} = v 34 | 35 | parts := strings.Split(key, ".") 36 | for i, part := range parts { 37 | mcursor, ok = cursor.(map[string]interface{}) 38 | if !ok { 39 | sofar := strings.Join(parts[:i], ".") 40 | return fmt.Errorf("%s key is not a map", sofar) 41 | } 42 | 43 | // last part? set here 44 | if i == (len(parts) - 1) { 45 | mcursor[part] = value 46 | break 47 | } 48 | 49 | cursor, ok = mcursor[part] 50 | if !ok || cursor == nil { // create map if this is empty or is null 51 | mcursor[part] = map[string]interface{}{} 52 | cursor = mcursor[part] 53 | } 54 | } 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /bin/container_daemon: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | user=ipfs 4 | repo="$IPFS_PATH" 5 | 6 | if [ `id -u` -eq 0 ]; then 7 | echo "Changing user to $user" 8 | # ensure folder is writable 9 | su-exec "$user" test -w "$repo" || chown -R -- "$user" "$repo" 10 | # restart script with new privileges 11 | exec su-exec "$user" "$0" "$@" 12 | fi 13 | 14 | # 2nd invocation with regular user 15 | ipfs version 16 | 17 | if [ -e "$repo/config" ]; then 18 | echo "Found IPFS fs-repo at $repo" 19 | else 20 | ipfs init 21 | ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 22 | ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080 23 | fi 24 | 25 | # if the first argument is daemon 26 | if [ "$1" = "daemon" ]; then 27 | # filter the first argument until 28 | # https://github.com/ipfs/go-ipfs/pull/3573 29 | # has been resolved 30 | shift 31 | else 32 | # print deprecation warning 33 | # go-ipfs used to hardcode "ipfs daemon" in it's entrypoint 34 | # this workaround supports the new syntax so people start setting daemon explicitly 35 | # when overwriting CMD 36 | echo "DEPRECATED: arguments have been set but the first argument isn't 'daemon'" >&2 37 | echo "DEPRECATED: run 'docker run ipfs/go-ipfs daemon $@' instead" >&2 38 | echo "DEPRECATED: see the following PRs for more information:" >&2 39 | echo "DEPRECATED: * https://github.com/ipfs/go-ipfs/pull/3573" >&2 40 | echo "DEPRECATED: * https://github.com/ipfs/go-ipfs/pull/3685" >&2 41 | fi 42 | 43 | exec ipfs daemon "$@" 44 | -------------------------------------------------------------------------------- /test/sharness/t0063-daemon-init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2014 Juan Batiz-Benet 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test daemon --init command" 8 | 9 | . lib/test-lib.sh 10 | 11 | # We don't want the normal test_init_ipfs but we need to make sure the 12 | # IPFS_PATH is set correctly. 13 | export IPFS_PATH="$(pwd)/.ipfs" 14 | 15 | # safety check since we will be removing the directory 16 | if [ -e "$IPFS_PATH" ]; then 17 | echo "$IPFS_PATH exists" 18 | exit 1 19 | fi 20 | 21 | test_ipfs_daemon_init() { 22 | # Doing it manually since we want to launch the daemon with an 23 | # empty or non-existent repo; the normal 24 | # test_launch_ipfs_daemon does not work since it assumes the 25 | # repo was created a particular way with regard to the API 26 | # server. 27 | 28 | test_expect_success "'ipfs daemon --init' succeeds" ' 29 | ipfs daemon --init >actual_daemon 2>daemon_err & 30 | IPFS_PID=$! 31 | sleep 2 && 32 | if ! kill -0 $IPFS_PID; then cat daemon_err; return 1; fi 33 | ' 34 | 35 | test_expect_success "'ipfs daemon' can be killed" ' 36 | test_kill_repeat_10_sec $IPFS_PID 37 | ' 38 | } 39 | 40 | test_expect_success "remove \$IPFS_PATH dir" ' 41 | rm -rf "$IPFS_PATH" 42 | ' 43 | test_ipfs_daemon_init 44 | 45 | test_expect_success "create empty \$IPFS_PATH dir" ' 46 | rm -rf "$IPFS_PATH" && 47 | mkdir "$IPFS_PATH" 48 | ' 49 | 50 | test_ipfs_daemon_init 51 | 52 | test_done 53 | -------------------------------------------------------------------------------- /test/3nodetest/bootstrap/config: -------------------------------------------------------------------------------- 1 | { 2 | "Identity": { 3 | "PeerID": "QmNXuBh8HFsWq68Fid8dMbGNQTh7eG6hV9rr1fQyfmfomE", 4 | "PrivKey": "CAAS4gQwggJeAgEAAoGBAL+E7A0fcQS9+CHO3YAHj+JzHnWyVA7qqtiAIYbTnp9UvHBb2VFj2Q8eeyKFZD5wHoq3AtOqmIb4TUOMEtWYqXnE8o0T9np8vyCRK5dPn5SVoUw9uax6o2X7OxO1HqTcXHNHGbracawJUdwsk4yuZUpzXLez03yocWwneR0JpVJPAgMBAAECgYAXsa4ygW1OFOKZ7CnjKQxYC738+a8EmWvBlTiQoaXCOI2HqRVdyGiWQkMhpjccsmpU5wdmgHiWWinU7YN3AYgV3cP3qAjyNLBFoxy2dKsS9AOWVwRuuRP12tD05kCCjG4rJAX0JEOClOOtzvQ7/bXarMc3/tMHW7TMLNV8MzcYwQJBAOP9aYSHp8VnsO5j32Ju5SjOQorSdcCweqeUxwlAnXz50KdbNSCMypP3TOt7VeiXTuSITtN44yh+eogF5c4ehycCQQDXDHVmPeBN7uqqqZxZwW5pdeJWvx+REiXXCLE6KEPWlcxbw1D9ublpCCFLYuM68rjq1sjsIVGtiV1tYoMdHJSZAkEA0ddMZ070fB0UHFaQJGktQoGVfXB4MQI94kBtcXanfX/xLBgmre7oBYh4o8TBLXMWigFri/iYG41N+iRzf2NZwQJBAIh8rMpufT2ZZLFaoxRIc4ZVvojmFufhR8j6CFnsElpQivq2tWHEDcx+z3rkUWopgXnzRmSwJQHqTDTPsH26lQkCQQCehmxqaQEwE/QKAI8L8YVolgY2cjUGi6qF/awnI584lDSCuJRU3R/c6nc9R8qljtlJYTtp9iUr8vuN+jt48j+6" 5 | }, 6 | "Datastore": { 7 | "Type": "leveldb", 8 | "Path": "/root/.ipfs/datastore" 9 | }, 10 | "Addresses": { 11 | "Swarm": [ 12 | "/ip4/0.0.0.0/tcp/4011" 13 | ], 14 | "API": "/ip4/127.0.0.1/tcp/5001" 15 | }, 16 | "Mounts": { 17 | "IPFS": "/ipfs", 18 | "IPNS": "/ipns" 19 | }, 20 | "Version": { 21 | "Current": "0.1.7", 22 | "Check": "error", 23 | "CheckDate": "0001-01-01T00:00:00Z", 24 | "CheckPeriod": "172800000000000", 25 | "AutoUpdate": "minor" 26 | }, 27 | "Bootstrap": [ 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /bin/check_gx_program: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Check if a gx program is installed and if its version is at least 4 | # equal to a minimum version number. 5 | # 6 | # Call it for example like this: 7 | # 8 | # $ check_gx_program "gx-go" "0.2.0" "Use 'make gx_upgrade' to install or upgrade gx-go." 9 | # 10 | # or: 11 | # 12 | # $ check_gx_program "gx" "0.3" "Use 'make gx_upgrade' to install or upgrade gx." 13 | # 14 | 15 | USAGE="$0 GX_PROGRAM_NAME GX_MIN_VERSION UPGRADE_MSG" 16 | 17 | die() { 18 | printf >&2 "fatal: %s\n" "$@" 19 | exit 1 20 | } 21 | 22 | # Get arguments 23 | 24 | test "$#" -eq "3" || die "This program must be passed exactly 3 arguments" "Usage: $USAGE" 25 | 26 | GX_PROGRAM_NAME="$1" 27 | GX_MIN_VERSION="$2" 28 | UPGRADE_MSG="$3" 29 | 30 | # Get path to the directory containing this file 31 | # If $0 has no slashes, uses "./" 32 | PREFIX=$(expr "$0" : "\(.*\/\)") || PREFIX='./' 33 | # Include the 'check_at_least_version' function 34 | . ${PREFIX}check_version 35 | 36 | # Check that the gx program exists 37 | 38 | type "$GX_PROGRAM_NAME" >/dev/null 2>&1 || die_upgrade "Program $GX_PROGRAM_NAME is not installed!" 39 | 40 | # Check the gx program version 41 | 42 | VERS_STR=$($GX_PROGRAM_NAME -v 2>&1) || die "'$GX_PROGRAM_NAME -v' failed with output: $VERS_STR" 43 | 44 | GX_CUR_VERSION=$(expr "$VERS_STR" : ".*$GX_PROGRAM_NAME.* version \(.*\)") || die "Invalid '$GX_PROGRAM_NAME -v' output: $VERS_STR" 45 | 46 | check_at_least_version "$GX_MIN_VERSION" "$GX_CUR_VERSION" "$GX_PROGRAM_NAME" 47 | -------------------------------------------------------------------------------- /core/bootstrap_test.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | config "github.com/ipfs/go-ipfs/repo/config" 8 | pstore "gx/ipfs/QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr/go-libp2p-peerstore" 9 | testutil "gx/ipfs/QmQgLZP9haZheimMHqqAjJh2LhRmNfEoZDfbtkpeMhi9xK/go-testutil" 10 | ) 11 | 12 | func TestSubsetWhenMaxIsGreaterThanLengthOfSlice(t *testing.T) { 13 | var ps []pstore.PeerInfo 14 | sizeofSlice := 100 15 | for i := 0; i < sizeofSlice; i++ { 16 | pid, err := testutil.RandPeerID() 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | 21 | ps = append(ps, pstore.PeerInfo{ID: pid}) 22 | } 23 | out := randomSubsetOfPeers(ps, 2*sizeofSlice) 24 | if len(out) != len(ps) { 25 | t.Fail() 26 | } 27 | } 28 | 29 | func TestMultipleAddrsPerPeer(t *testing.T) { 30 | var bsps []config.BootstrapPeer 31 | for i := 0; i < 10; i++ { 32 | pid, err := testutil.RandPeerID() 33 | if err != nil { 34 | t.Fatal(err) 35 | } 36 | 37 | addr := fmt.Sprintf("/ip4/127.0.0.1/tcp/5001/ipfs/%s", pid.Pretty()) 38 | bsp1, err := config.ParseBootstrapPeer(addr) 39 | if err != nil { 40 | t.Fatal(err) 41 | } 42 | 43 | addr = fmt.Sprintf("/ip4/127.0.0.1/udp/5002/utp/ipfs/%s", pid.Pretty()) 44 | bsp2, err := config.ParseBootstrapPeer(addr) 45 | if err != nil { 46 | t.Fatal(err) 47 | } 48 | 49 | bsps = append(bsps, bsp1, bsp2) 50 | } 51 | 52 | pinfos := toPeerInfos(bsps) 53 | if len(pinfos) != len(bsps)/2 { 54 | t.Fatal("expected fewer peers") 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /core/corehttp/gateway.go: -------------------------------------------------------------------------------- 1 | package corehttp 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "net/http" 7 | 8 | core "github.com/ipfs/go-ipfs/core" 9 | coreapi "github.com/ipfs/go-ipfs/core/coreapi" 10 | config "github.com/ipfs/go-ipfs/repo/config" 11 | 12 | id "gx/ipfs/QmTzs3Gp2rU3HuNayjBVG7qBgbaKWE8bgtwJ7faRxAe9UP/go-libp2p/p2p/protocol/identify" 13 | ) 14 | 15 | type GatewayConfig struct { 16 | Headers map[string][]string 17 | Writable bool 18 | PathPrefixes []string 19 | } 20 | 21 | func GatewayOption(writable bool, paths ...string) ServeOption { 22 | return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 23 | cfg, err := n.Repo.Config() 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | gateway := newGatewayHandler(n, GatewayConfig{ 29 | Headers: cfg.Gateway.HTTPHeaders, 30 | Writable: writable, 31 | PathPrefixes: cfg.Gateway.PathPrefixes, 32 | }, coreapi.NewCoreAPI(n)) 33 | 34 | for _, p := range paths { 35 | mux.Handle(p+"/", gateway) 36 | } 37 | return mux, nil 38 | } 39 | } 40 | 41 | func VersionOption() ServeOption { 42 | return func(_ *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { 43 | mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { 44 | fmt.Fprintf(w, "Commit: %s\n", config.CurrentCommit) 45 | fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion) 46 | fmt.Fprintf(w, "Protocol Version: %s\n", id.LibP2PVersion) 47 | }) 48 | return mux, nil 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /core/coredag/dagpb.go: -------------------------------------------------------------------------------- 1 | package coredag 2 | 3 | import ( 4 | "io" 5 | "io/ioutil" 6 | "math" 7 | 8 | "github.com/ipfs/go-ipfs/merkledag" 9 | 10 | cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid" 11 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 12 | mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash" 13 | ) 14 | 15 | func dagpbJSONParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { 16 | data, err := ioutil.ReadAll(r) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | nd := &merkledag.ProtoNode{} 22 | 23 | err = nd.UnmarshalJSON(data) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | nd.SetPrefix(cidPrefix(mhType, mhLen)) 29 | 30 | return []node.Node{nd}, nil 31 | } 32 | 33 | func dagpbRawParser(r io.Reader, mhType uint64, mhLen int) ([]node.Node, error) { 34 | data, err := ioutil.ReadAll(r) 35 | if err != nil { 36 | return nil, err 37 | } 38 | 39 | nd, err := merkledag.DecodeProtobuf(data) 40 | if err != nil { 41 | return nil, err 42 | } 43 | 44 | nd.SetPrefix(cidPrefix(mhType, mhLen)) 45 | 46 | return []node.Node{nd}, nil 47 | } 48 | 49 | func cidPrefix(mhType uint64, mhLen int) *cid.Prefix { 50 | if mhType == math.MaxUint64 { 51 | mhType = mh.SHA2_256 52 | } 53 | 54 | prefix := &cid.Prefix{ 55 | MhType: mhType, 56 | MhLength: mhLen, 57 | Version: 1, 58 | Codec: cid.DagProtobuf, 59 | } 60 | 61 | if mhType == mh.SHA2_256 { 62 | prefix.Version = 0 63 | } 64 | 65 | return prefix 66 | } 67 | -------------------------------------------------------------------------------- /core/corerepo/stat.go: -------------------------------------------------------------------------------- 1 | package corerepo 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | 7 | context "context" 8 | "github.com/ipfs/go-ipfs/core" 9 | fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" 10 | 11 | humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize" 12 | ) 13 | 14 | type Stat struct { 15 | NumObjects uint64 16 | RepoSize uint64 // size in bytes 17 | RepoPath string 18 | Version string 19 | StorageMax uint64 // size in bytes 20 | } 21 | 22 | // NoLimit represents the value for unlimited storage 23 | const NoLimit uint64 = math.MaxUint64 24 | 25 | func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) { 26 | r := n.Repo 27 | 28 | usage, err := r.GetStorageUsage() 29 | if err != nil { 30 | return nil, err 31 | } 32 | 33 | allKeys, err := n.Blockstore.AllKeysChan(ctx) 34 | if err != nil { 35 | return nil, err 36 | } 37 | 38 | count := uint64(0) 39 | for range allKeys { 40 | count++ 41 | } 42 | 43 | path, err := fsrepo.BestKnownPath() 44 | if err != nil { 45 | return nil, err 46 | } 47 | 48 | cfg, err := r.Config() 49 | if err != nil { 50 | return nil, err 51 | } 52 | 53 | storageMax := NoLimit 54 | if cfg.Datastore.StorageMax != "" { 55 | storageMax, err = humanize.ParseBytes(cfg.Datastore.StorageMax) 56 | if err != nil { 57 | return nil, err 58 | } 59 | } 60 | 61 | return &Stat{ 62 | NumObjects: count, 63 | RepoSize: usage, 64 | RepoPath: path, 65 | Version: fmt.Sprintf("fs-repo@%d", fsrepo.RepoVersion), 66 | StorageMax: storageMax, 67 | }, nil 68 | } 69 | -------------------------------------------------------------------------------- /docs/releases.md: -------------------------------------------------------------------------------- 1 | # go-ipfs releases 2 | 3 | ## Release Schedule 4 | go-ipfs is on a six week release schedule. Following a release, there will be 5 | five weeks for code of any type (features, bugfixes, etc) to be added. After 6 | the five weeks is up, a release canidate is tagged and only important bugfixes 7 | will be allowed up to release day. 8 | 9 | ## Pre-Release Checklist 10 | - [ ] before release, tag 'release canidate' for users to test against 11 | - if bugs are found/fixed, do another release canidate 12 | - [ ] all tests pass (no exceptions) 13 | - [ ] webui works (for most definitions of 'works') 14 | - [ ] CHANGELOG.md has been updated 15 | - use `LAST=v0.4.2 ; for n in $(git log --oneline --merges --reverse -n-1 $LAST...master | cut -d'#' -f2 | cut -d' ' -f1); do echo https://github.com/ipfs/go-ipfs/pull/$n; done` 16 | - [ ] version string in `repo/config/version.go` has been updated 17 | - [ ] tag commit with vX.Y.Z 18 | - [ ] bump version string in `repo/config/version.go` to `vX.Y.Z-dev` 19 | - [ ] update release branch to point to release commit 20 | - [ ] publish dist.ipfs.io 21 | - [ ] publish next version to https://github.com/ipfs/npm-go-ipfs 22 | 23 | ## Post-Release 24 | - Communication 25 | - [ ] Create the release issue 26 | - [ ] Announcements (both pre-release and post-release) 27 | - [ ] Twitter 28 | - [ ] IRC 29 | - [ ] Reddit 30 | - [ ] Blog post (at minimum, paste the changelog. optionally add context and thank contributors.) 31 | - [ ] Update HTTP-API Documentation on the Website using https://github.com/ipfs/http-api-docs 32 | -------------------------------------------------------------------------------- /unixfs/io/resolve.go: -------------------------------------------------------------------------------- 1 | package io 2 | 3 | import ( 4 | "context" 5 | 6 | dag "github.com/ipfs/go-ipfs/merkledag" 7 | ft "github.com/ipfs/go-ipfs/unixfs" 8 | hamt "github.com/ipfs/go-ipfs/unixfs/hamt" 9 | 10 | node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format" 11 | ) 12 | 13 | // ResolveUnixfsOnce resolves a single hop of a path through a graph in a 14 | // unixfs context. This includes handling traversing sharded directories. 15 | func ResolveUnixfsOnce(ctx context.Context, ds dag.DAGService, nd node.Node, names []string) (*node.Link, []string, error) { 16 | switch nd := nd.(type) { 17 | case *dag.ProtoNode: 18 | upb, err := ft.FromBytes(nd.Data()) 19 | if err != nil { 20 | // Not a unixfs node, use standard object traversal code 21 | lnk, err := nd.GetNodeLink(names[0]) 22 | if err != nil { 23 | return nil, nil, err 24 | } 25 | 26 | return lnk, names[1:], nil 27 | } 28 | 29 | switch upb.GetType() { 30 | case ft.THAMTShard: 31 | s, err := hamt.NewHamtFromDag(ds, nd) 32 | if err != nil { 33 | return nil, nil, err 34 | } 35 | 36 | out, err := s.Find(ctx, names[0]) 37 | if err != nil { 38 | return nil, nil, err 39 | } 40 | 41 | return out, names[1:], nil 42 | default: 43 | lnk, err := nd.GetNodeLink(names[0]) 44 | if err != nil { 45 | return nil, nil, err 46 | } 47 | 48 | return lnk, names[1:], nil 49 | } 50 | default: 51 | lnk, rest, err := nd.ResolveLink(names) 52 | if err != nil { 53 | return nil, nil, err 54 | } 55 | return lnk, rest, nil 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/3nodetest/client/config: -------------------------------------------------------------------------------- 1 | { 2 | "Addresses": { 3 | "API": "/ip4/127.0.0.1/tcp/5001", 4 | "Swarm": [ 5 | "/ip4/0.0.0.0/tcp/4031" 6 | ] 7 | }, 8 | "Bootstrap": [ 9 | ], 10 | "Datastore": { 11 | "Path": "/root/.ipfs/datastore", 12 | "Type": "leveldb" 13 | }, 14 | "Identity": { 15 | "PeerID": "Qmbtc35vdjVh5o9w2AaT2SgcWwigsaoZUpRfq2FSrFD6mb", 16 | "PrivKey": "CAAS4AQwggJcAgEAAoGBANlJUjOCbPXgYUfo1Pr6nlIjJDPNwN81ACamhaoEZ9VRHXI3fPe7RVAaaXrWLHb892mRqFi1ScE2lcMTLc7WGfyc7dwPqBOZqkVvT0KpCx3Mg246+WvnG8I3HCbWyjSP9tJflOBQxVq6qT2yZSXjNTtDdO4skd4PsPqBco53guYTAgMBAAECgYEAtIcYhrdMNBSSfp5RpZxnwbJ0t52xK0HruDEOSK2UX0Ufg+/aIjEza1QmYupi0xFltg5QojMs7hyd3Q+oNXro5tKsYVeiqrLsUh9jMjaQofzSlV9Oc+bhkkl48YWvF6Y8qx88UYAX+oJqB627H4S1gxLdNEJhPjEAD6n/jql3zUECQQDmHP75wJ7nC4TlxT1SHim5syMAqWNs/SOHnvX8yLrFV9FrMRzsD5qMlIEGBrAjaESzEck6XpbqkyxB8KKGo7OjAkEA8brtEh/AMoQ/yoSWdYT2MRbJxCAn+KG2c6Hi9AMMmJ+K779HxywpUIDYIa22hzLKYumYIuRa1X++1glOAFGq0QJAPQgXwFoMSy9M8jwcBXmmi3AtqnFCw5doIwJQL9l1X/3ot0txZlLFJOAGUHjZoqp2/h+LhYWs9U5PgLW4BYnJjQJAPydY/J0y93+5ss1FCdr8/wI3IHhOORT2t+sZgiqxxcYY5F4TAKQ2/wNKdDIQN+47FfB1gNgsKw8+6mhv6oFroQJACBF2yssNVXiXa2Na/a9tKYutGvxbm3lXzOvmpkW3FukbsObKYS344J1vdg0nzM6EWQCaiBweSA5TQ27iNW6BzQ==" 17 | }, 18 | "Mounts": { 19 | "IPFS": "/ipfs", 20 | "IPNS": "/ipns" 21 | }, 22 | "Version": { 23 | "AutoUpdate": "minor", 24 | "Check": "error", 25 | "CheckDate": "0001-01-01T00:00:00Z", 26 | "CheckPeriod": "172800000000000", 27 | "Current": "0.1.7" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/3nodetest/server/config: -------------------------------------------------------------------------------- 1 | { 2 | "Addresses": { 3 | "API": "/ip4/127.0.0.1/tcp/5001", 4 | "Swarm": [ 5 | "/ip4/0.0.0.0/tcp/4021" 6 | ] 7 | }, 8 | "Bootstrap": [ 9 | ], 10 | "Datastore": { 11 | "Path": "/root/.ipfs/datastore", 12 | "Type": "leveldb" 13 | }, 14 | "Identity": { 15 | "PeerID": "Qmbtc2C7rqmAfdeMTM7FX4YF8CeBumMCfk5Z1GBCMbMTfY", 16 | "PrivKey": "CAAS4AQwggJcAgEAAoGBANW3mJMmDSJbdRyykO0Ze5t6WL6jeTtpOhklxePBIkJL/Uil78Va/tODx6Mvv3GMCkbGvzWslTZXpaHa9vBmjE3MVZSmd5fLRybKT0zZ3juABKcx+WIVNw8JlkpEORihJdwb+5tRUC5pUcMzxqHSmGX+d6e9KZqLnv7piNKg2+r7AgMBAAECgYAqc6+w+wv82SHoM2gqULeG6MScCajZLkvGFwS5+vEtLh7/wUZhc3PO3AxZ0/A5Q9H+wRfWN5PkGYDjJ7WJhzUzGfTbrQ821JV6B3IUR4UHo2IgJkZO4EUB5L9KBUqvYxDJigtGBopgQh0EeDSS+9X8vaGmit5l4zcAfi+UGYPgMQJBAOCJQU8N2HW5SawBo2QX0bnCAAnu5Ilk2QaqwDZbDQaM5JWFcpRpGnjBhsZihHwVWvKCbnq83JhAGRQvKAEepMUCQQDzqjvIyM+Au42nP7SFDHoMjEnHW8Nimvz8zPbyrSUEHe4l9/yS4+BeRPxpwI5xgzp8g1wEYfNeXt08buYwCsy/AkBXWg5mSuSjJ+pZWGnQTtPwiGCrfJy8NteXmGYev11Z5wYmhTwGML1zrRZZp4oTG9u97LA+X6sSMB2RlKbjiKBhAkEAgl/hoSshK+YugwCpHE9ytmgRyeOlhYscNj+NGofeOHezRwmLUSUwlgAfdo4bKU1n69t1TrsCNspXYdCMxcPhjQJAMNxkJ8t2tFMpucCQfWJ09wvFKZSHX1/iD9GKWL0Qk2FcMCg3NXiqei5NL3NYqCWpdC/IfjsAEGCJrTFwp/OoUw==" 17 | }, 18 | "Mounts": { 19 | "IPFS": "/ipfs", 20 | "IPNS": "/ipns" 21 | }, 22 | "Version": { 23 | "AutoUpdate": "minor", 24 | "Check": "error", 25 | "CheckDate": "0001-01-01T00:00:00Z", 26 | "CheckPeriod": "172800000000000", 27 | "Current": "0.1.7" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /blockservice/blockservice_test.go: -------------------------------------------------------------------------------- 1 | package blockservice 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/ipfs/go-ipfs/blocks/blockstore" 7 | butil "github.com/ipfs/go-ipfs/blocks/blocksutil" 8 | offline "github.com/ipfs/go-ipfs/exchange/offline" 9 | "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format" 10 | 11 | ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore" 12 | dssync "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync" 13 | ) 14 | 15 | func TestWriteThroughWorks(t *testing.T) { 16 | bstore := &PutCountingBlockstore{ 17 | blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())), 18 | 0, 19 | } 20 | bstore2 := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) 21 | exch := offline.Exchange(bstore2) 22 | bserv := NewWriteThrough(bstore, exch) 23 | bgen := butil.NewBlockGenerator() 24 | 25 | block := bgen.Next() 26 | 27 | t.Logf("PutCounter: %d", bstore.PutCounter) 28 | bserv.AddBlock(block) 29 | if bstore.PutCounter != 1 { 30 | t.Fatalf("expected just one Put call, have: %d", bstore.PutCounter) 31 | } 32 | 33 | bserv.AddBlock(block) 34 | if bstore.PutCounter != 2 { 35 | t.Fatalf("Put should have called again, should be 2 is: %d", bstore.PutCounter) 36 | } 37 | } 38 | 39 | var _ blockstore.Blockstore = (*PutCountingBlockstore)(nil) 40 | 41 | type PutCountingBlockstore struct { 42 | blockstore.Blockstore 43 | PutCounter int 44 | } 45 | 46 | func (bs *PutCountingBlockstore) Put(block blocks.Block) error { 47 | bs.PutCounter++ 48 | return bs.Blockstore.Put(block) 49 | } 50 | -------------------------------------------------------------------------------- /plugin/loader/load.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/ipfs/go-ipfs/plugin" 8 | 9 | logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log" 10 | ) 11 | 12 | var log = logging.Logger("plugin/loader") 13 | 14 | var loadPluginsFunc = func(string) ([]plugin.Plugin, error) { 15 | return nil, nil 16 | } 17 | 18 | // LoadPlugins loads and initializes plugins. 19 | func LoadPlugins(pluginDir string) ([]plugin.Plugin, error) { 20 | plMap := make(map[string]plugin.Plugin) 21 | for _, v := range preloadPlugins { 22 | plMap[v.Name()] = v 23 | } 24 | 25 | newPls, err := loadDynamicPlugins(pluginDir) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | for _, pl := range newPls { 31 | if ppl, ok := plMap[pl.Name()]; ok { 32 | // plugin is already preloaded 33 | return nil, fmt.Errorf( 34 | "plugin: %s, is duplicated in version: %s, "+ 35 | "while trying to load dynamically: %s", 36 | ppl.Name(), ppl.Version(), pl.Version()) 37 | } 38 | plMap[pl.Name()] = pl 39 | } 40 | 41 | pls := make([]plugin.Plugin, 0, len(plMap)) 42 | for _, v := range plMap { 43 | pls = append(pls, v) 44 | } 45 | 46 | err = initialize(pls) 47 | if err != nil { 48 | return nil, err 49 | } 50 | 51 | err = run(pls) 52 | return nil, err 53 | } 54 | 55 | func loadDynamicPlugins(pluginDir string) ([]plugin.Plugin, error) { 56 | _, err := os.Stat(pluginDir) 57 | if os.IsNotExist(err) { 58 | return nil, nil 59 | } 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | return loadPluginsFunc(pluginDir) 65 | } 66 | -------------------------------------------------------------------------------- /test/sharness/t0280-plugin-git.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2017 Jakub Sztandera 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | 7 | test_description="Test git plugin" 8 | 9 | . lib/test-lib.sh 10 | 11 | # if in travis CI, dont test mount (no fuse) 12 | if ! test_have_prereq PLUGIN; then 13 | skip_all='skipping git plugin tests, plugins not available' 14 | 15 | test_done 16 | fi 17 | 18 | test_init_ipfs 19 | 20 | test_expect_success "copy plugin" ' 21 | mkdir -p "$IPFS_PATH/plugins" && 22 | cp ../plugins/git.so "$IPFS_PATH/plugins/" 23 | ' 24 | 25 | # from https://github.com/ipfs/go-ipld-git/blob/master/make-test-repo.sh 26 | test_expect_success "prepare test data" ' 27 | tar xzf ../t0280-plugin-git-data/git.tar.gz 28 | ' 29 | 30 | test_dag_git() { 31 | test_expect_success "add objects via dag put" ' 32 | find objects -type f -exec ipfs dag put --format=git --input-enc=zlib {} \; -exec echo \; > hashes 33 | ' 34 | 35 | test_expect_success "successfully get added objects" ' 36 | cat hashes | xargs -i ipfs dag get -- {} > /dev/null 37 | ' 38 | 39 | test_expect_success "path traversals work" ' 40 | echo \"YmxvYiA3ACcsLnB5Zgo=\" > file1 && 41 | ipfs dag get z8mWaJh5RLq16Zwgtd8gZxd63P4hgwNNx/object/parents/0/tree/dir2/hash/f3/hash > out1 42 | ' 43 | 44 | test_expect_success "outputs look correct" ' 45 | test_cmp file1 out1 46 | ' 47 | } 48 | 49 | # should work offline 50 | #test_dag_git 51 | 52 | # should work online 53 | test_launch_ipfs_daemon 54 | test_dag_git 55 | test_kill_ipfs_daemon 56 | 57 | test_done 58 | -------------------------------------------------------------------------------- /bin/archive-branches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -x 5 | 6 | auth="" 7 | #auth="-u kubuxu:$GH_TOKEN" 8 | org=ipfs 9 | repo=go-ipfs 10 | arch_repo=go-ipfs-archived 11 | api_repo="repos/$org/$repo" 12 | 13 | exclusions=( 14 | 'master' 15 | 'release' 16 | 'feat/zcash' 17 | ) 18 | 19 | gh_api_next() { 20 | links=$(grep '^Link:' | sed -e 's/Link: //' -e 's/, /\n/g') 21 | echo "$links" | grep '; rel="next"' >/dev/null || return 22 | link=$(echo "$links" | grep '; rel="next"' | sed -e 's/^.*//') 23 | 24 | curl $auth -f -sD >(gh_api_next) "$link" 25 | } 26 | 27 | gh_api() { 28 | curl $auth -f -sD >(gh_api_next) "https://api.github.com/$1" | jq -s '[.[] | .[]]' 29 | } 30 | 31 | pr_branches() { 32 | gh_api "$api_repo/pulls" | jq -r '.[].head.label | select(test("^ipfs:"))' \ 33 | | sed 's/^ipfs://' 34 | } 35 | 36 | origin_refs() { 37 | format=${1-'%(refname:short)'} 38 | 39 | git for-each-ref --format "$format" refs/remotes/origin | sed 's|^origin/||' 40 | } 41 | 42 | active_branches() { 43 | origin_refs '%(refname:short) %(committerdate:unix)' |awk \ 44 | ' BEGIN { monthAgo = systime() - 31*24*60*60 } 45 | { if ($2 > monthAgo) print $1 } 46 | ' 47 | } 48 | 49 | git remote add archived "git@github.com:$org/$arch_repo.git" || true 50 | 51 | cat <(active_branches) <(pr_branches) <((IFS=$'\n'; echo "${exclusions[*]}")) \ 52 | | sort -u | comm - <(origin_refs | sort) -13 |\ 53 | while read -r ref; do 54 | git push archived "origin/$ref:refs/heads/$ref/$(date --rfc-3339=date)" 55 | git push origin --delete "$ref" 56 | done 57 | 58 | -------------------------------------------------------------------------------- /docs/developer-certificate-of-origin: -------------------------------------------------------------------------------- 1 | Developer Certificate of Origin 2 | Version 1.1 3 | 4 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 5 | 1 Letterman Drive 6 | Suite D4700 7 | San Francisco, CA, 94129 8 | 9 | Everyone is permitted to copy and distribute verbatim copies of this 10 | license document, but changing it is not allowed. 11 | 12 | 13 | Developer's Certificate of Origin 1.1 14 | 15 | By making a contribution to this project, I certify that: 16 | 17 | (a) The contribution was created in whole or in part by me and I 18 | have the right to submit it under the open source license 19 | indicated in the file; or 20 | 21 | (b) The contribution is based upon previous work that, to the best 22 | of my knowledge, is covered under an appropriate open source 23 | license and I have the right under that license to submit that 24 | work with modifications, whether created in whole or in part 25 | by me, under the same open source license (unless I am 26 | permitted to submit under a different license), as indicated 27 | in the file; or 28 | 29 | (c) The contribution was provided directly to me by some other 30 | person who certified (a), (b) or (c) and I have not modified 31 | it. 32 | 33 | (d) I understand and agree that this project and the contribution 34 | are public and that a record of the contribution (including all 35 | personal information I submit with it, including my sign-off) is 36 | maintained indefinitely and may be redistributed consistent with 37 | this project or the open source license(s) involved. 38 | --------------------------------------------------------------------------------