Skip to content

Commit

Permalink
Merge pull request #415 from evanlinjin/feature/hv-dmsg-tab-#407
Browse files Browse the repository at this point in the history
Hypervisor dmsg tab.

Former-commit-id: a15a789
  • Loading branch information
evanlinjin committed Jun 30, 2020
2 parents 76b0978 + d75d9a2 commit 004e833
Show file tree
Hide file tree
Showing 493 changed files with 47,223 additions and 16,712 deletions.
67 changes: 34 additions & 33 deletions cmd/hypervisor/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"fmt"
"context"
"net/http"
"os"
"time"
Expand Down Expand Up @@ -50,6 +50,9 @@ var rootCmd = &cobra.Command{
Use: "hypervisor",
Short: "Manages Skywire Visors",
Run: func(_ *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil {
log.Printf("Failed to output build info: %v", err)
}
Expand All @@ -72,29 +75,29 @@ var rootCmd = &cobra.Command{
log.Fatalf("Failed to obtain embedded static files: %v", err)
}

dmsgC := prepareDmsg(conf)

// Prepare hypervisor.
hv, err := hypervisor.New(assets, conf, restartCtx)
hv, err := hypervisor.New(conf, assets, restartCtx, dmsgC)
if err != nil {
log.Fatalln("Failed to start hypervisor:", err)
}

if mock {
prepareMockData(hv)
serveMockData(hv)
} else {
prepareDmsg(hv, conf)
serveDmsg(ctx, hv, conf)
}

// Serve HTTP(s).
log := log.
WithField("addr", conf.HTTPAddr).
WithField("tls", conf.EnableTLS)
log.WithField("addr", conf.HTTPAddr).
WithField("tls", conf.EnableTLS).
Info("Serving hypervisor...")

log.Info("Serving hypervisor...")

if conf.EnableTLS {
err = http.ListenAndServeTLS(conf.HTTPAddr, conf.TLSCertFile, conf.TLSKeyFile, hv)
if handler := hv.HTTPHandler(); conf.EnableTLS {
err = http.ListenAndServeTLS(conf.HTTPAddr, conf.TLSCertFile, conf.TLSKeyFile, handler)
} else {
err = http.ListenAndServe(conf.HTTPAddr, hv)
err = http.ListenAndServe(conf.HTTPAddr, handler)
}

if err != nil {
Expand All @@ -117,7 +120,25 @@ func prepareConfig(args []string) (conf hypervisor.Config) {
return conf
}

func prepareMockData(hv *hypervisor.Hypervisor) {
func prepareDmsg(conf hypervisor.Config) *dmsg.Client {
dmsgC := dmsg.NewClient(conf.PK, conf.SK, disc.NewHTTP(conf.DmsgDiscovery), dmsg.DefaultConfig())
go dmsgC.Serve()

<-dmsgC.Ready()
return dmsgC
}

func serveDmsg(ctx context.Context, hv *hypervisor.Hypervisor, conf hypervisor.Config) {
go func() {
if err := hv.ServeRPC(ctx, conf.DmsgPort); err != nil {
log.WithError(err).Fatal("Failed to serve RPC client over dmsg.")
}
}()
log.WithField("addr", dmsg.Addr{PK: conf.PK, Port: conf.DmsgPort}).
Info("Serving RPC client over dmsg.")
}

func serveMockData(hv *hypervisor.Hypervisor) {
err := hv.AddMockData(hypervisor.MockConfig{
Visors: mockVisors,
MaxTpsPerVisor: mockMaxTps,
Expand All @@ -129,26 +150,6 @@ func prepareMockData(hv *hypervisor.Hypervisor) {
}
}

func prepareDmsg(hv *hypervisor.Hypervisor, conf hypervisor.Config) {
// Prepare dmsg client.
dmsgC := dmsg.NewClient(conf.PK, conf.SK, disc.NewHTTP(conf.DmsgDiscovery), dmsg.DefaultConfig())
go dmsgC.Serve()

dmsgL, err := dmsgC.Listen(conf.DmsgPort)
if err != nil {
log.WithField("addr", fmt.Sprintf("dmsg://%s:%d", conf.PK, conf.DmsgPort)).
Fatal("Failed to listen over dmsg.")
}
go func() {
if err := hv.ServeRPC(dmsgC, dmsgL); err != nil {
log.WithError(err).
Fatal("Failed to serve RPC client over dmsg.")
}
}()
log.WithField("addr", fmt.Sprintf("dmsg://%s:%d", conf.PK, conf.DmsgPort)).
Info("Serving RPC client over dmsg.")
}

// Execute executes root CLI command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/hypervisor/statik/statik.go

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,37 @@ go 1.14

require (
github.com/AudriusButkevicius/pfilter v0.0.0-20190627213056-c55ef6137fc6
github.com/SkycoinProject/dmsg v0.2.2
github.com/SkycoinProject/dmsg v0.2.3-0.20200626071453-e2e73212a9ab
github.com/SkycoinProject/skycoin v0.27.0
github.com/SkycoinProject/yamux v0.0.0-20191213015001-a36efeefbf6a
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/go-chi/chi v4.0.2+incompatible
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/securecookie v1.1.1
github.com/klauspost/reedsolomon v1.9.9 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/libp2p/go-reuseport v0.0.1
github.com/mholt/archiver/v3 v3.3.0
github.com/mmcloughlin/avo v0.0.0-20200523190732-4439b6b2c061 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/profile v1.3.0
github.com/prometheus/client_golang v1.3.0
github.com/pkg/profile v1.5.0
github.com/prometheus/client_golang v1.7.1
github.com/rakyll/statik v0.1.7
github.com/schollz/progressbar/v2 v2.15.0
github.com/shirou/gopsutil v2.20.5+incompatible
github.com/sirupsen/logrus v1.5.0
github.com/sirupsen/logrus v1.6.0
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.5.1
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.6.1
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b // indirect
github.com/tjfoc/gmsm v1.3.1 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/xtaci/kcp-go v5.4.20+incompatible
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect
go.etcd.io/bbolt v1.3.4
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
go.etcd.io/bbolt v1.3.5
golang.org/x/net v0.0.0-20200625001655-4c5254603344
golang.zx2c4.com/wireguard v0.0.20200320
nhooyr.io/websocket v1.8.2
nhooyr.io/websocket v1.8.6
)

// Uncomment for tests with alternate branches of 'dmsg'
// replace github.com/SkycoinProject/dmsg => ../dmsg
Loading

0 comments on commit 004e833

Please sign in to comment.