Skip to content

Commit

Permalink
address comments from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 16, 2014
1 parent 736b4b2 commit 9301e61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion core/core.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions namesys/publisher.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions routing/dht/dht.go
Expand Up @@ -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
Expand Down

0 comments on commit 9301e61

Please sign in to comment.