Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Initial implementation #1

Merged
merged 71 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
93943f7
Initial structure, path stuff
magik6k Nov 6, 2018
df916c7
Partial ipld node impl
magik6k Nov 6, 2018
e06cddb
Init gx
magik6k Dec 20, 2018
a23d794
It builds
magik6k Dec 21, 2018
dfbe002
Skeleton for tests
magik6k Dec 30, 2018
d0c98b8
Block API
magik6k Jan 7, 2019
44696b8
Partial Unixfs.Add
magik6k Jan 7, 2019
0ffdef1
Partial Key API, ApiAddr funcion
magik6k Jan 8, 2019
c6472d9
Connect test swarms, don't compress api calls
magik6k Jan 8, 2019
16f77b2
Wrap single files in Unixfs.Add
magik6k Jan 8, 2019
e19e5f5
implement .Name
magik6k Jan 8, 2019
eb1944f
Implement .Unixfs.Ls()
magik6k Jan 8, 2019
dbf90ea
Imprement partian Pin API
magik6k Jan 8, 2019
6169321
Import missing unixfs dep
magik6k Jan 8, 2019
634b00b
api.WithOption
magik6k Jan 8, 2019
b31bee0
Implement Unixfs.Get()
magik6k Jan 8, 2019
3217104
Dag.Put
magik6k Jan 9, 2019
60321ed
Object.New
magik6k Jan 9, 2019
5b2c99a
Fix Dag.Put
magik6k Jan 9, 2019
2f3a77b
Unixfs.Add progress events
magik6k Jan 9, 2019
66593af
Pull updates from go-ipfs
magik6k Jan 15, 2019
281b2bf
Implement Key API
magik6k Jan 15, 2019
5bb7a58
Implement Pin API
magik6k Jan 15, 2019
38149e4
Implement Object API
magik6k Jan 15, 2019
c773550
Implement DHT Api
magik6k Jan 15, 2019
0110569
Implement Swarm Api
magik6k Jan 15, 2019
7abddda
Implement PubSub Api
magik6k Jan 15, 2019
163b25f
Use cids in DHT calls
magik6k Jan 15, 2019
f34a5f6
Reimplement DAG as DAGService
magik6k Jan 21, 2019
def6691
block: Pin option
magik6k Feb 4, 2019
904e8ee
tests: enable filestore
magik6k Feb 4, 2019
69cc3e8
apifile: Implement Seek
magik6k Feb 4, 2019
83dfd84
response: read trailing error headers
magik6k Feb 4, 2019
7bea2ef
dag: Interface updates
magik6k Feb 4, 2019
bb8d9d1
unixfs: updated ls
magik6k Feb 4, 2019
e85e856
pin: handle Rm options
magik6k Feb 4, 2019
19c65db
Check for redirects
magik6k Feb 6, 2019
fad467b
Update imports to use extracted interface
magik6k Feb 11, 2019
74ec5f5
Enable CI
magik6k Feb 12, 2019
62552b3
Fix govet warning in Dag
magik6k Feb 12, 2019
6e5a8e0
ci: build ipfs binary
magik6k Feb 12, 2019
d6c8cbd
Register iptb plugin once
magik6k Feb 12, 2019
bce6857
update iface to fix race in pubsub test
magik6k Feb 12, 2019
6bb2a28
Improve test node spawning
magik6k Feb 14, 2019
3393b83
Improve apifile error messages
magik6k Feb 14, 2019
b76413d
Implement missing methods
magik6k Feb 14, 2019
4d07c48
Don't use valid() pattern
magik6k Feb 14, 2019
934fc60
dag: remove unused waitgroup
magik6k Feb 14, 2019
0752a6e
Simplify Object.New, remove ipldnode.go
magik6k Feb 14, 2019
aa88b18
swarm: attach peerid if needed
magik6k Feb 14, 2019
81d671f
gx: fix dvcsimport
magik6k Feb 17, 2019
c880d4b
gx publish 0.0.1
magik6k Feb 17, 2019
7032dfc
pin: verify: parse bad node cids early
magik6k Feb 18, 2019
d451a49
pubsub: handle ctx
magik6k Feb 18, 2019
5c96c29
don't read all and then throw away the buffer
magik6k Feb 18, 2019
139e9e5
response: handle late errors
magik6k Feb 18, 2019
9f3d963
response: option to disable output draining
magik6k Feb 18, 2019
4926790
swarm: always append peer IDs
magik6k Feb 18, 2019
f3c2c35
gofmt
magik6k Feb 18, 2019
dbee4e2
return errors from constructor methods
magik6k Feb 19, 2019
e400fa3
pin verify: use temporary struct
magik6k Feb 19, 2019
902bc5e
response: Document zero-result Decode behaviour
magik6k Feb 19, 2019
217d194
use mime.ParseMediaType for Content-Type response parsing
magik6k Feb 19, 2019
fd7858d
cleanup Swarm.Peers
magik6k Feb 19, 2019
e34cd60
Add some docs to constructors
magik6k Feb 19, 2019
65cd935
gofmt
magik6k Feb 19, 2019
adbfda4
response: simplify Decode
magik6k Feb 20, 2019
4a87232
response: pass close error in decode
magik6k Feb 20, 2019
b7db17c
request: fix Content-Disposition header in Send
magik6k Feb 21, 2019
95ce0f3
test: don't panic on errors in async node construction
magik6k Feb 21, 2019
7941544
gx publish 0.1.0
magik6k Feb 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
os:
- linux

