func PutRecordToRouting(ctx context.Context, k ci.PrivKey, value path.Path, seqnum uint64, eol time.Time, r routing.IpfsRouting, id peer.ID) error { namekey, ipnskey := IpnsKeysForID(id) entry, err := CreateRoutingEntryData(k, value, seqnum, eol) if err != nil { return err } ttl, ok := checkCtxTTL(ctx) if ok { entry.Ttl = proto.Uint64(uint64(ttl.Nanoseconds())) } errs := make(chan error) go func() { errs <- PublishEntry(ctx, r, ipnskey, entry) }() go func() { errs <- PublishPublicKey(ctx, r, namekey, k.GetPublic()) }() err = waitOnErrChan(ctx, errs) if err != nil { return err } err = waitOnErrChan(ctx, errs) if err != nil { return err } return nil }
// MakePutRecord creates and signs a dht record for the given key/value pair func MakePutRecord(sk ci.PrivKey, key key.Key, value []byte, sign bool) (*pb.Record, error) { record := new(pb.Record) record.Key = proto.String(string(key)) record.Value = value pkh, err := sk.GetPublic().Hash() if err != nil { return nil, err } record.Author = proto.String(string(pkh)) if sign { blob := RecordBlobForSig(record) sig, err := sk.Sign(blob) if err != nil { return nil, err } record.Signature = sig } return record, nil }