Package de.fhkn.in.uce.stun.message

Examples of de.fhkn.in.uce.stun.message.Message


    @Override
    public void run() {
        while (this.socket.isConnected() && !this.socket.isClosed()) {
            try {
                final Message inMessage = this.receiveMessage();
                logger.debug("received message at local {}:{}", this.socket.getLocalAddress(), //$NON-NLS-1$
                        this.socket.getLocalPort());
                this.handleMessage(inMessage);
            } catch (final EOFException eofe) {
                // TODO why is this exception thrown?
View Full Code Here


            this.handleMessageWithChangeRequestAttribute(toHandle, remoteAddress);
        }
    }

    private void handleSimpleBindingRequest(final Message toHandle) throws Exception {
        final Message response = toHandle.buildSuccessResponse();
        final OtherAddress otherAddress = new OtherAddress(this.secondaryAddress);
        response.addAttribute(otherAddress);
        final XorMappedAddress clientAddress = this.getPublicClientAddressAsAttribute(toHandle);
        response.addAttribute(clientAddress);
        response.writeTo(this.socket.getOutputStream());
    }
View Full Code Here

    }

    private void sendIndicationViaNewSocket(final InetSocketAddress bindAddress, final Message message,
            final InetSocketAddress remoteAddress) {
        try {
            final Message indication = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.INDICATION,
                    STUNMessageMethod.BINDING);
            indication.addAttribute(this.getPublicClientAddressAsAttribute(message));
            final Socket newSocket = new Socket();
            newSocket.setReuseAddress(true);
            logger.debug("Binding new socket to {}", bindAddress); //$NON-NLS-1$
            newSocket.bind(bindAddress);
            logger.debug("Connecting to {}", remoteAddress.toString()); //$NON-NLS-1$
            newSocket.connect(remoteAddress, TIMEOUT_IN_SECONDS);
            logger.debug("Wrtiting indication"); //$NON-NLS-1$
            indication.writeTo(newSocket.getOutputStream());
            newSocket.close();
        } catch (IOException e) {
            logger.error("Connection to client not successfully established: {}", e.getMessage()); //$NON-NLS-1$
        }
    }
View Full Code Here

    @Override
    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 Socket socket = new Socket();
            socket.setReuseAddress(true);
            socket.bind(new InetSocketAddress(this.sourcePort));
            socket.connect(new InetSocketAddress(stunServerAddress, stunServerPort));
            this.sendBindingRequestToStunServer(socket.getOutputStream());
            final Message response = this.receiveBindingResponseFromStunServer(socket.getInputStream());
            socket.close();
            return response;
        } catch (final Exception e) {
            this.logger.error("Exception eccured while executing test", e);
            throw e;
View Full Code Here

        }
    }

    private void sendBindingRequestToStunServer(final OutputStream out) throws Exception {
        final MessageWriter writer = new MessageWriter(out);
        final Message request = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.BINDING);
        writer.writeMessage(request);
    }
View Full Code Here

        logger.debug("User {} added or updated", newUser.getUserId()); //$NON-NLS-1$
        this.sendSuccessResponse(registerMessage, controlConnection);
    }

    private void sendSuccessResponse(final Message toRespond, final Socket controlConnection) throws Exception {
        final Message response = toRespond.buildSuccessResponse();
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

    public void handleMessage(final Message message, final Socket controlConnection) throws Exception {
        this.mediatorUtil.checkForAttribute(message, Username.class);
        final Username username = message.getAttribute(Username.class);
        final UserData user = this.userList.getUserDataByUserId(username.getUsernameAsString());
        final NATBehavior userNat = user.getUserNat();
        final Message response = message.buildSuccessResponse();
        response.addAttribute(userNat);
        response.writeTo(controlConnection.getOutputStream());
        logger.debug("response to {}:{} sent", message.getMessageClass().toString(), message.getMessageMethod()
                .toString());
    }
View Full Code Here

    @Override
    public void run() {
        while (this.socket.isConnected()) {
            try {
                final Message inMessage = this.receiveMessage();
                logger.debug(
                        "Got message: {}, {}", inMessage.getMessageClass().toString(), inMessage.getMessageMethod().toString()); //$NON-NLS-1$
                logger.debug("Got message from {}", this.socket.toString()); //$NON-NLS-1$
                this.handleMessage(inMessage);
            } catch (final SocketException se) {
                logger.error("Socket exception, canceling processing for socket: {}", se.getMessage()); //$NON-NLS-1$
                return;
View Full Code Here

        this.travTechRequestHandler.handleMessage(travTechRequestMessage, this.socket);
    }

    private void sendFailureResponse(final Message toRespond, final STUNErrorCode errorCode, final String errorReason)
            throws Exception {
        final Message failureResponse = toRespond.buildFailureResponse(errorCode, errorReason);
        this.messageWriter.writeMessage(failureResponse);
    }
View Full Code Here

TOP

Related Classes of de.fhkn.in.uce.stun.message.Message

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.