sudo: false

language: go

go:
- 1.11.x

install:
- make deps
- go get -d github.com/ipfs/go-ipfs
- (cd $GOPATH/src/github.com/ipfs/go-ipfs; make install)

script:
- bash <(curl -s https://github.com/raw/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)

cache:
directories:
- $GOPATH/src/gx

notifications:
email: false

env: GOTFLAGS="-race"
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
all: deps
gx:
go get github.com/whyrusleeping/gx
go get github.com/whyrusleeping/gx-go
deps: gx
gx --verbose install --global
gx-go rewrite
test: deps
gx test -v -race -coverprofile=coverage.txt -covermode=atomic .
rw:
gx-go rewrite
rwundo:
gx-go rewrite --undo
publish: rwundo
gx publish
.PHONY: all gx deps test rw rwundo publish
183 changes: 183 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package httpapi

import (
"fmt"
"io/ioutil"
gohttp "net/http"
"os"
"path"
"strings"

iface "github.com/ipfs/interface-go-ipfs-core"
caopts "github.com/ipfs/interface-go-ipfs-core/options"
homedir "github.com/mitchellh/go-homedir"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr-net"
)

const (
DefaultPathName = ".ipfs"
DefaultPathRoot = "~/" + DefaultPathName
DefaultApiFile = "api"
EnvDir = "IPFS_PATH"
)

// HttpApi implements github.com/ipfs/interface-go-ipfs-core/CoreAPI using
// IPFS HTTP API.
//
// For interface docs see
// https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
type HttpApi struct {
url string
httpcli gohttp.Client

applyGlobal func(*RequestBuilder)
}

// NewLocalApi tries to construct new HttpApi instance communicating with local
// IPFS daemon
//
// Daemon api address is pulled from the $IPFS_PATH/api file.
// If $IPFS_PATH env var is not present, it defaults to ~/.ipfs
func NewLocalApi() (iface.CoreAPI, error) {
baseDir := os.Getenv(EnvDir)
if baseDir == "" {
baseDir = DefaultPathRoot
}

return NewPathApi(baseDir)
}

// NewPathApi constructs new HttpApi by pulling api address from specified
// ipfspath. Api file should be located at $ipfspath/api
func NewPathApi(ipfspath string) (iface.CoreAPI, error) {
a, err := ApiAddr(ipfspath)
if err != nil {
if os.IsNotExist(err) {
err = nil
}
return nil, err
}
return NewApi(a)
}

// ApiAddr reads api file in specified ipfs path
func ApiAddr(ipfspath string) (ma.Multiaddr, error) {
baseDir, err := homedir.Expand(ipfspath)
if err != nil {
return nil, err
}

apiFile := path.Join(baseDir, DefaultApiFile)

api, err := ioutil.ReadFile(apiFile)
if err != nil {
return nil, err
}

return ma.NewMultiaddr(strings.TrimSpace(string(api)))
}

// NewApi constructs HttpApi with specified endpoint
func NewApi(a ma.Multiaddr) (*HttpApi, error) {
c := &gohttp.Client{
Transport: &gohttp.Transport{
Proxy: gohttp.ProxyFromEnvironment,
DisableKeepAlives: true,
},
}

return NewApiWithClient(a, c)
}

// NewApiWithClient constructs HttpApi with specified endpoint and custom http client
func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
_, url, err := manet.DialArgs(a)
if err != nil {
return nil, err
}

if a, err := ma.NewMultiaddr(url); err == nil {
_, host, err := manet.DialArgs(a)
if err == nil {
url = host
}
}

api := &HttpApi{
url: url,
httpcli: *c,
applyGlobal: func(*RequestBuilder) {},
}

// We don't support redirects.
api.httpcli.CheckRedirect = func(_ *gohttp.Request, _ []*gohttp.Request) error {
return fmt.Errorf("unexpected redirect")
}

return api, nil
}

func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error) {
options, err := caopts.ApiOptions(opts...)
if err != nil {
return nil, err
}

subApi := *api
subApi.applyGlobal = func(req *RequestBuilder) {
if options.Offline {
req.Option("offline", options.Offline)
}
}

return &subApi, nil
}

func (api *HttpApi) request(command string, args ...string) *RequestBuilder {
return &RequestBuilder{
command: command,
args: args,
shell: api,
}
}

func (api *HttpApi) Unixfs() iface.UnixfsAPI {
return (*UnixfsAPI)(api)
}

func (api *HttpApi) Block() iface.BlockAPI {
return (*BlockAPI)(api)
}

func (api *HttpApi) Dag() iface.APIDagService {
return (*HttpDagServ)(api)
}

func (api *HttpApi) Name() iface.NameAPI {
return (*NameAPI)(api)
}

func (api *HttpApi) Key() iface.KeyAPI {
return (*KeyAPI)(api)
}

func (api *HttpApi) Pin() iface.PinAPI {
return (*PinAPI)(api)
}

func (api *HttpApi) Object() iface.ObjectAPI {
return (*ObjectAPI)(api)
}

func (api *HttpApi) Dht() iface.DhtAPI {
return (*DhtAPI)(api)
}

func (api *HttpApi) Swarm() iface.SwarmAPI {
return (*SwarmAPI)(api)
}

func (api *HttpApi) PubSub() iface.PubSubAPI {
return (*PubsubAPI)(api)
}
Loading