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

static check fixes #1076

Merged
merged 4 commits into from
Apr 29, 2021
Merged

Conversation

coryschwartz
Copy link
Contributor

various fixes for staticcheck

For context: protocol/.github#41

@@ -247,7 +247,15 @@ func (ar *AutoRelay) discoverRelays(ctx context.Context) ([]peer.AddrInfo, error

ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
return discovery.FindPeers(ctx, ar.discover, RelayRendezvous, discovery.Limit(1000))
var ret []peer.AddrInfo
ch, err := ar.discover.FindPeers(ctx, RelayRendezvous, discovery.Limit(1000))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be equivilent to the FindPeers util function in go-libp2p-discovery, to convert the channel into a slice.

@@ -20,7 +20,31 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) {
go func() {
select {
case <-time.After(AdvertiseBootDelay):
discovery.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL))
go func() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brought in from go-libp2p-discovery.

If it's better to use the Util Functions from there I can swtich back to using them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, those functions exist so we don't need to duplicate this code. What was the motivation for this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... I see.

@@ -368,7 +368,7 @@ func (ids *IDService) identifyConn(c network.Conn, signal chan struct{}) {

// ok give the response to our handler.
if err = msmux.SelectProtoOrFail(ID, s); err != nil {
log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err})
// log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a metric that should be emitted here in leiu of depreciated go-log Events?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a structured log message.

@@ -131,7 +130,7 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e
lm["error"] = err
lm["wantedPeer"] = func() interface{} { return wanted.Pretty() }
lm["gotPeer"] = func() interface{} { return got.Pretty() }
log.Event(ctx, "routingError", lm)
// log.Event(ctx, "routingError", lm)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this code commented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire function should be deleted and replaced with a call to log.Errorw.

Side note: please (almost) never comment out code unless you're actively debugging.

}
return p
}
// Unused code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete this?

@@ -20,7 +20,31 @@ func Advertise(ctx context.Context, advertise discovery.Advertiser) {
go func() {
select {
case <-time.After(AdvertiseBootDelay):
discovery.Advertise(ctx, advertise, RelayRendezvous, discovery.TTL(AdvertiseTTL))
go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, those functions exist so we don't need to duplicate this code. What was the motivation for this change?

@@ -131,7 +130,7 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e
lm["error"] = err
lm["wantedPeer"] = func() interface{} { return wanted.Pretty() }
lm["gotPeer"] = func() interface{} { return got.Pretty() }
log.Event(ctx, "routingError", lm)
// log.Event(ctx, "routingError", lm)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire function should be deleted and replaced with a call to log.Errorw.

Side note: please (almost) never comment out code unless you're actively debugging.

@Stebalien Stebalien merged commit 6391bff into libp2p:master Apr 29, 2021
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants