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

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


        if (null == connReq) {
            logger.debug("Connection request is NOT in list"); //$NON-NLS-1$
        }
        logger.debug(
                "Got connection request from list with transactionId={}", String.valueOf(connReq.getConnectionRequestMessage().getHeader().getTransactionId())); //$NON-NLS-1$
        final Message successResponse = connReq.getConnectionRequestMessage().buildSuccessResponse();
        final InetSocketAddress targetEndpoint = new InetSocketAddress(controlConnection.getInetAddress(),
                controlConnection.getPort());
        logger.debug("Sending connection request response with {} to source", targetEndpoint.toString()); //$NON-NLS-1$
        successResponse.addAttribute(new XorMappedAddress(targetEndpoint));
        successResponse.addAttribute(new EndpointClass(EndpointCategory.PUBLIC));
        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }
View Full Code Here


     * Sends a refresh request with the desired lifetime to the relay server.
     */
    @Override
    public void run() {
        try {
            final Message refreshRequestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                    STUNMessageMethod.KEEP_ALIVE);
            refreshRequestMessage.addAttribute(new RelayingLifetime(this.lifetime));
            this.controlConnectionWriter.writeMessage(refreshRequestMessage);
        } catch (final IOException e) {
            logger.error("IOException while sending refresh request"); //$NON-NLS-1$
        }
    }
View Full Code Here

        }
    }

    private void sendSuccessResponse(final Socket controlConnection, final Message request) throws IOException {
        logger.debug("Sending success response"); //$NON-NLS-1$
        final Message response = request.buildSuccessResponse();
        response.addAttribute(new ReversalAttribute());
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

    }

    private void sendFailureResponse(final Socket controlConnection, final Message request, final String errorReason)
            throws IOException {
        logger.debug(errorReason);
        final Message response = request.buildFailureResponse(STUNErrorCode.BAD_REQUEST, errorReason);
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

    @SuppressWarnings("unused")
    private boolean waitForSuccessResponse(final STUNMessageMethod method, final Socket controlConnection)
            throws IOException {
        boolean result = false;
        final MessageReader messageReader = MessageReader.createMessageReader();
        final Message responseMessage = messageReader.readSTUNMessage(controlConnection.getInputStream());
        if (responseMessage.isMethod(method) && responseMessage.isSuccessResponse()) {
            result = true;
        }
        return result;
    }
View Full Code Here

        if (this.successfullAllocation || this.discardedAllocation) {
            throw new IllegalStateException("You can create only one allocation with the same Relay Client object"); //$NON-NLS-1$
        }
        this.connectToRelayServerAndInitializeWriter();
        this.sendAllocationRequest();
        final Message response = this.receiveAllocationResponse();
        final InetSocketAddress addressAtRelayServer = this.getAddressAtRelayFromMessage(response);
        final int lifetime = response.getAttribute(RelayingLifetime.class).getLifeTime();
        this.startMessageHandler(lifetime);
        return addressAtRelayServer;
    }
View Full Code Here

        this.controlConnection.connect(this.relayServerSocketAddress);
        this.controlConnectionWriter = new MessageWriter(this.controlConnection.getOutputStream());
    }

    private synchronized void sendAllocationRequest() throws IOException {
        final Message allocationRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                RelayingMethod.ALLOCATION);
        allocationRequest.addAttribute(new RelayingLifetime(ALLOCATION_LIFETIME));
        logger.debug("Sending allocation request to relay server"); //$NON-NLS-1$
        this.controlConnectionWriter.writeMessage(allocationRequest);
    }
View Full Code Here

        this.controlConnectionWriter.writeMessage(allocationRequest);
    }

    private synchronized Message receiveAllocationResponse() throws IOException {
        final MessageReader messageReader = this.createCustomRelayingMessageReader();
        final Message allocationResponse = messageReader.readSTUNMessage(this.controlConnection.getInputStream());
        if (!allocationResponse.isMethod(RelayingMethod.ALLOCATION) || !allocationResponse.isSuccessResponse()
                || !allocationResponse.hasAttribute(XorMappedAddress.class)
                || !allocationResponse.hasAttribute(RelayingLifetime.class)) {
            throw new IOException("Unexpected response from Relay server"); //$NON-NLS-1$
        }
        return allocationResponse;
    }
View Full Code Here

            throw new IllegalStateException("You have first to create an allocation."); //$NON-NLS-1$
        }
    }

    private synchronized void sendDiscardMessage() throws IOException {
        final Message refreshRequestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.KEEP_ALIVE);
        refreshRequestMessage.addAttribute(new RelayingLifetime(0));
        this.controlConnectionWriter.writeMessage(refreshRequestMessage);
    }
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();
        // public endpoint
        successResponse.addAttribute(this.createXorMappedAddressFromSocket(controlConnection, successResponse
                .getHeader().getTransactionId()));
        // private endpoint
        successResponse.addAttribute(message.getAttribute(XorMappedAddress.class));
        logger.debug("Sending connection request response to {}", connReq.getControlConnection().toString()); //$NON-NLS-1$
        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }
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.