diff --git a/core/core.go b/core/core.go index 6262b1cc72fe..94c9e9d39f54 100644 --- a/core/core.go +++ b/core/core.go @@ -30,6 +30,8 @@ import ( ctxc "github.com/jbenet/go-ipfs/util/ctxcloser" ) +const IpnsValidatorTag = "ipns" + var log = u.Logger("core") // IpfsNode is IPFS Core module. It represents an IPFS instance. @@ -144,7 +146,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) { // setup routing service dhtRouting := dht.NewDHT(ctx, n.Identity, n.Peerstore, n.Network, dhtService, n.Datastore) - dhtRouting.Validators["ipns"] = namesys.ValidateIpnsRecord + dhtRouting.Validators[IpnsValidatorTag] = namesys.ValidateIpnsRecord // TODO(brian): perform this inside NewDHT factory method dhtService.SetHandler(dhtRouting) // wire the handler to the service. diff --git a/namesys/publisher.go b/namesys/publisher.go index 5b2da0c17c9e..a6be2a570b90 100644 --- a/namesys/publisher.go +++ b/namesys/publisher.go @@ -90,7 +90,7 @@ func createRoutingEntryData(pk ci.PrivKey, val string) ([]byte, error) { entry.Value = []byte(val) typ := pb.IpnsEntry_EOL entry.ValidityType = &typ - entry.Validity = []byte(time.Now().Add(time.Hour * 24).String()) + entry.Validity = []byte(u.FormatRFC3339(time.Now().Add(time.Hour * 24))) sig, err := pk.Sign(ipnsEntryDataForSig(entry)) if err != nil { @@ -119,8 +119,7 @@ func ValidateIpnsRecord(k u.Key, val []byte) error { } switch entry.GetValidityType() { case pb.IpnsEntry_EOL: - defaultTimeFormat := "2006-01-02 15:04:05.999999999 -0700 MST" - t, err := time.Parse(defaultTimeFormat, string(entry.GetValue())) + t, err := u.ParseRFC3339(string(entry.GetValue())) if err != nil { log.Error("Failed parsing time for ipns record EOL") return err diff --git a/routing/dht/dht.go b/routing/dht/dht.go index db17f9e7ebbc..efe457c6585c 100644 --- a/routing/dht/dht.go +++ b/routing/dht/dht.go @@ -273,6 +273,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer, // make sure record is still valid err = dht.verifyRecord(record) if err != nil { + log.Error("Received invalid record!") return nil, nil, err } return record.GetValue(), nil, nil