graphvent

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACLExtType      = ExtType("ACL")
	ListenerExtType = ExtType("LISTENER")
	LockableExtType = ExtType("LOCKABLE")
	GQLExtType      = ExtType("GQL")
	GroupExtType    = ExtType("GROUP")
	ECDHExtType     = ExtType("ECDH")

	GQLNodeType = NodeType("GQL")
)
View Source
const (
	RequirementOfPolicyType = PolicyType("REQUIREMENT_OF")
	PerNodePolicyType       = PolicyType("PER_NODE")
	AllNodesPolicyType      = PolicyType("ALL_NODES")
)
View Source
const EXTENSION_DB_HEADER_LEN = 16
View Source
const LinkSignalType = SignalType("LINK")
View Source
const LockSignalType = SignalType("LOCK")
View Source
const NODE_DB_HEADER_LEN = 20

Total length of the node database header, has magic to verify and type_hash to map to load function

View Source
const NODE_DB_MAGIC = 0x2491df14

Magic first four bytes of serialized DB content, stored big endian

View Source
const NODE_MSG_CHAN_DEFAULT = 1024

Default message channel size for nodes

View Source
const StatusSignalType = SignalType("STATUS")
View Source
const StopSignalType = SignalType("STOP")

Variables

View Source
var GQLInterfaceLockable = NewGQLInterface("Lockable", "DefaultLockable", []*graphql.Interface{GQLInterfaceNode.Interface}, []ExtType{LockableExtType}, func(gql *GQLInterface) {
	addLockableInterfaceFields(gql, gql)
}, func(gql *GQLInterface) {
	addLockableFields(gql.Default, gql.Interface, gql.List)
})
View Source
var GQLInterfaceNode = NewGQLInterface("Node", "DefaultNode", []*graphql.Interface{}, []ExtType{}, func(gql *GQLInterface) {
	AddNodeInterfaceFields(gql)
}, func(gql *GQLInterface) {
	AddNodeFields(gql.Default)
})
View Source
var GQLLockableInterfaces = append(GQLNodeInterfaces, GQLInterfaceLockable.Interface)
View Source
var GQLMutationStartChild = NewField(func() *graphql.Field {
	gql_mutation_start_child := &graphql.Field{
		Type: GQLTypeSignal.Type,
		Args: graphql.FieldConfigArgument{
			"parent_id": &graphql.ArgumentConfig{
				Type: graphql.String,
			},
			"child_id": &graphql.ArgumentConfig{
				Type: graphql.String,
			},
			"action": &graphql.ArgumentConfig{
				Type:         graphql.String,
				DefaultValue: "start",
			},
		},
		Resolve: func(p graphql.ResolveParams) (interface{}, error) {

			return nil, nil
		},
	}

	return gql_mutation_start_child
})
View Source
var GQLMutationStop = NewField(func() *graphql.Field {
	gql_mutation_stop := &graphql.Field{
		Type: GQLTypeSignal.Type,
		Args: graphql.FieldConfigArgument{
			"id": &graphql.ArgumentConfig{
				Type: graphql.String,
			},
		},
		Resolve: func(p graphql.ResolveParams) (interface{}, error) {
			return StopSignal, nil
		},
	}

	return gql_mutation_stop
})
View Source
var GQLNodeInterfaces = []*graphql.Interface{GQLInterfaceNode.Interface}
View Source
var GQLQuerySelf = &graphql.Field{
	Type: GQLInterfaceNode.Default,
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		_, ctx, err := PrepResolve(p)
		if err != nil {
			return nil, err
		}

		return ctx.Server, nil
	},
}
View Source
var GQLQueryUser = &graphql.Field{
	Type: GQLInterfaceNode.Default,
	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		_, ctx, err := PrepResolve(p)
		if err != nil {
			return nil, err
		}

		return ctx.User, nil
	},
}
View Source
var GQLSubscriptionSelf = NewField(func() *graphql.Field {
	gql_subscription_self := &graphql.Field{
		Type: GQLInterfaceNode.Default,
		Resolve: func(p graphql.ResolveParams) (interface{}, error) {
			return p.Source, nil
		},
		Subscribe: GQLSubscribeSelf,
	}

	return gql_subscription_self
})
View Source
var GQLSubscriptionUpdate = NewField(func() *graphql.Field {
	gql_subscription_update := &graphql.Field{
		Type: GQLTypeSignal.Type,
		Resolve: func(p graphql.ResolveParams) (interface{}, error) {
			return p.Source, nil
		},
		Subscribe: GQLSubscribeSignal,
	}
	return gql_subscription_update
})
View Source
var GQLTypeGQLNode = NewGQLNodeType(GQLNodeType, GQLNodeInterfaces, func(gql *GQLType) {
	AddNodeFields(gql.Type)

	gql.Type.AddFieldConfig("Listen", &graphql.Field{
		Type:    graphql.String,
		Resolve: GQLNodeListen,
	})
})
View Source
var GQLTypeSignal = NewSingleton(func() *graphql.Object {
	gql_type_signal := graphql.NewObject(graphql.ObjectConfig{
		Name: "Signal",
		IsTypeOf: func(p graphql.IsTypeOfParams) bool {
			_, ok := p.Value.(Signal)
			return ok
		},
		Fields: graphql.Fields{},
	})

	gql_type_signal.AddFieldConfig("Type", &graphql.Field{
		Type:    graphql.String,
		Resolve: GQLSignalType,
	})
	gql_type_signal.AddFieldConfig("Direction", &graphql.Field{
		Type:    graphql.String,
		Resolve: GQLSignalDirection,
	})
	gql_type_signal.AddFieldConfig("String", &graphql.Field{
		Type:    graphql.String,
		Resolve: GQLSignalString,
	})
	return gql_type_signal
}, nil)
View Source
var NodeNotFoundError = errors.New("Node not found in DB")
View Source
var ZeroID = NodeID(ZeroUUID)
View Source
var ZeroUUID = uuid.UUID{}

