Documentation
¶
Index ¶
- Constants
- Variables
- func AddLockableFields(object *graphql.Object)
- func AddLockableInterfaceFields(gql *GQLInterface)
- func AddNodeFields(object *graphql.Object)
- func AddNodeInterfaceFields(gql *GQLInterface)
- func AllNodesPolicyLoad(init_fn func(Actions) (Policy, error)) func(*Context, []byte) (Policy, error)
- func Allowed(ctx *Context, principal_id NodeID, action SignalType, node *Node) error
- func AuthHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)
- func BuildSchema(ctx *GQLExtContext) (graphql.Schema, error)
- func ExtractList[K interface{}](p graphql.ResolveParams, name string) ([]K, error)
- func ExtractParam[K interface{}](p graphql.ResolveParams, name string) (K, error)
- func GQLGroupMembers(p graphql.ResolveParams) (interface{}, error)
- func GQLHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)
- func GQLLockableDependencies(p graphql.ResolveParams) (interface{}, error)
- func GQLLockableOwner(p graphql.ResolveParams) (interface{}, error)
- func GQLLockableRequirements(p graphql.ResolveParams) (interface{}, error)
- func GQLNodeHasExtensions(extensions []ExtType) func(graphql.IsTypeOfParams) bool
- func GQLNodeID(p graphql.ResolveParams) (interface{}, error)
- func GQLNodeListen(p graphql.ResolveParams) (interface{}, error)
- func GQLNodeTypeHash(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalDirection(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalFn(p graphql.ResolveParams, ...) (interface{}, error)
- func GQLSignalString(p graphql.ResolveParams) (interface{}, error)
- func GQLSignalType(p graphql.ResolveParams) (interface{}, error)
- func GQLSubscribeFn(p graphql.ResolveParams, send_nil bool, ...) (interface{}, error)
- func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error)
- func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error)
- func GQLThreadChildren(p graphql.ResolveParams) (interface{}, error)
- func GQLThreadParent(p graphql.ResolveParams) (interface{}, error)
- func GQLThreadState(p graphql.ResolveParams) (interface{}, error)
- func GQLWSDo(ctx *Context, p graphql.Params) chan *graphql.Result
- func GQLWSHandler(ctx *Context, server *Node, gql_ext *GQLExt) func(http.ResponseWriter, *http.Request)
- func GetCtx[T Extension, C any](ctx *Context) (C, error)
- func GetExt[T Extension](node *Node) (T, error)
- func GraphiQLHandler() func(http.ResponseWriter, *http.Request)
- func LinkRequirement(ctx *Context, dependency *Node, requirement NodeID) error
- func LockLockable(ctx *Context, node *Node) error
- func NewField(init func() *graphql.Field) *graphql.Field
- func NodeHasExtensions(node *Node, extensions []ExtType) bool
- func NodeLoop(ctx *Context, node *Node) error
- func NodeResolver(required_extensions []ExtType, default_type **graphql.Object) func(graphql.ResolveTypeParams) *graphql.Object
- func ParseAuthRespJSON(resp AuthRespJSON, ecdsa_curve elliptic.Curve, ecdh_curve ecdh.Curve, ...) ([]byte, error)
- func PerNodePolicyLoad(init_fn func(NodeActions) (Policy, error)) func(*Context, []byte) (Policy, error)
- func PrepResolve(p graphql.ResolveParams) (*Node, *ResolveContext, error)
- func RunNode(ctx *Context, node *Node)
- func SaveNode(node *Node) string
- func SaveNodeList(nodes NodeMap) []string
- func SaveNodeMap(nodes NodeMap) map[string]string
- func StartGQLServer(ctx *Context, node *Node, gql_ext *GQLExt) error
- func StopGQLServer(gql_ext *GQLExt)
- func ValidateStateContext(context *StateContext, Type string, Finished bool) error
- func WriteNode(ctx *Context, node *Node) error
- type ACLExt
- type ACLExtContext
- type ACLInfo
- type ACLMap
- type Actions
- type AllNodesPolicy
- type AllNodesPolicyJSON
- type AuthReqJSON
- type AuthRespJSON
- type BaseSignal
- type ConsoleLogger
- func (logger *ConsoleLogger) Logf(component string, format string, items ...interface{})
- func (logger *ConsoleLogger) Logj(component string, s interface{}, format string, items ...interface{})
- func (logger *ConsoleLogger) Logm(component string, fields map[string]interface{}, format string, ...)
- func (logger *ConsoleLogger) SetComponents(components []string) error
- type Context
- func (ctx *Context) GetNode(id NodeID) (*Node, error)
- func (ctx *Context) RegisterExtension(ext_type ExtType, load_fn ExtensionLoadFunc, data interface{}) error
- func (ctx *Context) RegisterNodeType(node_type NodeType, extensions []ExtType) error
- func (ctx *Context) Send(source NodeID, dest NodeID, signal Signal) error
- type ECDHExt
- type ECDHExtJSON
- type ExtMap
- type ExtType
- type Extension
- func LoadACLExt(ctx *Context, data []byte) (Extension, error)
- func LoadECDHExt(ctx *Context, data []byte) (Extension, error)
- func LoadGQLExt(ctx *Context, data []byte) (Extension, error)
- func LoadGroupExt(ctx *Context, data []byte) (Extension, error)
- func LoadListenerExt(ctx *Context, data []byte) (Extension, error)
- func LoadLockableExt(ctx *Context, data []byte) (Extension, error)
- type ExtensionDB
- type ExtensionDBHeader
- type ExtensionInfo
- type ExtensionLoadFunc
- type GQLExt
- type GQLExtContext
- type GQLExtJSON
- type GQLInterface
- type GQLPayload
- type GQLType
- type GQLUnauthorized
- type GQLWSMsg
- type GroupExt
- type IDSignal
- type ListenerExt
- type LockableExt
- func (ext *LockableExt) HandleLinkSignal(ctx *Context, source NodeID, node *Node, signal StateSignal)
- func (ext *LockableExt) HandleLockSignal(ctx *Context, source NodeID, node *Node, signal StateSignal)
- func (ext *LockableExt) Process(ctx *Context, source NodeID, node *Node, signal Signal)
- func (ext *LockableExt) RecordLock(node NodeID, last_owner *NodeID)
- func (ext *LockableExt) RecordUnlock(node NodeID) *NodeID
- func (ext *LockableExt) Serialize() ([]byte, error)
- func (ext *LockableExt) Type() ExtType
- type Logger
- type Msg
- type Node
- type NodeActions
- type NodeDB
- type NodeDBHeader
- type NodeID
- type NodeInfo
- type NodeMap
- type NodeType
- type PerNodePolicy
- type Policy
- type PolicyInfo
- type PolicyLoadFunc
- type PolicyType
- type QueuedSignal
- type RequirementOfPolicy
- type ResolveContext
- type Serializable
- type Signal
- type SignalDirection
- type SignalType
- type Singleton
- type StartChildSignal
- type StateContext
- type StateFn
- type StateSignal
- type StatusSignal
Constants ¶
const ACLExtType = ExtType("ACL")
const AllNodesPolicyType = PolicyType("ALL_NODES")
const ECDHExtType = ExtType("ECDH")
const EXTENSION_DB_HEADER_LEN = 16
const GQLExtType = ExtType("gql_thread")
const GQLNodeType = NodeType("GQL")
const GroupExtType = ExtType("GROUP")
const LinkSignalType = SignalType("LINK")
const ListenerExtType = ExtType("LISTENER")
const LockSignalType = SignalType("LOCK")
const LockableExtType = ExtType("LOCKABLE")
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
const NODE_DB_MAGIC = 0x2491df14
Magic first four bytes of serialized DB content, stored big endian
const NODE_MSG_CHAN_DEFAULT = 1024
Default message channel size for nodes
const PerNodePolicyType = PolicyType("PER_NODE")
const RequirementOfPolicyType = PolicyType("REQUIREMENT_OF")
const StatusSignalType = SignalType("STATUS")
const StopSignalType = SignalType("STOP")
Variables ¶
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) })
var GQLInterfaceNode = NewGQLInterface("Node", "DefaultNode", []*graphql.Interface{}, []ExtType{}, func(gql *GQLInterface) { AddNodeInterfaceFields(gql) }, func(gql *GQLInterface) { AddNodeFields(gql.Default) })
var GQLLockableInterfaces = append(GQLNodeInterfaces, GQLInterfaceLockable.Interface)
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 })
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 })
var GQLNodeInterfaces = []*graphql.Interface{GQLInterfaceNode.Interface}
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 }, }
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 }, }
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 })
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 })
var GQLTypeGQLNode = NewGQLNodeType(GQLNodeType, GQLNodeInterfaces, func(gql *GQLType) { AddNodeFields(gql.Type) gql.Type.AddFieldConfig("Listen", &graphql.Field{ Type: graphql.String, Resolve: GQLNodeListen, }) })
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)
var NodeNotFoundError = errors.New("Node not found in DB")
var StopSignal = NewDownSignal(StopSignalType)
var ZeroID = NodeID(ZeroUUID)
var ZeroUUID = uuid.UUID{}
Base NodeID, used as a special value
Functions ¶
func AddLockableFields ¶ added in v0.2.0
func AddLockableInterfaceFields ¶ added in v0.2.0
func AddLockableInterfaceFields(gql *GQLInterface)
func AddNodeFields ¶ added in v0.2.0
func AddNodeInterfaceFields ¶ added in v0.2.0
func AddNodeInterfaceFields(gql *GQLInterface)
func AllNodesPolicyLoad ¶ added in v0.2.0
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 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 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 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 GQLWSHandler ¶
func GraphiQLHandler ¶
func GraphiQLHandler() func(http.ResponseWriter, *http.Request)
func LinkRequirement ¶ added in v0.2.0
func LockLockable ¶ added in v0.2.0
func NodeHasExtensions ¶ added in v0.2.0
func NodeLoop ¶ added in v0.2.0
Main Loop for Threads, starts a write context, so cannot be called from a write or read context
func NodeResolver ¶ added in v0.2.0
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 PrepResolve ¶ added in v0.2.0
func PrepResolve(p graphql.ResolveParams) (*Node, *ResolveContext, error)
func SaveNodeList ¶ added in v0.2.0
func SaveNodeMap ¶ added in v0.2.0
func StartGQLServer ¶ added in v0.2.0
func StopGQLServer ¶ added in v0.2.0
func StopGQLServer(gql_ext *GQLExt)
func ValidateStateContext ¶ added in v0.2.0
func ValidateStateContext(context *StateContext, Type string, Finished bool) error
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 (*ACLExt) Allows ¶ added in v0.2.0
Check if the extension allows the principal to perform action on node
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 ACLMap ¶ added in v0.2.0
func NewACLInfo ¶ added in v0.2.0
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 ¶
Create a new Context with the base library content added
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 ¶
Register a NodeType to the context, with the list of extensions it requires
type ECDHExtJSON ¶ added in v0.2.0
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 LoadListenerExt ¶ added in v0.2.0
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
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
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 (*GQLExt) NewSubscriptionChannel ¶ added in v0.2.0
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 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 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
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
type ListenerExt ¶ added in v0.2.0
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"`
Requirements map[NodeID]string `json:"requirements"`
Dependencies map[NodeID]string `json:"dependencies"`
LockStates map[NodeID]string `json:"lock_states"`
LocksHeld map[NodeID]*NodeID `json:"locks_held"`
}
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)
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) RecordLock ¶ added in v0.2.0
func (ext *LockableExt) RecordLock(node NodeID, last_owner *NodeID)
func (*LockableExt) RecordUnlock ¶ added in v0.2.0
func (ext *LockableExt) RecordUnlock(node NodeID) *NodeID
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 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 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 (*Node) ClearSignalQueue ¶ added in v0.2.0
func (node *Node) ClearSignalQueue()
func (*Node) QueueSignal ¶ added in v0.2.0
type NodeActions ¶ added in v0.2.0
type NodeDB ¶ added in v0.2.0
type NodeDB struct {
Header NodeDBHeader
QueuedSignals []QueuedSignal
Extensions []ExtensionDB
}
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 ¶
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
Create an ID from a fixed length byte array Ignore the error since we're enforcing 16 byte length at compile time
func (NodeID) MarshalJSON ¶ added in v0.2.0
func (*NodeID) UnmarshalJSON ¶ added in v0.2.0
type NodeMap ¶
func RestoreNodeList ¶ added in v0.2.0
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 PolicyType ¶ added in v0.2.0
type PolicyType string
func (PolicyType) Hash ¶ added in v0.2.0
func (policy PolicyType) Hash() uint64
type QueuedSignal ¶ added in v0.2.0
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 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
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 SignalType ¶ added in v0.2.0
type SignalType string
type StartChildSignal ¶ added in v0.2.0
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
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