Skip to content

Commit

Permalink
NoFetch gateway option
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
  • Loading branch information
magik6k committed Oct 26, 2018
1 parent a871f4c commit 17c877c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (
core "github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"

offline "gx/ipfs/QmT6dHGp3UYd3vUMpy7rzX2CXQv7HLcj42Vtq8qwwjgASb/go-ipfs-exchange-offline"
dag "gx/ipfs/QmY8BMUSpCwNiTmFhACmC9Bt1qT63cHP35AoQAus4x14qH/go-merkledag"
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
bserv "gx/ipfs/QmWfhv1D18DRSiSm73r4QGcByspzPtxxRTcmHW3axFXZo8/go-blockservice"
merkledag "gx/ipfs/QmY8BMUSpCwNiTmFhACmC9Bt1qT63cHP35AoQAus4x14qH/go-merkledag"
)

var log = logging.Logger("core/coreapi")
Expand Down Expand Up @@ -92,3 +95,10 @@ func (api *CoreAPI) getSession(ctx context.Context) *CoreAPI {
ng := dag.NewReadOnlyDagService(dag.NewSession(ctx, api.dag))
return &CoreAPI{api.node, ng}
}

// Offline returns new api with offline DAG
func (api *CoreAPI) Offline() *CoreAPI {
bs := api.node.Blocks.Blockstore()
ng := dag.NewDAGService(bserv.New(bs, offline.Exchange(bs)))
return &CoreAPI{api.node, ng}
}
7 changes: 6 additions & 1 deletion core/corehttp/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ func GatewayOption(writable bool, paths ...string) ServeOption {
return nil, err
}

api := coreapi.NewCoreAPI(n)
if cfg.Gateway.NoFetch {
api = api.(*coreapi.CoreAPI).Offline()
}

gateway := newGatewayHandler(n, GatewayConfig{
Headers: cfg.Gateway.HTTPHeaders,
Writable: writable,
PathPrefixes: cfg.Gateway.PathPrefixes,
}, coreapi.NewCoreAPI(n))
}, api)

for _, p := range paths {
mux.Handle(p+"/", gateway)
Expand Down

0 comments on commit 17c877c

Please sign in to comment.