Skip to content

Commit

Permalink
Updating github to v0.0.3
Browse files Browse the repository at this point in the history
Theres no vendor folder for now, so it wont build
Client and server is now both use this repo, so rip casper-client
If you want to see a sheer amount of work was done, just look at diff with previous commit
We might want to include some version of our internal changelog, sorry for this time
  • Loading branch information
comradekoval committed Apr 17, 2018
1 parent d2cc620 commit 43c63ad
Show file tree
Hide file tree
Showing 323 changed files with 8,271 additions and 1,488 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@

coverage.txt

# for docker
libdl.so.2

vendor/gitlab.com

.ipfs
bin/gx
bin/gx*
bin/tmp
.idea
.idea
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 0 additions & 33 deletions ISSUE_TEMPLATE.md

This file was deleted.

7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@





## ATTENTION
As of now we are not providing you folder "vendor", so server won't build, and nor client. Sorry for the inconvenience, we'll think of something the following week.
# CasperAPI provider application.
CasperAPI is a decentralized data storage.
We were deeply concerned with the state of the Internet and thought that with the state-of-art decentralized technologies we could at least start changing the way data is stored and distributed right now.
Expand Down
15 changes: 12 additions & 3 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import (
"os"
"path/filepath"

"github.com/Casper-dev/Casper-server/core"
"github.com/Casper-dev/Casper-server/core/coreunix"
uio "github.com/Casper-dev/Casper-server/unixfs/io"
uid "gitlab.com/casperDev/Casper-server/casper/uuid"
"gitlab.com/casperDev/Casper-server/core"
"gitlab.com/casperDev/Casper-server/core/coreunix"
uio "gitlab.com/casperDev/Casper-server/unixfs/io"

cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"

// this import keeps gx from thinking the dep isn't used
_ "gx/ipfs/QmdZ4PvPHFQVLLEve7DgoKDcSY19wwpGBB1GKjjKi2rEL1/dir-index-html"
)

var log = logging.Logger("assets")

