Skip to content

Commit f45d575

Browse files
whyrusleepingjbenet
authored andcommitted
address comments from PR
1 parent f1ee237 commit f45d575

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

core/core.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
3232
)
3333

34+
const IpnsValidatorTag = "ipns"
35+
3436
var log = u.Logger("core")
3537

3638
// 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) {
156158

157159
// setup routing service
158160
dhtRouting := dht.NewDHT(ctx, n.Identity, n.Peerstore, n.Network, dhtService, n.Datastore)
159-
dhtRouting.Validators["ipns"] = namesys.ValidateIpnsRecord
161+
dhtRouting.Validators[IpnsValidatorTag] = namesys.ValidateIpnsRecord
160162

161163
// TODO(brian): perform this inside NewDHT factory method
162164
dhtService.SetHandler(dhtRouting) // wire the handler to the service.

namesys/publisher.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func createRoutingEntryData(pk ci.PrivKey, val string) ([]byte, error) {
9090
entry.Value = []byte(val)
9191
typ := pb.IpnsEntry_EOL
9292
entry.ValidityType = &typ
93-
entry.Validity = []byte(time.Now().Add(time.Hour * 24).String())
93+
entry.Validity = []byte(u.FormatRFC3339(time.Now().Add(time.Hour * 24)))
9494

9595
sig, err := pk.Sign(ipnsEntryDataForSig(entry))
9696
if err != nil {
@@ -119,8 +119,7 @@ func ValidateIpnsRecord(k u.Key, val []byte) error {
119119
}
120120
switch entry.GetValidityType() {
121121
case pb.IpnsEntry_EOL:
122-
defaultTimeFormat := "2006-01-02 15:04:05.999999999 -0700 MST"
123-
t, err := time.Parse(defaultTimeFormat, string(entry.GetValue()))
122+
t, err := u.ParseRFC3339(string(entry.GetValue()))
124123
if err != nil {
125124
log.Error("Failed parsing time for ipns record EOL")
126125
return err

routing/dht/dht.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.Peer,
273273
// make sure record is still valid
274274
err = dht.verifyRecord(record)
275275
if err != nil {
276+
log.Error("Received invalid record!")
276277
return nil, nil, err
277278
}
278279
return record.GetValue(), nil, nil

0 commit comments

Comments
 (0)