From 1cf7a1824a3aa8c8224365b2678d3845f236588c Mon Sep 17 00:00:00 2001
From: Jeromy <jeromyj@gmail.com>
Date: Mon, 10 Nov 2014 15:48:49 -0800
Subject: [PATCH] validator functions and ipns completion

---
 namesys/publisher.go   |  2 +-
 namesys/routing.go     |  2 +-
 routing/dht/dht.go     |  3 +++
 routing/dht/records.go | 10 ++++++++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/namesys/publisher.go b/namesys/publisher.go
index 636e3fb49..365855b1b 100644
--- a/namesys/publisher.go
+++ b/namesys/publisher.go
@@ -53,7 +53,7 @@ func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error {
 
 	// Store associated public key
 	timectx, _ := context.WithDeadline(ctx, time.Now().Add(time.Second*4))
-	err = p.routing.PutValue(timectx, u.Key(nameb), pkbytes)
+	err = p.routing.PutValue(timectx, u.Key("/pk/"+string(nameb)), pkbytes)
 	if err != nil {
 		return err
 	}
diff --git a/namesys/routing.go b/namesys/routing.go
index 5f877bdc3..85eca331a 100644
--- a/namesys/routing.go
+++ b/namesys/routing.go
@@ -63,7 +63,7 @@ func (r *routingResolver) Resolve(name string) (string, error) {
 
 	// name should be a public key retrievable from ipfs
 	// /ipfs/<name>
-	key := u.Key(hash)
+	key := u.Key("/pk/" + string(hash))
 	pkval, err := r.routing.GetValue(ctx, key)
 	if err != nil {
 		log.Warning("RoutingResolve PubKey Get failed.")
diff --git a/routing/dht/dht.go b/routing/dht/dht.go
index 5d4caaa84..666387184 100644
--- a/routing/dht/dht.go
+++ b/routing/dht/dht.go
@@ -84,7 +84,10 @@ func NewDHT(ctx context.Context, p peer.Peer, ps peer.Peerstore, dialer inet.Dia
 	dht.routingTables[1] = kb.NewRoutingTable(20, kb.ConvertPeerID(p.ID()), time.Millisecond*1000)
 	dht.routingTables[2] = kb.NewRoutingTable(20, kb.ConvertPeerID(p.ID()), time.Hour)
 	dht.birth = time.Now()
+
 	dht.Validators = make(map[string]ValidatorFunc)
+	dht.Validators["ipns"] = ValidateIpnsRecord
+	dht.Validators["pk"] = ValidatePublicKeyRecord
 
 	if doPinging {
 		dht.Children().Add(1)
diff --git a/routing/dht/records.go b/routing/dht/records.go
index 692f04d4f..763b48f68 100644
--- a/routing/dht/records.go
+++ b/routing/dht/records.go
@@ -69,3 +69,13 @@ func (dht *IpfsDHT) verifyRecord(r *pb.Record) error {
 
 	return fnc(u.Key(r.GetKey()), r.GetValue())
 }
+
+func ValidateIpnsRecord(k u.Key, val []byte) error {
+	// TODO:
+	return nil
+}
+
+func ValidatePublicKeyRecord(k u.Key, val []byte) error {
+	// TODO:
+	return nil
+}
-- 
GitLab