use of org.jgroups.util.Tuple in project JGroups by belaban.
the class STATE_SOCK method createStreamToProvider.
protected Tuple<InputStream, Object> createStreamToProvider(Address provider, StateHeader hdr) throws Exception {
IpAddress address = hdr.bind_addr;
Socket socket = null;
try {
socket = getSocketFactory().createSocket("jgroups.state_sock.sock");
socket.bind(new InetSocketAddress(bind_addr, 0));
socket.setReceiveBufferSize(buffer_size);
Util.connect(socket, new InetSocketAddress(address.getIpAddress(), address.getPort()), 0);
log.debug("%s: connected to state provider %s:%d", local_addr, address.getIpAddress(), address.getPort());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
Util.writeAddress(local_addr, out);
return new Tuple<>(new BufferedInputStream(socket.getInputStream(), buffer_size), socket);
} catch (Throwable t) {
Util.close(socket);
if (t instanceof Exception)
throw (Exception) t;
throw new Exception("failed creating socket", t);
}
}
use of org.jgroups.util.Tuple in project JGroups by belaban.
the class SSL_KEY_EXCHANGE method accept.
protected void accept() {
try (SSLSocket client_sock = (SSLSocket) srv_sock.accept()) {
client_sock.setEnabledCipherSuites(client_sock.getSupportedCipherSuites());
client_sock.startHandshake();
SSLSession sslSession = client_sock.getSession();
log.debug("%s: accepted SSL connection from %s; protocol: %s, cipher suite: %s", local_addr, client_sock.getRemoteSocketAddress(), sslSession.getProtocol(), sslSession.getCipherSuite());
if (session_verifier != null)
session_verifier.verify(sslSession);
// Start handling application content
InputStream in = client_sock.getInputStream();
DataOutput out = new DataOutputStream(client_sock.getOutputStream());
byte ordinal = (byte) in.read();
Type req = Type.values()[ordinal];
if (req != Type.SECRET_KEY_REQ)
throw new IllegalStateException(String.format("expected request of %s but got type=%d", Type.SECRET_KEY_REQ, ordinal));
Tuple<SecretKey, byte[]> tuple = (Tuple<SecretKey, byte[]>) up_prot.up(new Event(Event.GET_SECRET_KEY));
if (tuple == null)
return;
byte[] version = tuple.getVal2();
byte[] secret_key = tuple.getVal1().getEncoded();
out.write(Type.SECRET_KEY_RSP.ordinal());
out.writeInt(version.length);
out.write(version, 0, version.length);
out.writeInt(secret_key.length);
out.write(secret_key);
} catch (Throwable t) {
log.trace("%s: failure handling client socket: %s", local_addr, t.getMessage());
}
}
use of org.jgroups.util.Tuple in project JGroups by belaban.
the class SSL_KEY_EXCHANGE method fetchSecretKeyFrom.
public void fetchSecretKeyFrom(Address target) throws Exception {
try (SSLSocket sock = createSocketTo(target)) {
DataInput in = new DataInputStream(sock.getInputStream());
OutputStream out = sock.getOutputStream();
// send the secret key request
out.write(Type.SECRET_KEY_REQ.ordinal());
out.flush();
byte ordinal = in.readByte();
Type rsp = Type.values()[ordinal];
if (rsp != Type.SECRET_KEY_RSP)
throw new IllegalStateException(String.format("expected response of %s but got type=%d", Type.SECRET_KEY_RSP, ordinal));
int version_len = in.readInt();
byte[] version = new byte[version_len];
in.readFully(version);
int secret_key_len = in.readInt();
byte[] secret_key = new byte[secret_key_len];
in.readFully(secret_key);
SecretKey sk = new SecretKeySpec(secret_key, secret_key_algorithm);
Tuple<SecretKey, byte[]> tuple = new Tuple<>(sk, version);
log.debug("%s: sending up secret key (version: %s)", local_addr, Util.byteArrayToHexString(version));
up_prot.up(new Event(Event.SET_SECRET_KEY, tuple));
}
}
use of org.jgroups.util.Tuple in project fabric8 by fabric8io.
the class KubernetesDiscovery method down.
public Object down(Event evt) {
Object retval = super.down(evt);
switch(evt.getType()) {
case Event.VIEW_CHANGE:
for (Address logical_addr : members) {
PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, logical_addr));
if (physical_addr != null && !kubernetesHosts.contains(physical_addr)) {
dynamic_hosts.addIfAbsent(physical_addr);
}
}
break;
case Event.SET_PHYSICAL_ADDRESS:
Tuple<Address, PhysicalAddress> tuple = (Tuple<Address, PhysicalAddress>) evt.getArg();
PhysicalAddress physical_addr = tuple.getVal2();
if (physical_addr != null && !kubernetesHosts.contains(physical_addr))
dynamic_hosts.addIfAbsent(physical_addr);
break;
}
return retval;
}
Aggregations