Local Pairing update for `StopNode` (#3536)

This commit is contained in:
Igor Sirotin 2023-06-01 08:33:57 +03:00 committed by GitHub
parent 790efc16aa
commit a7df4ed388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 11 deletions

View File

@ -1 +1 @@
0.153.1 0.154.0

View File

@ -85,7 +85,7 @@ type GethStatusBackend struct {
selectedAccountKeyID string selectedAccountKeyID string
log log.Logger log log.Logger
allowAllRPC bool // used only for tests, disables api method restrictions allowAllRPC bool // used only for tests, disables api method restrictions
localPairing bool // used to disable login/logout signalling
} }
// NewGethStatusBackend create a new GethStatusBackend instance // NewGethStatusBackend create a new GethStatusBackend instance
@ -109,6 +109,7 @@ func (b *GethStatusBackend) initialize() {
b.personalAPI = personalAPI b.personalAPI = personalAPI
b.statusNode.SetMultiaccountsDB(b.multiaccountsDB) b.statusNode.SetMultiaccountsDB(b.multiaccountsDB)
b.log = log.New("package", "status-go/api.GethStatusBackend") b.log = log.New("package", "status-go/api.GethStatusBackend")
b.localPairing = false
} }
// StatusNode returns reference to node manager // StatusNode returns reference to node manager
@ -395,7 +396,9 @@ func (b *GethStatusBackend) StartNodeWithKey(acc multiaccounts.Account, password
// Stop node for clean up // Stop node for clean up
_ = b.StopNode() _ = b.StopNode()
} }
signal.SendLoggedIn(err) if !b.localPairing {
signal.SendLoggedIn(err)
}
return err return err
} }
@ -512,7 +515,9 @@ func (b *GethStatusBackend) StartNodeWithAccount(acc multiaccounts.Account, pass
// Stop node for clean up // Stop node for clean up
_ = b.StopNode() _ = b.StopNode()
} }
signal.SendLoggedIn(err) if !b.localPairing {
signal.SendLoggedIn(err)
}
return err return err
} }
@ -1241,7 +1246,9 @@ func (b *GethStatusBackend) stopNode() error {
if b.statusNode == nil || !b.IsNodeRunning() { if b.statusNode == nil || !b.IsNodeRunning() {
return nil return nil
} }
defer signal.SendNodeStopped() if !b.localPairing {
defer signal.SendNodeStopped()
}
return b.statusNode.Stop() return b.statusNode.Stop()
} }
@ -1813,3 +1820,7 @@ func (b *GethStatusBackend) SwitchFleet(fleet string, conf *params.NodeConfig) e
return nil return nil
} }
func (b *GethStatusBackend) SetLocalPairing(value bool) {
b.localPairing = value
}

View File

@ -1007,10 +1007,22 @@ func GetConnectionStringForBeingBootstrapped(configJSON string) string {
if configJSON == "" { if configJSON == "" {
return makeJSONResponse(fmt.Errorf("no config given, PayloadSourceConfig is expected")) return makeJSONResponse(fmt.Errorf("no config given, PayloadSourceConfig is expected"))
} }
statusBackend.SetLocalPairing(true)
defer func() {
statusBackend.SetLocalPairing(false)
}()
cs, err := pairing.StartUpReceiverServer(statusBackend, configJSON) cs, err := pairing.StartUpReceiverServer(statusBackend, configJSON)
if err != nil { if err != nil {
return makeJSONResponse(err) return makeJSONResponse(err)
} }
err = statusBackend.Logout()
if err != nil {
return makeJSONResponse(err)
}
return cs return cs
} }
@ -1024,6 +1036,12 @@ func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string
if configJSON == "" { if configJSON == "" {
return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected")) return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected"))
} }
statusBackend.SetLocalPairing(true)
defer func() {
statusBackend.SetLocalPairing(false)
}()
cs, err := pairing.StartUpSenderServer(statusBackend, configJSON) cs, err := pairing.StartUpSenderServer(statusBackend, configJSON)
if err != nil { if err != nil {
return makeJSONResponse(err) return makeJSONResponse(err)
@ -1044,7 +1062,17 @@ func InputConnectionStringForBootstrapping(cs, configJSON string) string {
return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected")) return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected"))
} }
statusBackend.SetLocalPairing(true)
defer func() {
statusBackend.SetLocalPairing(false)
}()
err := pairing.StartUpReceivingClient(statusBackend, cs, configJSON) err := pairing.StartUpReceivingClient(statusBackend, cs, configJSON)
if err != nil {
return makeJSONResponse(err)
}
err = statusBackend.Logout()
return makeJSONResponse(err) return makeJSONResponse(err)
} }
@ -1060,6 +1088,11 @@ func InputConnectionStringForBootstrappingAnotherDevice(cs, configJSON string) s
return makeJSONResponse(fmt.Errorf("no config given, SenderClientConfig is expected")) return makeJSONResponse(fmt.Errorf("no config given, SenderClientConfig is expected"))
} }
statusBackend.SetLocalPairing(true)
defer func() {
statusBackend.SetLocalPairing(false)
}()
err := pairing.StartUpSendingClient(statusBackend, cs, configJSON) err := pairing.StartUpSendingClient(statusBackend, cs, configJSON)
return makeJSONResponse(err) return makeJSONResponse(err)
} }