Base NodeID, used as a special value

Functions

func AddLockableFields added in v0.2.0

func AddLockableFields(object *graphql.Object)

func AddLockableInterfaceFields added in v0.2.0

func AddLockableInterfaceFields(gql *GQLInterface)

func AddNodeFields added in v0.2.0

func AddNodeFields(object *graphql.Object)

func AddNodeInterfaceFields added in v0.2.0

func AddNodeInterfaceFields(gql *GQLInterface)

func AllNodesPolicyLoad added in v0.2.0

func AllNodesPolicyLoad(init_fn func(Actions) (Policy, error)) func(*Context, []byte) (Policy, error)

func Allowed added in v0.2.0

func Allowed(ctx *Context, principal_id NodeID, action SignalType, node *Node) error

func AuthHandler added in v0.2.0

func AuthHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)

func BuildSchema added in v0.2.0

func BuildSchema(ctx *GQLExtContext) (graphql.Schema, error)

func ExtractList added in v0.2.0

func ExtractList[K interface{}](p graphql.ResolveParams, name string) ([]K, error)

func ExtractParam added in v0.2.0

func ExtractParam[K interface{}](p graphql.ResolveParams, name string) (K, error)

TODO: Make composabe by checkinf if K is a slice, then recursing in the same way that ExtractList does

func GQLGroupMembers added in v0.2.0

func GQLGroupMembers(p graphql.ResolveParams) (interface{}, error)

func GQLHandler

func GQLHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)

func GQLLockableDependencies

func GQLLockableDependencies(p graphql.ResolveParams) (interface{}, error)

func GQLLockableOwner

func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error)

func GQLLockableRequirements

func GQLLockableRequirements(p graphql.ResolveParams) (interface{}, error)

func GQLNodeHasExtensions added in v0.2.0

func GQLNodeHasExtensions(extensions []ExtType) func(graphql.IsTypeOfParams) bool

func GQLNodeID

func GQLNodeID(p graphql.ResolveParams) (interface{}, error)

TODO: think about what permissions should be needed to read ID, and if there's ever a case where they haven't already been granted

func GQLNodeListen added in v0.2.0

func GQLNodeListen(p graphql.ResolveParams) (interface{}, error)

func GQLNodeTypeHash added in v0.2.0

func GQLNodeTypeHash(p graphql.ResolveParams) (interface{}, error)

func GQLSignalDirection

func GQLSignalDirection(p graphql.ResolveParams) (interface{}, error)

func GQLSignalFn

func GQLSignalFn(p graphql.ResolveParams, fn func(Signal, graphql.ResolveParams) (interface{}, error)) (interface{}, error)

func GQLSignalString

func GQLSignalString(p graphql.ResolveParams) (interface{}, error)

func GQLSignalType

func GQLSignalType(p graphql.ResolveParams) (interface{}, error)

func GQLSubscribeFn

func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, fn func(*Context, *Node, *GQLExt, Signal, graphql.ResolveParams) (interface{}, error)) (interface{}, error)

func GQLSubscribeSelf

func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error)

func GQLSubscribeSignal

func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error)

func GQLThreadChildren

func GQLThreadChildren(p graphql.ResolveParams) (interface{}, error)

func GQLThreadParent

func GQLThreadParent(p graphql.ResolveParams) (interface{}, error)

func GQLThreadState added in v0.2.0

func GQLThreadState(p graphql.ResolveParams) (interface{}, error)

