Skip to content

Commit 2047bfb

Browse files
committed
rerun
1 parent a40aeba commit 2047bfb

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

api/network.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"strings"
2424
"time"
2525

26-
"github.com/libp2p/go-libp2p/core/peer"
2726
"github.com/libp2p/go-libp2p/core/protocol"
2827
)
2928

@@ -77,14 +76,6 @@ const (
7776
TokenRefreshCheckInterval = 10 * time.Minute
7877
)
7978

80-
func CanonicalPeerID(s string) (string, error) {
81-
p, err := peer.Decode(s)
82-
if err != nil {
83-
return "", err
84-
}
85-
return p.String(), nil
86-
}
87-
8879
// EnrollChallenge is the payload a bootstrap enrollee signs to prove
8980
// possession of the private half of BootstrapEnrollRequest.public_key at
9081
// POST /enroll, carried in that message's timestamp/challenge_signature

internal/controlplane/mesh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ func canonicalPeerID(peerID string) string {
169169
if peerID == "" {
170170
return ""
171171
}
172-
canonical, err := api.CanonicalPeerID(peerID)
172+
p, err := peer.Decode(peerID)
173173
if err != nil {
174174
return peerID
175175
}
176-
return canonical
176+
return p.String()
177177
}
178178

179179
func (p *P2PMeshAdapter) DiscoverServices(ctx context.Context, serviceType string) ([]*ServiceAnnouncement, error) {

internal/storage/peer_id_canonicalization_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/google/sam/api"
2524
libcrypto "github.com/libp2p/go-libp2p/core/crypto"
2625
"github.com/libp2p/go-libp2p/core/peer"
2726
)
@@ -373,23 +372,23 @@ func TestCanonicalPeerID(t *testing.T) {
373372
id := newPeerID(t)
374373
alias := aliasOf(t, id)
375374

376-
canonical, err := api.CanonicalPeerID(alias)
375+
canonical, err := canonicalPeerID(alias)
377376
if err != nil {
378377
t.Fatalf("failed to canonicalize alias: %v", err)
379378
}
380379
if canonical != id.String() {
381380
t.Errorf("canonical = %q, want %q", canonical, id.String())
382381
}
383382

384-
canonical, err = api.CanonicalPeerID(id.String())
383+
canonical, err = canonicalPeerID(id.String())
385384
if err != nil {
386385
t.Fatalf("failed to canonicalize canonical id: %v", err)
387386
}
388387
if canonical != id.String() {
389388
t.Errorf("canonical form is not stable: %q", canonical)
390389
}
391390

392-
if _, err := api.CanonicalPeerID("not-a-peer-id"); err == nil {
391+
if _, err := canonicalPeerID("not-a-peer-id"); err == nil {
393392
t.Error("expected an error for an undecodable peer id")
394393
}
395394
}

internal/storage/sql_store.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/google/sam/api"
2727
log "github.com/ipfs/go-log/v2"
28+
"github.com/libp2p/go-libp2p/core/peer"
2829

2930
// Register PG and SQLite drivers
3031
_ "github.com/jackc/pgx/v5/stdlib"
@@ -519,6 +520,14 @@ func (s *SQLStore) rebind(query string) string {
519520
return result.String()
520521
}
521522

523+
func canonicalPeerID(raw string) (string, error) {
524+
p, err := peer.Decode(raw)
525+
if err != nil {
526+
return "", err
527+
}
528+
return p.String(), nil
529+
}
530+
522531
func migrateCanonicalPeerIDs(ctx context.Context, s *SQLStore, tx *sql.Tx) error {
523532
if err := canonicalizeNodePeerIDs(ctx, s, tx); err != nil {
524533
return err
@@ -548,7 +557,7 @@ func canonicalizeNodePeerIDs(ctx context.Context, s *SQLStore, tx *sql.Tx) error
548557
if err := rows.Scan(&r.rawPeerID, &r.banned); err != nil {
549558
return fmt.Errorf("failed to scan node: %w", err)
550559
}
551-
canonical, err := api.CanonicalPeerID(r.rawPeerID)
560+
canonical, err := canonicalPeerID(r.rawPeerID)
552561
if err != nil {
553562
logger.Warnw("Ignoring node with undecodable peer ID", "peer_id", r.rawPeerID)
554563
continue
@@ -607,7 +616,7 @@ func canonicalizeEnrollmentRequestPeerIDs(ctx context.Context, s *SQLStore, tx *
607616
if err := rows.Scan(&r.id, &r.rawPeerID, &r.createdAt); err != nil {
608617
return fmt.Errorf("failed to scan enrollment request: %w", err)
609618
}
610-
canonical, err := api.CanonicalPeerID(r.rawPeerID)
619+
canonical, err := canonicalPeerID(r.rawPeerID)
611620
if err != nil {
612621
logger.Warnw("Ignoring enrollment request with undecodable peer ID", "peer_id", r.rawPeerID)
613622
continue
@@ -668,7 +677,7 @@ func canonicalizeRouterPeerIDs(ctx context.Context, s *SQLStore, tx *sql.Tx) err
668677
if err := rows.Scan(&r.rawPeerID, &r.lastRenewal); err != nil {
669678
return fmt.Errorf("failed to scan router: %w", err)
670679
}
671-
canonical, err := api.CanonicalPeerID(r.rawPeerID)
680+
canonical, err := canonicalPeerID(r.rawPeerID)
672681
if err != nil {
673682
logger.Warnw("Ignoring router with undecodable peer ID", "peer_id", r.rawPeerID)
674683
continue

0 commit comments

Comments
 (0)