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

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


                if (message.isMethod(RelayingMethod.CONNECTION_ATTEMPT) && message.isIndication()) {
                    // Connect to the relay address to establish a
                    // data connection
                    Socket s = new Socket();
                    s.connect(relayServerEndpoint);
                    MessageWriter dataConnectionWriter = new MessageWriter(s.getOutputStream());
                    Message connectionBindRequestMessage = MessageStaticFactory.newSTUNMessageInstance(
                            STUNMessageClass.REQUEST, RelayingMethod.CONNECTION_BIND);
                    connectionBindRequestMessage.addAttribute(new Token(message.getAttribute(Token.class).getToken()));
                    dataConnectionWriter.writeMessage(connectionBindRequestMessage);
                    // TODO erfolgs oder fehlermeldung abwarten
                    socketQueue.add(s);
                } else if (message.isMethod(STUNMessageMethod.KEEP_ALIVE) && message.isSuccessResponse()) {
                    int lifetime = message.getAttribute(RelayingLifetime.class).getLifeTime();
                    logger.debug("Received lifetime response {}", lifetime);
View Full Code Here


     *             socket to the client
     */
    public MessageDispatcherTask(Socket s, Map<UUID, BlockingQueue<Socket>> connIDToQueue,
            Executor controlConnectionHandlerExecutor, Executor relayExecutor) throws IOException {
        this.s = s;
        this.controlConnectionWriter = new MessageWriter(s.getOutputStream());
        this.connIDToQueue = connIDToQueue;
        this.controlConnectionHandlerExecutor = controlConnectionHandlerExecutor;
        this.relayExecutor = relayExecutor;
    }
View Full Code Here

    private synchronized void connectToRelayServerAndInitializeWriter() throws IOException {
        this.controlConnection = new Socket();
        this.controlConnection.bind(new InetSocketAddress(this.localAddress, this.localPort));
        this.controlConnection.connect(this.relayServerSocketAddress);
        this.controlConnectionWriter = new MessageWriter(this.controlConnection.getOutputStream());
    }
View Full Code Here

            throw e;
        }
    }

    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

     * @throws IOException
     */
    public HandleMessageTask(final Socket socket) throws IOException {
        this.messageReader = MessageReader
                .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
        this.messageWriter = new MessageWriter(socket.getOutputStream());
        this.socket = socket;
        this.registerMessageHandler = new DefaultRegisterHandling();
        this.deregisterMessageHandler = new DefaultDeregisterHandling();
        this.keepAliveMessageHandler = new DefaultKeepAliveHandling();
        this.connectionRequestMessageHandler = new ConnectionRequestHandling();
View Full Code Here

    @Override
    public boolean authenticate(final Socket toBeAuthenticated, final Set<CancelableTask> relatedHolePunchingTasks,
            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);
View Full Code Here

                    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

        return result;
    }

    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

    @Override
    public boolean authenticate(final Socket toBeAuthenticated, final Set<CancelableTask> relatedHolePunchingTasks,
            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();
        // 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.MessageWriter

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.