feat: add empty client spool reconciliation
This commit is contained in:
@@ -59,3 +59,34 @@ func Handshake(ctx context.Context, transport Transport, hello *rvboxv1.ClientHe
|
||||
}
|
||||
return Session{ID: welcome.GetSessionId(), Generation: welcome.GetSessionGeneration(), Protocol: proto.Clone(payload.GetSelectedProtocol()).(*rvboxv1.ProtocolVersion)}, nil
|
||||
}
|
||||
|
||||
// Reconcile sends the complete retained client state after welcome. The caller
|
||||
// must apply the returned result durably before accepting fresh dispatch.
|
||||
func Reconcile(ctx context.Context, transport Transport, session Session, snapshot *rvboxv1.ReconcileSnapshot, limits agentproto.Limits) (*rvboxv1.ReconcileResult, error) {
|
||||
if transport == nil || session.ID == "" || session.Generation == 0 || snapshot == nil {
|
||||
return nil, ErrProtocolHandshake
|
||||
}
|
||||
request := &rvboxv1.AgentEnvelope{SessionId: session.ID, SessionGeneration: session.Generation, Payload: &rvboxv1.AgentEnvelope_ReconcileSnapshot{ReconcileSnapshot: snapshot}}
|
||||
if err := agentproto.ValidateEnvelope(request, limits, rvboxv1.Platform_PLATFORM_WINDOWS); err != nil {
|
||||
return nil, fmt.Errorf("validate reconciliation snapshot: %w", err)
|
||||
}
|
||||
encoded, err := proto.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := transport.Write(ctx, encoded); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
received, err := transport.Read(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := agentproto.DecodeEnvelope(received, limits, rvboxv1.Platform_PLATFORM_WINDOWS)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("decode ReconcileResult: %w", err)
|
||||
}
|
||||
if result.GetSessionId() != session.ID || result.GetSessionGeneration() != session.Generation || result.GetReconcileResult() == nil {
|
||||
return nil, ErrProtocolHandshake
|
||||
}
|
||||
return proto.Clone(result.GetReconcileResult()).(*rvboxv1.ReconcileResult), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user