diff --git a/p2p/ChordTopology.cxx b/p2p/ChordTopology.cxx index 775db5f3f..af91ed83b 100644 --- a/p2p/ChordTopology.cxx +++ b/p2p/ChordTopology.cxx @@ -19,8 +19,10 @@ using namespace p2p; #define RESIPROCATE_SUBSYSTEM P2PSubsystem::P2P -ChordTopology::ChordTopology(Profile& config, Dispatcher& dispatcher, Transporter& transporter) : - TopologyAPI(config, dispatcher, transporter), mJoined(false) +ChordTopology::ChordTopology(Profile& config, + Dispatcher& dispatcher, + Transporter& transporter) : + TopologyAPI(config, dispatcher, transporter), mJoined(false) { } @@ -189,6 +191,13 @@ ChordTopology::consume(LeaveReq& msg) } +void +ChordTopology::consume(ConnectReq& msg) +{ + DebugLog(<< "received CONNECT Req from: " << msg.getResponseNodeId()); +} + + void ChordTopology::consume(ConnectAns& msg) { @@ -244,6 +253,9 @@ ChordTopology::findNextHop( const NodeId& node ) // return the next pointer and increment around slowly assert( mNextTable.size() > 0 ); DebugLog(<< "findNextHop returning: " << mNextTable[0]); + + // TODO - deal with case wehre there is no next + return mNextTable[0]; } @@ -302,18 +314,22 @@ ChordTopology::getReplicationSet( const ResourceId& resource ) bool ChordTopology::isResponsible( const NodeId& node ) const { - // If it is us, then we are responsible - if(node == mProfile.nodeId()) - { - return true; - } - // for now we are going to assume that if the prev table is empty, then we have a // a new ring being formed and we are responsible for this request. We need to consider // the case where we are a node trying to join a stable ring, and the "join" process // has not completed yet - but we receive a message for another node. - if (mPrevTable.size() == 0) return true; - + if (mPrevTable.size() == 0) + { + if ( mProfile.isBootstrap() ) + { + return true; // only thing in the ring so responsible for everything + } + else + { + return false; // have not joined ring yet so responsible for nothing + } + } + if ( (mPrevTable[0] < node) && (node <= mProfile.nodeId()) ) { return true; diff --git a/p2p/ChordTopology.hxx b/p2p/ChordTopology.hxx index 815ccb959..8b1d395c2 100644 --- a/p2p/ChordTopology.hxx +++ b/p2p/ChordTopology.hxx @@ -20,7 +20,9 @@ class Dispatcher; class ChordTopology : public TopologyAPI { public: - ChordTopology(Profile& config, Dispatcher& dispatcher, Transporter& transporter); + ChordTopology(Profile& config, + Dispatcher& dispatcher, + Transporter& transporter); virtual ~ChordTopology(); virtual void joinOverlay(); @@ -41,6 +43,7 @@ class ChordTopology : public TopologyAPI // deal with responses virtual void consume(ConnectAns& msg); + virtual void consume(ConnectReq& msg); virtual void consume(JoinAns& msg); virtual void consume(UpdateAns& msg); virtual void consume(LeaveAns& msg); diff --git a/p2p/Profile.hxx b/p2p/Profile.hxx index d6c37b078..f5212bf9d 100644 --- a/p2p/Profile.hxx +++ b/p2p/Profile.hxx @@ -23,36 +23,40 @@ class Profile { public: Profile() : mNodeId(), mNumInitialFingers(8) {} - virtual ~Profile() {;} - - virtual const X509 *getCertificate() { return 0; } - virtual const EVP_PKEY *getPrivateKey() { return 0; } - - virtual resip::Data& signatureDigest() { return mSignatureDigest; } - virtual const resip::Data& signatureDigest() const { return mSignatureDigest; } - - virtual resip::Data& overlayName() { return mOverlayName; } - virtual const resip::Data& overlayName() const { return mOverlayName; } - - virtual NodeId& nodeId() { return mNodeId; } - virtual const NodeId nodeId() const { return mNodeId; } - - virtual UserName& userName() { return mUserName; } - virtual const UserName& userName() const { return mUserName; } - - virtual unsigned int& numInitialFingers() { return mNumInitialFingers; } - virtual const unsigned int numInitialFingers() const { return mNumInitialFingers; } - - virtual std::vector& bootstrapNodes() { return mBootstrapNodes; } - virtual const std::vector& bootstrapNodes() const { return mBootstrapNodes; } + virtual ~Profile() {;} -private: - resip::Data mOverlayName; - resip::Data mSignatureDigest; - NodeId mNodeId; - UserName mUserName; - unsigned int mNumInitialFingers; - std::vector mBootstrapNodes; + virtual const X509 *getCertificate() { return 0; } + virtual const EVP_PKEY *getPrivateKey() { return 0; } + + virtual resip::Data& signatureDigest() { return mSignatureDigest; } + virtual const resip::Data& signatureDigest() const { return mSignatureDigest; } + + virtual resip::Data& overlayName() { return mOverlayName; } + virtual const resip::Data& overlayName() const { return mOverlayName; } + + virtual bool& isBootstrap() { return mBootstrap; } + virtual const bool isBootstrap() const { return mBootstrap; } + + virtual NodeId& nodeId() { return mNodeId; } + virtual const NodeId nodeId() const { return mNodeId; } + + virtual UserName& userName() { return mUserName; } + virtual const UserName& userName() const { return mUserName; } + + virtual unsigned int& numInitialFingers() { return mNumInitialFingers; } + virtual const unsigned int numInitialFingers() const { return mNumInitialFingers; } + + virtual std::vector& bootstrapNodes() { return mBootstrapNodes; } + virtual const std::vector& bootstrapNodes() const { return mBootstrapNodes; } + + private: + resip::Data mOverlayName; + resip::Data mSignatureDigest; + NodeId mNodeId; + UserName mUserName; + unsigned int mNumInitialFingers; + std::vector mBootstrapNodes; + bool mBootstrap; }; } diff --git a/p2p/TopologyAPI.hxx b/p2p/TopologyAPI.hxx index 40d6ceea0..6793941ef 100644 --- a/p2p/TopologyAPI.hxx +++ b/p2p/TopologyAPI.hxx @@ -46,6 +46,7 @@ class TopologyAPI : public EventConsumer // deal with responses virtual void consume(ConnectAns& msg)=0; + virtual void consume(ConnectReq& msg)=0; virtual void consume(JoinAns& msg)=0; virtual void consume(UpdateAns& msg)=0; virtual void consume(LeaveAns& msg)=0;