Skip to content

Commit

Permalink
Merge pull request #820 from mrpalide:fixbug/visor-log-incomplete
Browse files Browse the repository at this point in the history
Complete Visor Logs
  • Loading branch information
jdknives authored Jun 24, 2021
2 parents e23328e + 0622e14 commit aac7d7e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pkg/snet/arclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type httpClient struct {
// * SW-Public: The specified public key.
// * SW-Nonce: The nonce for that public key.
// * SW-Sig: The signature of the payload + the nonce.
func NewHTTP(remoteAddr string, pk cipher.PubKey, sk cipher.SecKey) (APIClient, error) {
func NewHTTP(remoteAddr string, pk cipher.PubKey, sk cipher.SecKey, log *logging.Logger) (APIClient, error) {
remoteURL, err := url.Parse(remoteAddr)
if err != nil {
return nil, fmt.Errorf("parse URL: %w", err)
Expand All @@ -99,7 +99,7 @@ func NewHTTP(remoteAddr string, pk cipher.PubKey, sk cipher.SecKey) (APIClient,
}

client := &httpClient{
log: logging.MustGetLogger("address-resolver"),
log: log,
pk: pk,
sk: sk,
remoteHTTPAddr: remoteAddr,
Expand Down
8 changes: 4 additions & 4 deletions pkg/snet/arclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestClientAuth(t *testing.T) {
))

defer srv.Close()

apiClient, err := NewHTTP(srv.URL, testPubKey, testSecKey)
log := logging.MustGetLogger("test_client_auth")
apiClient, err := NewHTTP(srv.URL, testPubKey, testSecKey, log)
require.NoError(t, err)

c := apiClient.(*httpClient)
Expand Down Expand Up @@ -72,8 +72,8 @@ func TestBind(t *testing.T) {
})))

defer srv.Close()

c, err := NewHTTP(srv.URL, testPubKey, testSecKey)
log := logging.MustGetLogger("test_bind")
c, err := NewHTTP(srv.URL, testPubKey, testSecKey, log)
require.NoError(t, err)

err = c.BindSTCPR(context.TODO(), "1234")
Expand Down
4 changes: 2 additions & 2 deletions pkg/snet/directtp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ type client struct {
}

// NewClient creates a net Client.
func NewClient(conf Config) Client {
func NewClient(conf Config, masterLogger *logging.MasterLogger) Client {
return &client{
conf: conf,
log: logging.MustGetLogger(conf.Type),
log: masterLogger.PackageLogger(conf.Type),
porter: porter.New(porter.MinEphemeral),
listeners: make(map[uint16]*tplistener.Listener),
done: make(chan struct{}),
Expand Down
10 changes: 5 additions & 5 deletions pkg/snet/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Network struct {
}

// New creates a network from a config.
func New(conf Config, eb *appevent.Broadcaster) (*Network, error) {
func New(conf Config, eb *appevent.Broadcaster, masterLogger *logging.MasterLogger) (*Network, error) {
clients := NetworkClients{
Direct: make(map[string]directtp.Client),
}
Expand All @@ -123,7 +123,7 @@ func New(conf Config, eb *appevent.Broadcaster) (*Network, error) {
},
}
clients.DmsgC = dmsg.NewClient(conf.PubKey, conf.SecKey, disc.NewHTTP(conf.NetworkConfigs.Dmsg.Discovery), dmsgConf)
clients.DmsgC.SetLogger(logging.MustGetLogger("snet.dmsgC"))
clients.DmsgC.SetLogger(masterLogger.PackageLogger("snet.dmsgC"))
}

if conf.NetworkConfigs.STCP != nil {
Expand All @@ -140,7 +140,7 @@ func New(conf Config, eb *appevent.Broadcaster) (*Network, error) {
return nil
},
}
clients.Direct[tptypes.STCP] = directtp.NewClient(conf)
clients.Direct[tptypes.STCP] = directtp.NewClient(conf, masterLogger)
}

if conf.ARClient != nil {
Expand All @@ -157,7 +157,7 @@ func New(conf Config, eb *appevent.Broadcaster) (*Network, error) {
},
}

clients.Direct[tptypes.STCPR] = directtp.NewClient(stcprConf)
clients.Direct[tptypes.STCPR] = directtp.NewClient(stcprConf, masterLogger)

sudphConf := directtp.Config{
Type: tptypes.SUDPH,
Expand All @@ -166,7 +166,7 @@ func New(conf Config, eb *appevent.Broadcaster) (*Network, error) {
AddressResolver: conf.ARClient,
}

clients.Direct[tptypes.SUDPH] = directtp.NewClient(sudphConf)
clients.Direct[tptypes.SUDPH] = directtp.NewClient(sudphConf, masterLogger)
}

return NewRaw(conf, clients), nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/snet/snettest/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/nettest"
Expand Down Expand Up @@ -115,7 +116,7 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {
LocalAddr: networkConfigs.STCP.LocalAddr,
}

clients.Direct[tptypes.STCP] = directtp.NewClient(conf)
clients.Direct[tptypes.STCP] = directtp.NewClient(conf, logging.NewMasterLogger())
}

if hasStcpr {
Expand All @@ -126,7 +127,7 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {
AddressResolver: addressResolver,
}

clients.Direct[tptypes.STCPR] = directtp.NewClient(conf)
clients.Direct[tptypes.STCPR] = directtp.NewClient(conf, logging.NewMasterLogger())
}

if hasSudph {
Expand All @@ -137,7 +138,7 @@ func NewEnv(t *testing.T, keys []KeyPair, networks []string) *Env {
AddressResolver: addressResolver,
}

clients.Direct[tptypes.SUDPH] = directtp.NewClient(conf)
clients.Direct[tptypes.SUDPH] = directtp.NewClient(conf, logging.NewMasterLogger())
}

snetConfig := snet.Config{
Expand Down
4 changes: 2 additions & 2 deletions pkg/transport/setup/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type TransportListener struct {
}

// NewTransportListener makes a TransportListener from configuration
func NewTransportListener(ctx context.Context, conf *visorconfig.V1, dmsgC *dmsg.Client, tm *transport.Manager) (*TransportListener, error) {
log := logging.MustGetLogger("transport_setup")
func NewTransportListener(ctx context.Context, conf *visorconfig.V1, dmsgC *dmsg.Client, tm *transport.Manager, masterLogger *logging.MasterLogger) (*TransportListener, error) {
log := masterLogger.PackageLogger("transport_setup")
log.WithField("local_pk", conf.PK).Info("Connecting to the dmsg network.")

go dmsgC.Serve(ctx)
Expand Down
6 changes: 3 additions & 3 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func initEventBroadcaster(ctx context.Context, v *Visor, log *logging.Logger) er
func initAddressResolver(ctx context.Context, v *Visor, log *logging.Logger) error {
conf := v.conf.Transport

arClient, err := arclient.NewHTTP(conf.AddressResolver, v.conf.PK, v.conf.SK)
arClient, err := arclient.NewHTTP(conf.AddressResolver, v.conf.PK, v.conf.SK, log)
if err != nil {
err := fmt.Errorf("failed to create address resolver client: %w", err)
return err
Expand Down Expand Up @@ -193,7 +193,7 @@ func initSNet(ctx context.Context, v *Visor, log *logging.Logger) error {
NetworkConfigs: nc,
}

n, err := snet.New(conf, v.ebc)
n, err := snet.New(conf, v.ebc, v.MasterLogger())
if err != nil {
return err
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func initTransport(ctx context.Context, v *Visor, log *logging.Logger) error {

func initTransportSetup(ctx context.Context, v *Visor, log *logging.Logger) error {
ctx, cancel := context.WithCancel(ctx)
ts, err := ts.NewTransportListener(ctx, v.conf, v.net.Dmsg(), v.tpM)
ts, err := ts.NewTransportListener(ctx, v.conf, v.net.Dmsg(), v.tpM, v.MasterLogger())
if err != nil {
cancel()
return err
Expand Down

0 comments on commit aac7d7e

Please sign in to comment.