-
Notifications
You must be signed in to change notification settings - Fork 10
Improve go-namesys documentation #1
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ import ( | |
|
||
const ipnsPrefix = "/ipns/" | ||
|
||
// DefaultRecordEOL specifies the time that the network will cache IPNS | ||
// records after being publihsed. Records should be re-published before this | ||
// interval expires. | ||
const DefaultRecordEOL = 24 * time.Hour | ||
|
||
// IpnsPublisher is capable of publishing and resolving names to the IPFS | ||
|
@@ -49,11 +52,13 @@ func (p *IpnsPublisher) Publish(ctx context.Context, k ci.PrivKey, value path.Pa | |
return p.PublishWithEOL(ctx, k, value, time.Now().Add(DefaultRecordEOL)) | ||
} | ||
|
||
// IpnsDsKey returns a datastore key given an IPNS identifier (peer | ||
// ID). Defines the storage key for IPNS records in the local datastore. | ||
func IpnsDsKey(id peer.ID) ds.Key { | ||
return ds.NewKey("/ipns/" + base32.RawStdEncoding.EncodeToString([]byte(id))) | ||
} | ||
|
||
// PublishedNames returns the latest IPNS records published by this node and | ||
// ListPublished returns the latest IPNS records published by this node and | ||
// their expiration times. | ||
// | ||
// This method will not search the routing system for records published by other | ||
|
@@ -212,6 +217,10 @@ func checkCtxTTL(ctx context.Context) (time.Duration, bool) { | |
return d, ok | ||
} | ||
|
||
// PutRecordToRouting publishes the given entry using the provided ValueStore, | ||
// using the ID associated to the provided public key and embedding the public | ||
// key in the IPNS entry when it cannot be extracted from the ID. In that | ||
// case, it calls PublishPublicKey in addition to PublishEntry. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is true, although it's something we may drop as more of the IPFS DHT upgrades as it needlessly slows down publishes. Unfortunately, the comment below about waiting for go-ipfs v0.4.16 to be widespread was overly optimistic as the code was still bugged and was only fixed in ipfs/kubo#7549 (go-ipfs v0.7.0). All this is just to say that no one should be relying on this behavior as part of the function contract. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I change the godoc line and not mention the embedding part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, IMO a library developer doesn't need to be aware of all the optimization details here (i.e. smaller Ed25519 keys will save a bunch of space compared with larger RSA keys). Continuing below where we can use GitHub suggestions (my bad for not referencing the whole block in my initial comment).
hsanjuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k ci.PubKey, entry *pb.IpnsEntry) error { | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
@@ -260,6 +269,8 @@ func waitOnErrChan(ctx context.Context, errs chan error) error { | |
} | ||
} | ||
|
||
// PublishPublicKey stores the given public key in the ValueStore with the | ||
// given key. | ||
func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk ci.PubKey) error { | ||
log.Debugf("Storing pubkey at: %s", k) | ||
pkbytes, err := pubk.Bytes() | ||
|
@@ -271,6 +282,8 @@ func PublishPublicKey(ctx context.Context, r routing.ValueStore, k string, pubk | |
return r.PutValue(ctx, k, pkbytes) | ||
} | ||
|
||
// PublishEntry stores the given IpnsEntry in the ValueStore with the given | ||
// ipnskey. | ||
func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec *pb.IpnsEntry) error { | ||
data, err := proto.Marshal(rec) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.
Note: we probably want to allow access to partial resolutions (or returning the full resolution path), but that's later 😄