protocol

package
v0.0.0-...-75fa6d2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: GPL-3.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BroadcastChannel = make(chan *BroadcastBlock)

TODO: may need to find a better way to save the channel

View Source
var MessageTypeMap = map[string]reflect.Type{
	"info":            reflect.TypeOf(Info{}),
	"error":           reflect.TypeOf(Error{}),
	"request:blocks":  reflect.TypeOf(RequestBlocks{}),
	"request:peers":   reflect.TypeOf(RequestPeers{}),
	"response:blocks": reflect.TypeOf(ResponseBlocks{}),
	"response:peers":  reflect.TypeOf(ResponsePeers{}),
	"broadcast:block": reflect.TypeOf(BroadcastBlock{}),
}

Functions

func HandleJSONData

func HandleJSONData(sender interface{}, data []byte) [][]byte

func MapType

func MapType(i Behavior) string

Types

type Behavior

type Behavior interface {
	// returns an Error if invalid, otherwise returns nil
	Validate() *Error

	// Call Validate() before this method
	React() []Behavior

	// Description for debuging
	String() string
}

func DeserializeBehavior

func DeserializeBehavior(msg *Message) (Behavior, error)

Deserialize

func MapBehavior

func MapBehavior(t string) Behavior

type BroadcastBlock

type BroadcastBlock struct {
	Block json.RawMessage `json:"block"`

	ID     string
	Sender interface{}
	// contains filtered or unexported fields
}

func (*BroadcastBlock) Message

func (b *BroadcastBlock) Message() *Message

func (*BroadcastBlock) React

func (b *BroadcastBlock) React() []Behavior

func (BroadcastBlock) Serialize

func (b BroadcastBlock) Serialize() []byte

func (*BroadcastBlock) SetBlock

func (b *BroadcastBlock) SetBlock(block *blockchain.Block)

func (BroadcastBlock) String

func (b BroadcastBlock) String() string

func (*BroadcastBlock) Validate

func (b *BroadcastBlock) Validate() *Error

type Error

type Error struct {
	Code string `json:"code"`
	Desc string `json:"desc"`
}

func BadRequestError

func BadRequestError(err string) *Error

func BlockValidationError

func BlockValidationError(err blockchain.BlockValidationError) *Error

func ChainNotAcceptError

func ChainNotAcceptError(err string) *Error

func DuplicateBroadcastError

func DuplicateBroadcastError(err string) *Error

func IncompatibleProtocolVersionError

func IncompatibleProtocolVersionError(err string) *Error

func InvalidBehaviorError

func InvalidBehaviorError(err string) *Error

func InvalidMessageError

func InvalidMessageError(err string) *Error

func InvalidURLError

func InvalidURLError(err string) *Error

func JSONDecodeError

func JSONDecodeError(err string) *Error

func (Error) React

func (e Error) React() []Behavior

func (Error) String

func (e Error) String() string

func (Error) Validate

func (e Error) Validate() *Error

type Info

type Info struct {
	Version  string            `json:"version"`
	Peers    int               `json:"peers"`
	Chains   map[string]uint64 `json:"chains"`
	Platform map[string]string `json:"platform"`
	FullNode bool              `json:"full_node"`
}

- Declarations

func NewInfo

func NewInfo() *Info

func (Info) React

func (b Info) React() []Behavior

- Reactions

func (Info) String

func (b Info) String() string

- Stringer

func (Info) Validate

func (b Info) Validate() *Error

- Validations

type Message

type Message struct {
	ID   string          `json:"id"`
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

func DeserializeMessage

func DeserializeMessage(jsonData []byte) (*Message, error)

func NewMessage

func NewMessage(data Behavior) *Message

func (Message) Serialize

func (m Message) Serialize() []byte

type RequestBlocks

type RequestBlocks struct {
	ChainID string `json:"chain_id"`
	From    uint64 `json:"from"`
	To      uint64 `json:"to"`
}

func (RequestBlocks) React

func (b RequestBlocks) React() []Behavior

Split blocks for every 1 MB

func (RequestBlocks) String

func (b RequestBlocks) String() string

func (RequestBlocks) Validate

func (b RequestBlocks) Validate() *Error

type RequestPeers

type RequestPeers struct {
	Count int `json:"count"`
}

func (RequestPeers) React

func (b RequestPeers) React() []Behavior

func (RequestPeers) String

func (b RequestPeers) String() string

func (RequestPeers) Validate

func (b RequestPeers) Validate() *Error

type ResponseBlocks

type ResponseBlocks struct {
	Blocks []json.RawMessage `json:"blocks"`
	// contains filtered or unexported fields
}

func (ResponseBlocks) React

func (b ResponseBlocks) React() []Behavior

func (ResponseBlocks) Serialize

func (b ResponseBlocks) Serialize() []byte

- Serializations

func (ResponseBlocks) String

func (b ResponseBlocks) String() string

func (*ResponseBlocks) Validate

func (b *ResponseBlocks) Validate() *Error

type ResponsePeers

type ResponsePeers struct {
	Peers []string `json:"peers"`
}

func (ResponsePeers) React

func (b ResponsePeers) React() []Behavior

func (ResponsePeers) String

func (b ResponsePeers) String() string

func (ResponsePeers) Validate

func (b ResponsePeers) Validate() *Error

type Serializable

type Serializable interface {
	Serialize() []byte
}

Jump to

Keyboard shortcuts

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