diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-11-21 17:13:19 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-11-21 17:13:19 +0000 |
commit | 551f6ce11e2c94772209b13e0e5c8230fc2c50d3 (patch) | |
tree | 4c057360e217cc4b5ea3951e90ef59b3b30b7bf7 /cpp/src | |
parent | Fix (diff) | |
download | ice-551f6ce11e2c94772209b13e0e5c8230fc2c50d3.tar.bz2 ice-551f6ce11e2c94772209b13e0e5c8230fc2c50d3.tar.xz ice-551f6ce11e2c94772209b13e0e5c8230fc2c50d3.zip |
Added Ice.Default.PreferSecure
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/DefaultsAndOverrides.cpp | 3 | ||||
-rw-r--r-- | cpp/src/Ice/DefaultsAndOverrides.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/PropertyNames.cpp | 3 | ||||
-rw-r--r-- | cpp/src/Ice/PropertyNames.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Proxy.cpp | 21 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.cpp | 85 | ||||
-rw-r--r-- | cpp/src/Ice/Reference.h | 15 | ||||
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.cpp | 29 | ||||
-rw-r--r-- | cpp/src/Ice/ReferenceFactory.h | 4 |
10 files changed, 132 insertions, 37 deletions
diff --git a/cpp/src/Ice/DefaultsAndOverrides.cpp b/cpp/src/Ice/DefaultsAndOverrides.cpp index 91ffcb59293..3b7e4e727a3 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.cpp +++ b/cpp/src/Ice/DefaultsAndOverrides.cpp @@ -71,4 +71,7 @@ IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& pro const_cast<int&>(defaultLocatorCacheTimeout) = properties->getPropertyAsIntWithDefault("Ice.Default.LocatorCacheTimeout", -1); + + const_cast<bool&>(defaultPreferSecure) = + properties->getPropertyAsIntWithDefault("Ice.Default.PreferSecure", 0) > 0; } diff --git a/cpp/src/Ice/DefaultsAndOverrides.h b/cpp/src/Ice/DefaultsAndOverrides.h index 0f2aa6efd5a..9a0dc4277ec 100644 --- a/cpp/src/Ice/DefaultsAndOverrides.h +++ b/cpp/src/Ice/DefaultsAndOverrides.h @@ -29,6 +29,7 @@ public: std::string defaultLocator; bool defaultCollocationOptimization; int defaultLocatorCacheTimeout; + bool defaultPreferSecure; bool overrideTimeout; Ice::Int overrideTimeoutValue; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index db34f634e92..a77a2f7bb6f 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -865,7 +865,8 @@ Ice::ObjectAdapterI::newDirectProxy(const Identity& ident, const string& facet) // Create a reference and return a proxy for this reference. // ReferencePtr ref = _instance->referenceFactory()->create( - ident, _instance->getDefaultContext(), facet, Reference::ModeTwoway, false, endpoints, 0, + ident, _instance->getDefaultContext(), facet, Reference::ModeTwoway, false, + _instance->defaultsAndOverrides()->defaultPreferSecure, endpoints, 0, _instance->defaultsAndOverrides()->defaultCollocationOptimization); return _instance->proxyFactory()->referenceToProxy(ref); @@ -878,7 +879,8 @@ Ice::ObjectAdapterI::newIndirectProxy(const Identity& ident, const string& facet // Create an indirect reference with the given adapter id. // ReferencePtr ref = _instance->referenceFactory()->create( - ident, _instance->getDefaultContext(), facet, Reference::ModeTwoway, false, id, 0, + ident, _instance->getDefaultContext(), facet, Reference::ModeTwoway, false, + _instance->defaultsAndOverrides()->defaultPreferSecure, id, 0, _locatorInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization, _instance->defaultsAndOverrides()->defaultLocatorCacheTimeout); diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index 96b8f8564b0..05418d70f0d 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -7,7 +7,7 @@ // // ********************************************************************** -// Generated by makeprops.py from file `../../config/PropertyNames.def', Fri Nov 17 10:58:20 2006 +// Generated by makeprops.py from file `../config/PropertyNames.def', Tue Nov 21 10:08:31 2006 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -25,6 +25,7 @@ const char* IceInternal::PropertyNames::IceProps[] = "Ice.Default.Locator", "Ice.Default.LocatorCacheTimeout", "Ice.Default.Package", + "Ice.Default.PreferSecure", "Ice.Default.Protocol", "Ice.Default.Router", "Ice.GC.Interval", diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index af6c054eef4..17a339b22a5 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -7,7 +7,7 @@ // // ********************************************************************** -// Generated by makeprops.py from file `../../config/PropertyNames.def', Fri Nov 17 10:58:20 2006 +// Generated by makeprops.py from file `../config/PropertyNames.def', Tue Nov 21 10:08:31 2006 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index 44636a6e387..50bac167724 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -548,6 +548,27 @@ IceProxy::Ice::Object::ice_secure(bool b) const } } +bool +IceProxy::Ice::Object::ice_isPreferSecure() const +{ + return _reference->getPreferSecure(); +} + +ObjectPrx +IceProxy::Ice::Object::ice_preferSecure(bool b) const +{ + if(b == _reference->getPreferSecure()) + { + return ObjectPrx(const_cast< ::IceProxy::Ice::Object*>(this)); + } + else + { + ObjectPrx proxy(new ::IceProxy::Ice::Object()); + proxy->setup(_reference->changePreferSecure(b)); + return proxy; + } +} + RouterPrx IceProxy::Ice::Object::ice_getRouter() const { diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 9a7aab95a3d..53307f531b8 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -450,6 +450,12 @@ IceInternal::FixedReference::getSecure() const return false; } +bool +IceInternal::FixedReference::getPreferSecure() const +{ + return false; +} + int IceInternal::FixedReference::getLocatorCacheTimeout() const { @@ -493,6 +499,12 @@ IceInternal::FixedReference::changeSecure(bool) const } ReferencePtr +IceInternal::FixedReference::changePreferSecure(bool) const +{ + throw FixedProxyException(__FILE__, __LINE__); +} + +ReferencePtr IceInternal::FixedReference::changeRouter(const RouterPrx&) const { throw FixedProxyException(__FILE__, __LINE__); @@ -736,6 +748,12 @@ IceInternal::RoutableReference::getSecure() const } bool +IceInternal::RoutableReference::getPreferSecure() const +{ + return _preferSecure; +} + +bool IceInternal::RoutableReference::getCollocationOptimization() const { return _collocationOptimization; @@ -766,6 +784,18 @@ IceInternal::RoutableReference::changeSecure(bool newSecure) const } ReferencePtr +IceInternal::RoutableReference::changePreferSecure(bool newPreferSecure) const +{ + if(newPreferSecure == _preferSecure) + { + return RoutableReferencePtr(const_cast<RoutableReference*>(this)); + } + RoutableReferencePtr r = RoutableReferencePtr::dynamicCast(getInstance()->referenceFactory()->copy(this)); + r->_preferSecure = newPreferSecure; + return r; +} + +ReferencePtr IceInternal::RoutableReference::changeRouter(const RouterPrx& newRouter) const { RouterInfoPtr newRouterInfo = getInstance()->routerManager()->get(newRouter); @@ -874,6 +904,10 @@ IceInternal::RoutableReference::operator==(const Reference& r) const { return false; } + if(_preferSecure != rhs->_preferSecure) + { + return false; + } if(_collocationOptimization != rhs->_collocationOptimization) { return false; @@ -930,6 +964,14 @@ IceInternal::RoutableReference::operator<(const Reference& r) const { return false; } + else if(!_preferSecure && rhs->_preferSecure) + { + return true; + } + else if(rhs->_preferSecure < _preferSecure) + { + return false; + } if(!_collocationOptimization && rhs->_collocationOptimization) { return true; @@ -1007,10 +1049,11 @@ IceInternal::RoutableReference::operator<(const Reference& r) const IceInternal::RoutableReference::RoutableReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, const SharedContextPtr& ctx, const string& fs, - Mode md, bool sec, const RouterInfoPtr& rtrInfo, + Mode md, bool sec, bool prefSec, const RouterInfoPtr& rtrInfo, bool collocationOpt) : Reference(inst, com, ident, ctx, fs, md), _secure(sec), + _preferSecure(prefSec), _routerInfo(rtrInfo), _collocationOptimization(collocationOpt), _cacheConnection(true), @@ -1025,6 +1068,7 @@ IceInternal::RoutableReference::RoutableReference(const InstancePtr& inst, const IceInternal::RoutableReference::RoutableReference(const RoutableReference& r) : Reference(r), _secure(r._secure), + _preferSecure(r._preferSecure), _routerInfo(r._routerInfo), _collocationOptimization(r._collocationOptimization), _cacheConnection(r._cacheConnection), @@ -1100,12 +1144,12 @@ IceInternal::RoutableReference::createConnection(const vector<EndpointIPtr>& all break; } } - + // // If a secure connection is requested or secure overrides is set, - // remove all non-secure endpoints. Otherwise make non-secure - // endpoints preferred over secure endpoints by partitioning the - // endpoint vector, so that non-secure endpoints come first. + // remove all non-secure endpoints. Otherwise if preferSecure is set + // make secure endpoints prefered. By default make non-secure + // endpoints preferred over secure endpoints. // DefaultsAndOverridesPtr overrides = getInstance()->defaultsAndOverrides(); if(overrides->overrideSecure ? overrides->overrideSecureValue : getSecure()) @@ -1113,6 +1157,15 @@ IceInternal::RoutableReference::createConnection(const vector<EndpointIPtr>& all endpoints.erase(remove_if(endpoints.begin(), endpoints.end(), not1(Ice::constMemFun(&EndpointI::secure))), endpoints.end()); } + else if(getPreferSecure()) + { + // + // We must use stable_partition() instead of just simply + // partition(), because otherwise some STL implementations + // order our now randomized endpoints. + // + stable_partition(endpoints.begin(), endpoints.end(), Ice::constMemFun(&EndpointI::secure)); + } else { // @@ -1196,10 +1249,10 @@ void IceInternal::incRef(IceInternal::DirectReference* p) { p->__incRef(); } void IceInternal::decRef(IceInternal::DirectReference* p) { p->__decRef(); } IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const CommunicatorPtr& com, - const Identity& ident, const SharedContextPtr& ctx, const string& fs, Mode md, - bool sec, const vector<EndpointIPtr>& endpts, + const Identity& ident, const SharedContextPtr& ctx, const string& fs, + Mode md, bool sec, bool prefSec, const vector<EndpointIPtr>& endpts, const RouterInfoPtr& rtrInfo, bool collocationOpt) : - RoutableReference(inst, com, ident, ctx, fs, md, sec, rtrInfo, collocationOpt), + RoutableReference(inst, com, ident, ctx, fs, md, sec, prefSec, rtrInfo, collocationOpt), _endpoints(endpts) { } @@ -1290,8 +1343,8 @@ IceInternal::DirectReference::changeAdapterId(const string& newAdapterId) const LocatorInfoPtr locatorInfo = getInstance()->locatorManager()->get(getInstance()->referenceFactory()->getDefaultLocator()); return getInstance()->referenceFactory()->create(getIdentity(), getContext(), getFacet(), getMode(), - getSecure(), newAdapterId, getRouterInfo(), locatorInfo, - getCollocationOptimization(), + getSecure(), getPreferSecure(), newAdapterId, getRouterInfo(), + locatorInfo, getCollocationOptimization(), getLocatorCacheTimeout()); } else @@ -1448,11 +1501,11 @@ void IceInternal::incRef(IceInternal::IndirectReference* p) { p->__incRef(); } void IceInternal::decRef(IceInternal::IndirectReference* p) { p->__decRef(); } IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const CommunicatorPtr& com, - const Identity& ident, const SharedContextPtr& ctx, const string& fs, Mode md, - bool sec, const string& adptid, const RouterInfoPtr& rtrInfo, - const LocatorInfoPtr& locInfo, bool collocationOpt, - int locatorCacheTimeout) : - RoutableReference(inst, com, ident, ctx, fs, md, sec, rtrInfo, collocationOpt), + const Identity& ident, const SharedContextPtr& ctx, const string& fs, + Mode md, bool sec, bool prefSec, const string& adptid, + const RouterInfoPtr& rtrInfo, const LocatorInfoPtr& locInfo, + bool collocationOpt, int locatorCacheTimeout) : + RoutableReference(inst, com, ident, ctx, fs, md, sec, prefSec, rtrInfo, collocationOpt), _adapterId(adptid), _locatorInfo(locInfo), _locatorCacheTimeout(locatorCacheTimeout) @@ -1514,7 +1567,7 @@ IceInternal::IndirectReference::changeEndpoints(const vector<EndpointIPtr>& newE if(!newEndpoints.empty()) { return getInstance()->referenceFactory()->create(getIdentity(), getContext(), getFacet(), getMode(), - getSecure(), newEndpoints, getRouterInfo(), + getSecure(), getPreferSecure(), newEndpoints, getRouterInfo(), getCollocationOptimization()); } else diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index a483d612015..9ae58fefbf3 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -65,6 +65,7 @@ public: virtual Type getType() const = 0; virtual bool getSecure() const = 0; + virtual bool getPreferSecure() const = 0; virtual std::string getAdapterId() const = 0; virtual std::vector<EndpointIPtr> getEndpoints() const = 0; virtual bool getCollocationOptimization() const = 0; @@ -83,6 +84,7 @@ public: ReferencePtr changeFacet(const std::string&) const; virtual ReferencePtr changeSecure(bool) const = 0; + virtual ReferencePtr changePreferSecure(bool) const = 0; virtual ReferencePtr changeRouter(const Ice::RouterPrx&) const = 0; virtual ReferencePtr changeLocator(const Ice::LocatorPrx&) const = 0; virtual ReferencePtr changeCompress(bool) const = 0; @@ -150,6 +152,7 @@ public: virtual Type getType() const; virtual bool getSecure() const; + virtual bool getPreferSecure() const; virtual std::string getAdapterId() const; virtual std::vector<EndpointIPtr> getEndpoints() const; virtual bool getCollocationOptimization() const; @@ -158,6 +161,7 @@ public: virtual Ice::EndpointSelectionType getEndpointSelection() const; virtual ReferencePtr changeSecure(bool) const; + virtual ReferencePtr changePreferSecure(bool) const; virtual ReferencePtr changeRouter(const Ice::RouterPrx&) const; virtual ReferencePtr changeLocator(const Ice::LocatorPrx&) const; virtual ReferencePtr changeCollocationOptimization(bool) const; @@ -200,11 +204,13 @@ public: std::vector<EndpointIPtr> getRoutedEndpoints() const; virtual bool getSecure() const; + virtual bool getPreferSecure() const; virtual bool getCollocationOptimization() const; virtual bool getCacheConnection() const; virtual Ice::EndpointSelectionType getEndpointSelection() const; virtual ReferencePtr changeSecure(bool) const; + virtual ReferencePtr changePreferSecure(bool) const; virtual ReferencePtr changeRouter(const Ice::RouterPrx&) const; virtual ReferencePtr changeCollocationOptimization(bool) const; virtual ReferencePtr changeCompress(bool) const; @@ -226,7 +232,7 @@ public: protected: RoutableReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const SharedContextPtr&, - const std::string&, Mode, bool, const RouterInfoPtr&, bool); + const std::string&, Mode, bool, bool, const RouterInfoPtr&, bool); RoutableReference(const RoutableReference&); Ice::ConnectionIPtr createConnection(const std::vector<EndpointIPtr>&, bool&) const; @@ -235,6 +241,7 @@ protected: private: bool _secure; + bool _preferSecure; RouterInfoPtr _routerInfo; // Null if no router is used. bool _collocationOptimization; bool _cacheConnection; @@ -252,7 +259,7 @@ class DirectReference : public RoutableReference public: DirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const SharedContextPtr&, - const std::string&, Mode, bool, const std::vector<EndpointIPtr>&, const RouterInfoPtr&, bool); + const std::string&, Mode, bool, bool, const std::vector<EndpointIPtr>&, const RouterInfoPtr&, bool); virtual Type getType() const; virtual int getLocatorCacheTimeout() const; @@ -291,8 +298,8 @@ class IndirectReference : public RoutableReference public: IndirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const SharedContextPtr&, - const std::string&, Mode, bool, const std::string&, const RouterInfoPtr&, const LocatorInfoPtr&, - bool, int); + const std::string&, Mode, bool, bool, const std::string&, const RouterInfoPtr&, + const LocatorInfoPtr&, bool, int); virtual LocatorInfoPtr getLocatorInfo() const { return _locatorInfo; } diff --git a/cpp/src/Ice/ReferenceFactory.cpp b/cpp/src/Ice/ReferenceFactory.cpp index 6b720ec6321..39770b2de32 100644 --- a/cpp/src/Ice/ReferenceFactory.cpp +++ b/cpp/src/Ice/ReferenceFactory.cpp @@ -53,6 +53,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, const string& facet, Reference::Mode mode, bool secure, + bool preferSecure, const vector<EndpointIPtr>& endpoints, const RouterInfoPtr& routerInfo, bool collocationOptimization) @@ -72,7 +73,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // // Create new reference // - return new DirectReference(_instance, _communicator, ident, context, facet, mode, secure, + return new DirectReference(_instance, _communicator, ident, context, facet, mode, secure, preferSecure, endpoints, routerInfo, collocationOptimization); } @@ -82,6 +83,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, const string& facet, Reference::Mode mode, bool secure, + bool preferSecure, const string& adapterId, const RouterInfoPtr& routerInfo, const LocatorInfoPtr& locatorInfo, @@ -103,7 +105,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // // Create new reference // - return new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure, + return new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure, preferSecure, adapterId, routerInfo, locatorInfo, collocationOptimization, locatorCacheTimeout); } @@ -417,7 +419,8 @@ IceInternal::ReferenceFactory::create(const string& str) if(beg == string::npos) { - return create(ident, _instance->getDefaultContext(), facet, mode, secure, "", routerInfo, + return create(ident, _instance->getDefaultContext(), facet, mode, secure, + _instance->defaultsAndOverrides()->defaultPreferSecure, "", routerInfo, locatorInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization, _instance->defaultsAndOverrides()->defaultLocatorCacheTimeout); } @@ -471,8 +474,9 @@ IceInternal::ReferenceFactory::create(const string& str) } } - return create(ident, _instance->getDefaultContext(), facet, mode, secure, endpoints, - routerInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization); + return create(ident, _instance->getDefaultContext(), facet, mode, secure, + _instance->defaultsAndOverrides()->defaultPreferSecure, endpoints, routerInfo, + _instance->defaultsAndOverrides()->defaultCollocationOptimization); break; } case '@': @@ -522,8 +526,9 @@ IceInternal::ReferenceFactory::create(const string& str) adapter = tmpAdapter; } - return create(ident, _instance->getDefaultContext(), facet, mode, secure, adapter, - routerInfo, locatorInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization, + return create(ident, _instance->getDefaultContext(), facet, mode, secure, + _instance->defaultsAndOverrides()->defaultPreferSecure, adapter, routerInfo, locatorInfo, + _instance->defaultsAndOverrides()->defaultCollocationOptimization, _instance->defaultsAndOverrides()->defaultLocatorCacheTimeout); break; } @@ -594,14 +599,16 @@ IceInternal::ReferenceFactory::create(const Identity& ident, BasicStream* s) EndpointIPtr endpoint = _instance->endpointFactoryManager()->read(s); endpoints.push_back(endpoint); } - return create(ident, _instance->getDefaultContext(), facet, mode, secure, endpoints, - routerInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization); + return create(ident, _instance->getDefaultContext(), facet, mode, secure, + _instance->defaultsAndOverrides()->defaultPreferSecure, endpoints, routerInfo, + _instance->defaultsAndOverrides()->defaultCollocationOptimization); } else { s->read(adapterId); - return create(ident, _instance->getDefaultContext(), facet, mode, secure, adapterId, - routerInfo, locatorInfo, _instance->defaultsAndOverrides()->defaultCollocationOptimization, + return create(ident, _instance->getDefaultContext(), facet, mode, secure, + _instance->defaultsAndOverrides()->defaultPreferSecure, adapterId, routerInfo, locatorInfo, + _instance->defaultsAndOverrides()->defaultCollocationOptimization, _instance->defaultsAndOverrides()->defaultLocatorCacheTimeout); } } diff --git a/cpp/src/Ice/ReferenceFactory.h b/cpp/src/Ice/ReferenceFactory.h index 49f6c04a470..f012d8e284d 100644 --- a/cpp/src/Ice/ReferenceFactory.h +++ b/cpp/src/Ice/ReferenceFactory.h @@ -32,13 +32,13 @@ public: // Create a direct reference. // ReferencePtr create(const ::Ice::Identity&, const SharedContextPtr&, const ::std::string&, - Reference::Mode, bool, const ::std::vector<EndpointIPtr>&, + Reference::Mode, bool, bool, const ::std::vector<EndpointIPtr>&, const RouterInfoPtr&, bool); // // Create an indirect reference. // ReferencePtr create(const ::Ice::Identity&, const SharedContextPtr&, const ::std::string&, - Reference::Mode, bool, const ::std::string&, + Reference::Mode, bool, bool, const ::std::string&, const RouterInfoPtr&, const LocatorInfoPtr&, bool, int); // // Create a fixed reference. |