Local Pairing update for `StopNode` (#3536)
This commit is contained in:
parent
790efc16aa
commit
a7df4ed388
|
@ -85,7 +85,7 @@ type GethStatusBackend struct {
|
|||
selectedAccountKeyID string
|
||||
log log.Logger
|
||||
allowAllRPC bool // used only for tests, disables api method restrictions
|
||||
|
||||
localPairing bool // used to disable login/logout signalling
|
||||
}
|
||||
|
||||
// NewGethStatusBackend create a new GethStatusBackend instance
|
||||
|
@ -109,6 +109,7 @@ func (b *GethStatusBackend) initialize() {
|
|||
b.personalAPI = personalAPI
|
||||
b.statusNode.SetMultiaccountsDB(b.multiaccountsDB)
|
||||
b.log = log.New("package", "status-go/api.GethStatusBackend")
|
||||
b.localPairing = false
|
||||
}
|
||||
|
||||
// StatusNode returns reference to node manager
|
||||
|
@ -395,7 +396,9 @@ func (b *GethStatusBackend) StartNodeWithKey(acc multiaccounts.Account, password
|
|||
// Stop node for clean up
|
||||
_ = b.StopNode()
|
||||
}
|
||||
if !b.localPairing {
|
||||
signal.SendLoggedIn(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -512,7 +515,9 @@ func (b *GethStatusBackend) StartNodeWithAccount(acc multiaccounts.Account, pass
|
|||
// Stop node for clean up
|
||||
_ = b.StopNode()
|
||||
}
|
||||
if !b.localPairing {
|
||||
signal.SendLoggedIn(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -1241,7 +1246,9 @@ func (b *GethStatusBackend) stopNode() error {
|
|||
if b.statusNode == nil || !b.IsNodeRunning() {
|
||||
return nil
|
||||
}
|
||||
if !b.localPairing {
|
||||
defer signal.SendNodeStopped()
|
||||
}
|
||||
|
||||
return b.statusNode.Stop()
|
||||
}
|
||||
|
@ -1813,3 +1820,7 @@ func (b *GethStatusBackend) SwitchFleet(fleet string, conf *params.NodeConfig) e
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) SetLocalPairing(value bool) {
|
||||
b.localPairing = value
|
||||
}
|
||||
|
|
|
@ -1007,10 +1007,22 @@ func GetConnectionStringForBeingBootstrapped(configJSON string) string {
|
|||
if configJSON == "" {
|
||||
return makeJSONResponse(fmt.Errorf("no config given, PayloadSourceConfig is expected"))
|
||||
}
|
||||
|
||||
statusBackend.SetLocalPairing(true)
|
||||
defer func() {
|
||||
statusBackend.SetLocalPairing(false)
|
||||
}()
|
||||
|
||||
cs, err := pairing.StartUpReceiverServer(statusBackend, configJSON)
|
||||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
err = statusBackend.Logout()
|
||||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
return cs
|
||||
}
|
||||
|
||||
|
@ -1024,6 +1036,12 @@ func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string
|
|||
if configJSON == "" {
|
||||
return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected"))
|
||||
}
|
||||
|
||||
statusBackend.SetLocalPairing(true)
|
||||
defer func() {
|
||||
statusBackend.SetLocalPairing(false)
|
||||
}()
|
||||
|
||||
cs, err := pairing.StartUpSenderServer(statusBackend, configJSON)
|
||||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
|
@ -1044,7 +1062,17 @@ func InputConnectionStringForBootstrapping(cs, configJSON string) string {
|
|||
return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected"))
|
||||
}
|
||||
|
||||
statusBackend.SetLocalPairing(true)
|
||||
defer func() {
|
||||
statusBackend.SetLocalPairing(false)
|
||||
}()
|
||||
|
||||
err := pairing.StartUpReceivingClient(statusBackend, cs, configJSON)
|
||||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
err = statusBackend.Logout()
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
|
@ -1060,6 +1088,11 @@ func InputConnectionStringForBootstrappingAnotherDevice(cs, configJSON string) s
|
|||
return makeJSONResponse(fmt.Errorf("no config given, SenderClientConfig is expected"))
|
||||
}
|
||||
|
||||
statusBackend.SetLocalPairing(true)
|
||||
defer func() {
|
||||
statusBackend.SetLocalPairing(false)
|
||||
}()
|
||||
|
||||
err := pairing.StartUpSendingClient(statusBackend, cs, configJSON)
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package pairing
|
||||
|
||||
import "github.com/status-im/status-go/multiaccounts"
|
||||
|
||||
// EventType type for event types.
|
||||
type EventType string
|
||||
|
||||
|
@ -37,3 +39,8 @@ const (
|
|||
ActionPairingInstallation
|
||||
ActionPeerDiscovery
|
||||
)
|
||||
|
||||
type AccountData struct {
|
||||
Account *multiaccounts.Account `json:"account,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ type BasePayloadReceiver struct {
|
|||
receiveCallback func()
|
||||
}
|
||||
|
||||
func NewBaseBasePayloadReceiver(e *PayloadEncryptor, um ProtobufUnmarshaller, s PayloadStorer, callback func()) *BasePayloadReceiver {
|
||||
func NewBasePayloadReceiver(e *PayloadEncryptor, um ProtobufUnmarshaller, s PayloadStorer, callback func()) *BasePayloadReceiver {
|
||||
return &BasePayloadReceiver{
|
||||
PayloadLockPayload: &PayloadLockPayload{e},
|
||||
PayloadReceived: &PayloadReceived{e},
|
||||
|
@ -63,11 +63,16 @@ func (bpr *BasePayloadReceiver) Receive(data []byte) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = bpr.storer.Store()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if bpr.receiveCallback != nil {
|
||||
bpr.receiveCallback()
|
||||
}
|
||||
|
||||
return bpr.storer.Store()
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -92,9 +97,10 @@ func NewAccountPayloadReceiver(e *PayloadEncryptor, p *AccountPayload, config *R
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return NewBaseBasePayloadReceiver(e, NewPairingPayloadMarshaller(p, l), aps,
|
||||
return NewBasePayloadReceiver(e, NewPairingPayloadMarshaller(p, l), aps,
|
||||
func() {
|
||||
signal.SendLocalPairingEvent(Event{Type: EventReceivedAccount, Action: ActionPairingAccount, Data: p.multiaccount})
|
||||
data := AccountData{Account: p.multiaccount, Password: p.password}
|
||||
signal.SendLocalPairingEvent(Event{Type: EventReceivedAccount, Action: ActionPairingAccount, Data: data})
|
||||
},
|
||||
), nil
|
||||
}
|
||||
|
@ -220,7 +226,7 @@ func NewRawMessagePayloadReceiver(accountPayload *AccountPayload, e *PayloadEncr
|
|||
e = e.Renew()
|
||||
payload := NewRawMessagesPayload()
|
||||
|
||||
return NewBaseBasePayloadReceiver(e,
|
||||
return NewBasePayloadReceiver(e,
|
||||
NewRawMessagePayloadMarshaller(payload),
|
||||
NewRawMessageStorer(backend, payload, accountPayload, config), nil)
|
||||
}
|
||||
|
@ -268,7 +274,7 @@ func NewInstallationPayloadReceiver(e *PayloadEncryptor, backend *api.GethStatus
|
|||
e = e.Renew()
|
||||
payload := NewRawMessagesPayload()
|
||||
|
||||
return NewBaseBasePayloadReceiver(e,
|
||||
return NewBasePayloadReceiver(e,
|
||||
NewRawMessagePayloadMarshaller(payload),
|
||||
NewInstallationPayloadStorer(backend, payload, deviceType), nil)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue