提交 0417af6a 编写于 作者: B bessani@gmail.com

Improved code for shuting down the client if the servers are not available......

Improved code for shuting down the client if the servers are not available... additionally, exchanged Hastables by HashMaps
上级 43d7fb8c
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
package navigators.smart.communication.client.netty; package navigators.smart.communication.client.netty;
import java.util.HashMap;
import static org.jboss.netty.channel.Channels.pipeline; import static org.jboss.netty.channel.Channels.pipeline;
import java.util.Hashtable;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
...@@ -41,7 +41,7 @@ public class NettyClientPipelineFactory implements ChannelPipelineFactory { ...@@ -41,7 +41,7 @@ public class NettyClientPipelineFactory implements ChannelPipelineFactory {
NettyClientServerCommunicationSystemClientSide ncs; NettyClientServerCommunicationSystemClientSide ncs;
boolean isClient; boolean isClient;
Hashtable sessionTable; HashMap sessionTable;
SecretKey authKey; SecretKey authKey;
int macLength; int macLength;
int signatureLength; int signatureLength;
...@@ -53,7 +53,7 @@ public class NettyClientPipelineFactory implements ChannelPipelineFactory { ...@@ -53,7 +53,7 @@ public class NettyClientPipelineFactory implements ChannelPipelineFactory {
ReentrantReadWriteLock rl; ReentrantReadWriteLock rl;
ReentrantLock lock; ReentrantLock lock;
public NettyClientPipelineFactory(NettyClientServerCommunicationSystemClientSide ncs, boolean isClient, Hashtable sessionTable, SecretKey authKey, int macLength, ViewManager manager, ReentrantReadWriteLock rl, int signatureLength, ReentrantLock lock) { public NettyClientPipelineFactory(NettyClientServerCommunicationSystemClientSide ncs, boolean isClient, HashMap sessionTable, SecretKey authKey, int macLength, ViewManager manager, ReentrantReadWriteLock rl, int signatureLength, ReentrantLock lock) {
this.ncs = ncs; this.ncs = ncs;
this.isClient = isClient; this.isClient = isClient;
this.sessionTable = sessionTable; this.sessionTable = sessionTable;
......
...@@ -21,20 +21,17 @@ import java.io.ByteArrayOutputStream; ...@@ -21,20 +21,17 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.nio.channels.ClosedChannelException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.Signature; import java.security.Signature;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
...@@ -45,6 +42,7 @@ import navigators.smart.communication.client.CommunicationSystemClientSide; ...@@ -45,6 +42,7 @@ import navigators.smart.communication.client.CommunicationSystemClientSide;
import navigators.smart.communication.client.ReplyReceiver; import navigators.smart.communication.client.ReplyReceiver;
import navigators.smart.reconfiguration.ViewManager; import navigators.smart.reconfiguration.ViewManager;
import navigators.smart.tom.core.messages.TOMMessage; import navigators.smart.tom.core.messages.TOMMessage;
import navigators.smart.tom.util.Logger;
import navigators.smart.tom.util.TOMUtil; import navigators.smart.tom.util.TOMUtil;
import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.bootstrap.ClientBootstrap;
...@@ -70,12 +68,10 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -70,12 +68,10 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
private static final String PASSWORD = "newcs"; private static final String PASSWORD = "newcs";
//private static final int BENCHMARK_PERIOD = 10000; //private static final int BENCHMARK_PERIOD = 10000;
protected ReplyReceiver trr; protected ReplyReceiver trr;
//******* EDUARDO BEGIN **************// //******* EDUARDO BEGIN **************//
private ViewManager manager; private ViewManager manager;
//******* EDUARDO END **************// //******* EDUARDO END **************//
private HashMap sessionTable = new HashMap();
private Hashtable sessionTable;
private ReentrantReadWriteLock rl; private ReentrantReadWriteLock rl;
private SecretKey authKey; private SecretKey authKey;
//the signature engine used in the system //the signature engine used in the system
...@@ -92,7 +88,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -92,7 +88,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
authKey = fac.generateSecret(spec); authKey = fac.generateSecret(spec);
this.manager = manager; this.manager = manager;
this.sessionTable = new Hashtable();
//this.st = new Storage(BENCHMARK_PERIOD); //this.st = new Storage(BENCHMARK_PERIOD);
this.rl = new ReentrantReadWriteLock(); this.rl = new ReentrantReadWriteLock();
Mac macDummy = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm()); Mac macDummy = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm());
...@@ -110,10 +105,11 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -110,10 +105,11 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true); bootstrap.setOption("keepAlive", true);
bootstrap.setOption("connectTimeoutMillis", 10000);
// Set up the default event pipeline. // Set up the default event pipeline.
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable, bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable,
authKey, macDummy.getMacLength(), manager, rl, signatureLength, new ReentrantLock())); authKey, macDummy.getMacLength(), manager, rl, signatureLength, new ReentrantLock()));
//******* EDUARDO BEGIN **************// //******* EDUARDO BEGIN **************//
...@@ -126,92 +122,30 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -126,92 +122,30 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
Mac macReceive = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm()); Mac macReceive = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm());
macReceive.init(authKey); macReceive.init(authKey);
NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend,
macReceive, currV[i], manager.getStaticConf().getRSAPublicKey(currV[i]), new ReentrantLock()); macReceive, currV[i], manager.getStaticConf().getRSAPublicKey(currV[i]), new ReentrantLock());
sessionTable.put(currV[i], cs); sessionTable.put(currV[i], cs);
System.out.println("Connecting to replica " + currV[i] + " at " + manager.getRemoteAddress(currV[i])); System.out.println("Connecting to replica " + currV[i] + " at " + manager.getRemoteAddress(currV[i]));
//******* EDUARDO END **************// //******* EDUARDO END **************//
future.awaitUninterruptibly(); future.awaitUninterruptibly();
}catch (java.lang.NullPointerException ex){ if (!future.isSuccess()) {
System.out.println("Deve resolver o problema, e acho que não trás outras implicações :-), " + System.err.println("Impossible to connect to " + currV[i]);
"mas temos que fazer os servidores armazenarem as view em um lugar default."); }
} catch (InvalidKeyException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (InvalidKeySpecException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
}
}
/*public NettyClientServerCommunicationSystemClientSide(ViewManager manager) {
try {
SecretKeyFactory fac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
PBEKeySpec spec = new PBEKeySpec(PASSWORD.toCharArray());
authKey = fac.generateSecret(spec);
this.manager = manager;
this.sessionTable = new Hashtable();
//this.st = new Storage(BENCHMARK_PERIOD);
this.rl = new ReentrantReadWriteLock();
Mac macDummy = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm());
signatureLength = TOMUtil.getSignatureSize(manager);
int[] currV = manager.getCurrentViewProcesses();
for (int i = 0; i < currV.length; i++) {
try {
// Configure the client.
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
// Set up the default event pipeline.
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable, authKey, macDummy.getMacLength(), manager, rl, signatureLength, new ReentrantLock()));
//******* EDUARDO BEGIN **************
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(manager.getStaticConf().getRemoteAddress(currV[i]));
//creates MAC stuff
Mac macSend = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm());
macSend.init(authKey);
Mac macReceive = Mac.getInstance(manager.getStaticConf().getHmacAlgorithm());
macReceive.init(authKey);
NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, macReceive, currV[i], manager.getStaticConf().getRSAPublicKey(currV[i]), new ReentrantLock());
sessionTable.put(currV[i], cs);
System.out.println("Connecting to replica " + currV[i] + " at " + manager.getStaticConf().getRemoteAddress(currV[i]));
//******* EDUARDO END **************
future.awaitUninterruptibly();
} catch (java.lang.NullPointerException ex) {
//What the fuck is this??? This is not possible!!!
System.err.println("Deve resolver o problema, e acho que não trás outras implicações :-), "
+ "mas temos que fazer os servidores armazenarem as view em um lugar default.");
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} catch (InvalidKeySpecException ex) { } catch (InvalidKeySpecException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
}*/ }
//TODO: Falta fechar as conexoes para servidores q sairam //TODO: Falta fechar as conexoes para servidores q sairam
public void updateConnections() { public void updateConnections() {
...@@ -234,6 +168,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -234,6 +168,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true); bootstrap.setOption("keepAlive", true);
bootstrap.setOption("connectTimeoutMillis", 10000);
// Set up the default event pipeline. // Set up the default event pipeline.
bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable, authKey, macDummy.getMacLength(), manager, rl, signatureLength, new ReentrantLock())); bootstrap.setPipelineFactory(new NettyClientPipelineFactory(this, true, sessionTable, authKey, macDummy.getMacLength(), manager, rl, signatureLength, new ReentrantLock()));
...@@ -254,27 +189,21 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -254,27 +189,21 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
System.out.println("Connecting to replica " + currV[i] + " at " + manager.getRemoteAddress(currV[i])); System.out.println("Connecting to replica " + currV[i] + " at " + manager.getRemoteAddress(currV[i]));
//******* EDUARDO END **************// //******* EDUARDO END **************//
future.awaitUninterruptibly(); future.awaitUninterruptibly();
} catch (InvalidKeyException ex) { } catch (InvalidKeyException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} }
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
@Override @Override
public void exceptionCaught( public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
ChannelHandlerContext ctx, ExceptionEvent e) { //if (!(e.getCause() instanceof ClosedChannelException) && !(e.getCause() instanceof ConnectException)) {
e.getCause().getMessage();
if (!(e.getCause() instanceof ClosedChannelException) && !(e.getCause() instanceof ConnectException)) { //}
e.getCause().printStackTrace();
}
} }
@Override @Override
...@@ -299,18 +228,17 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -299,18 +228,17 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
//sleeps 10 seconds before trying to reconnect //sleeps 10 seconds before trying to reconnect
Thread.sleep(10000); Thread.sleep(10000);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
//System.out.println("Channel closed");
rl.writeLock().lock(); rl.writeLock().lock();
//tries to reconnect the channel Iterator sessions = sessionTable.values().iterator();
Enumeration sessionElements = sessionTable.elements(); while (sessions.hasNext()) {
while (sessionElements.hasMoreElements()) { NettyClientServerSession ncss = (NettyClientServerSession) sessions.next();
NettyClientServerSession ncss = (NettyClientServerSession) sessionElements.nextElement();
if (ncss.getChannel() == ctx.getChannel()) { if (ncss.getChannel() == ctx.getChannel()) {
try { try {
...@@ -331,9 +259,8 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -331,9 +259,8 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, macReceive, ncss.getReplicaId(), manager.getStaticConf().getRSAPublicKey(ncss.getReplicaId()), new ReentrantLock()); NettyClientServerSession cs = new NettyClientServerSession(future.getChannel(), macSend, macReceive, ncss.getReplicaId(), manager.getStaticConf().getRSAPublicKey(ncss.getReplicaId()), new ReentrantLock());
sessionTable.remove(ncss.getReplicaId()); sessionTable.remove(ncss.getReplicaId());
sessionTable.put(ncss.getReplicaId(), cs); sessionTable.put(ncss.getReplicaId(), cs);
//System.out.println("RE-Connecting to replica "+ncss.getReplicaId()+" at " + conf.getRemoteAddress(ncss.getReplicaId())); //System.out.println("RE-Connecting to replica "+ncss.getReplicaId()+" at " + conf.getRemoteAddress(ncss.getReplicaId()));
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
...@@ -347,10 +274,12 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -347,10 +274,12 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
rl.writeLock().unlock(); rl.writeLock().unlock();
} }
@Override
public void setReplyReceiver(ReplyReceiver trr) { public void setReplyReceiver(ReplyReceiver trr) {
this.trr = trr; this.trr = trr;
} }
@Override
public void send(boolean sign, int[] targets, TOMMessage sm, boolean serializeClassHeaders) { public void send(boolean sign, int[] targets, TOMMessage sm, boolean serializeClassHeaders) {
if (sm.serializedMessage == null) { if (sm.serializedMessage == null) {
//serialize message //serialize message
...@@ -374,7 +303,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -374,7 +303,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
data = baos.toByteArray(); data = baos.toByteArray();
sm.serializedMessage = data; sm.serializedMessage = data;
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex); Logger.println("Impossible to serialize message: " + sm);
} finally { } finally {
try { try {
if (dos != null) { if (dos != null) {
...@@ -384,7 +313,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -384,7 +313,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
oos.close(); oos.close();
} }
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
} else { } else {
...@@ -399,6 +327,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -399,6 +327,7 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
sm.serializedMessageSignature = data2; sm.serializedMessageSignature = data2;
} }
int sent = 0;
for (int i = targets.length - 1; i >= 0; i--) { for (int i = targets.length - 1; i >= 0; i--) {
/**********************************************************/ /**********************************************************/
/********************MALICIOUS CODE************************/ /********************MALICIOUS CODE************************/
...@@ -420,27 +349,16 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -420,27 +349,16 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
if (channel.isConnected()) { if (channel.isConnected()) {
sm.signed = sign; sm.signed = sign;
channel.write(sm); channel.write(sm);
sent++;
} else { } else {
//System.out.println("WARNING: channel is not connected"); Logger.println("Channel to " + targets[i] + " is not connected");
} }
}
if (sent < manager.getCurrentViewF() + 1) {
throw new RuntimeException("Impossible to connect to servers!");
} }
/*
//statistics about signature execution time
count++;
if (count % BENCHMARK_PERIOD == 0) {
int myId = conf.getProcessId();
System.out.println("--Signature benchmark:--");
System.out.println("(" + myId + ")Average time for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getAverage(true) / 1000 + " us ");
System.out.println("(" + myId + ")Standard desviation for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getDP(true) / 1000 + " us ");
System.out.println("(" + myId + ")Average time for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getAverage(false) / 1000 + " us ");
System.out.println("(" + myId + ")Standard desviation for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getDP(false) / 1000 + " us ");
System.out.println("(" + myId + ")Maximum time for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getMax(true) / 1000 + " us ");
System.out.println("(" + myId + ")Maximum time for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getMax(false) / 1000 + " us ");
System.out.println("(" + myId + ")----------------------------------------------------------------------");
count = 0;
st.reset();
}
*/
} }
public void sign(TOMMessage sm) { public void sign(TOMMessage sm) {
...@@ -455,12 +373,10 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -455,12 +373,10 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
data = baos.toByteArray(); data = baos.toByteArray();
sm.serializedMessage = data; sm.serializedMessage = data;
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} finally { } finally {
try { try {
dos.close(); dos.close();
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(NettyClientServerCommunicationSystemClientSide.class.getName()).log(Level.SEVERE, null, ex);
} }
} }
...@@ -470,23 +386,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -470,23 +386,6 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
//******* EDUARDO END **************// //******* EDUARDO END **************//
sm.serializedMessageSignature = data2; sm.serializedMessageSignature = data2;
/*
//statistics about signature execution time
count++;
if (count % BENCHMARK_PERIOD == 0) {
int myId = conf.getProcessId();
System.out.println("--Signature benchmark:--");
System.out.println("(" + myId + ")Average time for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getAverage(true) / 1000 + " us ");
System.out.println("(" + myId + ")Standard desviation for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getDP(true) / 1000 + " us ");
System.out.println("(" + myId + ")Average time for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getAverage(false) / 1000 + " us ");
System.out.println("(" + myId + ")Standard desviation for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getDP(false) / 1000 + " us ");
System.out.println("(" + myId + ")Maximum time for " + BENCHMARK_PERIOD + " signatures (-10%) = " + this.st.getMax(true) / 1000 + " us ");
System.out.println("(" + myId + ")Maximum time for " + BENCHMARK_PERIOD + " signatures (all samples) = " + this.st.getMax(false) / 1000 + " us ");
System.out.println("(" + myId + ")----------------------------------------------------------------------");
count = 0;
st.reset();
}
*/
} }
public byte[] signMessage(PrivateKey key, byte[] message) { public byte[] signMessage(PrivateKey key, byte[] message) {
...@@ -509,11 +408,12 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne ...@@ -509,11 +408,12 @@ public class NettyClientServerCommunicationSystemClientSide extends SimpleChanne
} }
} }
@Override
public void close() { public void close() {
this.closed = true; this.closed = true;
Enumeration sessionElements = sessionTable.elements(); Iterator sessions = sessionTable.values().iterator();
while (sessionElements.hasMoreElements()) { while (sessions.hasNext()) {
NettyClientServerSession ncss = (NettyClientServerSession) sessionElements.nextElement(); NettyClientServerSession ncss = (NettyClientServerSession) sessions.next();
ncss.getChannel().close(); ncss.getChannel().close();
} }
} }
......
...@@ -27,7 +27,7 @@ import java.security.NoSuchAlgorithmException; ...@@ -27,7 +27,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Hashtable; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -75,7 +75,7 @@ public class NettyClientServerCommunicationSystemServerSide extends SimpleChanne ...@@ -75,7 +75,7 @@ public class NettyClientServerCommunicationSystemServerSide extends SimpleChanne
private static final String PASSWORD = "newcs"; private static final String PASSWORD = "newcs";
private RequestReceiver requestReceiver; private RequestReceiver requestReceiver;
private Hashtable sessionTable; private HashMap sessionTable;
private ReentrantReadWriteLock rl; private ReentrantReadWriteLock rl;
private SecretKey authKey; private SecretKey authKey;
//private long numReceivedMsgs = 0; //private long numReceivedMsgs = 0;
...@@ -94,7 +94,7 @@ public class NettyClientServerCommunicationSystemServerSide extends SimpleChanne ...@@ -94,7 +94,7 @@ public class NettyClientServerCommunicationSystemServerSide extends SimpleChanne
authKey = fac.generateSecret(spec); authKey = fac.generateSecret(spec);
this.manager = manager; this.manager = manager;
sessionTable = new Hashtable(); sessionTable = new HashMap();
rl = new ReentrantReadWriteLock(); rl = new ReentrantReadWriteLock();
//Configure the server. //Configure the server.
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package navigators.smart.communication.client.netty; package navigators.smart.communication.client.netty;
import java.util.HashMap;
import static org.jboss.netty.channel.Channels.pipeline; import static org.jboss.netty.channel.Channels.pipeline;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -39,7 +40,7 @@ public class NettyServerPipelineFactory implements ChannelPipelineFactory { ...@@ -39,7 +40,7 @@ public class NettyServerPipelineFactory implements ChannelPipelineFactory {
NettyClientServerCommunicationSystemServerSide ncs; NettyClientServerCommunicationSystemServerSide ncs;
boolean isClient; boolean isClient;
Hashtable sessionTable; HashMap sessionTable;
SecretKey authKey; SecretKey authKey;
int macLength; int macLength;
int signatureLength; int signatureLength;
...@@ -47,7 +48,7 @@ public class NettyServerPipelineFactory implements ChannelPipelineFactory { ...@@ -47,7 +48,7 @@ public class NettyServerPipelineFactory implements ChannelPipelineFactory {
ReentrantReadWriteLock rl; ReentrantReadWriteLock rl;
ReentrantLock lock; ReentrantLock lock;
public NettyServerPipelineFactory(NettyClientServerCommunicationSystemServerSide ncs, boolean isClient, Hashtable sessionTable, SecretKey authKey, int macLength, ReconfigurationManager manager, ReentrantReadWriteLock rl, int signatureLength, ReentrantLock lock) { public NettyServerPipelineFactory(NettyClientServerCommunicationSystemServerSide ncs, boolean isClient, HashMap sessionTable, SecretKey authKey, int macLength, ReconfigurationManager manager, ReentrantReadWriteLock rl, int signatureLength, ReentrantLock lock) {
this.ncs = ncs; this.ncs = ncs;
this.isClient = isClient; this.isClient = isClient;
this.sessionTable = sessionTable; this.sessionTable = sessionTable;
......
...@@ -27,7 +27,7 @@ import java.security.NoSuchAlgorithmException; ...@@ -27,7 +27,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.PublicKey; import java.security.PublicKey;
import java.security.Signature; import java.security.Signature;
import java.util.Arrays; import java.util.Arrays;
import java.util.Hashtable; import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -61,7 +61,7 @@ public class NettyTOMMessageDecoder extends FrameDecoder { ...@@ -61,7 +61,7 @@ public class NettyTOMMessageDecoder extends FrameDecoder {
//private final int BENCHMARK_PERIOD = 10000; //private final int BENCHMARK_PERIOD = 10000;
private boolean isClient; private boolean isClient;
private Hashtable sessionTable; private HashMap sessionTable;
private SecretKey authKey; private SecretKey authKey;
//private Storage st; //private Storage st;
private int macSize; private int macSize;
...@@ -81,7 +81,7 @@ public class NettyTOMMessageDecoder extends FrameDecoder { ...@@ -81,7 +81,7 @@ public class NettyTOMMessageDecoder extends FrameDecoder {
private Signature signatureEngine; private Signature signatureEngine;
private boolean useMAC; private boolean useMAC;
public NettyTOMMessageDecoder(boolean isClient, Hashtable sessionTable, SecretKey authKey, int macLength, ViewManager manager, ReentrantReadWriteLock rl, int signatureLength, boolean useMAC){ public NettyTOMMessageDecoder(boolean isClient, HashMap sessionTable, SecretKey authKey, int macLength, ViewManager manager, ReentrantReadWriteLock rl, int signatureLength, boolean useMAC){
this.isClient = isClient; this.isClient = isClient;
this.sessionTable = sessionTable; this.sessionTable = sessionTable;
this.authKey = authKey; this.authKey = authKey;
......
...@@ -20,7 +20,7 @@ package navigators.smart.communication.client.netty; ...@@ -20,7 +20,7 @@ package navigators.smart.communication.client.netty;
import static org.jboss.netty.buffer.ChannelBuffers.buffer; import static org.jboss.netty.buffer.ChannelBuffers.buffer;
import java.util.Hashtable; import java.util.HashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.crypto.Mac; import javax.crypto.Mac;
...@@ -39,13 +39,13 @@ import org.jboss.netty.channel.SimpleChannelHandler; ...@@ -39,13 +39,13 @@ import org.jboss.netty.channel.SimpleChannelHandler;
public class NettyTOMMessageEncoder extends SimpleChannelHandler { public class NettyTOMMessageEncoder extends SimpleChannelHandler {
private boolean isClient; private boolean isClient;
private Hashtable sessionTable; private HashMap sessionTable;
private int macLength; private int macLength;
private int signatureLength; private int signatureLength;
private ReentrantReadWriteLock rl; private ReentrantReadWriteLock rl;
private boolean useMAC; private boolean useMAC;
public NettyTOMMessageEncoder(boolean isClient, Hashtable sessionTable, int macLength, ReentrantReadWriteLock rl, int signatureLength, boolean useMAC){ public NettyTOMMessageEncoder(boolean isClient, HashMap sessionTable, int macLength, ReentrantReadWriteLock rl, int signatureLength, boolean useMAC){
this.isClient = isClient; this.isClient = isClient;
this.sessionTable = sessionTable; this.sessionTable = sessionTable;
this.macLength = macLength; this.macLength = macLength;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册