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
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
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
swarm "github.com/libp2p/go-libp2p-swarm"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"

logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.1.3
github.com/jbenet/go-cienv v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/libp2p/go-addr-util v0.0.2
Expand All @@ -21,7 +21,6 @@ require (
github.com/libp2p/go-libp2p-circuit v0.4.0
github.com/libp2p/go-libp2p-core v0.8.5
github.com/libp2p/go-libp2p-discovery v0.5.0
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-mplex v0.4.1
github.com/libp2p/go-libp2p-nat v0.0.6
github.com/libp2p/go-libp2p-netutil v0.1.0
Expand Down
4 changes: 1 addition & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdr
github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
github.com/ipfs/go-log v1.0.2/go.mod h1:1MNjMxe0u6xvJZgeqbJ8vdo2TKaGwZ1a0Bpza+sr2Sk=
github.com/ipfs/go-log v1.0.3/go.mod h1:OsLySYkwIbiSUR/yBTdv1qPtcE4FW3WPWk/ewz9Ru+A=
github.com/ipfs/go-log v1.0.4 h1:6nLQdX4W8P9yZZFH7mO+X/PzjN8Laozm/lMJ6esdgzY=
github.com/ipfs/go-log v1.0.4/go.mod h1:oDCg2FkjogeFOhqqb+N39l2RpTNPL6F/StPkB3kPgcs=
github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8=
github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo=
github.com/ipfs/go-log/v2 v2.0.2/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0=
github.com/ipfs/go-log/v2 v2.0.3/go.mod h1:O7P1lJt27vWHhOwQmcFEvlmo49ry2VY2+JfBWFaa9+0=
github.com/ipfs/go-log/v2 v2.0.5/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscwkWG+dw=
Expand Down Expand Up @@ -287,7 +286,6 @@ github.com/libp2p/go-libp2p-discovery v0.2.0/go.mod h1:s4VGaxYMbw4+4+tsoQTqh7wfx
github.com/libp2p/go-libp2p-discovery v0.3.0/go.mod h1:o03drFnz9BVAZdzC/QUQ+NeQOu38Fu7LJGEOK2gQltw=
github.com/libp2p/go-libp2p-discovery v0.5.0 h1:Qfl+e5+lfDgwdrXdu4YNCWyEo3fWuP+WgN9mN0iWviQ=
github.com/libp2p/go-libp2p-discovery v0.5.0/go.mod h1:+srtPIU9gDaBNu//UHvcdliKBIcr4SfDcm0/PfPJLug=
github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8=
github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90=
github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo=
github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE=
Expand Down
6 changes: 2 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ func FilterAddresses(addrs ...*net.IPNet) Option {
if cfg.ConnectionGater != nil {
var ok bool
if f, ok = cfg.ConnectionGater.(*filtersConnectionGater); !ok {
return errors.New("cannot configure both Filters and Connection Gater. " +
"\n Please consider configuring just a ConnectionGater instead.")
return errors.New("cannot configure both Filters and Connection Gater; please consider configuring just a ConnectionGater instead")
}
}

Expand Down Expand Up @@ -371,8 +370,7 @@ func FilterAddresses(addrs ...*net.IPNet) Option {
func Filters(filters *ma.Filters) Option {
return func(cfg *Config) error {
if cfg.ConnectionGater != nil {
return errors.New("cannot configure both Filters and Connection Gater. " +
"\n Please consider configuring just a ConnectionGater instead.")
return errors.New("cannot configure both Filters and Connection Gater; please consider configuring just a ConnectionGater instead")

}
cfg.ConnectionGater = (*filtersConnectionGater)(filters)
Expand Down
12 changes: 6 additions & 6 deletions p2p/discovery/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peer"

logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/whyrusleeping/mdns"
Expand Down Expand Up @@ -76,7 +76,7 @@ func NewMdnsService(ctx context.Context, peerhost host.Host, interval time.Durat

addrs, err := getDialableListenAddrs(peerhost)
if err != nil {
log.Warning(err)
log.Warn(err)
} else {
port = addrs[0].Port
for _, a := range addrs {
Expand Down Expand Up @@ -158,9 +158,9 @@ func (m *mdnsService) pollForEntries(ctx context.Context) {

func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
log.Debugf("Handling MDNS entry: [IPv4 %s][IPv6 %s]:%d %s", e.AddrV4, e.AddrV6, e.Port, e.Info)
mpeer, err := peer.IDB58Decode(e.Info)
mpeer, err := peer.Decode(e.Info)
if err != nil {
log.Warning("Error parsing peer ID from mdns entry: ", err)
log.Warn("Error parsing peer ID from mdns entry: ", err)
return
}

Expand All @@ -175,7 +175,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
} else if e.AddrV6 != nil {
addr = e.AddrV6
} else {
log.Warning("Error parsing multiaddr from mdns entry: no IP address found")
log.Warn("Error parsing multiaddr from mdns entry: no IP address found")
return
}

Expand All @@ -184,7 +184,7 @@ func (m *mdnsService) handleEntry(e *mdns.ServiceEntry) {
Port: e.Port,
})
if err != nil {
log.Warning("Error parsing multiaddr from mdns entry: ", err)
log.Warn("Error parsing multiaddr from mdns entry: ", err)
return
}

Expand Down
9 changes: 4 additions & 5 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import (
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
"github.com/libp2p/go-netroute"

logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"

"github.com/multiformats/go-multiaddr"
ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
manet "github.com/multiformats/go-multiaddr/net"
Expand Down Expand Up @@ -393,7 +392,7 @@ func (h *BasicHost) newStreamHandler(s network.Stream) {
if err == io.EOF {
logf := log.Debugf
if took > time.Second*10 {
logf = log.Warningf
logf = log.Warnf
}
logf("protocol EOF: %s (took %s)", s.Conn().RemotePeer(), took)
} else {
Expand Down Expand Up @@ -465,7 +464,7 @@ func makeUpdatedAddrEvent(prev, current []ma.Multiaddr) *event.EvtLocalAddresses
}

func (h *BasicHost) makeSignedPeerRecord(evt *event.EvtLocalAddressesUpdated) (*record.Envelope, error) {
current := make([]multiaddr.Multiaddr, 0, len(evt.Current))
current := make([]ma.Multiaddr, 0, len(evt.Current))
for _, a := range evt.Current {
current = append(current, a.Address)
}
Expand Down Expand Up @@ -734,7 +733,7 @@ func (h *BasicHost) resolveAddrs(ctx context.Context, pi peer.AddrInfo) ([]ma.Mu
// We've resolved too many addresses. We can keep all the fully
// resolved addresses but we'll need to skip the rest.
if resolveSteps >= maxAddressResolution {
log.Warningf(
log.Warnf(
"peer %s asked us to resolve too many addresses: %s/%s",
pi.ID,
resolveSteps,
Expand Down
3 changes: 1 addition & 2 deletions p2p/host/relay/addrsplosion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package relay
import (
"encoding/binary"

circuit "github.com/libp2p/go-libp2p-circuit"
ma "github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
)
Expand Down Expand Up @@ -41,7 +40,7 @@ func isRelayAddr(a ma.Multiaddr) bool {

ma.ForEach(a, func(c ma.Component) bool {
switch c.Protocol().Code {
case circuit.P_CIRCUIT:
case ma.P_CIRCUIT:
isRelay = true
return false
default:
Expand Down
12 changes: 10 additions & 2 deletions p2p/host/relay/autorelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"sync"
"time"

"github.com/libp2p/go-libp2p-core/discovery"
"github.com/libp2p/go-libp2p-core/event"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/routing"

circuit "github.com/libp2p/go-libp2p-circuit"
discovery "github.com/libp2p/go-libp2p-discovery"
basic "github.com/libp2p/go-libp2p/p2p/host/basic"

ma "github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -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.

if err != nil {
return nil, err
}
for p := range ch {
ret = append(ret, p)
}
return ret, nil
}

func (ar *AutoRelay) selectRelays(ctx context.Context, pis []peer.AddrInfo) []peer.AddrInfo {
Expand Down
8 changes: 4 additions & 4 deletions p2p/host/relay/autorelay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestAutoRelay(t *testing.T) {

// verify that we don't advertise relay addrs initially
for _, addr := range h3.Addrs() {
_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
t.Fatal("relay addr advertised before auto detection")
}
Expand All @@ -189,7 +189,7 @@ func TestAutoRelay(t *testing.T) {
t.Fatal("unspecific relay addr advertised")
}

_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
haveRelay = true
}
Expand All @@ -202,7 +202,7 @@ func TestAutoRelay(t *testing.T) {
// verify that we can connect through the relay
var raddrs []ma.Multiaddr
for _, addr := range h3.Addrs() {
_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
raddrs = append(raddrs, addr)
}
Expand All @@ -220,7 +220,7 @@ func TestAutoRelay(t *testing.T) {
t.Fatal("unspecific relay addr advertised")
}

_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err == nil {
haveRelay = true
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/relay/log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package relay

import (
logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"
)

var log = logging.Logger("autorelay")
28 changes: 26 additions & 2 deletions p2p/host/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/libp2p/go-libp2p-discovery"
"github.com/libp2p/go-libp2p-core/discovery"

ma "github.com/multiformats/go-multiaddr"
)
Expand All @@ -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.

for {
ttl, err := advertise.Advertise(ctx, RelayRendezvous, discovery.TTL(AdvertiseTTL))
if err != nil {
log.Debugf("Error advertising %s: %s", RelayRendezvous, err.Error())
if ctx.Err() != nil {
return
}

select {
case <-time.After(2 * time.Minute):
continue
case <-ctx.Done():
return
}
}

wait := 7 * ttl / 8
select {
case <-time.After(wait):
case <-ctx.Done():
return
}
}
}()
case <-ctx.Done():
}
}()
Expand Down
20 changes: 7 additions & 13 deletions p2p/host/routed/routed.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/protocol"

logging "github.com/ipfs/go-log"
circuit "github.com/libp2p/go-libp2p-circuit"
lgbl "github.com/libp2p/go-libp2p-loggables"
logging "github.com/ipfs/go-log/v2"

ma "github.com/multiformats/go-multiaddr"
)
Expand Down Expand Up @@ -73,7 +71,7 @@ func (rh *RoutedHost) Connect(ctx context.Context, pi peer.AddrInfo) error {
// we need to make sure the relay's addr itself is in the peerstore or else
// we wont be able to dial it.
for _, addr := range addrs {
_, err := addr.ValueForProtocol(circuit.P_CIRCUIT)
_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
if err != nil {
// not a relay address
continue
Expand Down Expand Up @@ -119,21 +117,17 @@ func (rh *RoutedHost) findPeerAddrs(ctx context.Context, id peer.ID) ([]ma.Multi

if pi.ID != id {
err = fmt.Errorf("routing failure: provided addrs for different peer")
logRoutingErrDifferentPeers(ctx, id, pi.ID, err)
log.Errorw("got wrong peer",
"error", err,
"wantedPeer", id,
"gotPeer", pi.ID,
)
return nil, err
}

return pi.Addrs, nil
}

func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err error) {
lm := make(lgbl.DeferredMap)
lm["error"] = err
lm["wantedPeer"] = func() interface{} { return wanted.Pretty() }
lm["gotPeer"] = func() interface{} { return got.Pretty() }
log.Event(ctx, "routingError", lm)
}

func (rh *RoutedHost) ID() peer.ID {
return rh.host.ID()
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/conngater/conngater.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
"github.com/ipfs/go-datastore/query"
logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"
)

// BasicConnectionGater implements a connection gater that allows the application to perform
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mocknet
import (
"context"

logging "github.com/ipfs/go-log"
logging "github.com/ipfs/go-log/v2"
)

var log = logging.Logger("mocknet")
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/mock/mock_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ func (mn *mocknet) validate(n network.Network) (*peernet, error) {

nr, ok := n.(*peernet)
if !ok {
return nil, fmt.Errorf("Network not supported (use mock package nets only)")
return nil, fmt.Errorf("network not supported (use mock package nets only)")
}

if _, found := mn.nets[nr.peer]; !found {
return nil, fmt.Errorf("Network not on mocknet. is it from another mocknet?")
return nil, fmt.Errorf("network not on mocknet. is it from another mocknet?")
}

return nr, nil
Expand Down
9 changes: 0 additions & 9 deletions p2p/net/mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,10 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
"github.com/libp2p/go-libp2p-core/test"
"github.com/libp2p/go-libp2p-testing/ci"
tnet "github.com/libp2p/go-libp2p-testing/net"
)

func randPeer(t *testing.T) peer.ID {
p, err := test.RandPeerID()
if err != nil {
t.Fatal(err)
}
return p
}

func TestNetworkSetup(t *testing.T) {
ctx := context.Background()
id1 := tnet.RandIdentityOrFatal(t)
Expand Down
Loading