diff --git a/namesys/dns_test.go b/namesys/dns_test.go index cde077e47..adab3e7d2 100644 --- a/namesys/dns_test.go +++ b/namesys/dns_test.go @@ -21,7 +21,6 @@ func (m *mockDNS) lookupTXT(ctx context.Context, name string) (txt []string, err } func TestDnsEntryParsing(t *testing.T) { - goodEntries := []string{ "QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", "dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index 6ae94a6cf..c3e553429 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -160,7 +160,7 @@ func TestPublishWithTTL(t *testing.T) { ttl := 1 * time.Second eol := time.Now().Add(2 * time.Second) - ctx := context.WithValue(context.Background(), "ipns-publish-ttl", ttl) + ctx := ContextWithTTL(context.Background(), ttl) err = nsys.Publish(ctx, priv, p) if err != nil { t.Fatal(err) diff --git a/namesys/publisher.go b/namesys/publisher.go index 37dab0ed2..edf57375a 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -206,7 +206,7 @@ func (p *IpnsPublisher) PublishWithEOL(ctx context.Context, k ci.PrivKey, value // as such, i'm using the context to wire it through to avoid changing too // much code along the way. func checkCtxTTL(ctx context.Context) (time.Duration, bool) { - v := ctx.Value("ipns-publish-ttl") + v := ctx.Value(ttlContextKey) if v == nil { return 0, false } @@ -296,3 +296,13 @@ func PublishEntry(ctx context.Context, r routing.ValueStore, ipnskey string, rec func PkKeyForID(id peer.ID) string { return "/pk/" + string(id) } + +// contextKey is a private comparable type used to hold value keys in contexts +type contextKey string + +var ttlContextKey contextKey = "ipns-publish-ttl" + +// ContextWithTTL returns a copy of the parent context with an added value representing the TTL +func ContextWithTTL(ctx context.Context, ttl time.Duration) context.Context { + return context.WithValue(context.Background(), ttlContextKey, ttl) +} diff --git a/namesys/publisher_test.go b/namesys/publisher_test.go index 625103383..afc9efcc2 100644 --- a/namesys/publisher_test.go +++ b/namesys/publisher_test.go @@ -3,10 +3,11 @@ package namesys import ( "context" "crypto/rand" - "github.com/ipfs/go-path" "testing" "time" + "github.com/ipfs/go-path" + ds "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" dshelp "github.com/ipfs/go-ipfs-ds-help"