Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
4c0f18cb
Commit
4c0f18cb
authored
Sep 12, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Oct 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement ipns publisher code
parent
8ddfb57c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
21 deletions
+95
-21
core/core.go
core/core.go
+0
-2
namesys/entry.pb.go
namesys/entry.pb.go
+7
-7
namesys/entry.proto
namesys/entry.proto
+1
-1
namesys/publisher.go
namesys/publisher.go
+64
-0
namesys/resolver.go
namesys/resolver.go
+14
-1
namesys/routing.go
namesys/routing.go
+9
-10
No files found.
core/core.go
View file @
4c0f18cb
...
...
@@ -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
()
{}
namesys/entry.pb.go
View file @
4c0f18cb
...
...
@@ -9,7 +9,7 @@ It is generated from these files:
entry.proto
It has these top-level messages:
I
n
psEntry
Ip
n
sEntry
*/
package
namesys
...
...
@@ -20,24 +20,24 @@ import math "math"
var
_
=
proto
.
Marshal
var
_
=
math
.
Inf
type
I
n
psEntry
struct
{
type
Ip
n
sEntry
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
*
I
n
psEntry
)
Reset
()
{
*
m
=
I
n
psEntry
{}
}
func
(
m
*
I
n
psEntry
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
I
n
psEntry
)
ProtoMessage
()
{}
func
(
m
*
Ip
n
sEntry
)
Reset
()
{
*
m
=
Ip
n
sEntry
{}
}
func
(
m
*
Ip
n
sEntry
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Ip
n
sEntry
)
ProtoMessage
()
{}
func
(
m
*
I
n
psEntry
)
GetValue
()
[]
byte
{
func
(
m
*
Ip
n
sEntry
)
GetValue
()
[]
byte
{
if
m
!=
nil
{
return
m
.
Value
}
return
nil
}
func
(
m
*
I
n
psEntry
)
GetSignature
()
[]
byte
{
func
(
m
*
Ip
n
sEntry
)
GetSignature
()
[]
byte
{
if
m
!=
nil
{
return
m
.
Signature
}
...
...
namesys/entry.proto
View file @
4c0f18cb
package
namesys
;
message
I
n
psEntry
{
message
Ip
n
sEntry
{
required
bytes
value
=
1
;
required
bytes
signature
=
2
;
}
namesys/publisher.go
0 → 100644
View file @
4c0f18cb
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
)
}
namesys/resolver.go
View file @
4c0f18cb
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
)
...
...
namesys/routing.go
View file @
4c0f18cb
...
...
@@ -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
(
I
n
psEntry
)
entry
:=
new
(
Ip
n
sEntry
)
err
=
proto
.
Unmarshal
(
val
,
entry
)
if
err
!=
nil
{
return
""
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment