Skip to content

Commit

Permalink
Do not publish public keys extractable from ID
Browse files Browse the repository at this point in the history
Initial implementation for ipfs#3896

The function `peer.ExtractPublicKey()` is part of PR libp2p/go-libp2p-peer#14

cc @whyrusleeping
  • Loading branch information
JustinDrake committed Jun 21, 2017
1 parent db6073b commit cc76407
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions namesys/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,36 @@ func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqn
entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds()))
}

errs := make(chan error, 2)
var errorChanSize int
var errorChan chan error

go func() {
errs <- PublishEntry(ctx, r, ipnskey, entry)
}()
// Attempt to extract the public key from the ID
var extractedPublicKey = peer.ExtractPublicKey()

if extractedPublicKey == nil {
errorChanSize = 2 // IPNS and public key
} else {
errorChanSize = 1 // IPNS only
}

errorChan = make(chan error, errorChanSize)

go func() {
errs <- PublishPublicKey(ctx, r, namekey, k.GetPublic())
errorChan <- PublishEntry(ctx, r, ipnskey, entry)
}()

if err := waitOnErrChan(ctx, errs); err != nil {
return err
// Publish the public key if a public key cannot be extracted from the ID
if extractedPublicKey == nil {
go func() {
errorChan <- PublishPublicKey(ctx, r, namekey, k.GetPublic())
}()

if err := waitOnErrChan(ctx, errorChan); err != nil {
return err
}
}

return waitOnErrChan(ctx, errs)
return waitOnErrChan(ctx, errorChan)
}

func waitOnErrChan(ctx context.Context, errs chan error) error {
Expand Down

0 comments on commit cc76407

Please sign in to comment.