diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-03-09 16:08:29 -0800 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-03-10 00:44:55 +0000 |
commit | 8bf475745726c1fd672eed2b34c52cf5bfad58e0 (patch) | |
tree | ccf28b2693b955d65f5a01565624557a398af680 | |
parent | cd7a3a2d4bc87d5c39648f1ebba0b5cfa63f547f (diff) | |
download | libweave-8bf475745726c1fd672eed2b34c52cf5bfad58e0.tar.gz |
Fail setup/start if device already registered
Previously device didn't check condition until wifi is switched.
Bug we can detect the issue and reply to client in the same request.
BUG: 27432528
Change-Id: I6564c47fba86671dbd59dc0ff70cfba3a25d60dc
Reviewed-on: https://weave-review.googlesource.com/2890
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
-rw-r--r-- | examples/daemon/common/daemon.h | 6 | ||||
-rw-r--r-- | src/device_registration_info.h | 5 | ||||
-rw-r--r-- | src/privet/cloud_delegate.cc | 8 | ||||
-rw-r--r-- | src/privet/privet_handler.cc | 3 |
4 files changed, 15 insertions, 7 deletions
diff --git a/examples/daemon/common/daemon.h b/examples/daemon/common/daemon.h index 22591a2..23a08d2 100644 --- a/examples/daemon/common/daemon.h +++ b/examples/daemon/common/daemon.h @@ -114,10 +114,8 @@ class Daemon { private: static void OnRegisterDeviceDone(weave::Device* device, weave::ErrorPtr error) { - if (error) - LOG(ERROR) << "Fail to register device: " << error->GetMessage(); - else - LOG(INFO) << "Device registered: " << device->GetSettings().cloud_id; + CHECK(!error) << "Registration failed device: " << error->GetMessage(); + LOG(INFO) << "Device registered: " << device->GetSettings().cloud_id; } std::unique_ptr<weave::examples::EventTaskRunner> task_runner_; diff --git a/src/device_registration_info.h b/src/device_registration_info.h index a488bae..db08ef9 100644 --- a/src/device_registration_info.h +++ b/src/device_registration_info.h @@ -115,6 +115,9 @@ class DeviceRegistrationInfo : public NotificationDelegate, GcdState GetGcdState() const { return gcd_state_; } + // Checks whether we have credentials generated during registration. + bool HaveRegistrationCredentials() const; + private: friend class DeviceRegistrationInfoTest; @@ -124,8 +127,6 @@ class DeviceRegistrationInfo : public NotificationDelegate, return weak_factory_.GetWeakPtr(); } - // Checks whether we have credentials generated during registration. - bool HaveRegistrationCredentials() const; // Calls HaveRegistrationCredentials() and logs an error if no credentials // are available. bool VerifyRegistrationCredentials(ErrorPtr* error) const; diff --git a/src/privet/cloud_delegate.cc b/src/privet/cloud_delegate.cc index ef9c59e..d7e9bef 100644 --- a/src/privet/cloud_delegate.cc +++ b/src/privet/cloud_delegate.cc @@ -26,6 +26,8 @@ namespace privet { namespace { +const char kErrorAlreayRegistered[] = "already_registered"; + const BackoffEntry::Policy register_backoff_policy = {0, 1000, 2.0, 0.2, 5000, -1, false}; @@ -103,6 +105,12 @@ class CloudDelegateImpl : public CloudDelegate { bool Setup(const RegistrationData& registration_data, ErrorPtr* error) override { VLOG(1) << "GCD Setup started. "; + if (device_->HaveRegistrationCredentials()) { + Error::AddTo(error, FROM_HERE, kErrorAlreayRegistered, + "Unable to register already registered device"); + return false; + } + // Set (or reset) the retry counter, since we are starting a new // registration process. registation_retry_count_ = kMaxDeviceRegistrationRetries; diff --git a/src/privet/privet_handler.cc b/src/privet/privet_handler.cc index 97cacc5..41936b6 100644 --- a/src/privet/privet_handler.cc +++ b/src/privet/privet_handler.cc @@ -837,8 +837,9 @@ void PrivetHandler::HandleSetupStart(const base::DictionaryValue& input, return ReturnError(*error, callback); if (!registration_data.ticket_id.empty() && - !cloud_->Setup(registration_data, &error)) + !cloud_->Setup(registration_data, &error)) { return ReturnError(*error, callback); + } ReplyWithSetupStatus(callback); } |