func GQLWSDo

func GQLWSDo(ctx *Context, p graphql.Params) chan *graphql.Result

func GQLWSHandler

func GQLWSHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)

func GetCtx added in v0.2.0

func GetCtx[T Extension, C any](ctx *Context) (C, error)

func GetExt added in v0.2.0

func GetExt[T Extension](node *Node) (T, error)

func GraphiQLHandler

func GraphiQLHandler() func(http.ResponseWriter, *http.Request)

func Hash added in v0.2.3

func Hash(t Type) uint64

func LinkRequirement added in v0.2.0

func LinkRequirement(ctx *Context, dependency *Node, requirement NodeID) error

func LockLockable added in v0.2.0

func LockLockable(ctx *Context, node *Node) error

func NewField added in v0.2.0

func NewField(init func() *graphql.Field) *graphql.Field

func NodeHasExtensions added in v0.2.0

func NodeHasExtensions(node *Node, extensions []ExtType) bool

func NodeResolver added in v0.2.0

func NodeResolver(required_extensions []ExtType, default_type **graphql.Object) func(graphql.ResolveTypeParams) *graphql.Object

func ParseAuthRespJSON added in v0.2.0

func ParseAuthRespJSON(resp AuthRespJSON, ecdsa_curve elliptic.Curve, ecdh_curve ecdh.Curve, ec_key *ecdh.PrivateKey) ([]byte, error)

func PerNodePolicyLoad added in v0.2.0

func PerNodePolicyLoad(init_fn func(NodeActions) (Policy, error)) func(*Context, []byte) (Policy, error)

func PrepResolve added in v0.2.0

func PrepResolve(p graphql.ResolveParams) (*Node, *ResolveContext, error)

func SaveNode added in v0.2.0

func SaveNode(node *Node) string

func SaveNodeList added in v0.2.0

func SaveNodeList(nodes NodeMap) []string

func SaveNodeMap added in v0.2.0

func SaveNodeMap(nodes NodeMap) map[string]string

func StartGQLServer added in v0.2.0

func StartGQLServer(ctx *Context, node *Node, gql_ext *GQLExt) error

func StopGQLServer added in v0.2.0

func StopGQLServer(gql_ext *GQLExt)

func UnlockLockable added in v0.2.1

func UnlockLockable(ctx *Context, node *Node) error

func ValidateStateContext added in v0.2.0

func ValidateStateContext(context *StateContext, Type string, Finished bool) error

func WriteNode added in v0.2.0

func WriteNode(ctx *Context, node *Node) error

Write a node to the database

Types

type ACLExt added in v0.2.0

type ACLExt struct {
	Policies map[PolicyType]Policy
}

Extension to allow a node to hold ACL policies

func NewACLExt added in v0.2.0

func NewACLExt(policies ...Policy) *ACLExt

func (*ACLExt) Allows added in v0.2.0

func (ext *ACLExt) Allows(ctx *Context, principal_id NodeID, action SignalType, node *Node) error

Check if the extension allows the principal to perform action on node

func (*ACLExt) Process added in v0.2.0

func (ext *ACLExt) Process(ctx *Context, princ_id NodeID, node *Node, signal Signal)

func (*ACLExt) Serialize added in v0.2.0

func (ext *ACLExt) Serialize() ([]byte, error)

func (*ACLExt) Type added in v0.2.0

func (ext *ACLExt) Type() ExtType

type ACLExtContext added in v0.2.0

type ACLExtContext struct {
	Types map[PolicyType]PolicyInfo
}

func NewACLExtContext added in v0.2.0

func NewACLExtContext() *ACLExtContext

type ACLInfo added in v0.2.0

type ACLInfo struct {
	Node      *Node
	Resources []string
}

type ACLMap added in v0.2.0

type ACLMap map[NodeID]ACLInfo

func ACLList added in v0.2.0

func ACLList(list []*Node, resources []string) ACLMap

func ACLListM added in v0.2.0

func ACLListM(m map[NodeID]*Node, resources []string) ACLMap

func NewACLInfo added in v0.2.0

func NewACLInfo(node *Node, resources []string) ACLMap

func NewACLMap added in v0.2.0

func NewACLMap(requests ...ACLMap) ACLMap

type Actions added in v0.2.0

type Actions []SignalType

func (Actions) Allows added in v0.2.0

func (actions Actions) Allows(action SignalType) error

type AllNodesPolicy added in v0.2.0

type AllNodesPolicy struct {
	Actions Actions
}

func NewAllNodesPolicy added in v0.2.0

func NewAllNodesPolicy(actions Actions) AllNodesPolicy

func (*AllNodesPolicy) Allows added in v0.2.0

