-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remote): Beginning of "remote" mode implementation
On the remote side, the following is being added: * The flag --remote-mode which enables remote mode * An api /dataset that can be posted to, only in remote mode * Receive method that calculates size of dag, and fails if too large On the client side: * The `qri publish` command has a "--remote" to control where to publish * Publishing to a remote sends a dag.Info instead of dataset head * Remove call to CanonicalizeDatasetRef in base/ Missing: * Remote mode should act like read-only * dag.Info is a stub for now * `qri publish --remote ...` is ignoring name of remote * dSync when a push to a remote succeeds
- Loading branch information
Showing
13 changed files
with
276 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package api | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
|
||
util "github.com/datatogether/api/apiutil" | ||
"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 | ||
} | ||
|
||
// NewRemoteHandlers allocates a RemoteHandlers pointer | ||
func NewRemoteHandlers(node *p2p.QriNode) *RemoteHandlers { | ||
req := lib.NewRemoteRequests(node, nil) | ||
return &RemoteHandlers{*req} | ||
} | ||
|
||
// ReceiveHandler is the endpoint for remotes to receive daginfo | ||
func (h *RemoteHandlers) ReceiveHandler(w http.ResponseWriter, r *http.Request) { | ||
switch r.Method { | ||
case "POST": | ||
h.receiveDataset(w, r) | ||
default: | ||
util.NotFoundHandler(w, r) | ||
} | ||
} | ||
|
||
func (h *RemoteHandlers) receiveDataset(w http.ResponseWriter, r *http.Request) { | ||
content, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
util.WriteErrResponse(w, http.StatusInternalServerError, err) | ||
return | ||
} | ||
var result bool | ||
params := lib.ReceiveParams{Body: string(content)} | ||
err = h.Receive(¶ms, &result) | ||
if err != nil { | ||
util.WriteErrResponse(w, http.StatusInternalServerError, err) | ||
return | ||
} | ||
// TODO(dlong): Perform dsync | ||
if result { | ||
util.WriteResponse(w, "Accepted") | ||
return | ||
} | ||
util.WriteResponse(w, "Denied") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.