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-dms3
Commits
4d7b87df
Commit
4d7b87df
authored
Oct 08, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ipns' of github.com:jbenet/go-ipfs into ipns
parents
1aafd285
31cc605c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
14 deletions
+187
-14
Godeps/Godeps.json
Godeps/Godeps.json
+1
-1
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/keytransform.go
...thub.com/jbenet/datastore.go/keytransform/keytransform.go
+88
-0
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/keytransform_test.go
...com/jbenet/datastore.go/keytransform/keytransform_test.go
+60
-0
core/datastore.go
core/datastore.go
+5
-1
unixfs/data.pb.go
unixfs/data.pb.go
+1
-1
util/util.go
util/util.go
+32
-11
No files found.
Godeps/Godeps.json
View file @
4d7b87df
...
...
@@ -64,7 +64,7 @@
},
{
"ImportPath"
:
"github.com/jbenet/datastore.go"
,
"Rev"
:
"
e7d6f7cb9e3c207a04c5397c449d10a6f9d403a0
"
"Rev"
:
"
60ebc56447b5a8264cfed3ae3ff48deb984d7cf1
"
},
{
"ImportPath"
:
"github.com/jbenet/go-base58"
,
...
...
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/keytransform.go
0 → 100644
View file @
4d7b87df
package
keytransform
import
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
// KeyTransform is a function that transforms one key into another.
type
KeyTransform
func
(
ds
.
Key
)
ds
.
Key
// Datastore is a keytransform.Datastore
type
Datastore
interface
{
ds
.
Shim
// Transform runs the transformation function
Transform
(
ds
.
Key
)
ds
.
Key
// TransformFunc returns the KeyTransform function
TransformFunc
()
KeyTransform
}
// ktds keeps a KeyTransform function
type
ktds
struct
{
child
ds
.
Datastore
xform
KeyTransform
}
// WrapDatastore wraps a given datastore with a KeyTransform function.
// The resulting wrapped datastore will use the transform on all Datastore
// operations.
func
WrapDatastore
(
child
ds
.
Datastore
,
f
KeyTransform
)
Datastore
{
if
f
==
nil
{
panic
(
"f (KeyTransform) is nil"
)
}
if
child
==
nil
{
panic
(
"child (ds.Datastore) is nil"
)
}
return
&
ktds
{
child
,
f
}
}
// TransformFunc returns the KeyTransform function
func
(
d
*
ktds
)
TransformFunc
()
KeyTransform
{
return
d
.
xform
}
// Transform runs the KeyTransform function
func
(
d
*
ktds
)
Transform
(
k
ds
.
Key
)
ds
.
Key
{
return
d
.
xform
(
k
)
}
// Children implements ds.Shim
func
(
d
*
ktds
)
Children
()
[]
ds
.
Datastore
{
return
[]
ds
.
Datastore
{
d
.
child
}
}
// Put stores the given value, transforming the key first.
func
(
d
*
ktds
)
Put
(
key
ds
.
Key
,
value
interface
{})
(
err
error
)
{
return
d
.
child
.
Put
(
d
.
Transform
(
key
),
value
)
}
// Get returns the value for given key, transforming the key first.
func
(
d
*
ktds
)
Get
(
key
ds
.
Key
)
(
value
interface
{},
err
error
)
{
return
d
.
child
.
Get
(
d
.
Transform
(
key
))
}
// Has returns whether the datastore has a value for a given key, transforming
// the key first.
func
(
d
*
ktds
)
Has
(
key
ds
.
Key
)
(
exists
bool
,
err
error
)
{
return
d
.
child
.
Has
(
d
.
Transform
(
key
))
}
// Delete removes the value for given key
func
(
d
*
ktds
)
Delete
(
key
ds
.
Key
)
(
err
error
)
{
return
d
.
child
.
Delete
(
d
.
Transform
(
key
))
}
// KeyList returns a list of all keys in the datastore, transforming keys out.
func
(
d
*
ktds
)
KeyList
()
([]
ds
.
Key
,
error
)
{
keys
,
err
:=
d
.
child
.
KeyList
()
if
err
!=
nil
{
return
nil
,
err
}
for
i
,
k
:=
range
keys
{
keys
[
i
]
=
d
.
Transform
(
k
)
}
return
keys
,
nil
}
Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform/keytransform_test.go
0 → 100644
View file @
4d7b87df
package
keytransform_test
import
(
"bytes"
"testing"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
kt
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform"
.
"launchpad.net/gocheck"
)
// Hook up gocheck into the "go test" runner.
func
Test
(
t
*
testing
.
T
)
{
TestingT
(
t
)
}
type
DSSuite
struct
{
dir
string
ds
ds
.
Datastore
}
var
_
=
Suite
(
&
DSSuite
{})
func
(
ks
*
DSSuite
)
TestBasic
(
c
*
C
)
{
mpds
:=
ds
.
NewMapDatastore
()
ktds
:=
kt
.
WrapDatastore
(
mpds
,
func
(
k
ds
.
Key
)
ds
.
Key
{
return
k
.
Reverse
()
})
keys
:=
strsToKeys
([]
string
{
"foo"
,
"foo/bar"
,
"foo/bar/baz"
,
"foo/barb"
,
"foo/bar/bazb"
,
"foo/bar/baz/barb"
,
})
for
_
,
k
:=
range
keys
{
err
:=
ktds
.
Put
(
k
,
[]
byte
(
k
.
String
()))
c
.
Check
(
err
,
Equals
,
nil
)
}
for
_
,
k
:=
range
keys
{
v1
,
err
:=
ktds
.
Get
(
k
)
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v1
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
v2
,
err
:=
mpds
.
Get
(
k
.
Reverse
())
c
.
Check
(
err
,
Equals
,
nil
)
c
.
Check
(
bytes
.
Equal
(
v2
.
([]
byte
),
[]
byte
(
k
.
String
())),
Equals
,
true
)
}
}
func
strsToKeys
(
strs
[]
string
)
[]
ds
.
Key
{
keys
:=
make
([]
ds
.
Key
,
len
(
strs
))
for
i
,
s
:=
range
strs
{
keys
[
i
]
=
ds
.
NewKey
(
s
)
}
return
keys
}
core/datastore.go
View file @
4d7b87df
...
...
@@ -5,9 +5,12 @@ import (
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
fsds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/fs"
ktds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/keytransform"
lds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/leveldb"
syncds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go/sync"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
)
func
makeDatastore
(
cfg
config
.
Datastore
)
(
ds
.
ThreadSafeDatastore
,
error
)
{
...
...
@@ -28,7 +31,8 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
syncds
.
MutexWrap
(
d
),
nil
ktd
:=
ktds
.
WrapDatastore
(
d
,
u
.
DsKeyB58Encode
)
return
syncds
.
MutexWrap
(
ktd
),
nil
}
return
nil
,
fmt
.
Errorf
(
"Unknown datastore type: %s"
,
cfg
.
Type
)
...
...
unixfs/data.pb.go
View file @
4d7b87df
...
...
@@ -13,7 +13,7 @@ It has these top-level messages:
*/
package
unixfs
import
proto
"code.google.com/p/goprotobuf/proto"
import
proto
"
github.com/jbenet/go-ipfs/Godeps/_workspace/src/
code.google.com/p/goprotobuf/proto"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
...
...
util/util.go
View file @
4d7b87df
...
...
@@ -55,14 +55,34 @@ func (k Key) Pretty() string {
// DsKey returns a Datastore key
func
(
k
Key
)
DsKey
()
ds
.
Key
{
return
ds
.
NewKey
(
k
.
Pretty
(
))
return
ds
.
NewKey
(
string
(
k
))
}
// KeyFromDsKey returns a Datastore key
func
KeyFromDsKey
(
dsk
ds
.
Key
)
Key
{
l
:=
dsk
.
List
()
enc
:=
l
[
len
(
l
)
-
1
]
return
Key
(
b58
.
Decode
(
enc
))
return
Key
(
dsk
.
BaseNamespace
())
}
// DsKeyB58Encode returns a B58 encoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Encode
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
b58
.
Encode
([]
byte
(
n
)))
}
return
k
}
// DsKeyB58Decode returns a b58 decoded Datastore key
// TODO: this is hacky because it encodes every path component. some
// path components may be proper strings already...
func
DsKeyB58Decode
(
dsk
ds
.
Key
)
ds
.
Key
{
k
:=
ds
.
NewKey
(
"/"
)
for
_
,
n
:=
range
dsk
.
Namespaces
()
{
k
=
k
.
Child
(
string
(
b58
.
Decode
(
n
)))
}
return
k
}
// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
...
...
@@ -134,13 +154,14 @@ func SetupLogging() {
logging
.
SetBackend
(
backend
)
logging
.
SetFormatter
(
logging
.
MustStringFormatter
(
LogFormat
))
/*
if Debug {
logging.SetLevel(logging.DEBUG, "")
} else {
logging.SetLevel(logging.ERROR, "")
}
*/
// just uncomment Debug = True right here for all logging.
// but please don't commit that.
// Debug = True
if
Debug
{
logging
.
SetLevel
(
logging
.
DEBUG
,
""
)
}
else
{
logging
.
SetLevel
(
logging
.
ERROR
,
""
)
}
for
n
,
log
:=
range
loggers
{
logging
.
SetLevel
(
logging
.
ERROR
,
n
)
...
...
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