Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove heartbeat | Add Deregister #884

Merged
merged 17 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/skywire-visor/commands/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package commands

import (
"context"

"github.com/getlantern/systray"
"github.com/skycoin/skycoin/src/util/logging"

Expand Down
2 changes: 1 addition & 1 deletion internal/gui/gui_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
pngIconPath = "/Applications/Skywire.app/Contents/Resources/icon.png"
iconPath = "/Applications/Skywire.app/Contents/Resources/tray_icon.tiff"
deinstallerPath = "/Applications/Skywire.app/Contents/deinstaller"
appPath = "/Applications/Skywire.app"
appPath = "/Applications/Skywire.app"
)

func preReadIcon() error {
Expand Down
42 changes: 42 additions & 0 deletions pkg/app/appdisc/discovery_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package appdisc
jdknives marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"

"github.com/skycoin/skywire/pkg/servicedisc"
)

// Updater updates the associated app discovery
type Updater interface {

// Start starts the updater.
Start()

// Stop stops the updater.
Stop()
}

// emptyUpdater is for apps that do not require discovery updates.
type emptyUpdater struct{}

func (emptyUpdater) Start() {}
func (emptyUpdater) Stop() {}

// serviceUpdater updates service-discovery entry of locally running App.
type serviceUpdater struct {
client *servicedisc.HTTPClient
}

func (u *serviceUpdater) Start() {
ctx := context.Background()
if err := u.client.Register(ctx); err != nil {
return
}
}

func (u *serviceUpdater) Stop() {
ctx := context.Background()
if err := u.client.DeleteEntry(ctx); err != nil {
return
}
}
26 changes: 11 additions & 15 deletions pkg/app/updatedisc/factory.go → pkg/app/appdisc/factory.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package updatedisc
package appdisc

import (
"time"

"github.com/sirupsen/logrus"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/skycoin/src/util/logging"
Expand All @@ -14,20 +12,16 @@ import (

// Factory creates appdisc.Updater instances based on the app name.
type Factory struct {
Log logrus.FieldLogger
PK cipher.PubKey
SK cipher.SecKey
UpdateInterval time.Duration
ServiceDisc string // Address of service-discovery
Log logrus.FieldLogger
PK cipher.PubKey
SK cipher.SecKey
ServiceDisc string // Address of service-discovery
}

func (f *Factory) setDefaults() {
if f.Log == nil {
f.Log = logging.MustGetLogger("appdisc")
}
if f.UpdateInterval == 0 {
f.UpdateInterval = skyenv.ServiceDiscUpdateInterval
}
if f.ServiceDisc == "" {
f.ServiceDisc = skyenv.DefaultServiceDiscAddr
}
Expand All @@ -49,8 +43,7 @@ func (f *Factory) VisorUpdater(port uint16) Updater {
}

return &serviceUpdater{
client: servicedisc.NewClient(f.Log, conf),
interval: f.UpdateInterval,
client: servicedisc.NewClient(f.Log, conf),
}
}

Expand Down Expand Up @@ -81,8 +74,11 @@ func (f *Factory) AppUpdater(conf appcommon.ProcConfig) (Updater, bool) {
switch conf.AppName {
case skyenv.VPNServerName:
jdknives marked this conversation as resolved.
Show resolved Hide resolved
return &serviceUpdater{
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeVPN)),
interval: f.UpdateInterval,
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeVPN)),
}, true
case skyenv.SkysocksName:
return &serviceUpdater{
client: servicedisc.NewClient(log, getServiceDiscConf(conf, servicedisc.ServiceTypeProxy)),
}, true
default:
return &emptyUpdater{}, false
Expand Down
30 changes: 6 additions & 24 deletions pkg/app/appserver/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/rpc"
"os"
"os/exec"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand All @@ -16,8 +15,8 @@ import (
"github.com/skycoin/skycoin/src/util/logging"

"github.com/skycoin/skywire/pkg/app/appcommon"
"github.com/skycoin/skywire/pkg/app/appdisc"
"github.com/skycoin/skywire/pkg/app/appnet"
"github.com/skycoin/skywire/pkg/app/updatedisc"
)

var (
Expand All @@ -29,7 +28,7 @@ var (
// communication.
// TODO(evanlinjin): In the future, we will implement the ability to run multiple instances (procs) of a single app.
type Proc struct {
disc updatedisc.Updater // app discovery client
disc appdisc.Updater // app discovery client
conf appcommon.ProcConfig
log *logging.Logger

Expand Down Expand Up @@ -57,7 +56,7 @@ type Proc struct {
}

// NewProc constructs `Proc`.
func NewProc(mLog *logging.MasterLogger, conf appcommon.ProcConfig, disc updatedisc.Updater, m ProcManager,
func NewProc(mLog *logging.MasterLogger, conf appcommon.ProcConfig, disc appdisc.Updater, m ProcManager,
appName string) *Proc {
if mLog == nil {
mLog = logging.NewMasterLogger()
Expand Down Expand Up @@ -136,26 +135,6 @@ func (p *Proc) awaitConn() bool {
panic(err)
}

connDelta := p.rpcGW.cm.AddDeltaInformer()
go func() {
for n := range connDelta.Chan() {
if err := p.disc.ChangeValue(updatedisc.ConnCountValue, []byte(strconv.Itoa(n))); err != nil {
p.log.WithError(err).WithField("value", updatedisc.ConnCountValue).
Error("Failed to change app discovery value.")
}
}
}()

lisDelta := p.rpcGW.lm.AddDeltaInformer()
go func() {
for n := range lisDelta.Chan() {
if err := p.disc.ChangeValue(updatedisc.ListenerCountValue, []byte(strconv.Itoa(n))); err != nil {
p.log.WithError(err).WithField("value", updatedisc.ListenerCountValue).
Error("Failed to change app discovery value.")
}
}
}()

go rpcS.ServeConn(p.conn)

p.log.Info("Associated and serving proc conn.")
Expand Down Expand Up @@ -259,6 +238,9 @@ func (p *Proc) Stop() error {
}
}

// deregister discovery service
p.disc.Stop()
jdknives marked this conversation as resolved.
Show resolved Hide resolved

// the lock will be acquired as soon as the cmd finishes its work
p.waitMx.Lock()
defer func() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/app/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/skycoin/skycoin/src/util/logging"

"github.com/skycoin/skywire/pkg/app/appcommon"
"github.com/skycoin/skywire/pkg/app/appdisc"
"github.com/skycoin/skywire/pkg/app/appevent"
"github.com/skycoin/skywire/pkg/app/updatedisc"
)

//go:generate mockery -name ProcManager -case underscore -inpkg
Expand Down Expand Up @@ -57,7 +57,7 @@ type procManager struct {
conns map[string]net.Conn
connsWG sync.WaitGroup

discF *updatedisc.Factory
discF *appdisc.Factory
procs map[string]*Proc
procsByKey map[appcommon.ProcKey]*Proc

Expand All @@ -69,12 +69,12 @@ type procManager struct {
}

// NewProcManager constructs `ProcManager`.
func NewProcManager(mLog *logging.MasterLogger, discF *updatedisc.Factory, eb *appevent.Broadcaster, addr string) (ProcManager, error) {
func NewProcManager(mLog *logging.MasterLogger, discF *appdisc.Factory, eb *appevent.Broadcaster, addr string) (ProcManager, error) {
if mLog == nil {
mLog = logging.NewMasterLogger()
}
if discF == nil {
discF = new(updatedisc.Factory)
discF = new(appdisc.Factory)
}
if eb == nil {
eb = appevent.NewBroadcaster(mLog.PackageLogger("event_broadcaster"), time.Second)
Expand Down
10 changes: 0 additions & 10 deletions pkg/app/updatedisc/const.go

This file was deleted.

83 changes: 0 additions & 83 deletions pkg/app/updatedisc/discovery_updater.go

This file was deleted.

Loading