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

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


     * the message is an connection bind request a {@link ConnectionBindHandler}
     * gets used to handle the message. If the message was of unknown type a bad
     * request error is returned to the client.
     */
    public void run() {
        Message message;
        try {
            final MessageReader messageReader = this.createCustomRelayingMessageReader();
            logger.debug("Reading incoming message from {}", s.toString()); //$NON-NLS-1$
            message = messageReader.readSTUNMessage(s.getInputStream());
        } catch (IOException e) {
            logger.error("IOEXception while receiving message: {}", e.getMessage());
            return;
        }
        if (message.isMethod(RelayingMethod.ALLOCATION) && message.isRequest()) {
            logger.info("Received allocation request");
            new RelayAllocationHandler(s, controlConnectionWriter, connIDToQueue, message,
                    controlConnectionHandlerExecutor, relayExecutor).handle();
        } else if (message.isMethod(RelayingMethod.CONNECTION_BIND) && message.isRequest()) {
            logger.info("Received connection bind");
            new ConnectionBindHandler(s, message, connIDToQueue).handle();
        } else {
            // unknown message
            logger.error("Received wrong message tye {}", message.getMessageMethod());
            try {
                Message errorResponse = message.buildFailureResponse(STUNErrorCode.BAD_REQUEST,
                        "Did not expect message " + message.getMessageMethod());
                controlConnectionWriter.writeMessage(errorResponse);
            } catch (IOException e) {
                logger.error("IOException while sending error response");
            }
View Full Code Here


        return this.createSocketToEndpoint(targetAddress, new InetSocketAddress(controlConnection.getLocalAddress(),
                controlConnection.getLocalPort()));
    }

    private void sendConnectionRequest(final String targetId, final Socket controlConnection) throws Exception {
        final Message requestConnectionMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST);
        requestConnectionMessage.addAttribute(new DirectconnectionAttribute());
        requestConnectionMessage.addAttribute(new Username(targetId));
        requestConnectionMessage.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

    }

    private InetSocketAddress processConnectionRequestResponse(final Socket controlConnection) throws Exception {
        InetSocketAddress result;
        final MessageReader messageReader = MessageReader.createMessageReader();
        final Message responseMessage = messageReader.readSTUNMessage(controlConnection.getInputStream());
        if (responseMessage.hasAttribute(XorMappedAddress.class)) {
            final XorMappedAddress xorMappedAddress = responseMessage.getAttribute(XorMappedAddress.class);
            result = xorMappedAddress.getEndpoint();
        } else {
            throw new Exception("The target endpoint is not returned by the mediator"); //$NON-NLS-1$
        }
        return result;
View Full Code Here

        int refreshInterval = initRefreshInterval;
        try {
            while (true) {
                controlConnection.setSoTimeout(refreshInterval * 1000);
                final MessageReader messageReader = this.createCustomRelayingMessageReader();
                final Message message = messageReader.readSTUNMessage(controlConnection.getInputStream());
                // check if it is refresh message (atm the only one that is
                // allowed)
                if (message == null) {
                    // connection closed
                    logger.error("Received message was null");
                    break;
                }
                if (message.isMethod(STUNMessageMethod.KEEP_ALIVE) && message.isRequest()) {
                    int lifetime = message.getAttribute(RelayingLifetime.class).getLifeTime();
                    logger.info("Received refresh request with lifetime {}", lifetime);
                    if (lifetime > 0) {
                        refreshInterval = (lifetime < RelayingConstants.ALLOCATION_LIFETIME_MAX) ? lifetime
                                : RelayingConstants.ALLOCATION_LIFETIME_MAX;
                        // send refresh response
                        Message successResponse = message.buildSuccessResponse();
                        successResponse.addAttribute(new RelayingLifetime(refreshInterval));
                        controlConnectionWriter.writeMessage(successResponse);
                    } else {
                        // send refresh response (unallocate)
                        Message successResponse = message.buildSuccessResponse();
                        successResponse.addAttribute(new RelayingLifetime(0));
                        controlConnectionWriter.writeMessage(successResponse);
                        break;
                    }
                } else {
                    logger.error("Received unexpected message: {}", message.getMessageMethod());
                    Message errorResponse = message.buildFailureResponse(STUNErrorCode.BAD_REQUEST,
                            "Expected refresh request");
                    controlConnectionWriter.writeMessage(errorResponse);
                }
            }
        } catch (SocketTimeoutException e) {
View Full Code Here

    }

    @Override
    public void run() {
        try {
            final Message keepAliveMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                    STUNMessageMethod.KEEP_ALIVE);
            final Username userNameAttribute = new Username(this.targetId);
            keepAliveMessage.addAttribute(userNameAttribute);
            keepAliveMessage.writeTo(this.controlConnection.getOutputStream());
        } catch (final Exception e) {
            logger.error("Exception while sending keep-alive message: {}", e.getMessage()); //$NON-NLS-1$
        }
    }
View Full Code Here

        return serverSocket;
    }

    private void sendResponseForTargetIsReady(final Socket controlConnection, final Message connectionRequestMessage)
            throws IOException {
        final Message response = connectionRequestMessage.buildSuccessResponse();
        response.addAttribute(new DirectconnectionAttribute());
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

        logger.debug("Accepted peer connection from: {}", socketToPeer);
        UUID connectionId = UUID.randomUUID();
        BlockingQueue<Socket> connectionBindQueue = new ArrayBlockingQueue<Socket>(1);
        connIDToQueue.put(connectionId, connectionBindQueue);
        try {
            Message connectionAttemptMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.INDICATION,
                    RelayingMethod.CONNECTION_ATTEMPT);
            connectionAttemptMessage.addAttribute(new Token(connectionId));
            controlConnection.writeMessage(connectionAttemptMessage);
        } catch (IOException ex) {
            logger.error("IOException while sending Connection Attempt: {}", ex);
            connIDToQueue.remove(connectionId);
            try {
View Full Code Here

    private void handleConnectionRequestResponse(final Message message, final Socket controlConnection)
            throws Exception {
        final ConnectionRequest connReq = this.connectionRequests.getConnectionRequest(new String(message.getHeader()
                .getTransactionId()));
        final Message successResponse = connReq.getConnectionRequestMessage().buildSuccessResponse();
        final XorMappedAddress endpointAtRelay = message.getAttribute(XorMappedAddress.class);
        successResponse.addAttribute(endpointAtRelay);
        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }
View Full Code Here

    }

    private void callTarget(final UserData target, final Message connectionRequestFromSource) throws Exception {
        final Socket toTarget = target.getSocketToUser();
        logger.debug("Calling target {}", toTarget.toString());
        final Message connectionRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST, connectionRequestFromSource.getHeader().getTransactionId());
        connectionRequest.addAttribute(new RelayingAttribute());
        connectionRequest.writeTo(toTarget.getOutputStream());
        // return this.waitForTarget(toTarget);
    }
View Full Code Here

    }

    private void sendFailureResponse(final Message message, final String errorReaon, final STUNErrorCode errorCode,
            final OutputStream out) throws Exception {
        logger.debug(errorReaon);
        final Message failureResponse = message.buildFailureResponse(errorCode, errorReaon);
        failureResponse.writeTo(out);
    }
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.