func (policy *AllNodesPolicy) Allows(principal_id NodeID, action SignalType, node *Node) error

TODO: Update with change from principal *Node to principal_id so sane policies can still be made

func (*AllNodesPolicy) Serialize added in v0.2.0

func (policy *AllNodesPolicy) Serialize() ([]byte, error)

func (*AllNodesPolicy) Type added in v0.2.0

func (policy *AllNodesPolicy) Type() PolicyType

type AllNodesPolicyJSON added in v0.2.0

type AllNodesPolicyJSON struct {
	Actions Actions `json:"actions"`
}

type AuthReqJSON added in v0.2.0

type AuthReqJSON struct {
	Time       time.Time `json:"time"`
	Pubkey     []byte    `json:"pubkey"`
	ECDHPubkey []byte    `json:"ecdh_client"`
	Signature  []byte    `json:"signature"`
}

func NewAuthReqJSON added in v0.2.0

func NewAuthReqJSON(curve ecdh.Curve, id *ecdsa.PrivateKey) (AuthReqJSON, *ecdh.PrivateKey, error)

type AuthRespJSON added in v0.2.0

type AuthRespJSON struct {
	Granted    time.Time `json:"granted"`
	ECDHPubkey []byte    `json:"echd_server"`
	Signature  []byte    `json:"signature"`
}

func NewAuthRespJSON added in v0.2.0

func NewAuthRespJSON(gql_ext *GQLExt, req AuthReqJSON) (AuthRespJSON, *ecdsa.PublicKey, []byte, error)

type BaseSignal

type BaseSignal struct {
	SignalDirection SignalDirection `json:"direction"`
	SignalType      SignalType      `json:"type"`
}

func NewBaseSignal

func NewBaseSignal(signal_type SignalType, direction SignalDirection) BaseSignal

func NewDirectSignal

func NewDirectSignal(signal_type SignalType) BaseSignal

func NewDownSignal

func NewDownSignal(signal_type SignalType) BaseSignal

func NewUpSignal added in v0.2.0

func NewUpSignal(signal_type SignalType) BaseSignal

func (BaseSignal) Direction

func (signal BaseSignal) Direction() SignalDirection

func (BaseSignal) Serialize added in v0.2.0

func (signal BaseSignal) Serialize() ([]byte, error)

func (BaseSignal) Type

func (signal BaseSignal) Type() SignalType

type ConsoleLogger

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

A ConsoleLogger logs to stdout

func NewConsoleLogger

func NewConsoleLogger(components []string) *ConsoleLogger

func (*ConsoleLogger) Logf

func (logger *ConsoleLogger) Logf(component string, format string, items ...interface{})

func (*ConsoleLogger) Logj

func (logger *ConsoleLogger) Logj(component string, s interface{}, format string, items ...interface{})

func (*ConsoleLogger) Logm

func (logger *ConsoleLogger) Logm(component string, fields map[string]interface{}, format string, items ...interface{})

func (*ConsoleLogger) SetComponents

func (logger *ConsoleLogger) SetComponents(components []string) error

type Context

type Context struct {
	// DB is the database connection used to load and write nodes
	DB *badger.DB
	// Logging interface
	Log Logger
	// Map between database extension hashes and the registered info
	Extensions map[uint64]ExtensionInfo
	// Map between database type hashes and the registered info
	Types map[uint64]NodeInfo
	// Routing map to all the nodes local to this context
	Nodes map[NodeID]*Node
}

A Context stores all the data to run a graphvent process

func NewContext

func NewContext(db *badger.DB, log Logger) (*Context, error)

Create a new Context with the base library content added

func (*Context) GetNode added in v0.2.0

func (ctx *Context) GetNode(id NodeID) (*Node, error)

func (*Context) RegisterExtension added in v0.2.0

func (ctx *Context) RegisterExtension(ext_type ExtType, load_fn ExtensionLoadFunc, data interface{}) error

Add a node to a context, returns an error if the def is invalid or already exists in the context

func (*Context) RegisterNodeType

func (ctx *Context) RegisterNodeType(node_type NodeType, extensions []ExtType) error

Register a NodeType to the context, with the list of extensions it requires

func (*Context) Send added in v0.2.0

func (ctx *Context) Send(source NodeID, dest NodeID, signal Signal) error

Route a Signal to dest. Currently only local context routing is supported

func (*Context) Stop added in v0.2.1

func (ctx *Context) Stop()

Stop every running loop

type ECDHExt added in v0.2.0

type ECDHExt struct {
	Granted time.Time
	Pubkey  *ecdsa.PublicKey
	Shared  []byte
}

func (*ECDHExt) Process added in v0.2.0

func (ext *ECDHExt) Process(ctx *Context, princ_id NodeID, node *Node, signal Signal)

