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

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


    }

    private void callTarget(final UserData target, final Message connectionRequestFromSource) throws Exception {
        logger.debug("Calling target {}", target.getUserId()); //$NON-NLS-1$
        final Socket toTarget = target.getSocketToUser();
        final Message connectionRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST, connectionRequestFromSource.getHeader().getTransactionId());
        connectionRequest.addAttribute(new DirectconnectionAttribute());
        logger.debug("Forwarding connection request to target"); //$NON-NLS-1$
        connectionRequest.writeTo(toTarget.getOutputStream());
    }
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

    @Override
    public Socket createSourceSideConnection(final String targetId, final Socket controlConnection)
            throws ConnectionNotEstablishedException {
        try {
            this.sendConnectionRequest(targetId, controlConnection);
            final Message responseMessage = this.receiveConnectionResponse(controlConnection);
            final InetSocketAddress endpointAtRelayServer = this.getEndpointFromMessage(responseMessage);
            return this.connectToTargetEndpoint(endpointAtRelayServer);
        } catch (final Exception e) {
            logger.error(e.getMessage());
            throw new ConnectionNotEstablishedException(this.metaData.getTraversalTechniqueName(),
View Full Code Here

        }
    }

    private void sendConnectionRequest(final String targetId, final Socket controlConnection) throws Exception {
        logger.debug("Sending connection request"); //$NON-NLS-1$
        final Message requestConnectionMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST);
        requestConnectionMessage.addAttribute(new Username(targetId));
        requestConnectionMessage.addAttribute(new RelayingAttribute());
        requestConnectionMessage.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

        return socket;
    }

    private void sendConnectionRequestResponse(final Socket controlConnection, final Message connectionRequest,
            final InetSocketAddress endpointAtRelay) throws IOException {
        final Message response = connectionRequest.buildSuccessResponse();
        response.addAttribute(new RelayingAttribute());
        XorMappedAddress endpointAtRelayAttribute;
        if (endpointAtRelay.getAddress() instanceof Inet6Address) {
            endpointAtRelayAttribute = new XorMappedAddress(endpointAtRelay, ByteBuffer.wrap(
                    response.getHeader().getTransactionId()).getInt());
        } else {
            endpointAtRelayAttribute = new XorMappedAddress(endpointAtRelay);
        }
        response.addAttribute(endpointAtRelayAttribute);
        response.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

            while (!this.isInterrupted()) {
                logger.info("listen on {}:{}", this.controlConnection.getLocalPort(), this.controlConnection //$NON-NLS-1$
                        .getLocalAddress().getHostAddress());
                while (!this.isInterrupted()) {
                    final MessageReader messageReader = MessageReader.createMessageReader();
                    final Message requestMessage = messageReader.readSTUNMessage(this.controlConnection
                            .getInputStream());
                    if (requestMessage.isMethod(STUNMessageMethod.CONNECTION_REQUEST)) {
                        this.handleConnectionRequestMessage(requestMessage);
                    } else if (requestMessage.isMethod(STUNMessageMethod.KEEP_ALIVE)) {
                        this.handleKeepAliveMessage(requestMessage);
                    } else {
                        logger.error("Unknown message"); //$NON-NLS-1$
                    }
                }
View Full Code Here

    /**
     * Waits for new messages from the relay server and handles them. It can
     * handle connection attempt indications and allocation refresh responses.
     */
    public void run() {
        Message message;
        while (!cancelled) {
            try {
                final MessageReader messageReader = this.createCustomRelayingMessageReader();
                message = messageReader.readSTUNMessage(controlConnection.getInputStream());
                if (message == null) {
                    // server closed connection
                    logger.error("IOException while receiving message (message was null)");
                    socketQueue.add(new Socket());
                    return;
                }
                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();
View Full Code Here

        serverSocket.setSoTimeout(this.socketTimeoutInMillis);
        return serverSocket;
    }

    private void sendConnectionRequest(final String targetId, final Socket controlConnection) throws IOException {
        final Message requestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST);
        requestMessage.addAttribute(new Username(targetId));
        requestMessage.addAttribute(new ReversalAttribute());
        logger.info("send connection request for target {}", targetId); //$NON-NLS-1$
        requestMessage.writeTo(controlConnection.getOutputStream());
    }
View Full Code Here

                    Thread.currentThread().interrupt();
                }
            } else {
                logger.error("Connection id (" + connectionId + ") does not refer to an existing pending connection.");
                try {
                    Message errorResponse = connBindMessage.buildFailureResponse(STUNErrorCode.BAD_REQUEST,
                            "Connection ID (" + connectionId + ") does not refer to an existing pending connection.");
                    errorResponse.writeTo(s.getOutputStream());
                } catch (IOException e) {
                    logger.error("IOException while sending Error Response: {}", e);
                }
            }
        } else {
            logger.error("Received Connection Bind Message without Connection ID");
            try {
                Message errorResponse = connBindMessage.buildFailureResponse(STUNErrorCode.BAD_REQUEST,
                        "Connection Bind Message did not contain Connection ID.");

                errorResponse.writeTo(s.getOutputStream());
            } catch (IOException e) {
                logger.error("IOException while sending Error Response: {}", e);
            }
        }
    }
View Full Code Here

            }
            // Create ServerSocket for peers
            ServerSocket peerSS = createServerSocketWithinPortRange();
            if (peerSS == null) {
                logger.info("Insufficient Capacity");
                Message errorResponse = relayAllocationMessage.buildFailureResponse(
                        STUNErrorCode.INSUFFICIENT_CAPACITY, "Insufficient Capacity");
                controlConnectionWriter.writeMessage(errorResponse);
            } else {
                // TODO listener tasks in threadpool, listener also in pool?
                logger.info("Created allocation on {}", peerSS.getLocalSocketAddress());
                SocketListener peerSocketListener = new SocketListener(peerSS, Executors.newCachedThreadPool(),
                        new PeerHandlerTaskFactory(connIDToQueue, controlConnectionWriter, relayExecutor));
                controlConnectionHandlerExecutor.execute(new RefreshMessageHandlerTask(controlConnection,
                        controlConnectionWriter, lifetime, peerSocketListener));
                peerSocketListener.start();
                Message successResponse = relayAllocationMessage.buildSuccessResponse();
                successResponse.addAttribute(new XorMappedAddress(new InetSocketAddress(peerSS.getInetAddress(), peerSS
                        .getLocalPort())));
                successResponse.addAttribute(new EndpointClass(EndpointCategory.RELAY));
                successResponse.addAttribute(new RelayingLifetime(lifetime));
                controlConnectionWriter.writeMessage(successResponse);
            }
        } catch (IOException e) {
            logger.error("IOException while handling allocation request: {}", e);
        }
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.