bluzelle

package module
v0.0.0-...-156e0f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

Bluzelle-go

Build Status codecov GoDoc Gitter chat

About bluzelle-go

bluzelle-go is a go client built on top of WebSocket API that connect to Bluzelle SwarmDB for basic CRUD operations. Under active development to support Bernoulli release.

Getting Started

  • Installation
go get github.com/Developer-piyush/bzlbry
  • Compile protobuf
protoc -I=proto/proto --go_out=pb proto/proto/*.proto
  • Import
import "github.com/Developer-piyush/bzlbry"
  • Initialize
blz := blz.Connect("127.0.0.1", 51010, "80174b53-2dda-49f1-9d6a-6a780d4")

List of API

  • Create
err := blz.Create("key1", []byte("value1"))
  • Read
value, err := blz.Read("key1")
  • Update
err := blz.Update("key1", []byte("value2"))
  • Remove
err := blz.Remove("key1")
  • Has
has, err := blz.Has("key1")
  • Keys
keys, err := blz.Keys()
  • Size
size, err := blz.Size()

Reference

Visit the official bluzelle documentation

Documentation

Index

Constants

View Source
const (
	// EcPrivateKey pem format required
	EcPrivateKey string = "EC PRIVATE KEY"
)
View Source
const (
	// RequestTimeout time limit per db request
	RequestTimeout = 3 * time.Second
)

Variables

View Source
var (
	// ErrPemfileNotECDSA is returned when a wrong pem file format is provided.
	ErrPemfileNotECDSA = errors.New("crypto: pem file loaded not ecdsa")

	// ErrInvalidPayloadCase is returned when could not find a payload case.
	ErrInvalidPayloadCase = errors.New("crypto: invalid payload case")

	// ErrSigVerificationFailed is returned when a the priv/pub key generation failed.
	ErrSigVerificationFailed = errors.New("crypto: fail to verify sig")
)
View Source
var (
	// ErrRequestTimeout is returned when a outgoing request is timed out.
	ErrRequestTimeout = errors.New("blz: request timed out")
)
View Source
var (
	// ErrWsConnNotInitialized is returned when writing to a nil websocket.
	ErrWsConnNotInitialized = errors.New("conn: websocket connection not initialized")
)

Functions

func ReadPemFile

func ReadPemFile(path string) ([]byte, error)

ReadPemFile reads a private pem file.

Types

type Bluzelle

type Bluzelle struct {
	// Layers
	*Metadata
	*Crypto
	*Conn

	Entry string
	UUID  string
	// contains filtered or unexported fields
}

Bluzelle represents a client connection to the bluzelle network.

func Connect

func Connect(entry, uuid string, privPem []byte) (*Bluzelle, error)

Connect initialize a new bluzelle struct.

func (*Bluzelle) AddWriters

func (blz *Bluzelle) AddWriters(pubKeys ...string)

AddWriters add writers to the writers list. May only be executed by the owner of the database.

func (*Bluzelle) Close

func (blz *Bluzelle) Close()

Close just closes the connection to the daemon.

func (*Bluzelle) Create

func (blz *Bluzelle) Create()

func (*Bluzelle) CreateDB

func (blz *Bluzelle) CreateDB() error

CreateDB creates a new database at the given uuid.

func (*Bluzelle) Delete

func (blz *Bluzelle) Delete()

func (*Bluzelle) DeleteDB

func (blz *Bluzelle) DeleteDB() error

DeleteDB deletes the database at the given uuid.

func (*Bluzelle) DeleteWriters

func (blz *Bluzelle) DeleteWriters(pubKeys ...string)

DeleteWriters deletes writers from the writers list. May only be executed by the owner of the database.

func (*Bluzelle) GetWriters

func (blz *Bluzelle) GetWriters()

GetWriters gets the owner and writers of the given database. The owner is the public key of the user that created the database. The writers array lists the public keys of users that are allowed to make changes to the database.

Response: JSON {
  owner: 'MFYwEAY...EpZop6A==',
  writers: [
    'MFYwEAYH...0FEoB==', ...
  ]
}

func (*Bluzelle) Has

func (blz *Bluzelle) Has()

func (*Bluzelle) HasDB

func (blz *Bluzelle) HasDB() error

HasDB queries to see if a database exists at the given uuid.

func (*Bluzelle) Keys

func (blz *Bluzelle) Keys()

func (*Bluzelle) PublicKey

func (blz *Bluzelle) PublicKey() string

PublicKey returns a public key from the private pem given in the constructor.

func (*Bluzelle) QuickRead

func (blz *Bluzelle) QuickRead()

func (*Bluzelle) Read

func (blz *Bluzelle) Read()

func (*Bluzelle) Size

func (blz *Bluzelle) Size() error

func (*Bluzelle) Status

func (blz *Bluzelle) Status() error

Status returns the status of the daemon. Response: JSON-encoded swarm status.

func (*Bluzelle) Update

func (blz *Bluzelle) Update()

type Conn

type Conn struct {
	// Endpoint represents the entry point for the bluzelle network.
	Endpoint string

	// IncomingMsg
	IncomingMsg chan []byte
	// contains filtered or unexported fields
}

Conn represents the persistent layer for Bluzelle.

func NewConn

func NewConn(endpoint string) *Conn

NewConn creates a new conn

func (*Conn) Dial

func (conn *Conn) Dial() error

Dial initiates the websocket connection to blz endpoint.

func (*Conn) EndpointURL

func (conn *Conn) EndpointURL() string

EndpointURL formats the endpoint to a ws protocol.

type Crypto

type Crypto struct {
	// contains filtered or unexported fields
}

Crypto represents the cryptographic layer for payload signing and verification.

func NewCrypto

func NewCrypto(privPem []byte) (*Crypto, error)

func (*Crypto) GenPubKey

func (ct *Crypto) GenPubKey() []byte

func (*Crypto) PPubKey

func (ct *Crypto) PPubKey() string

func (*Crypto) SignMsg

func (ct *Crypto) SignMsg(dbMsg *pb.DatabaseMsg) ([]byte, error)

SignMsg signg a proto msg with the set private key.

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL