Search in sources :

Example 76 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class SSL_KEY_EXCHANGE method createSocketTo.

protected SSLSocket createSocketTo(Address target) throws Exception {
    SSLSocketFactory sslSocketFactory = this.client_ssl_ctx.getSocketFactory();
    if (target instanceof IpAddress)
        return createSocketTo((IpAddress) target, sslSocketFactory);
    IpAddress dest = (IpAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, target));
    SSLSocket sock;
    for (int i = 0; i <= port_range; i++) {
        try {
            sock = (SSLSocket) sslSocketFactory.createSocket(dest.getIpAddress(), port + i);
            sock.setSoTimeout(socket_timeout);
            sock.setEnabledCipherSuites(sock.getSupportedCipherSuites());
            sock.startHandshake();
            SSLSession sslSession = sock.getSession();
            log.debug("%s: created SSL connection to %s (%s); protocol: %s, cipher suite: %s", local_addr, target, sock.getRemoteSocketAddress(), sslSession.getProtocol(), sslSession.getCipherSuite());
            if (session_verifier != null)
                session_verifier.verify(sslSession);
            return sock;
        } catch (SecurityException sec_ex) {
            throw sec_ex;
        } catch (Throwable t) {
        }
    }
    throw new IllegalStateException(String.format("failed connecting to %s (port range [%d - %d])", dest.getIpAddress(), port, port + port_range));
}
Also used : Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress)

Example 77 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class TCPGOSSIP method removeInitialHost.

@ManagedOperation
public boolean removeInitialHost(String hostname, int port) {
    InetSocketAddress isa = new InetSocketAddress(hostname, port);
    stubManager.unregisterStub(new IpAddress(isa.getAddress(), isa.getPort()));
    return initial_hosts.remove(isa);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) ManagedOperation(org.jgroups.annotations.ManagedOperation)

Example 78 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method testStreamable.

public void testStreamable() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream oos = new DataOutputStream(bos);
    byte[] buf = null;
    ByteArrayInputStream bis = null;
    DataInputStream ois;
    IpAddress a2, b2, x, x2, y, y2;
    x = createStackConformantAddress(5555);
    y = createStackConformantAddress(1111);
    a.writeTo(oos);
    b.writeTo(oos);
    x.writeTo(oos);
    y.writeTo(oos);
    buf = bos.toByteArray();
    bis = new ByteArrayInputStream(buf);
    ois = new DataInputStream(bis);
    a2 = new IpAddress();
    a2.readFrom(ois);
    b2 = new IpAddress();
    b2.readFrom(ois);
    x2 = new IpAddress();
    x2.readFrom(ois);
    y2 = new IpAddress();
    y2.readFrom(ois);
    Assert.assertEquals(a, a2);
    Assert.assertEquals(b, b2);
    assert y2.getIpAddress() != null;
    Assert.assertEquals(1111, y2.getPort());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) IpAddress(org.jgroups.stack.IpAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 79 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method setUp.

@BeforeClass
void setUp() throws Exception {
    StackType type = Util.getIpStackType();
    if (type == StackType.IPv6) {
        a = new IpAddress("::1", 5555);
        b = new IpAddress("::1", 5555);
        d = new IpAddress("::1", 5556);
        e = new IpAddress("::1", 5555);
        f = new IpAddress("2001:0db8:0000:0000:0000:002e:0370:2334", 80);
        g = new IpAddress("2001:0db8:0000:0000:0000:002e:0370:2334", 8080);
        h = new IpAddress("ff0e::3:4:5", 5555);
    } else {
        a = new IpAddress("localhost", 5555);
        b = new IpAddress("localhost", 5555);
        d = new IpAddress("localhost", 5556);
        e = new IpAddress("127.0.0.1", 5555);
        f = new IpAddress("www.ibm.com", 80);
        g = new IpAddress("www.ibm.com", 8080);
        h = new IpAddress("224.0.0.1", 5555);
    }
    c = b;
}
Also used : StackType(org.jgroups.util.StackType) IpAddress(org.jgroups.stack.IpAddress) BeforeClass(org.testng.annotations.BeforeClass)

Example 80 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class IpAddressTest method testConstructor.

public void testConstructor() throws Exception {
    IpAddress tmp = new IpAddress("192.168.1.5:7800");
    assert tmp.getPort() == 7800;
    assert tmp.getIpAddress().equals(InetAddress.getByName("192.168.1.5"));
    tmp = new IpAddress("10.1.2.3");
    assert tmp.getPort() == 0;
    assert tmp.getIpAddress().equals(InetAddress.getByName("10.1.2.3"));
    tmp = new IpAddress("fe80::21b:21ff:fe07:a3b0:6000");
    assert tmp.getPort() == 6000;
    assert tmp.getIpAddress().equals(InetAddress.getByName("fe80::21b:21ff:fe07:a3b0"));
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)87 InetSocketAddress (java.net.InetSocketAddress)15 Address (org.jgroups.Address)13 InetAddress (java.net.InetAddress)7 Test (org.testng.annotations.Test)7 Event (org.jgroups.Event)6 PhysicalAddress (org.jgroups.PhysicalAddress)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 IOException (java.io.IOException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 JChannel (org.jgroups.JChannel)3 ManagedOperation (org.jgroups.annotations.ManagedOperation)3 DefaultSocketFactory (org.jgroups.util.DefaultSocketFactory)3 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 ServerSocket (java.net.ServerSocket)2