Skip to content

Commit

Permalink
Paused progress on hypervisor endpoints refactor.
Browse files Browse the repository at this point in the history
The following has been commented out:

* WIP: Visor endpoints exposed for hypervisor switched to RESTful.

* WIP: Various new helper functions for having http over dmsg.
  • Loading branch information
志宇 committed Feb 24, 2020
1 parent 1699469 commit 04ade12
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 131 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ module github.com/SkycoinProject/skywire-mainnet
go 1.13

require (
github.com/SkycoinProject/dmsg v0.0.0-20200220122410-79d9d7bac617
github.com/SkycoinProject/dmsg v0.0.0-20200224064625-1b539081519c
github.com/SkycoinProject/skycoin v0.27.0
github.com/SkycoinProject/yamux v0.0.0-20191213015001-a36efeefbf6a
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/go-chi/chi v4.0.2+incompatible
github.com/google/uuid v1.1.1
github.com/gorilla/handlers v1.4.2
github.com/gorilla/securecookie v1.1.1
github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/SkycoinProject/dmsg v0.0.0-20200220122410-79d9d7bac617 h1:dTlZiB/kaSMezzwyEsOs2fjbbDkgoLzdLSwh7GmOIK4=
github.com/SkycoinProject/dmsg v0.0.0-20200220122410-79d9d7bac617/go.mod h1:eCoemDDyfyfNTFrapYKNEItwtRIj54UGpu4Ffcznuds=
github.com/SkycoinProject/dmsg v0.0.0-20200224064625-1b539081519c h1:TBwm7dzyUYnOG/Ycb3HBh7JshQavePHHfh5NOAzlNww=
github.com/SkycoinProject/dmsg v0.0.0-20200224064625-1b539081519c/go.mod h1:eCoemDDyfyfNTFrapYKNEItwtRIj54UGpu4Ffcznuds=
github.com/SkycoinProject/skycoin v0.26.0 h1:8/ZRZb2VM2DM4YTIitRJMZ3Yo/3H1FFmbCMx5o6ekmA=
github.com/SkycoinProject/skycoin v0.26.0/go.mod h1:xqPLOKh5B6GBZlGA7B5IJfQmCy7mwimD9NlqxR3gMXo=
github.com/SkycoinProject/skycoin v0.27.0 h1:N3IHxj8ossHOcsxLYOYugT+OaELLncYHJHxbbYLPPmY=
Expand Down
86 changes: 0 additions & 86 deletions pkg/httputil/httputil.go

This file was deleted.

3 changes: 2 additions & 1 deletion pkg/hypervisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

"github.com/SkycoinProject/dmsg/cipher"

"github.com/SkycoinProject/dmsg/httputil"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"
"github.com/SkycoinProject/skywire-mainnet/pkg/httputil"
"github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil"
)

Expand Down
34 changes: 1 addition & 33 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (

"github.com/SkycoinProject/dmsg"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/dmsg/httputil"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/google/uuid"

"github.com/SkycoinProject/skywire-mainnet/pkg/app"
"github.com/SkycoinProject/skywire-mainnet/pkg/httputil"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
"github.com/SkycoinProject/skywire-mainnet/pkg/visor"
)
Expand Down Expand Up @@ -168,7 +168,6 @@ func (m *Hypervisor) ServeHTTP(w http.ResponseWriter, req *http.Request) {
r.Delete("/visors/{pk}/routes/{rid}", m.deleteRoute())
r.Get("/visors/{pk}/loops", m.getLoops())
r.Get("/visors/{pk}/restart", m.restart())
r.Post("/visors/{pk}/exec", m.exec())
})
})

Expand Down Expand Up @@ -228,37 +227,6 @@ func (m *Hypervisor) getUptime() http.HandlerFunc {
})
}

// executes a command and returns its output
func (m *Hypervisor) exec() http.HandlerFunc {
return m.withCtx(m.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
var reqBody struct {
Command string `json:"command"`
}

if err := httputil.ReadJSON(r, &reqBody); err != nil {
if err != io.EOF {
log.Warnf("exec request: %v", err)
}

httputil.WriteJSON(w, r, http.StatusBadRequest, ErrMalformedRequest)

return
}

out, err := ctx.RPC.Exec(reqBody.Command)
if err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}

output := struct {
Output string `json:"output"`
}{string(out)}

httputil.WriteJSON(w, r, http.StatusOK, output)
})
}

type summaryResp struct {
TCPAddr string `json:"tcp_addr"`
Online bool `json:"online"`
Expand Down
4 changes: 3 additions & 1 deletion pkg/hypervisor/user_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/google/uuid"
"github.com/gorilla/securecookie"

"github.com/SkycoinProject/skywire-mainnet/pkg/httputil"
"github.com/SkycoinProject/dmsg/httputil"
)

const (
Expand All @@ -30,6 +30,8 @@ var (
ErrUserNotFound = errors.New("user is either deleted or not found")
)

// Other errors

// for use with context.Context
type ctxKey string

Expand Down
Loading

0 comments on commit 04ade12

Please sign in to comment.