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

Complete Visor Logs #820

Merged
merged 2 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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