func (*ECDHExt) Serialize added in v0.2.0

func (ext *ECDHExt) Serialize() ([]byte, error)

func (*ECDHExt) Type added in v0.2.0

func (ext *ECDHExt) Type() ExtType

type ECDHExtJSON added in v0.2.0

type ECDHExtJSON struct {
	Granted time.Time `json:"granted"`
	Pubkey  []byte    `json:"pubkey"`
	Shared  []byte    `json:"shared"`
}

type ExtMap added in v0.2.0

type ExtMap map[uint64]Extension

type ExtType added in v0.2.0

type ExtType string

func (ExtType) Prefix added in v0.2.3

func (ext ExtType) Prefix() string

func (ExtType) String added in v0.2.3

func (ext ExtType) String() string

type Extension added in v0.2.0

type Extension interface {
	Serializable[ExtType]
	Process(context *Context, source NodeID, node *Node, signal Signal)
}

Extensions are data attached to nodes that process signals

func LoadACLExt added in v0.2.0

func LoadACLExt(ctx *Context, data []byte) (Extension, error)

func LoadECDHExt added in v0.2.0

func LoadECDHExt(ctx *Context, data []byte) (Extension, error)

func LoadGQLExt added in v0.2.0

func LoadGQLExt(ctx *Context, data []byte) (Extension, error)

func LoadGroupExt added in v0.2.0

func LoadGroupExt(ctx *Context, data []byte) (Extension, error)

func LoadListenerExt added in v0.2.0

func LoadListenerExt(ctx *Context, data []byte) (Extension, error)

func LoadLockableExt added in v0.2.0

func LoadLockableExt(ctx *Context, data []byte) (Extension, error)

type ExtensionDB added in v0.2.0

type ExtensionDB struct {
	Header ExtensionDBHeader
	Data   []byte
}

func (ExtensionDB) Serialize added in v0.2.0

func (extension ExtensionDB) Serialize() []byte

type ExtensionDBHeader added in v0.2.0

type ExtensionDBHeader struct {
	TypeHash uint64
	Length   uint64
}

func (ExtensionDBHeader) Serialize added in v0.2.0

func (header ExtensionDBHeader) Serialize() []byte

type ExtensionInfo added in v0.2.0

type ExtensionInfo struct {
	Load ExtensionLoadFunc
	Type ExtType
	Data interface{}
}

Information about a registered extension

type ExtensionLoadFunc added in v0.2.0

type ExtensionLoadFunc func(*Context, []byte) (Extension, error)

Function to load an extension from bytes

type GQLExt added in v0.2.0

type GQLExt struct {
	Listen             string
	Users              NodeMap
	Key                *ecdsa.PrivateKey
	ECDH               ecdh.Curve
	SubscribeLock      sync.Mutex
	SubscribeListeners []chan Signal
	// contains filtered or unexported fields
}

func NewGQLExt added in v0.2.0

func NewGQLExt(listen string, ecdh_curve ecdh.Curve, key *ecdsa.PrivateKey, tls_cert []byte, tls_key []byte) *GQLExt

func (*GQLExt) NewSubscriptionChannel added in v0.2.0

func (ext *GQLExt) NewSubscriptionChannel(buffer int) chan Signal

func (*GQLExt) Process added in v0.2.0

func (ext *GQLExt) Process(context *Context, princ_id NodeID, node *Node, signal Signal)

func (*GQLExt) Serialize added in v0.2.0

func (ext *GQLExt) Serialize() ([]byte, error)

func (*GQLExt) Type added in v0.2.0

func (ext *GQLExt) Type() ExtType

type GQLExtContext added in v0.2.0

type GQLExtContext struct {
	// Generated GQL schema
	Schema graphql.Schema

	// Custom graphql types, mapped to NodeTypes
	NodeTypes  map[NodeType]*graphql.Object
	Interfaces []*GQLInterface

	// Schema parameters
	Types        []graphql.Type
	Query        *graphql.Object
	Mutation     *graphql.Object
	Subscription *graphql.Object
}

GQL Specific Context information

func NewGQLExtContext added in v0.2.0

func NewGQLExtContext() *GQLExtContext

func (*GQLExtContext) AddInterface added in v0.2.0

func (ctx *GQLExtContext) AddInterface(i *GQLInterface) error

func (*GQLExtContext) RegisterNodeType added in v0.2.0

func (ctx *GQLExtContext) RegisterNodeType(node_type NodeType, gql_type *graphql.Object) error

type GQLExtJSON added in v0.2.0

type GQLExtJSON struct {
	Listen  string `json:"listen"`
	Key     []byte `json:"key"`
	ECDH    uint8  `json:"ecdh_curve"`
	TLSKey  []byte `json:"ssl_key"`
	TLSCert []byte `json:"ssl_cert"`
}

