Do nothing when the same proxy is set.

GitOrigin-RevId: 69611358667c598a1ce009944cbe21bbdad4b3ad
This commit is contained in:
levlam 2018-02-20 00:44:52 +03:00
parent 20ffe41d80
commit d3c980e5d3
2 changed files with 36 additions and 23 deletions

View File

@ -142,30 +142,30 @@ class PingActor : public Actor {
} // namespace detail
template <class T>
void parse(Proxy &proxy, T &parser) {
void Proxy::parse(T &parser) {
using td::parse;
parse(proxy.type_, parser);
if (proxy.type() == Proxy::Type::Socks5) {
parse(proxy.server_, parser);
parse(proxy.port_, parser);
parse(proxy.user_, parser);
parse(proxy.password_, parser);
parse(type_, parser);
if (type_ == Proxy::Type::Socks5) {
parse(server_, parser);
parse(port_, parser);
parse(user_, parser);
parse(password_, parser);
} else {
CHECK(proxy.type() == Proxy::Type::None);
CHECK(type_ == Proxy::Type::None);
}
}
template <class T>
void store(const Proxy &proxy, T &storer) {
void Proxy::store(T &storer) const {
using td::store;
store(proxy.type_, storer);
if (proxy.type() == Proxy::Type::Socks5) {
store(proxy.server_, storer);
store(proxy.port_, storer);
store(proxy.user_, storer);
store(proxy.password_, storer);
store(type_, storer);
if (type_ == Proxy::Type::Socks5) {
store(server_, storer);
store(port_, storer);
store(user_, storer);
store(password_, storer);
} else {
CHECK(proxy.type() == Proxy::Type::None);
CHECK(type_ == Proxy::Type::None);
}
}
@ -203,6 +203,10 @@ void ConnectionCreator::set_proxy(Proxy proxy) {
}
void ConnectionCreator::set_proxy_impl(Proxy proxy, bool from_db) {
if (proxy_ == proxy) {
return;
}
proxy_ = std::move(proxy);
send_closure(G()->state_manager(), &StateManager::on_proxy, proxy_.type() != Proxy::Type::None);

View File

@ -103,20 +103,29 @@ class Proxy {
return type_;
}
template <class T>
void parse(T &parser);
template <class T>
void store(T &storer) const;
private:
Type type_{Type::None};
string server_;
int32 port_;
int32 port_ = 0;
string user_;
string password_;
template <class T>
friend void parse(Proxy &proxy, T &parser);
template <class T>
friend void store(const Proxy &proxy, T &store);
};
inline bool operator==(const Proxy &lhs, const Proxy &rhs) {
return lhs.type() == rhs.type() && lhs.server() == rhs.server() && lhs.port() == rhs.port() &&
lhs.user() == rhs.user() && lhs.password() == rhs.password();
}
inline bool operator!=(const Proxy &lhs, const Proxy &rhs) {
return !(lhs == rhs);
}
class ConnectionCreator : public Actor {
public:
explicit ConnectionCreator(ActorShared<> parent);