Package de.fhkn.in.uce.stun.attribute

Examples of de.fhkn.in.uce.stun.attribute.XorMappedAddress


    public NATFeatureRealization executeTest() {
        NATFeatureRealization result = NATFeatureRealization.DONT_CARE;
        try {
            final Message responseI = this.executeTestI(this.primaryStunServerAddress.getAddress(),
                    this.primaryStunServerAddress.getPort());
            final XorMappedAddress mappedAddressI = responseI.getAttribute(XorMappedAddress.class);
            final String localAddress = InetAddress.getLocalHost().getHostAddress();
            if (localAddress.equals(mappedAddressI.getEndpoint().getHostName())
                    && this.sourcePort == mappedAddressI.getEndpoint().getPort()) {
                result = NATFeatureRealization.NOT_REALIZED;
            } else {
                final InetSocketAddress alternateAddress = this.getAlternateSTUNServerAddressFromMessage(responseI);
                final Message responseII = this.executeTestII(alternateAddress.getAddress(),
                        this.primaryStunServerAddress.getPort());
                final XorMappedAddress mappedAddressII = responseII.getAttribute(XorMappedAddress.class);
                if (mappedAddressII.equals(mappedAddressI)) {
                    result = NATFeatureRealization.ENDPOINT_INDEPENDENT;
                } else {
                    final Message responseIII = this.executeTestIII(alternateAddress.getAddress(),
                            alternateAddress.getPort());
                    final XorMappedAddress mappedAddressIII = responseIII.getAttribute(XorMappedAddress.class);
                    if (mappedAddressIII.equals(mappedAddressII)) {
                        result = NATFeatureRealization.ADDRESS_DEPENDENT;
                    } else {
                        final Message responseIV = this.executeTestRun(this.primaryStunServerAddress.getAddress(),
                                this.primaryStunServerAddress.getPort());
                        final XorMappedAddress mappedAddressIV = responseIV.getAttribute(XorMappedAddress.class);
                        if (!mappedAddressIV.equals(mappedAddressI)) {
                            result = NATFeatureRealization.CONNECTION_DEPENDENT;
                        } else {
                            result = NATFeatureRealization.ADDRESS_AND_PORT_DEPENDENT;
                        }
                    }
View Full Code Here


        final InetSocketAddress publicAddress = new InetSocketAddress(socket.getInetAddress(), socket.getPort());
        return new Endpoint(publicAddress, EndpointCategory.PUBLIC);
    }

    private Endpoint createEndpointFromAttributes(final Message registerMessage) {
        final XorMappedAddress address = registerMessage.getAttribute(XorMappedAddress.class);
        EndpointCategory category = EndpointCategory.PRIVATE;
        if (registerMessage.hasAttribute(EndpointClass.class)) {
            category = registerMessage.getAttribute(EndpointClass.class).getEndpointCategory();
        }
        return new Endpoint(address.getEndpoint(), category);
    }
View Full Code Here

        // target id
        registerMessage.addAttribute(new Username(this.targetId));
        // private endpoint
        final InetAddress privateAddress = this.socketToMediator.getLocalAddress();
        if (privateAddress instanceof Inet6Address) {
            registerMessage.addAttribute(new XorMappedAddress(new InetSocketAddress(this.socketToMediator
                    .getLocalAddress(), this.socketToMediator.getLocalPort()), ByteBuffer.wrap(
                    registerMessage.getHeader().getTransactionId()).getInt()));
        } else {
            registerMessage.addAttribute(new XorMappedAddress(new InetSocketAddress(this.socketToMediator
                    .getLocalAddress(), this.socketToMediator.getLocalPort())));
        }
        final MessageWriter messageWriter = new MessageWriter(this.socketToMediator.getOutputStream());
        logger.info("Sending RegisterMessage for {}", this.targetId); //$NON-NLS-1$
        messageWriter.writeMessage(registerMessage);
View Full Code Here

        final Message response = connectionRequest.buildSuccessResponse();
        response.addAttribute(new HolePunchingAttribute());
        // add private endpoint
        final InetAddress privateAddress = controlConnection.getLocalAddress();
        if (privateAddress instanceof Inet6Address) {
            response.addAttribute(new XorMappedAddress(new InetSocketAddress(controlConnection.getLocalAddress(),
                    controlConnection.getLocalPort()), ByteBuffer.wrap(response.getHeader().getTransactionId())
                    .getInt()));
        } else {
            response.addAttribute(new XorMappedAddress(new InetSocketAddress(controlConnection.getLocalAddress(),
                    controlConnection.getLocalPort())));
        }
        response.writeTo(controlConnection.getOutputStream());
        logger.debug("Connection request response send"); //$NON-NLS-1$
    }
View Full Code Here

        final Message connectionRequestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST);
        connectionRequestMessage.addAttribute(new HolePunchingAttribute());
        connectionRequestMessage.addAttribute(new Username(targetId));
        final InetSocketAddress localAddress = (InetSocketAddress) controlConnection.getLocalSocketAddress();
        connectionRequestMessage.addAttribute(new XorMappedAddress(localAddress));
        connectionRequestMessage.addAttribute(authentificationToken);
        messageWriter.writeMessage(connectionRequestMessage);
    }
View Full Code Here

TOP

Related Classes of de.fhkn.in.uce.stun.attribute.XorMappedAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.