Search in sources :

Example 6 with Tuple

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Tuple(org.jgroups.util.Tuple) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 7 with Tuple

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());
    }
}
Also used : AttributeType(org.jgroups.conf.AttributeType) SecretKey(javax.crypto.SecretKey) Event(org.jgroups.Event) Tuple(org.jgroups.util.Tuple)

Example 8 with Tuple

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));
    }
}
Also used : AttributeType(org.jgroups.conf.AttributeType) SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Event(org.jgroups.Event) Tuple(org.jgroups.util.Tuple)

Example 9 with 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;
}
Also used : IpAddress(org.jgroups.stack.IpAddress) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) Tuple(org.jgroups.util.Tuple)

Aggregations

Tuple (org.jgroups.util.Tuple)9 Address (org.jgroups.Address)4 Event (org.jgroups.Event)4 SecretKey (javax.crypto.SecretKey)3 IpAddress (org.jgroups.stack.IpAddress)3 PhysicalAddress (org.jgroups.PhysicalAddress)2 AttributeType (org.jgroups.conf.AttributeType)2 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Cipher (javax.crypto.Cipher)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 BlockingInputStream (org.jgroups.util.BlockingInputStream)1