Added PostDeserialize to GQLExt to initialize temporary maps/slices

gql_cataclysm
noah metz 2023-09-20 11:05:47 -06:00
parent d86d424cd7
commit b09e150c46
4 changed files with 23 additions and 16 deletions

@ -1195,6 +1195,13 @@ type GQLExt struct {
Listen string `gv:"listen"` Listen string `gv:"listen"`
} }
func (ext *GQLExt) PostDeserialize(*Context) error {
ext.resolver_response = map[uuid.UUID]chan Signal{}
ext.subscriptions = []SubscriptionInfo{}
return nil
}
func (ext *GQLExt) AddSubscription(id uuid.UUID) (chan interface{}, error) { func (ext *GQLExt) AddSubscription(id uuid.UUID) (chan interface{}, error) {
ext.subscriptions_lock.Lock() ext.subscriptions_lock.Lock()
defer ext.subscriptions_lock.Unlock() defer ext.subscriptions_lock.Unlock()
@ -1265,7 +1272,7 @@ func (ext *GQLExt) Process(ctx *Context, node *Node, source NodeID, signal Signa
if response_chan != nil { if response_chan != nil {
select { select {
case response_chan <- sig: case response_chan <- sig:
ctx.Log.Logf("gql", "Forwarded error to resolver, %+v", sig) ctx.Log.Logf("gql", "Forwarded error to resolver, %+v", sig.Error)
default: default:
ctx.Log.Logf("gql", "Resolver channel overflow %+v", sig) ctx.Log.Logf("gql", "Resolver channel overflow %+v", sig)
} }
@ -1309,14 +1316,6 @@ func (ext *GQLExt) Process(ctx *Context, node *Node, source NodeID, signal Signa
return nil return nil
} }
func (ext *GQLExt) Type() ExtType {
return GQLExtType
}
func (ext *GQLExt) MarshalBinary() ([]byte, error) {
return json.Marshal(ext)
}
var ecdsa_curves = map[uint8]elliptic.Curve{ var ecdsa_curves = map[uint8]elliptic.Curve{
0: elliptic.P256(), 0: elliptic.P256(),
} }
@ -1333,11 +1332,6 @@ var ecdh_curve_ids = map[ecdh.Curve]uint8{
ecdh.P256(): 0, ecdh.P256(): 0,
} }
func (ext *GQLExt) Deserialize(ctx *Context, data []byte) error {
ext.resolver_response = map[uuid.UUID]chan Signal{}
return json.Unmarshal(data, &ext)
}
func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) (*GQLExt, error) { func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) (*GQLExt, error) {
if tls_cert == nil || tls_key == nil { if tls_cert == nil || tls_key == nil {
ssl_key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) ssl_key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
@ -1378,6 +1372,7 @@ func NewGQLExt(ctx *Context, listen string, tls_cert []byte, tls_key []byte) (*G
tls_cert = ssl_cert_pem tls_cert = ssl_cert_pem
tls_key = ssl_key_pem tls_key = ssl_key_pem
} }
return &GQLExt{ return &GQLExt{
Listen: listen, Listen: listen,
resolver_response: map[uuid.UUID]chan Signal{}, resolver_response: map[uuid.UUID]chan Signal{},

@ -67,6 +67,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
if err != nil { if err != nil {
return nil, err return nil, err
} }
ctx.Context.Log.Logf("gql", "ACL Fields from request: %+v", ext_fields)
responses := make([]NodeResult, len(ids)) responses := make([]NodeResult, len(ids))
@ -107,6 +108,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
} else { } else {
read_signal = NewReadSignal(ext_fields) read_signal = NewReadSignal(ext_fields)
} }
ctx.Context.Log.Logf("gql", "READ_SIGNAL for %s - %+v", id, read_signal)
// Create a read signal, send it to the specified node, and add the wait to the response map if the send returns no error // Create a read signal, send it to the specified node, and add the wait to the response map if the send returns no error
msgs := Messages{} msgs := Messages{}
msgs = msgs.Add(ctx.Context, ctx.Server.ID, ctx.Key, read_signal, id) msgs = msgs.Add(ctx.Context, ctx.Server.ID, ctx.Key, read_signal, id)
@ -121,8 +123,12 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
ctx.Ext.FreeResponseChannel(read_signal.ID) ctx.Ext.FreeResponseChannel(read_signal.ID)
return nil, err return nil, err
} }
ctx.Context.Log.Logf("gql", "SENT_READ_SIGNAL to %+s", id)
} }
ctx.Context.Log.Logf("gql", "Resolved cached nodes: %+v", responses)
for sig_id, response_chan := range(resp_channels) { for sig_id, response_chan := range(resp_channels) {
// Wait for the response, returning an error on timeout // Wait for the response, returning an error on timeout
response, err := WaitForSignal(response_chan, time.Millisecond*100, func(sig *ReadResultSignal)bool{ response, err := WaitForSignal(response_chan, time.Millisecond*100, func(sig *ReadResultSignal)bool{

@ -300,7 +300,7 @@ func nodeLoop(ctx *Context, node *Node) error {
if princ_id != node.ID { if princ_id != node.ID {
pends, resp := node.Allows(ctx, princ_id, msg.Signal.Permission()) pends, resp := node.Allows(ctx, princ_id, msg.Signal.Permission())
if resp == Deny { if resp == Deny {
ctx.Log.Logf("policy", "SIGNAL_POLICY_DENY: %s->%s - %s", princ_id, node.ID, msg.Signal.Permission()) ctx.Log.Logf("policy", "SIGNAL_POLICY_DENY: %s->%s - %+v(%+s)", princ_id, node.ID, reflect.TypeOf(msg.Signal), msg.Signal)
ctx.Log.Logf("policy", "SIGNAL_POLICY_SOURCE: %s", msg.Source) ctx.Log.Logf("policy", "SIGNAL_POLICY_SOURCE: %s", msg.Source)
msgs := Messages{} msgs := Messages{}
msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(msg.Signal.Header().ID, "acl denied"), msg.Source) msgs = msgs.Add(ctx, node.ID, node.Key, NewErrorSignal(msg.Signal.Header().ID, "acl denied"), msg.Source)

@ -24,7 +24,12 @@ func (header SignalHeader) Header() SignalHeader {
return header return header
} }
func (header SignalHeader) String() string {
return fmt.Sprintf("Signal(%d, %s->%s)", header.Direction, header.ID, header.ReqID)
}
type Signal interface { type Signal interface {
fmt.Stringer
Header() SignalHeader Header() SignalHeader
Permission() Tree Permission() Tree
} }
@ -190,7 +195,7 @@ func NewStatusSignal(source NodeID, status string) *StatusSignal {
type LinkSignal struct { type LinkSignal struct {
SignalHeader SignalHeader
NodeID NodeID NodeID
Action string Action string
} }
@ -206,6 +211,7 @@ func (signal LinkSignal) Permission() Tree {
}, },
} }
} }
func NewLinkSignal(action string, id NodeID) Signal { func NewLinkSignal(action string, id NodeID) Signal {
return &LinkSignal{ return &LinkSignal{
NewSignalHeader(Direct), NewSignalHeader(Direct),