View File

@ -1,5 +1,7 @@
package pairing package pairing
import "github.com/status-im/status-go/multiaccounts"
// EventType type for event types. // EventType type for event types.
type EventType string type EventType string
@ -37,3 +39,8 @@ const (
ActionPairingInstallation ActionPairingInstallation
ActionPeerDiscovery ActionPeerDiscovery
) )
type AccountData struct {
Account *multiaccounts.Account `json:"account,omitempty"`
Password string `json:"password,omitempty"`
}

View File

@ -40,7 +40,7 @@ type BasePayloadReceiver struct {
receiveCallback func() 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{ return &BasePayloadReceiver{
PayloadLockPayload: &PayloadLockPayload{e}, PayloadLockPayload: &PayloadLockPayload{e},
PayloadReceived: &PayloadReceived{e}, PayloadReceived: &PayloadReceived{e},
@ -63,11 +63,16 @@ func (bpr *BasePayloadReceiver) Receive(data []byte) error {
return err return err
} }
err = bpr.storer.Store()
if err != nil {
return err
}
if bpr.receiveCallback != nil { if bpr.receiveCallback != nil {
bpr.receiveCallback() bpr.receiveCallback()
} }
return bpr.storer.Store() return nil
} }
/* /*
@ -92,9 +97,10 @@ func NewAccountPayloadReceiver(e *PayloadEncryptor, p *AccountPayload, config *R
return nil, err return nil, err
} }
return NewBaseBasePayloadReceiver(e, NewPairingPayloadMarshaller(p, l), aps, return NewBasePayloadReceiver(e, NewPairingPayloadMarshaller(p, l), aps,
func() { 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 ), nil
} }
@ -220,7 +226,7 @@ func NewRawMessagePayloadReceiver(accountPayload *AccountPayload, e *PayloadEncr
e = e.Renew() e = e.Renew()
payload := NewRawMessagesPayload() payload := NewRawMessagesPayload()
return NewBaseBasePayloadReceiver(e, return NewBasePayloadReceiver(e,
NewRawMessagePayloadMarshaller(payload), NewRawMessagePayloadMarshaller(payload),
NewRawMessageStorer(backend, payload, accountPayload, config), nil) NewRawMessageStorer(backend, payload, accountPayload, config), nil)
} }
@ -268,7 +274,7 @@ func NewInstallationPayloadReceiver(e *PayloadEncryptor, backend *api.GethStatus
e = e.Renew() e = e.Renew()
payload := NewRawMessagesPayload() payload := NewRawMessagesPayload()
return NewBaseBasePayloadReceiver(e, return NewBasePayloadReceiver(e,
NewRawMessagePayloadMarshaller(payload), NewRawMessagePayloadMarshaller(payload),
NewInstallationPayloadStorer(backend, payload, deviceType), nil) NewInstallationPayloadStorer(backend, payload, deviceType), nil)
} }