1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

address comments from PR

This commit is contained in:
Jeromy
2014-11-14 11:00:45 -08:00
committed by Juan Batiz-Benet
parent f1ee23770d
commit f45d575a96
3 changed files with 6 additions and 4 deletions

View File

@ -31,6 +31,8 @@ import (
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser" ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
) )
const IpnsValidatorTag = "ipns"
var log = u.Logger("core") var log = u.Logger("core")
// IpfsNode is IPFS Core module. It represents an IPFS instance. // IpfsNode is IPFS Core module. It represents an IPFS instance.
@ -156,7 +158,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
// setup routing service // setup routing service
dhtRouting := dht.NewDHT(ctx, n.Identity, n.Peerstore, n.Network, dhtService, n.Datastore) 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 // TODO(brian): perform this inside NewDHT factory method
dhtService.SetHandler(dhtRouting) // wire the handler to the service. dhtService.SetHandler(dhtRouting) // wire the handler to the service.

View File

@ -90,7 +90,7 @@ func createRoutingEntryData(pk ci.PrivKey, val string) ([]byte, error) {
entry.Value = []byte(val) entry.Value = []byte(val)
typ := pb.IpnsEntry_EOL typ := pb.IpnsEntry_EOL
entry.ValidityType = &typ 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)) sig, err := pk.Sign(ipnsEntryDataForSig(entry))
if err != nil { if err != nil {
@ -119,8 +119,7 @@ func ValidateIpnsRecord(k u.Key, val []byte) error {
} }
switch entry.GetValidityType() { switch entry.GetValidityType() {
case pb.IpnsEntry_EOL: case pb.IpnsEntry_EOL:
defaultTimeFormat := "2006-01-02 15:04:05.999999999 -0700 MST" t, err := u.ParseRFC3339(string(entry.GetValue()))
t, err := time.Parse(defaultTimeFormat, string(entry.GetValue()))
if err != nil { if err != nil {
log.Error("Failed parsing time for ipns record EOL") log.Error("Failed parsing time for ipns record EOL")
return err return err

View File

@ -273,6 +273,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
// make sure record is still valid // make sure record is still valid
err = dht.verifyRecord(record) err = dht.verifyRecord(record)
if err != nil { if err != nil {
log.Error("Received invalid record!")
return nil, nil, err return nil, nil, err
} }
return record.GetValue(), nil, nil return record.GetValue(), nil, nil