Commit 5ee3a504 authored by tavit ohanian's avatar tavit ohanian

initial port

parent 7a572606
Pipeline #282 passed with stages
in 6 minutes and 56 seconds
stages:
- build
- test
variables:
BUILD_DIR: "/tmp/$CI_CONCURRENT_PROJECT_ID"
before_script:
- mkdir -p $BUILD_DIR/src
- cd $BUILD_DIR/src
- if [ -d $CI_PROJECT_DIR ]
- then
- echo "soft link $CI_PROJECT_DIR exists"
- else
- echo "creating soft link $CI_PROJECT_DIR"
- ln -s $CI_PROJECT_DIR
- fi
- cd $CI_PROJECT_DIR
build:
stage: build
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go build
test:
stage: test
tags:
- testing
script:
- echo $CI_JOB_STAGE
- go test -cover
coverage: '/coverage: \d+.\d+% of statements/'
......@@ -15,6 +15,7 @@ github.com/ipfs/go-ipld-format v0.0.1 h1:HCu4eB/Gh+KD/Q0M8u888RFkorTWNIL3da4oc5d
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
......@@ -25,14 +26,26 @@ github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM=
github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA=
github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs=
github.com/multiformats/go-multibase v0.0.3 h1:l/B6bJDQjvQ5G52jw4QGSYeOTZoAwIO77RblWplfIqk=
github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc=
github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash v0.0.10 h1:lMoNbh2Ssd9PUF74Nz008KGzGPlfeV6wH3rit5IIGCM=
github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-multihash v0.0.14 h1:QoBceQYQQtNUuf6s7wHxnE2c8bhbMqhfGzNI032se/I=
github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc=
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY=
github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992 h1:bzMe+2coZJYHnhGgVlcQKuRy4FSny4ds8dLQjw5P1XE=
github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
......@@ -45,6 +58,16 @@ github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 h1:qOpVTI+BrstcjT
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
gitlab.dms3.io/dms3/public/go-block-format v0.0.1 h1:PQ6+E7zY6kUIHET86uJTQHTTj4Z9ZNfP7w281ZdExgk=
gitlab.dms3.io/dms3/public/go-block-format v0.0.1/go.mod h1:xlvtW/OF72rOzLa2RVWXX2Uw18qTAWTQEs/Xp7SCnuY=
gitlab.dms3.io/dms3/public/go-cid v0.0.0 h1:DKvGTYv5GqSEeVLfQAHBbsFZuWCZFNK5BHdBFykF45E=
gitlab.dms3.io/dms3/public/go-cid v0.0.1 h1:qs4dtkDigcLGY/58dIZaFjKLt+orrTcmTBvtqaM3570=
gitlab.dms3.io/dms3/public/go-cid v0.0.1/go.mod h1:GQw3gc4CSrFY+aX6M+OBQDlg0p5/eQJoRrayaZzkAOQ=
gitlab.dms3.io/dms3/public/go-dms3-util v0.0.1 h1:Gd+kJl1Rc+ZEUb9CIS1ZctQnF9G1oruNFyxUC//QBUQ=
gitlab.dms3.io/dms3/public/go-dms3-util v0.0.1/go.mod h1:ymlwtzTNMq8Ug+gVtPAMxXKCKTXwXJAzXS+SUihfKgo=
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.0 h1:8qdR3jeldkq5EJM1ZeFjfKOvxsnuMiZBGdhth+Xgr4s=
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.1 h1:G2jFwYHYNg1xNyNelCqPHWcP643G1WetNKrM9GzUuOo=
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.1/go.mod h1:S3ODpdL+sAHW0BHDdmx+wn4wwpuf83dHO3EbyhJEfEU=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
......
......@@ -8,16 +8,16 @@ import (
"strconv"
"strings"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
node "github.com/ipfs/go-ipld-format"
mh "github.com/multiformats/go-multihash"
blocks "gitlab.dms3.io/dms3/public/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid"
node "gitlab.dms3.io/dms3/public/go-dms3ld-format"
)
// CBORTagLink is the integer used to represent tags in CBOR.
const CBORTagLink = 42
// Node represents an IPLD node.
// Node represents an DMS3LD node.
type Node struct {
obj interface{}
tree []string
......@@ -38,18 +38,18 @@ var (
ErrArrayOutOfRange = errors.New("array index out of range")
ErrNoLinks = errors.New("tried to resolve through object that had no links")
ErrEmptyLink = errors.New("link value was empty")
ErrInvalidMultibase = errors.New("invalid multibase on IPLD link")
ErrInvalidMultibase = errors.New("invalid multibase on DMS3LD link")
ErrNonStringLink = errors.New("link should have been a string")
)
// DecodeBlock decodes a CBOR encoded Block into an IPLD Node.
// DecodeBlock decodes a CBOR encoded Block into an DMS3LD Node.
//
// This method *does not* canonicalize and *will* preserve the CID. As a matter
// of fact, it will assume that `block.Cid()` returns the correct CID and will
// make no effort to validate this assumption.
//
// In general, you should not be calling this method directly. Instead, you
// should be calling the `Decode` method from the `go-ipld-format` package. That
// should be calling the `Decode` method from the `go-dms3ld-format` package. That
// method will pick the right decoder based on the Block's CID.
//
// Note: This function keeps a reference to `block` and assumes that it is
......@@ -83,7 +83,7 @@ func newObject(block blocks.Block, m interface{}) (*Node, error) {
var _ node.DecodeBlockFunc = DecodeBlock
// Decode decodes a CBOR object into an IPLD Node.
// Decode decodes a CBOR object into an DMS3LD Node.
//
// If passed a non-canonical CBOR node, this function will canonicalize it.
// Therefore, `bytes.Equal(b, Decode(b).RawData())` may not hold. If you already
......@@ -103,7 +103,7 @@ func Decode(b []byte, mhType uint64, mhLen int) (*Node, error) {
return WrapObject(m, mhType, mhLen)
}
// DecodeInto decodes a serialized IPLD cbor object into the given object.
// DecodeInto decodes a serialized DMS3LD cbor object into the given object.
func DecodeInto(b []byte, v interface{}) error {
return unmarshaller.Unmarshal(b, v)
}
......
......@@ -12,10 +12,10 @@ import (
"strings"
"testing"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
u "github.com/ipfs/go-ipfs-util"
mh "github.com/multiformats/go-multihash"
blocks "gitlab.dms3.io/dms3/public/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid"
u "gitlab.dms3.io/dms3/public/go-dms3-util"
)
func init() {
......@@ -30,6 +30,27 @@ func assertCid(c cid.Cid, exp string) error {
}
func TestNonObject(t *testing.T) {
//
// patterns used to generate known good Cids to test against
// objx := map[string]interface{}{
// "a": "DMS3",
// }
//
// ndx, err := WrapObject(objx, mh.SHA2_256, -1)
// objx := `{
// "a": "DMS3",
// "b": null,
// "c": [1]
// }`
// ndx, err := FromJSON(bytes.NewReader([]byte(objx)), mh.SHA2_256, -1)
//
// if err != nil {
// t.Fatal(err)
// }
// fmt.Println(ndx.Cid())
//
nd, err := WrapObject("", mh.SHA2_256, -1)
if err != nil {
t.Fatal(err)
......@@ -375,6 +396,8 @@ func TestExamples(t *testing.T) {
"true": "bafyreibhvppn37ufanewvxvwendgzksh3jpwhk6sxrx2dh3m7s3t5t7noa",
`{"a":"IPFS"}`: "bafyreihyyz2badz34h5pvcgof4fj3qwwr7mopoucejwbnpzs7soorkrct4",
`{"a":"IPFS","b":null,"c":[1]}`: "bafyreigg2gcszayx2lywb3edqfoftyvus7gxeanmudqla3e6eh2okei25a",
`{"a":"DMS3"}`: "bafyreihowikcorpbjzhfhuifmstj7arukumtnjtvjhvt3jvqlpwz5wjqqe",
`{"a":"DMS3","b":null,"c":[1]}`: "bafyreihtinusljdobhjhqedzfw752zdqme7w7lwjmwjtza2zmsxzcvxf5u",
`{"a":[]}`: "bafyreian4t6wau4jdqt6nys76dfvsn6g7an4ulbv326yzutdgnrr5cjpui",
}
for originalJSON, expcid := range examples {
......
......@@ -3,14 +3,14 @@ package cbornode
import (
"math/big"
cid "github.com/ipfs/go-cid"
cid "gitlab.dms3.io/dms3/public/go-cid"
encoding "github.com/ipfs/go-ipld-cbor/encoding"
encoding "gitlab.dms3.io/dms3/public/go-dms3ld-cbor/encoding"
"github.com/polydawn/refmt/obj/atlas"
)
// This atlas describes the CBOR Tag (42) for IPLD links, such that refmt can marshal and unmarshal them
// This atlas describes the CBOR Tag (42) for DMS3LD links, such that refmt can marshal and unmarshal them
var cidAtlasEntry = atlas.BuildEntry(cid.Cid{}).
UseTag(CBORTagLink).
Transform().
......@@ -35,7 +35,7 @@ var BigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform().
})).
Complete()
// CborAtlas is the refmt.Atlas used by the CBOR IPLD decoder/encoder.
// CborAtlas is the refmt.Atlas used by the CBOR DMS3LD decoder/encoder.
var CborAtlas atlas.Atlas
var cborSortingMode = atlas.KeySortMode_RFC7049
var atlasEntries = []*atlas.AtlasEntry{cidAtlasEntry}
......
......@@ -5,54 +5,54 @@ import (
"context"
"fmt"
block "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
recbor "github.com/polydawn/refmt/cbor"
atlas "github.com/polydawn/refmt/obj/atlas"
cbg "github.com/whyrusleeping/cbor-gen"
block "gitlab.dms3.io/dms3/public/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid"
)
// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type IpldStore interface {
// Dms3LdStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type Dms3LdStore interface {
Get(ctx context.Context, c cid.Cid, out interface{}) error
Put(ctx context.Context, v interface{}) (cid.Cid, error)
}
// IpldBlockstore defines a subset of the go-ipfs-blockstore Blockstore interface providing methods
// Dms3LdBlockstore defines a subset of the go-dms3-blockstore Blockstore interface providing methods
// for storing and retrieving block-centered data.
type IpldBlockstore interface {
type Dms3LdBlockstore interface {
Get(cid.Cid) (block.Block, error)
Put(block.Block) error
}
// IpldBlockstoreViewer is a trait that enables zero-copy access to blocks in
// Dms3LdBlockstoreViewer is a trait that enables zero-copy access to blocks in
// a blockstore.
type IpldBlockstoreViewer interface {
type Dms3LdBlockstoreViewer interface {
// View provides zero-copy access to blocks in a blockstore. The callback
// function will be invoked with the value for the key. The user MUST not
// modify the byte array, as it could be memory-mapped.
View(cid.Cid, func([]byte) error) error
}
// BasicIpldStore wraps and IpldBlockstore and implements the IpldStore interface.
type BasicIpldStore struct {
Blocks IpldBlockstore
Viewer IpldBlockstoreViewer
// BasicDms3LdStore wraps and Dms3LdBlockstore and implements the Dms3LdStore interface.
type BasicDms3LdStore struct {
Blocks Dms3LdBlockstore
Viewer Dms3LdBlockstoreViewer
Atlas *atlas.Atlas
}
var _ IpldStore = &BasicIpldStore{}
var _ Dms3LdStore = &BasicDms3LdStore{}
// NewCborStore returns an IpldStore implementation backed by the provided IpldBlockstore.
func NewCborStore(bs IpldBlockstore) *BasicIpldStore {
viewer, _ := bs.(IpldBlockstoreViewer)
return &BasicIpldStore{Blocks: bs, Viewer: viewer}
// NewCborStore returns an Dms3LdStore implementation backed by the provided Dms3LdBlockstore.
func NewCborStore(bs Dms3LdBlockstore) *BasicDms3LdStore {
viewer, _ := bs.(Dms3LdBlockstoreViewer)
return &BasicDms3LdStore{Blocks: bs, Viewer: viewer}
}
// Get reads and unmarshals the content at `c` into `out`.
func (s *BasicIpldStore) Get(ctx context.Context, c cid.Cid, out interface{}) error {
func (s *BasicDms3LdStore) Get(ctx context.Context, c cid.Cid, out interface{}) error {
if s.Viewer != nil {
// zero-copy path.
return s.Viewer.View(c, func(b []byte) error {
......@@ -67,7 +67,7 @@ func (s *BasicIpldStore) Get(ctx context.Context, c cid.Cid, out interface{}) er
return s.decode(blk.RawData(), out)
}
func (s *BasicIpldStore) decode(b []byte, out interface{}) error {
func (s *BasicDms3LdStore) decode(b []byte, out interface{}) error {
cu, ok := out.(cbg.CBORUnmarshaler)
if ok {
if err := cu.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
......@@ -88,7 +88,7 @@ type cidProvider interface {
}
// Put marshals and writes content `v` to the backing blockstore returning its CID.
func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
func (s *BasicDms3LdStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
mhType := uint64(mh.BLAKE2B_MIN + 31)
mhLen := -1
codec := uint64(cid.DagCBOR)
......@@ -175,7 +175,7 @@ func (se SerializationError) Is(o error) bool {
return ok
}
func NewMemCborStore() IpldStore {
func NewMemCborStore() Dms3LdStore {
return NewCborStore(newMockBlocks())
}
......
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