// initDocPaths lists the paths for the docs we want to seed during --init
var initDocPaths = []string{
filepath.Join("init-doc", "about"),
Expand Down Expand Up @@ -47,12 +52,15 @@ func SeedInitDirIndex(nd *core.IpfsNode) (*cid.Cid, error) {
func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
dirb := uio.NewDirectory(nd.DAG)

log.Debugf("%v", l)
for _, p := range l {
d, err := Asset(p)
if err != nil {
return nil, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
}

log.Debugf("Few first bytes: %x", d[:uid.UUIDLen])
// s, err := coreunix.Add(nd, bytes.NewBuffer(append(bl.NullUUID, d...)))
s, err := coreunix.Add(nd, bytes.NewBuffer(d))
if err != nil {
return nil, fmt.Errorf("assets: could not Add '%s': %s", p, err)
Expand All @@ -65,6 +73,7 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
return nil, err
}

log.Debugf("Trying to find CID %s", c.String())
node, err := nd.DAG.Get(nd.Context(), c)
if err != nil {
return nil, err
Expand Down
134 changes: 134 additions & 0 deletions blocks/blocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Package blocks implements interface blocks.Block from go-block-format
// augmented with UUID.
// A block is raw data accompanied by a CID. The CID contains the multihash
// corresponding to the block.
package blocks

import (
"fmt"
"runtime/debug"

"gitlab.com/casperDev/Casper-server/casper/uuid"

cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util"
blocks "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
"gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
mh "gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
)

var log = logging.Logger("blocks")

// A BasicBlock is a singular block of data in ipfs. It implements the Block
// interface.
type BasicBlock struct {
cid *cid.Cid
data []byte
uuid []byte
}

// SplitData extracts UUID and Data from byte slice
func SplitData(rawdata []byte) (uid []byte, data []byte) {
if len(rawdata) < uuid.UUIDLen {
panic(fmt.Sprintf("Data is too small and has no UUID %x", rawdata))
}

return rawdata[:uuid.UUIDLen], rawdata[uuid.UUIDLen:]
}

// NewBlock creates a Block object from opaque data. It will hash the data.
func NewBlock(data []byte) *BasicBlock {
cid := cid.NewCidV0(u.Hash(data))

log.Debugf("NewBlock of length %d and with CID %s", len(data), cid.String())

return &BasicBlock{data: data, cid: cid}
}

func NewBlockWithUUID(data []byte) *BasicBlock {
var id *cid.Cid

uid, d := SplitData(data)
if uuid.IsUUIDNull(uid) {
uid = nil
id = cid.NewCidV0(u.Hash(data))
} else {
id = cid.NewCidV0(u.Hash(uid))
}

log.Debugf("NewBlockWithUUID of length %d with CID %s", len(d), id.String())

// Do not store UUID if it is zero
return &BasicBlock{data: d, uuid: uid, cid: id}
}

// NewBlockWithCid creates a new block when the hash of the data
// is already known, this is used to save time in situations where
// we are able to be confident that the data is correct.
func NewBlockWithCid(data []byte, c *cid.Cid) (*BasicBlock, error) {
id, d := SplitData(data)
log.Debugf("NewBlockWithCid: splitted uuid %d + %d %s", len(id), len(d), base58.Encode(id))

if u.Debug {
var rd = id
if uuid.IsUUIDNull(id) {
rd = d
}
chkc, err := c.Prefix().Sum(rd)

if err != nil {
return nil, err
}

if !chkc.Equals(c) {
log.Debugf("Calculated hash %s != Argument hash %s", chkc.String(), c.String())
debug.PrintStack()
return nil, blocks.ErrWrongHash
}
}

return &BasicBlock{data: d, uuid: id, cid: c}, nil
}

// Multihash returns the hash contained in the block CID.
func (b *BasicBlock) Multihash() mh.Multihash {
return b.cid.Hash()
}

// RawData returns the block raw contents as a byte slice.
func (b *BasicBlock) RawData() []byte {
if b.uuid != nil {
return append(b.uuid, b.data...)
}

return append(uuid.NullUUID, b.data...)
}

// UUID returns the uuid of the block
func (b *BasicBlock) UUID() []byte {
if b.uuid != nil {
return b.uuid
}

return uuid.NullUUID
}

// Cid returns the content identifier of the block.
func (b *BasicBlock) Cid() *cid.Cid {
return b.cid
}

// String provides a human-readable representation of the block CID.
func (b *BasicBlock) String() string {
return fmt.Sprintf("[Block %s, UUID: %s]", b.Cid(), base58.Encode(b.UUID()))
}

// Loggable returns a go-log loggable item.
func (b *BasicBlock) Loggable() map[string]interface{} {
return map[string]interface{}{
"block": b.Cid().String(),
"data": b.data,
"uuid": b.uuid,
}
}
23 changes: 15 additions & 8 deletions blocks/blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"sync"
"sync/atomic"

dshelp "github.com/Casper-dev/Casper-server/thirdparty/ds-help"
blocks "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format"

bl "gitlab.com/casperDev/Casper-server/blocks"

dshelp "gitlab.com/casperDev/Casper-server/thirdparty/ds-help"

cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
Expand Down Expand Up @@ -122,13 +125,16 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
if err != nil {
return nil, err
}

bdata, ok := maybeData.([]byte)
if !ok {
return nil, ErrValueTypeMismatch
}

//if false {
if bs.rehash {
rbcid, err := k.Prefix().Sum(bdata)
uuid, _ := bl.SplitData(bdata)
rbcid, err := k.Prefix().Sum(uuid)
if err != nil {
return nil, err
}
Expand All @@ -137,19 +143,20 @@ func (bs *blockstore) Get(k *cid.Cid) (blocks.Block, error) {
return nil, ErrHashMismatch
}

return blocks.NewBlockWithCid(bdata, rbcid)
return bl.NewBlockWithCid(bdata, k)
}
return blocks.NewBlockWithCid(bdata, k)
return bl.NewBlockWithCid(bdata, k)
}

func (bs *blockstore) Put(block blocks.Block) error {
k := dshelp.CidToDsKey(block.Cid())

// Has is cheaper than Put, so see if we already have it
exists, err := bs.datastore.Has(k)
if err == nil && exists {
return nil // already stored.
}
//exists, err := bs.datastore.Has(k)
//if err == nil && exists {
// return nil // already stored.
//}
//return bs.datastore.Put(k, block.RawData())
return bs.datastore.Put(k, block.RawData())
}

Expand Down
3 changes: 2 additions & 1 deletion blocks/blockstore/blockstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"fmt"
"testing"

dshelp "github.com/Casper-dev/Casper-server/thirdparty/ds-help"
blocks "gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format"

dshelp "gitlab.com/casperDev/Casper-server/thirdparty/ds-help"

cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util"
ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
Expand Down
6 changes: 3 additions & 3 deletions blocks/blockstore/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type CacheOpts struct {
// DefaultCacheOpts returns a CacheOpts initialized with default values.
func DefaultCacheOpts() CacheOpts {
return CacheOpts{
HasBloomFilterSize: 512 << 10,
HasBloomFilterHashes: 7,
HasARCCacheSize: 64 << 10,
HasBloomFilterSize: 0, //512 << 10,
HasBloomFilterHashes: 0, //7,
HasARCCacheSize: 0, //64 << 10,
}
}

Expand Down
Loading

0 comments on commit 43c63ad

Please sign in to comment.