Skip to content

Commit

Permalink
feat(ipfs_http): support for ipfs_http store
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Aug 21, 2019
1 parent e6341fc commit aaf7d0a
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 299 deletions.
7 changes: 3 additions & 4 deletions actions/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,17 @@ func DsyncSendBlocks(node *p2p.QriNode, location, sessionID string, manifest, di
}
ng := dag.NewNodeGetter(capi.Dag())

remote := &dsync.HTTPRemote{
remote := &dsync.HTTPClient{
URL: fmt.Sprintf("%s/dsync", location),
}

ctx := context.Background()
send, err := dsync.NewSend(ctx, ng, manifest, remote)
push, err := dsync.NewPush(ng, &dag.Info{Manifest: manifest}, remote, true)
if err != nil {
return err
}

err = send.PerformSend(sessionID, manifest, diff)
if err != nil {
if err = push.Do(ctx); err != nil {
return err
}

Expand Down
43 changes: 20 additions & 23 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import (

golog "github.com/ipfs/go-log"
"github.com/qri-io/apiutil"
"github.com/qri-io/dag"
"github.com/qri-io/dag/dsync"
"github.com/qri-io/qfs/cafs"
"github.com/qri-io/qri/lib"
"github.com/qri-io/qri/p2p"
)

var log = golog.Logger("qriapi")
Expand Down Expand Up @@ -250,18 +247,18 @@ func NewServerRoutes(s Server) *http.ServeMux {
m.Handle("/connections", s.middleware(ph.ConnectionsHandler))

if cfg.API.RemoteMode {
log.Info("This server is running in `remote` mode")
receivers, err := makeDagReceiver(node)
if err != nil {
panic(err)
}

// TODO (b5): this should be refactored to use an instance:
// remh := NewRemoteHandlers(s.inst, receivers)
remh := NewRemoteHandlers(node, cfg, receivers)
m.Handle("/dsync/push", s.middleware(remh.ReceiveHandler))
m.Handle("/dsync", s.middleware(receivers.HTTPHandler()))
m.Handle("/dsync/complete", s.middleware(remh.CompleteHandler))
// log.Info("This server is running in `remote` mode")
// receivers, err := makeDagReceiver(node)
// if err != nil {
// panic(err)
// }

// // TODO (b5): this should be refactored to use an instance:
// // remh := NewRemoteHandlers(s.inst, receivers)
// remh := NewRemoteHandlers(node, cfg, receivers)
// m.Handle("/dsync/push", s.middleware(remh.ReceiveHandler))
// m.Handle("/dsync", s.middleware(receivers.HTTPHandler()))
// m.Handle("/dsync/complete", s.middleware(remh.CompleteHandler))
}

dsh := NewDatasetHandlers(node, cfg.API.ReadOnly)
Expand Down Expand Up @@ -313,11 +310,11 @@ func NewServerRoutes(s Server) *http.ServeMux {
return m
}

// makeDagReceiver constructs a Receivers (HTTP router) from a qri p2p node
func makeDagReceiver(node *p2p.QriNode) (*dsync.Receivers, error) {
capi, err := node.IPFSCoreAPI()
if err != nil {
return nil, err
}
return dsync.NewReceivers(context.Background(), dag.NewNodeGetter(capi.Dag()), capi.Block()), nil
}
// // makeDagReceiver constructs a Receivers (HTTP router) from a qri p2p node
// func makeDagReceiver(node *p2p.QriNode) (*dsync.Receivers, error) {
// capi, err := node.IPFSCoreAPI()
// if err != nil {
// return nil, err
// }
// return dsync.NewReceivers(context.Background(), dag.NewNodeGetter(capi.Dag()), capi.Block()), nil
// }
11 changes: 4 additions & 7 deletions api/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"net/http"

util "github.com/qri-io/apiutil"
"github.com/qri-io/dag/dsync"
"github.com/qri-io/qri/config"
"github.com/qri-io/qri/lib"
"github.com/qri-io/qri/p2p"
)

// RemoteHandlers wraps a request struct to interface with http.HandlerFunc
type RemoteHandlers struct {
*lib.RemoteRequests
*lib.RemoteMethods
}

// NewRemoteHandlers allocates a RemoteHandlers pointer
func NewRemoteHandlers(node *p2p.QriNode, cfg *config.Config, rec *dsync.Receivers) *RemoteHandlers {
req := lib.NewRemoteRequests(node, cfg, nil)
req.Receivers = rec
func NewRemoteHandlers(inst *lib.Instance) *RemoteHandlers {
req := lib.NewRemoteMethods(inst)
// req.Receivers = rec
return &RemoteHandlers{req}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Factory interface {

ConfigMethods() (*lib.ConfigMethods, error)
DatasetRequests() (*lib.DatasetRequests, error)
RemoteRequests() (*lib.RemoteRequests, error)
RemoteMethods() (*lib.RemoteMethods, error)
RegistryRequests() (*lib.RegistryRequests, error)
LogRequests() (*lib.LogRequests, error)
ExportRequests() (*lib.ExportRequests, error)
Expand Down
6 changes: 3 additions & 3 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type PublishOptions struct {
RemoteName string

DatasetRequests *lib.DatasetRequests
RemoteRequests *lib.RemoteRequests
RemoteMethods *lib.RemoteMethods
}

// Complete adds any missing configuration that can only be added just before calling Run
Expand All @@ -68,7 +68,7 @@ func (o *PublishOptions) Complete(f Factory, args []string) (err error) {
if o.DatasetRequests, err = f.DatasetRequests(); err != nil {
return err
}
o.RemoteRequests, err = f.RemoteRequests()
o.RemoteMethods, err = f.RemoteMethods()
return
}

Expand All @@ -82,7 +82,7 @@ func (o *PublishOptions) Run() error {
RemoteName: o.RemoteName,
}
var res bool
if err := o.RemoteRequests.PushToRemote(&p, &res); err != nil {
if err := o.RemoteMethods.PushToRemote(&p, &res); err != nil {
return err
}
// TODO(dlong): Check if the operation succeeded or failed. Perform dsync.
Expand Down
6 changes: 3 additions & 3 deletions cmd/qri.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ func (o *QriOptions) DatasetRequests() (*lib.DatasetRequests, error) {
return lib.NewDatasetRequests(o.inst.Node(), o.inst.RPC()), nil
}

// RemoteRequests generates a lib.RemoteRequests from internal state
func (o *QriOptions) RemoteRequests() (*lib.RemoteRequests, error) {
// RemoteMethods generates a lib.RemoteMethods from internal state
func (o *QriOptions) RemoteMethods() (*lib.RemoteMethods, error) {
if err := o.Init(); err != nil {
return nil, err
}
return lib.NewRemoteRequests(o.inst.Node(), o.inst.Config(), o.inst.RPC()), nil
return lib.NewRemoteMethods(o.inst), nil
}

// RegistryRequests generates a lib.RegistryRequests from internal state
Expand Down
1 change: 1 addition & 0 deletions config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func (cfg Store) Validate() error {
"type": "string",
"enum": [
"ipfs",
"ipfs_http",
"map"
]
}
Expand Down
39 changes: 20 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@ module github.com/qri-io/qri

go 1.12

replace github.com/go-critic/go-critic v0.0.0-20181204210945-c3db6069acc5 => github.com/go-critic/go-critic v0.0.0-20190422201921-c3db6069acc5

replace github.com/go-critic/go-critic v0.0.0-20181204210945-ee9bf5809ead => github.com/go-critic/go-critic v0.0.0-20190210220443-ee9bf5809ead

replace github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6

replace github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196

replace github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98

replace github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547

replace github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217
replace (
github.com/qri-io/dag => /Users/b5/go/src/github.com/qri-io/dag
github.com/qri-io/qfs => /Users/b5/go/src/github.com/qri-io/qfs
github.com/qri-io/registry => /Users/b5/go/src/github.com/qri-io/registry
)

replace mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34
replace (
github.com/go-critic/go-critic v0.0.0-20181204210945-c3db6069acc5 => github.com/go-critic/go-critic v0.0.0-20190422201921-c3db6069acc5
github.com/go-critic/go-critic v0.0.0-20181204210945-ee9bf5809ead => github.com/go-critic/go-critic v0.0.0-20190210220443-ee9bf5809ead
github.com/golangci/errcheck v0.0.0-20181003203344-ef45e06d44b6 => github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6
github.com/golangci/go-tools v0.0.0-20180109140146-af6baa5dc196 => github.com/golangci/go-tools v0.0.0-20190318060251-af6baa5dc196
github.com/golangci/gofmt v0.0.0-20181105071733-0b8337e80d98 => github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98
github.com/golangci/gosec v0.0.0-20180901114220-66fb7fc33547 => github.com/golangci/gosec v0.0.0-20190211064107-66fb7fc33547
github.com/golangci/lint-1 v0.0.0-20180610141402-ee948d087217 => github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217
mvdan.cc/unparam v0.0.0-20190124213536-fbb59629db34 => mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34
)

require (
github.com/beme/abide v0.0.0-20181227202223-4c487ef9d895
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.0
github.com/google/flatbuffers v1.11.0
github.com/google/go-cmp v0.2.0
github.com/google/go-cmp v0.3.0
github.com/ipfs/go-cid v0.0.2
github.com/ipfs/go-ipfs v0.4.21
github.com/ipfs/go-ipld-format v0.0.2
Expand All @@ -47,7 +48,7 @@ require (
github.com/multiformats/go-multihash v0.0.5
github.com/qri-io/apiutil v0.1.0
github.com/qri-io/bleve v0.5.1-0.20190530204435-e47ddda1936d
github.com/qri-io/dag v0.1.0
github.com/qri-io/dag v0.1.1-0.20190605213518-cb095ea6b6d9
github.com/qri-io/dataset v0.1.3-0.20190719194105-19b550e95f71
github.com/qri-io/deepdiff v0.1.0
github.com/qri-io/doggos v0.1.0
Expand All @@ -62,8 +63,8 @@ require (
github.com/spf13/cobra v0.0.4
github.com/theckman/go-flock v0.7.1
go.starlark.net v0.0.0-20190528202925-30ae18b8564f
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
golang.org/x/sys v0.0.0-20190522044717-8097e1b27ff5
golang.org/x/tools/gopls v0.1.3 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae
gopkg.in/yaml.v2 v2.2.2
)
Loading

0 comments on commit aaf7d0a

Please sign in to comment.