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

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


    @Override
    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 Message response = message.buildSuccessResponse();
        for (final NATTraversalTechniqueAttribute attr : user.getSupportedNatTraversalTechniques()) {
            response.addAttribute(attr);
        }
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here


        logger.debug("User {} removed", username.getUsernameAsString()); //$NON-NLS-1$
        this.sendSuccessResponse(deregisterMessage, 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

            final CancelableTask ownTask, final Object sharedLock) throws IOException {
        boolean result = false;
        logger.info("Trying to authenticate socket: {}", toBeAuthenticated); //$NON-NLS-1$
        final MessageWriter messageWriter = new MessageWriter(toBeAuthenticated.getOutputStream());
        final MessageReader messageReader = this.hpUtil.getCustomHolePunchingMessageReader();
        final Message receivedMessage = messageReader.readSTUNMessage(toBeAuthenticated.getInputStream());
        if ((receivedMessage.getMessageMethod() == STUNMessageMethod.AUTHENTICATE)
                && receivedMessage.hasAttribute(Token.class)) {
            final Token receivedToken = receivedMessage.getAttribute(Token.class);
            if (receivedToken.getToken().equals(this.authentikationToken)) {
                final Message tokenAckMessage = receivedMessage.buildSuccessResponse();
                synchronized (sharedLock) {
                    messageWriter.writeMessage(tokenAckMessage);
                    final Message receveidAckMessage = messageReader
                            .readSTUNMessage(toBeAuthenticated.getInputStream());
                    if (this.hpUtil.isAuthenticationAcknowledgmentMessage(receveidAckMessage)) {
                        logger.debug("Authentication successfull, stopping hole punching threads"); //$NON-NLS-1$
                        this.hpUtil.stopCancableTasksExceptOwnTask(relatedHolePunchingTasks, ownTask);
                        result = true;
View Full Code Here

        this.startMessageHandler(endpoints, authentificationToken);
    }

    @SuppressWarnings("unused")
    private void sendRegisterMessage() throws IOException {
        final Message registerMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.REGISTER);
        // 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

        this.userList.refreshUserTimestamp(username.getUsernameAsString());
        this.sendSuccessResponse(keepaliveMessage, 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

        }
    }

    private void sendConnectionRequestResponse(final Socket controlConnection, final Message connectionRequest)
            throws Exception {
        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

        Socket result = null;
        logger.debug("Trying to connect to {}", targetId); //$NON-NLS-1$
        // this.connectToMediator(mediatorAddress);
        final Token token = new Token(UUID.randomUUID());
        this.sendConnectionRequest(controlConnection, targetId, token);
        final Message receivedMessage = this.receiveMessage(controlConnection);
        // if (this.isForwardedEndpointsMessage(receivedMessage)) {
        logger.debug("Received forwarding endpoints message"); //$NON-NLS-1$
        final List<XorMappedAddress> addresses = receivedMessage.getAttributes(XorMappedAddress.class);
        final BlockingQueue<Socket> socketQueue = new ArrayBlockingQueue<Socket>(1);
        final InetSocketAddress localAddress = (InetSocketAddress) controlConnection.getLocalSocketAddress();
        final ConnectionListener connectionListener = new ConnectionListener(localAddress.getAddress(),
                localAddress.getPort());
        logger.debug("Starting hole puncher"); //$NON-NLS-1$
View Full Code Here

    }

    private void sendConnectionRequest(final Socket controlConnection, final String targetId,
            final Token authentificationToken) throws IOException {
        final MessageWriter messageWriter = new MessageWriter(controlConnection.getOutputStream());
        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

        boolean result = false;
        logger.info("Trying to authenticate socket: {}", toBeAuthenticated); //$NON-NLS-1$
        final MessageWriter messageWriter = new MessageWriter(toBeAuthenticated.getOutputStream());
        final MessageReader messageReader = this.hpUtil.getCustomHolePunchingMessageReader();
        // sending authentication message
        final Message authenticationMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.AUTHENTICATE);
        authenticationMessage.addAttribute(new Token(this.authentikationToken));
        logger.info("Sending AuthenticationMessage: {}", authenticationMessage); //$NON-NLS-1$
        messageWriter.writeMessage(authenticationMessage);
        // receiving authentication acknowledgment message
        final Message reveivedAckMessage = messageReader.readSTUNMessage(toBeAuthenticated.getInputStream());
        if (this.hpUtil.isAuthenticationAcknowledgmentMessage(reveivedAckMessage)) {
            synchronized (sharedLock) {
                // sending second authentication acknowledgment message
                final Message secondAckMessage = reveivedAckMessage.buildSuccessResponse();
                messageWriter.writeMessage(secondAckMessage);
                logger.debug("Authentication successfull, stopping hole punching threads"); //$NON-NLS-1$
                this.hpUtil.stopCancableTasksExceptOwnTask(relatedHolePunchingTasks, ownTask);
                result = true;
            }
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.