Search in sources :

Example 1 with IpAddress

use of org.jgroups.stack.IpAddress in project wildfly by wildfly.

the class ChannelNodeFactory method createNode.

@Override
public Node createNode(Address key) {
    return this.nodes.computeIfAbsent(key, (Address address) -> {
        IpAddress ipAddress = (IpAddress) this.channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, address));
        // Physical address might be null if node is no longer a member of the cluster
        InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
        String name = this.channel.getName(address);
        if (name == null) {
            // If no logical name exists, create one using physical address
            name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());
        }
        return new AddressableNode(address, name, socketAddress);
    });
}
Also used : Address(org.jgroups.Address) InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) InetSocketAddress(java.net.InetSocketAddress) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress)

Example 2 with IpAddress

use of org.jgroups.stack.IpAddress in project geode by apache.

the class JGroupsMessenger method establishLocalAddress.

private void establishLocalAddress() {
    UUID logicalAddress = (UUID) myChannel.getAddress();
    logicalAddress = logicalAddress.copy();
    IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
    if (ipaddr != null) {
        this.jgAddress = new JGAddress(logicalAddress, ipaddr);
    } else {
        UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
        try {
            Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
            getAddress.setAccessible(true);
            ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
            this.jgAddress = new JGAddress(logicalAddress, ipaddr);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
        }
    // if (this.jgAddress == null) {
    // String addr = udp.getLocalPhysicalAddress();
    // int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
    // String host = addr.substring(0, cidx);
    // int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
    // try {
    // this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
    // jgport));
    // } catch (UnknownHostException e) {
    // myChannel.disconnect();
    // throw new SystemConnectException("unable to initialize jgroups address", e);
    // }
    // }
    }
    // install the address in the JGroups channel protocols
    myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
    DistributionConfig config = services.getConfig().getDistributionConfig();
    boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
    // establish the DistributedSystem's address
    DurableClientAttributes dca = null;
    if (config.getDurableClientId() != null) {
        dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
    }
    MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
    OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
    config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
    localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
    // add the JGroups logical address to the GMSMember
    UUID uuid = this.jgAddress;
    GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
    gmsMember.setUUID(uuid);
    gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
    gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
Also used : UDP(org.jgroups.protocols.UDP) MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Example 3 with IpAddress

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

the class Util method parseCommaDelimitedHosts.

/**
 * Input is "daddy[8880],sindhu[8880],camille[5555]. Returns a list of IpAddresses
 */
public static List<PhysicalAddress> parseCommaDelimitedHosts(String hosts, int port_range) throws UnknownHostException {
    StringTokenizer tok = hosts != null ? new StringTokenizer(hosts, ",") : null;
    String t;
    IpAddress addr;
    Set<PhysicalAddress> retval = new HashSet<>();
    while (tok != null && tok.hasMoreTokens()) {
        t = tok.nextToken().trim();
        String host = t.substring(0, t.indexOf('['));
        host = host.trim();
        int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
        for (int i = port; i <= port + port_range; i++) {
            addr = new IpAddress(host, i);
            retval.add(addr);
        }
    }
    return new LinkedList<>(retval);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 4 with IpAddress

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

the class AUTHTest method testFixedMembershipTokenIPv6.

public void testFixedMembershipTokenIPv6() throws Exception {
    FixedMembershipToken tok = new FixedMembershipToken();
    tok.setMemberList("fe80::aa20:66ff:fe11:d346,2a02:120b:2c45:1b70:aa20:66ff:fe11:d346/7500,2a02:120b:2c45:1b70:f474:e6ca:3038:6b5f/7500");
    assert tok.isInMembersList(new IpAddress("2a02:120b:2c45:1b70:f474:e6ca:3038:6b5f", 7500));
}
Also used : FixedMembershipToken(org.jgroups.auth.FixedMembershipToken) IpAddress(org.jgroups.stack.IpAddress)

Example 5 with IpAddress

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

the class DNS_PINGTest method test_valid_dns_response.

@Test
public void test_valid_dns_response() throws Exception {
    // given
    DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 500, TimeUnit.SECONDS).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START)).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START + 1));
    // when
    boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
    // then
    Assert.assertTrue(was_view_received);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) Test(org.testng.annotations.Test)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)68 InetSocketAddress (java.net.InetSocketAddress)12 Address (org.jgroups.Address)9 IpAddressUUID (org.jgroups.stack.IpAddressUUID)8 Event (org.jgroups.Event)6 ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)6 ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 InetAddress (java.net.InetAddress)4 PhysicalAddress (org.jgroups.PhysicalAddress)4 Test (org.testng.annotations.Test)4 UUID (org.jgroups.util.UUID)3 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 ByteBuffer (java.nio.ByteBuffer)2 ManagedOperation (org.jgroups.annotations.ManagedOperation)2 FixedMembershipToken (org.jgroups.auth.FixedMembershipToken)2