type GQLInterface added in v0.2.0

type GQLInterface struct {
	Interface  *graphql.Interface
	Default    *graphql.Object
	List       *graphql.List
	Extensions []ExtType
}

func NewGQLInterface added in v0.2.0

func NewGQLInterface(if_name string, default_name string, interfaces []*graphql.Interface, extensions []ExtType, init_1 func(*GQLInterface), init_2 func(*GQLInterface)) *GQLInterface

type GQLPayload added in v0.2.0

type GQLPayload struct {
	OperationName string                 `json:"operationName,omitempty"`
	Query         string                 `json:"query,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
	Extensions    map[string]interface{} `json:"extensions,omitempty"`
	Data          string                 `json:"data,omitempty"`
}

type GQLType added in v0.2.0

type GQLType struct {
	Type *graphql.Object
	List *graphql.List
}

func NewGQLNodeType added in v0.2.0

func NewGQLNodeType(node_type NodeType, interfaces []*graphql.Interface, init func(*GQLType)) *GQLType

type GQLUnauthorized added in v0.2.0

type GQLUnauthorized string

func (GQLUnauthorized) Error added in v0.2.0

func (e GQLUnauthorized) Error() string

func (GQLUnauthorized) Is added in v0.2.0

func (e GQLUnauthorized) Is(target error) bool

func (GQLUnauthorized) MarshalJSON added in v0.2.0

func (e GQLUnauthorized) MarshalJSON() ([]byte, error)

type GQLWSMsg

type GQLWSMsg struct {
	ID      string     `json:"id,omitempty"`
	Type    string     `json:"type"`
	Payload GQLPayload `json:"payload,omitempty"`
}

type GroupExt added in v0.2.0

type GroupExt struct {
	Members NodeMap
}

func NewGroupExt added in v0.2.0

func NewGroupExt(members NodeMap) *GroupExt

func (*GroupExt) Process added in v0.2.0

func (ext *GroupExt) Process(ctx *Context, princ_id NodeID, node *Node, signal Signal)

func (*GroupExt) Serialize added in v0.2.0

func (ext *GroupExt) Serialize() ([]byte, error)

func (*GroupExt) Type added in v0.2.0

func (ext *GroupExt) Type() ExtType

type IDSignal added in v0.2.0

type IDSignal struct {
	BaseSignal
	ID NodeID `json:"id"`
}

func NewIDSignal added in v0.2.0

func NewIDSignal(signal_type SignalType, direction SignalDirection, id NodeID) IDSignal

func (IDSignal) String added in v0.2.0

func (signal IDSignal) String() string

type ListenerExt added in v0.2.0

type ListenerExt struct {
	Buffer int
	Chan   chan Signal
}

func NewListenerExt added in v0.2.0

func NewListenerExt(buffer int) *ListenerExt

func (*ListenerExt) Process added in v0.2.0

func (ext *ListenerExt) Process(ctx *Context, princ_id NodeID, node *Node, signal Signal)

func (*ListenerExt) Serialize added in v0.2.0

func (ext *ListenerExt) Serialize() ([]byte, error)

func (*ListenerExt) Type added in v0.2.0

func (listener *ListenerExt) Type() ExtType

type LockableExt added in v0.2.0

type LockableExt struct {
	Owner        *NodeID             `json:"owner"`
	PendingOwner *NodeID             `json:"pending_owner"`
	Requirements map[NodeID]ReqState `json:"requirements"`
	Dependencies map[NodeID]string   `json:"dependencies"`
}

func NewLockableExt added in v0.2.0

func NewLockableExt() *LockableExt

func (*LockableExt) HandleLinkSignal added in v0.2.0

func (ext *LockableExt) HandleLinkSignal(ctx *Context, source NodeID, node *Node, signal StateSignal)

TODO: don't allow changes to requirements or dependencies while being locked or locked TODO: add unlink

func (*LockableExt) HandleLockSignal added in v0.2.0

func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node, signal StateSignal)

func (*LockableExt) Process added in v0.2.0

func (ext *LockableExt) Process(ctx *Context, source NodeID, node *Node, signal Signal)

func (*LockableExt) Serialize added in v0.2.0

func (ext *LockableExt) Serialize() ([]byte, error)

func (*LockableExt) Type added in v0.2.0

func (ext *LockableExt) Type() ExtType

type Logger

type Logger interface {
	SetComponents(components []string) error
	// Log a formatted string
	Logf(component string, format string, items ...interface{})
	// Log a map of attributes and a format string
	Logm(component string, fields map[string]interface{}, format string, items ...interface{})
	// Log a structure to a file by marshalling and unmarshalling the json
	Logj(component string, s interface{}, format string, items ...interface{})
}

A Logger is passed around to record events happening to components enabled by SetComponents

type Msg added in v0.2.0

type Msg struct {
	Source NodeID
	Signal Signal
}

type Node

type Node struct {
	ID         NodeID
	Type       NodeType
	Extensions map[ExtType]Extension

	// Channel for this node to receive messages from the Context
	MsgChan chan Msg
	// Channel for this node to process delayed signals
	TimeoutChan <-chan time.Time

	Active atomic.Bool

	SignalQueue []QueuedSignal
	NextSignal  *QueuedSignal
}

Nodes represent a group of extensions that can be collectively addressed

func LoadNode

func LoadNode(ctx *Context, id NodeID) (*Node, error)

func NewNode added in v0.2.0

func NewNode(ctx *Context, id NodeID, node_type NodeType, queued_signals []QueuedSignal, extensions ...Extension) *Node

Create a new node in memory and start it's event loop

func RestoreNode added in v0.2.0

func RestoreNode(ctx *Context, id_str string) (*Node, error)

func (*Node) ClearSignalQueue added in v0.2.0

func (node *Node) ClearSignalQueue()

func (*Node) Process added in v0.2.0

func (node *Node) Process(ctx *Context, source NodeID, signal Signal)

func (*Node) QueueSignal added in v0.2.0

func (node *Node) QueueSignal(time time.Time, signal Signal)

func (*Node) Serialize

func (node *Node) Serialize() ([]byte, error)

type NodeActions added in v0.2.0

type NodeActions map[NodeID]Actions

type NodeDB added in v0.2.0

type NodeDB struct {
	Header        NodeDBHeader
	QueuedSignals []QueuedSignal
	Extensions    []ExtensionDB
}

func NewNodeDB added in v0.2.0

func NewNodeDB(data []byte) (NodeDB, error)

TODO: add size safety checks

func (NodeDB) Serialize added in v0.2.0

func (node NodeDB) Serialize() []byte

type NodeDBHeader added in v0.2.0

type NodeDBHeader struct {
	Magic            uint32
	NumExtensions    uint32
	NumQueuedSignals uint32
	TypeHash         uint64
}

A DBHeader is parsed from the first NODE_DB_HEADER_LEN bytes of a serialized DB node

func (NodeDBHeader) Serialize added in v0.2.0

func (header NodeDBHeader) Serialize() []byte

type NodeID

type NodeID uuid.UUID

A NodeID uniquely identifies a Node

func ExtractID added in v0.2.0

func ExtractID(p graphql.ResolveParams, name string) (NodeID, error)

func IDFromBytes added in v0.2.0

func IDFromBytes(bytes [16]byte) NodeID

Create an ID from a fixed length byte array Ignore the error since we're enforcing 16 byte length at compile time

func ParseID added in v0.2.0

func ParseID(str string) (NodeID, error)

Parse an ID from a string

func RandID

func RandID() NodeID

Generate a random NodeID

func (NodeID) MarshalJSON added in v0.2.0

func (id NodeID) MarshalJSON() ([]byte, error)

func (NodeID) Serialize

func (id NodeID) Serialize() []byte

func (NodeID) String added in v0.2.0

func (id NodeID) String() string

func (*NodeID) UnmarshalJSON added in v0.2.0

func (id *NodeID) UnmarshalJSON(bytes []byte) error

type NodeInfo added in v0.2.0

type NodeInfo struct {
	Type       NodeType
	Extensions []ExtType
}

Information about a registered node type

type NodeMap

type NodeMap map[NodeID]*Node

func NodeList

func NodeList(nodes ...*Node) NodeMap

func RestoreNodeList added in v0.2.0

func RestoreNodeList(ctx *Context, ids []string) (NodeMap, error)

func RestoreNodeMap added in v0.2.0

func RestoreNodeMap(ctx *Context, ids map[string]string) (NodeMap, error)

type NodeType

type NodeType string

func (NodeType) Prefix added in v0.2.3

func (node NodeType) Prefix() string

func (NodeType) String added in v0.2.3

func (node NodeType) String() string

type PerNodePolicy added in v0.2.0

type PerNodePolicy struct {
	NodeActions NodeActions `json:"node_actions"`
}

func NewPerNodePolicy added in v0.2.0

func NewPerNodePolicy(node_actions NodeActions) PerNodePolicy

func (*PerNodePolicy) Allows added in v0.2.0

func (policy *PerNodePolicy) Allows(principal_id NodeID, action SignalType, node *Node) error

func (*PerNodePolicy) Serialize added in v0.2.0

func (policy *PerNodePolicy) Serialize() ([]byte, error)

func (*PerNodePolicy) Type added in v0.2.0

func (policy *PerNodePolicy) Type() PolicyType

type Policy added in v0.2.0

type Policy interface {
	Serializable[PolicyType]
	Allows(principal_id NodeID, action SignalType, node *Node) error
}

type PolicyInfo added in v0.2.0

type PolicyInfo struct {
	Load PolicyLoadFunc
}

type PolicyLoadFunc added in v0.2.0

type PolicyLoadFunc func(*Context, []byte) (Policy, error)

type PolicyType added in v0.2.0

type PolicyType string

func (PolicyType) Prefix added in v0.2.3

func (policy PolicyType) Prefix() string

func (PolicyType) String added in v0.2.3

func (policy PolicyType) String() string

type QueuedSignal added in v0.2.0

type QueuedSignal struct {
	Signal Signal
	Time   time.Time
}

A QueuedSignal is a Signal that has been Queued to trigger at a set time

func SoonestSignal added in v0.2.0

func SoonestSignal(signals []QueuedSignal) (*QueuedSignal, <-chan time.Time)

type ReqState added in v0.2.1

type ReqState struct {
	Link string `json:"link"`
	Lock string `json:"lock"`
}

type RequirementOfPolicy added in v0.2.0

type RequirementOfPolicy struct {
	AllNodesPolicy
}

func NewRequirementOfPolicy added in v0.2.0

func NewRequirementOfPolicy(actions Actions) RequirementOfPolicy

func (*RequirementOfPolicy) Allows added in v0.2.0

func (policy *RequirementOfPolicy) Allows(principal_id NodeID, action SignalType, node *Node) error

func (*RequirementOfPolicy) Type added in v0.2.0

func (policy *RequirementOfPolicy) Type() PolicyType

type ResolveContext added in v0.2.0

type ResolveContext struct {
	Context    *Context
	GQLContext *GQLExtContext
	Server     *Node
	Ext        *GQLExt
	User       *Node
}

func NewResolveContext added in v0.2.0

func NewResolveContext(ctx *Context, server *Node, gql_ext *GQLExt, r *http.Request) (*ResolveContext, error)

type Serializable added in v0.2.0

type Serializable[I comparable] interface {
	Type() I
	Serialize() ([]byte, error)
}

A Serializable has a type that can be used to map to it, and a function to serialize the current state

type Signal added in v0.2.0

type Signal interface {
	Serializable[SignalType]
	Direction() SignalDirection
}

type SignalDirection

type SignalDirection int
const (
	Up SignalDirection = iota
	Down
	Direct
)

type SignalType added in v0.2.0

type SignalType string

type Singleton added in v0.2.0

type Singleton[K graphql.Type] struct {
	Type K
	List *graphql.List
}

func NewSingleton added in v0.2.0

func NewSingleton[K graphql.Type](init func() K, post_init func(K, *graphql.List)) *Singleton[K]

type StartChildSignal added in v0.2.0

type StartChildSignal struct {
	IDSignal
	Action string `json:"action"`
}

func NewStartChildSignal added in v0.2.0

func NewStartChildSignal(child_id NodeID, action string) StartChildSignal

type StateContext added in v0.2.0

type StateContext struct {
	// Type of the state context
	Type string
	// The wrapped graph context
	Graph *Context
	// Granted permissions in the context
	Permissions map[NodeID]ACLMap
	// Locked extensions in the context
	Locked map[NodeID]*Node

	// Context state for validation
	Started  bool
	Finished bool
}

Context of running state usage(read/write)

func NewReadContext added in v0.2.0

func NewReadContext(ctx *Context) *StateContext

func NewWriteContext added in v0.2.0

func NewWriteContext(ctx *Context) *StateContext

type StateFn added in v0.2.0

type StateFn func(*StateContext) error

type StateSignal added in v0.2.0

type StateSignal struct {
	BaseSignal
	State string `json:"state"`
}

func NewLinkSignal added in v0.2.0

func NewLinkSignal(state string) StateSignal

func NewLockSignal added in v0.2.0

func NewLockSignal(state string) StateSignal

func (StateSignal) Serialize added in v0.2.0

func (signal StateSignal) Serialize() ([]byte, error)

func (StateSignal) String added in v0.2.0

func (signal StateSignal) String() string

type StatusSignal added in v0.2.0

type StatusSignal struct {
	IDSignal
	Status string `json:"status"`
}

func NewStatusSignal added in v0.2.0

func NewStatusSignal(status string, source NodeID) StatusSignal

func (StatusSignal) String added in v0.2.0

func (signal StatusSignal) String() string

type Type added in v0.2.3

type Type interface {
	String() string
	Prefix() string
}

Jump to

Keyboard shortcuts

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