sidecar: add CurrentState() method to side car negotiator
This methods makes writing tests easier as the test context can
introspect into the negotiator's state.
@@ -163,6 +163,8 @@ type AutoAcceptorConfig struct {
// provider and recipient of a sidecar channel to complete the manual steps in
// automated manner.
type SidecarNegotiator struct {
+ currentState uint32
+
cfg AutoAcceptorConfig
wg sync.WaitGroup
@@ -173,6 +175,7 @@ type SidecarNegotiator struct {
func NewSidecarNegotiator(cfg AutoAcceptorConfig) *SidecarNegotiator {
return &SidecarNegotiator{
cfg: cfg,
+ currentState: uint32(cfg.StartingPkt.CurrentState),
}
}
@@ -291,7 +294,12 @@ func (a *SidecarNegotiator) autoSidecarReceiver(ctx context.Context,
continue
}
- currentState = newPktState.CurrentState
+ // TODO(roasbeef): make into method for easier
+ // assertions?
+ atomic.StoreUint32(
+ &a.currentState, uint32(newPktState.CurrentState),
+ )
+
localTicket = newPktState.ReceiverTicket
// If our next target state is the completion state,
@@ -489,6 +497,10 @@ func (a *SidecarNegotiator) autoSidecarProvider(ctx context.Context, startingPkt
currentState = newPktState.CurrentState
localTicket = newPktState.ProviderTicket
+ atomic.StoreUint32(
+ &a.currentState, uint32(newPktState.CurrentState),
+ )
+
switch {
case priorState == currentState:
fallthrough
@@ -515,6 +527,12 @@ func (a *SidecarNegotiator) autoSidecarProvider(ctx context.Context, startingPkt
}
}
+// CurrentState returns the current state of the sidecar negotiator.
+func (a *SidecarNegotiator) CurrentState() sidecar.State {
+ state := atomic.LoadUint32(&a.currentState)
+ return sidecar.State(state)
+}
+
// stateStepProvider is the state transition function for the provider of a
// sidecar ticket. It takes the current transcript state, the provider's
// account, and canned bid and returns a new transition to a new ticket state.
