Skip to content

Commit

Permalink
refactor(p2p): implement hlib suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Jun 26, 2023
1 parent a00ae46 commit 39f3fbb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
3 changes: 2 additions & 1 deletion p2p/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func WithChainID[T ClientParameters](chainID string) Option[T] {
}
}

// TODO @renaynay
// WithPeerIDStore is a functional option that sets a peerIDStore to be used
// inside the peerTracker.
func WithPeerIDStore[T ClientParameters](pidstore PeerIDStore) Option[T] {
return func(p *T) {
switch t := any(p).(type) { //nolint:gocritic
Expand Down
2 changes: 1 addition & 1 deletion p2p/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (p *peerTracker) gc() {
}

// dumpPeers stores peers to the peerTracker's PeerIDStore if
// it exists.
// present.
func (p *peerTracker) dumpPeers(ctx context.Context) {
if p.pidstore == nil {
return
Expand Down
15 changes: 2 additions & 13 deletions p2p/peer_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ package p2p

import (
"context"
"crypto/rand"
"crypto/rsa"
"encoding/json"
"errors"
"testing"
"time"

"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
testpeer "github.com/libp2p/go-libp2p/core/test"
"github.com/libp2p/go-libp2p/p2p/net/conngater"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -109,16 +107,7 @@ func (d *dummyPIDStore) Load(ctx context.Context) ([]peer.ID, error) {
func generateRandomPeerlist(t *testing.T, length int) []peer.ID {
peerlist := make([]peer.ID, length)
for i := range peerlist {
key, err := rsa.GenerateKey(rand.Reader, 2096)
require.NoError(t, err)

_, pubkey, err := crypto.KeyPairFromStdKey(key)
require.NoError(t, err)

peerID, err := peer.IDFromPublicKey(pubkey)
require.NoError(t, err)

peerlist[i] = peerID
peerlist[i] = testpeer.RandPeerIDFatal(t)
}
return peerlist
}

0 comments on commit 39f3fbb

Please sign in to comment.