Skip to content
Browse files

Added condition to check whether current keys server needs to stop be…

…ing a key server and fetch the new secret key from the new key server (https://issues.jboss.org/browse/JGRP-1376)
  • Loading branch information...
1 parent 7487616 commit 64f1f0361d607fb77671649db3a217888bc9d20d @belaban committed Oct 18, 2011
View
49 src/org/jgroups/protocols/ENCRYPT.java
@@ -419,15 +419,13 @@ public Object up(Event evt) {
case Event.VIEW_CHANGE:
View view=(View)evt.getArg();
if(log.isInfoEnabled())
- log.info("handling view-change up: " + view);
+ log.info("new view: " + view);
if(!suppliedKey) {
handleViewChange(view, false);
}
break;
case Event.TMP_VIEW:
view=(View)evt.getArg();
- if(log.isInfoEnabled())
- log.info("handling tmp-view up: " + view);
if(!suppliedKey) {
// if a tmp_view then we are trying to become coordinator so
// make us keyserver
@@ -460,7 +458,7 @@ private synchronized void handleViewChange(View view, boolean makeServer) {
// if view is a bit broken set me as keyserver
List<Address> members = view.getMembers();
if (members == null || members.isEmpty() || members.get(0) == null) {
- becomeKeyServer(local_addr);
+ becomeKeyServer(local_addr, false);
return;
}
// otherwise get keyserver from view controller
@@ -469,10 +467,10 @@ private synchronized void handleViewChange(View view, boolean makeServer) {
//I am new keyserver - either first member of group or old key server is no more and
// I have been voted new controller
if(makeServer || (tmpKeyServer.equals(local_addr) && (keyServerAddr == null || (!tmpKeyServer.equals(keyServerAddr))))) {
- becomeKeyServer(tmpKeyServer);
+ becomeKeyServer(tmpKeyServer, makeServer);
// a new keyserver has been set and it is not me
}
- else if(keyServerAddr == null || (!tmpKeyServer.equals(keyServerAddr))) {
+ else if(keyServerAddr == null || (!tmpKeyServer.equals(keyServerAddr)) || (keyServer && !tmpKeyServer.equals(local_addr))) {
handleNewKeyServer(tmpKeyServer);
}
else {
@@ -487,11 +485,11 @@ else if(keyServerAddr == null || (!tmpKeyServer.equals(keyServerAddr))) {
*
* @param tmpKeyServer
*/
- private void becomeKeyServer(Address tmpKeyServer) {
+ private void becomeKeyServer(Address tmpKeyServer, boolean forced) {
keyServerAddr=tmpKeyServer;
keyServer=true;
- if(log.isInfoEnabled())
- log.info("I have become key server " + keyServerAddr);
+ if(log.isInfoEnabled() && !forced)
+ log.info("[" + local_addr + "] I have become the new key server ");
queue_down=false;
queue_up=false;
}
@@ -512,7 +510,7 @@ private void handleNewKeyServer(Address newKeyServer) {
keyServerAddr=newKeyServer;
keyServer=false;
if(log.isInfoEnabled())
- log.info("Sending key request");
+ log.info("[" + local_addr + "] " + keyServerAddr + " has become the new key server, sending key request to it");
// create a key request message
sendKeyRequest();
@@ -541,8 +539,8 @@ private void handleUpMessage(Event evt) throws Exception {
// try and get the encryption header
if(hdr == null) {
if(log.isTraceEnabled())
- log.trace("dropping message as ENCRYPT header is null or has not been recognized, msg will not be passed up, " + "headers are "
- + msg.printHeaders());
+ log.trace("dropping message as ENCRYPT header is null or has not been recognized, msg will not be passed up, " +
+ "headers are " + msg.printHeaders());
return;
}
@@ -657,21 +655,19 @@ private void handleUpMessage(Event evt) throws Exception {
* @throws Exception
*/
private void drainUpQueue() throws Exception {
- //we do not synchronize here as we only have one up thread so we should never get an issue
- //synchronized(upLock){
+ if(log.isTraceEnabled()) {
+ int size=upMessageQueue.size();
+ if(size > 0)
+ log.trace("draining " + size + " messages from the up queue");
+ }
Event tmp=null;
while((tmp=upMessageQueue.poll(0L, TimeUnit.MILLISECONDS)) != null) {
Message msg=decryptMessage(symDecodingCipher, ((Message)tmp.getArg()).copy());
- if(msg != null) {
- if(log.isTraceEnabled()) {
- log.trace("passing up message from drain " + msg);
- }
+ if(msg != null)
passItUp(new Event(Event.MSG, msg));
- }
- else {
+ else
log.warn("discarding message in queue up drain as cannot decode it");
- }
}
}
@@ -855,7 +851,7 @@ public Object down(Event evt) {
case Event.VIEW_CHANGE:
View view=(View)evt.getArg();
if(log.isInfoEnabled())
- log.info("handling view-change down: " + view);
+ log.info("new view: " + view);
if(!suppliedKey) {
handleViewChange(view, false);
}
@@ -869,8 +865,6 @@ public Object down(Event evt) {
case Event.TMP_VIEW:
view=(View)evt.getArg();
- if(log.isInfoEnabled())
- log.info("handling tmp-view down: " + view);
if(!suppliedKey) {
// if a tmp_view then we are trying to become coordinator so
// make us keyserver
@@ -894,8 +888,11 @@ public Object passItDown(Event evt) {
* @throws QueueClosedException
*/
private void drainDownQueue() throws Exception {
- // we do not synchronize here as we only have one down thread so we should never get an issue
- // first lets replay any oustanding events
+ if(log.isTraceEnabled()) {
+ int size=downMessageQueue.size();
+ if(size > 0)
+ log.trace("draining " + size + " messages from the down queue");
+ }
Event tmp=null;
while((tmp=downMessageQueue.poll(0L, TimeUnit.MILLISECONDS)) != null) {
sendDown(tmp);
View
1 tests/junit-functional/org/jgroups/protocols/ENCRYPT14KeystoreTest.java
@@ -34,7 +34,6 @@ public static void testInitWrongKeystoreProperties() {
}
catch(Exception e) {
System.out.println("didn't find incorrect keystore (as expected): " + e.getMessage());
- assert e.getMessage().equals("Unable to load keystore " + "unkownKeystore.keystore" + " ensure file is on classpath");
}
}

0 comments on commit 64f1f03

Please sign in to comment.
Something went wrong with that request. Please try again.