jail

package
v0.0.0-...-c274cf5 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventLocalStorageSet   = "local_storage.set"
	EventSendMessage       = "jail.send_message"
	EventShowSuggestions   = "jail.show_suggestions"
	LocalStorageMaxDataLen = 256
)
View Source
const (
	// JailCellRequestTimeout seconds before jailed request times out
	JailCellRequestTimeout = 60
)
View Source
const (
	// SendTransactionRequest is triggered on send transaction request
	SendTransactionRequest = "eth_sendTransaction"
)

Variables

View Source
var (
	ErrInvalidJail = errors.New("jail environment is not properly initialized")
)

errors

Functions

This section is empty.

Types

type JSONError

type JSONError struct {
	Error string `json:"error"`
}

JSONError is wrapper around errors, that are sent upwards

type Jail

type Jail struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Jail represents jailed environment inside of which we hold multiple cells. Each cell is a separate JavaScript VM.

func New

func New(nodeManager common.NodeManager) *Jail

New returns new Jail environment

func (*Jail) BaseJS

func (jail *Jail) BaseJS(js string)

BaseJS allows to setup initial JavaScript to be loaded on each jail.Parse()

func (*Jail) Call

func (jail *Jail) Call(chatID string, path string, args string) string

Call executes given JavaScript function w/i a jail cell context identified by the chatID. Jail cell is clonned before call is executed i.e. all calls execute w/i their own contexts.

func (*Jail) JailCellVM

func (jail *Jail) JailCellVM(chatID string) (*otto.Otto, error)

JailCellVM returns instance of Otto VM (which is persisted w/i jail cell) by chatID

func (*Jail) NewJailCell

func (jail *Jail) NewJailCell(id string) common.JailCell

NewJailCell initializes and returns jail cell

func (*Jail) Parse

func (jail *Jail) Parse(chatID string, js string) string

Parse creates a new jail cell context, with the given chatID as identifier. New context executes provided JavaScript code, right after the initialization.

func (*Jail) Send

func (jail *Jail) Send(chatID string, call otto.FunctionCall) (response otto.Value)

Send will serialize the first argument, send it to the node and returns the response. nolint: errcheck, unparam

type JailCell

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

JailCell represents single jail cell, which is basically a JavaScript VM.

func (*JailCell) CellLoop

func (cell *JailCell) CellLoop() *loop.Loop

CellLoop returns the ottoext.Loop instance which provides underline timeout/setInternval event runtime for the Jail vm.

func (*JailCell) CellVM

func (cell *JailCell) CellVM() *otto.Otto

CellVM returns the associated otto.Vm connect to the giving cell.

func (*JailCell) Copy

func (cell *JailCell) Copy() (common.JailCell, error)

Copy returns a new JailCell instance with a new eventloop runtime associated with the given cell.

func (*JailCell) Exec

func (cell *JailCell) Exec(val string) (otto.Value, error)

Exec evaluates the giving js string on the associated vm loop returning an error.

func (*JailCell) Executor

func (cell *JailCell) Executor() common.JailExecutor

Executor returns a structure which implements the common.JailExecutor.

func (*JailCell) Fetch

func (cell *JailCell) Fetch(url string, callback func(otto.Value)) (otto.Value, error)

Fetch attempts to call the underline Fetch API added through the ottoext package.

func (*JailCell) Run

func (cell *JailCell) Run(val string) (otto.Value, error)

Run evaluates the giving js string on the associated vm llop.

type LocalStorageSetEvent

type LocalStorageSetEvent struct {
	ChatID string `json:"chat_id"`
	Data   string `json:"data"`
}

LocalStorageSetEvent is a signal sent whenever local storage Set method is called

type RPCCall

type RPCCall struct {
	ID     int64
	Method string
	Params []interface{}
}

RPCCall represents RPC call parameters

type RequestManager

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

RequestManager represents interface to manage jailed requests. Whenever some request passed to a Jail, needs to be pre/post processed, request manager is the right place for that.

func NewRequestManager

func NewRequestManager(nodeManager common.NodeManager) *RequestManager

func (*RequestManager) PostProcessRequest

func (m *RequestManager) PostProcessRequest(vm *otto.Otto, req RPCCall, messageID string)

PostProcessRequest post-processes a given RPC call to a given Otto VM

func (*RequestManager) PreProcessRequest

func (m *RequestManager) PreProcessRequest(vm *otto.Otto, req RPCCall) (string, error)

PreProcessRequest pre-processes a given RPC call to a given Otto VM

func (*RequestManager) ProcessSendTransactionRequest

func (m *RequestManager) ProcessSendTransactionRequest(vm *otto.Otto, req RPCCall) (gethcommon.Hash, error)

ProcessSendTransactionRequest processes send transaction request. Both pre and post processing happens within this function. Pre-processing happens before transaction is send to backend, and post processing occurs when backend notifies that transaction sending is complete (either successfully or with error)

func (*RequestManager) RPCClient

func (m *RequestManager) RPCClient() (*rpc.Client, error)

RPCClient returns RPC client instance, creating it if necessary.

type SendMessageEvent

type SendMessageEvent struct {
	ChatID  string `json:"chat_id"`
	Message string `json:"message"`
}

SendMessageEvent wraps Jail send signals

type ShowSuggestionsEvent

type ShowSuggestionsEvent struct {
	ChatID string `json:"chat_id"`
	Markup string `json:"markup"`
}

ShowSuggestionsEvent wraps Jail show suggestion signals

Jump to

Keyboard shortcuts

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