Commit 4c0f18cb authored by Jeromy's avatar Jeromy Committed by Juan Batiz-Benet

implement ipns publisher code

parent 8ddfb57c
......@@ -238,5 +238,3 @@ func (n *IpfsNode) PinDagNode(nd *merkledag.Node) error {
u.DOut("Pinning node. Currently No-Op\n")
return nil
}
func (n *IpfsNode) SetIpnsEntry() {}
......@@ -9,7 +9,7 @@ It is generated from these files:
entry.proto
It has these top-level messages:
InpsEntry
IpnsEntry
*/
package namesys
......@@ -20,24 +20,24 @@ import math "math"
var _ = proto.Marshal
var _ = math.Inf
type InpsEntry struct {
type IpnsEntry struct {
Value []byte `protobuf:"bytes,1,req,name=value" json:"value,omitempty"`
Signature []byte `protobuf:"bytes,2,req,name=signature" json:"signature,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *InpsEntry) Reset() { *m = InpsEntry{} }
func (m *InpsEntry) String() string { return proto.CompactTextString(m) }
func (*InpsEntry) ProtoMessage() {}
func (m *IpnsEntry) Reset() { *m = IpnsEntry{} }
func (m *IpnsEntry) String() string { return proto.CompactTextString(m) }
func (*IpnsEntry) ProtoMessage() {}
func (m *InpsEntry) GetValue() []byte {
func (m *IpnsEntry) GetValue() []byte {
if m != nil {
return m.Value
}
return nil
}
func (m *InpsEntry) GetSignature() []byte {
func (m *IpnsEntry) GetSignature() []byte {
if m != nil {
return m.Signature
}
......
package namesys;
message InpsEntry {
message IpnsEntry {
required bytes value = 1;
required bytes signature = 2;
}
package namesys
import (
"code.google.com/p/goprotobuf/proto"
ci "github.com/jbenet/go-ipfs/crypto"
mdag "github.com/jbenet/go-ipfs/merkledag"
routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util"
)
type IpnsPublisher struct {
dag *mdag.DAGService
routing routing.IpfsRouting
}
// Publish accepts a keypair and a value,
func (p *IpnsPublisher) Publish(k ci.PrivKey, value u.Key) error {
data, err := CreateEntryData(k, value)
if err != nil {
return err
}
pubkey := k.GetPublic()
pkbytes, err := pubkey.Bytes()
if err != nil {
return nil
}
nameb, err := u.Hash(pkbytes)
if err != nil {
return nil
}
namekey := u.Key(nameb).Pretty()
ipnskey, err := u.Hash([]byte("ipns:" + namekey))
if err != nil {
return err
}
// Store associated public key
err = p.routing.PutValue(u.Key(nameb), pkbytes)
if err != nil {
return err
}
// Store ipns entry at h("ipns:"+b58(h(pubkey)))
err = p.routing.PutValue(u.Key(ipnskey), data)
if err != nil {
return err
}
return nil
}
func CreateEntryData(pk ci.PrivKey, val u.Key) ([]byte, error) {
entry := new(IpnsEntry)
sig, err := pk.Sign([]byte(val))
if err != nil {
return nil, err
}
entry.Signature = sig
entry.Value = []byte(val)
return proto.Marshal(entry)
}
package namesys
import "strings"
import (
"strings"
mdag "github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/routing"
)
type MasterResolver struct {
dns *DNSResolver
......@@ -8,6 +13,14 @@ type MasterResolver struct {
pro *ProquintResolver
}
func NewMasterResolver(r routing.IpfsRouting, dag *mdag.DAGService) *MasterResolver {
mr := new(MasterResolver)
mr.dns = new(DNSResolver)
mr.pro = new(ProquintResolver)
mr.routing = NewRoutingResolver(r, dag)
return mr
}
func (mr *MasterResolver) Resolve(name string) (string, error) {
if strings.Contains(name, ".") {
return mr.dns.Resolve(name)
......
......@@ -13,18 +13,17 @@ import (
mh "github.com/jbenet/go-multihash"
)
// RoutingName is the de-serialized name structure that is stored (serialized)
// in the routing system. Basically, a hash + a digital signature. (serialization can be
// protobuf, or a simple binary format)
type RoutingName struct {
Hash u.Key
Signature []byte
}
// RoutingResolver implements NSResolver for the main IPFS SFS-like naming
type RoutingResolver struct {
routing routing.IpfsRouting
dag mdag.DAGService
dag *mdag.DAGService
}
func NewRoutingResolver(route routing.IpfsRouting, dagservice *mdag.DAGService) *RoutingResolver {
return &RoutingResolver{
routing: route,
dag: dagservice,
}
}
func (r *RoutingResolver) Resolve(name string) (string, error) {
......@@ -47,7 +46,7 @@ func (r *RoutingResolver) Resolve(name string) (string, error) {
return "", err
}
entry := new(InpsEntry)
entry := new(IpnsEntry)
err = proto.Unmarshal(val, entry)
if err != nil {
return "", err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment