some comments
Jeromy committed
Nov 11, 2014 at 19:43 UTC
cd4e23bc2e81d8d5dcd103fc08cbb7b3d0c083c4
2 files changed
+14
namesys/publisher.go
+4
@@ -20,6 +20,8 @@ import (
20
// invalid due to being too old
21
var ErrExpiredRecord = errors.New("expired record")
22
23
+// ErrUnrecognizedValidity is returned when an IpnsRecord has an
24
+// unknown validity type.
25
var ErrUnrecognizedValidity = errors.New("unrecognized validity type")
26
27
// ipnsPublisher is capable of publishing and resolving names to the IPFS
@@ -107,6 +109,8 @@ func ipnsEntryDataForSig(e *pb.IpnsEntry) []byte {
109
[]byte{})
110
}
111
112
+// ValidateIpnsRecord implements ValidatorFunc and verifies that the
113
+// given 'val' is an IpnsEntry and that that entry is valid.
114
func ValidateIpnsRecord(k u.Key, val []byte) error {
115
entry := new(pb.IpnsEntry)
116
err := proto.Unmarshal(val, entry)
routing/dht/records.go
+10
@@ -14,9 +14,16 @@ import (
14
u "github.com/jbenet/go-ipfs/util"
15
)
16
17
+// ValidatorFunc is a function that is called to validate a given
18
+// type of DHTRecord.
19
type ValidatorFunc func(u.Key, []byte) error
20
21
+// ErrBadRecord is returned any time a dht record is found to be
22
+// incorrectly formatted or signed.
23
var ErrBadRecord = errors.New("bad dht record")
24
+
25
+// ErrInvalidRecordType is returned if a DHTRecord keys prefix
26
+// is not found in the Validator map of the DHT.
27
var ErrInvalidRecordType = errors.New("invalid record keytype")
28
29
// creates and signs a dht record for the given key/value pair
@@ -96,6 +103,9 @@ func (dht *IpfsDHT) verifyRecord(r *pb.Record) error {
103
return fnc(u.Key(r.GetKey()), r.GetValue())
104
}
105
106
+// ValidatePublicKeyRecord implements ValidatorFunc and
107
+// verifies that the passed in record value is the PublicKey
108
+// that matches the passed in key.
109
func ValidatePublicKeyRecord(k u.Key, val []byte) error {
110
keyparts := bytes.Split([]byte(k), []byte("/"))
111
if len(keyparts) < 3 {