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

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


     */
    public List<NATTraversalTechniqueAttribute> requestSupportedTraversalTechniques(final String targetId)
            throws Exception {
        this.logger.debug("Requesting supported nat traversal techniques of {}", targetId); //$NON-NLS-1$
        final List<NATTraversalTechniqueAttribute> result = new ArrayList<NATTraversalTechniqueAttribute>();
        final Message requestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.SUPPORTED_TRAV_TECHS_REQUEST);
        requestMessage.addAttribute(new Username(targetId));
        requestMessage.writeTo(this.controlConnection.getOutputStream());
        final Message response = this.messageReader.readSTUNMessage(this.controlConnection.getInputStream());
        for (final NATTraversalTechniqueAttribute suppTravTech : response
                .getAttributes(NATTraversalTechniqueAttribute.class)) {
            result.add(suppTravTech);
            this.logger.debug("User {} supports traversal technique {}", targetId, suppTravTech.getEncoded()); //$NON-NLS-1$
        }
        return Collections.unmodifiableList(result);
View Full Code Here


        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }

    private void forwardReversalRequestToTarget(final Socket toSource, final UserData user,
            final Message connectionRequestFromSource) throws IOException {
        final Message connectionRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST, connectionRequestFromSource.getHeader().getTransactionId());
        XorMappedAddress clientAddress;
        if (toSource.getInetAddress() instanceof Inet6Address) {
            clientAddress = new XorMappedAddress(new InetSocketAddress(toSource.getInetAddress(), toSource.getPort()),
                    ByteBuffer.wrap(connectionRequest.getHeader().getTransactionId()).getInt());
        } else {
            clientAddress = new XorMappedAddress(new InetSocketAddress(toSource.getInetAddress(), toSource.getPort()));
        }
        connectionRequest.addAttribute(clientAddress);
        connectionRequest.addAttribute(new EndpointClass(EndpointCategory.PUBLIC));
        connectionRequest.addAttribute(new ReversalAttribute());
        final Socket toTarget = user.getSocketToUser();
        connectionRequest.writeTo(toTarget.getOutputStream());
    }
View Full Code Here

    public NATFeatureRealization executeTest() {
        NATFeatureRealization result = NATFeatureRealization.DONT_CARE;
        Socket toStunServer = null;
        try {
            toStunServer = this.createConnectedSocket(this.primaryStunServerAddress);
            final Message responseTestI = this.executeTestI(toStunServer);
            if (responseTestI.hasAttribute(OtherAddress.class)) {
                try {
                    final Message responseTestII = this.executeTestII(toStunServer);
                    if (responseTestII.hasAttribute(XorMappedAddress.class)) {
                        result = NATFeatureRealization.ENDPOINT_INDEPENDENT;
                    }
                } catch (final SocketTimeoutException eII) {
                    try {
                        final Message responseTestIII = this.executeTestIII(toStunServer);
                        if (responseTestIII.hasAttribute(XorMappedAddress.class)) {
                            result = NATFeatureRealization.ADDRESS_DEPENDENT;
                        }
                    } catch (final SocketTimeoutException eIII) {
                        try {
                            final Message reponseIV = this.executeTestForConnectionDependent(toStunServer);
                            if (reponseIV.hasAttribute(XorMappedAddress.class)) {
                                result = NATFeatureRealization.ADDRESS_AND_PORT_DEPENDENT;
                            }
                        } catch (final SocketTimeoutException eIV) {
                            result = NATFeatureRealization.CONNECTION_DEPENDENT;
                        }
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

        }
        return result;
    }

    private Message executeTestI(final Socket toStunServer) throws IOException {
        final Message bindingRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.BINDING);
        bindingRequest.writeTo(toStunServer.getOutputStream());
        final Message bindingResponse = this.messageReader.readSTUNMessage(toStunServer.getInputStream());
        return bindingResponse;
    }
View Full Code Here

        return bindingResponse;
    }

    private Message executeTestII(final Socket toStunServer) throws IOException {
        this.sendIndicationWithChangeRequestAttribute(ChangeRequest.CHANGE_IP_AND_PORT, toStunServer);
        final Message receivedMessage = this.receiveMessageFromStunServer();
        return receivedMessage;
    }
View Full Code Here

        return receivedMessage;
    }

    private Message executeTestIII(final Socket toStunServer) throws IOException {
        this.sendIndicationWithChangeRequestAttribute(ChangeRequest.CHANGE_PORT, toStunServer);
        final Message response = this.receiveMessageFromStunServer();
        return response;
    }
View Full Code Here

        return response;
    }

    private Message executeTestForConnectionDependent(final Socket toStunServer) throws IOException {
        this.sendIndicationWithChangeRequestAttribute(ChangeRequest.FLAGS_NOT_SET, toStunServer);
        final Message receivedMessage = this.receiveMessageFromStunServer();
        return receivedMessage;
    }
View Full Code Here

    }

    private void sendIndicationWithChangeRequestAttribute(final int changeRequestFlag, final Socket sendSocket)
            throws IOException {
        logger.debug("Sending indication with change request flag = {}", changeRequestFlag); //$NON-NLS-1$
        final Message indication = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.INDICATION,
                STUNMessageMethod.BINDING);
        indication.addAttribute(new ChangeRequest(changeRequestFlag));
        indication.writeTo(sendSocket.getOutputStream());
    }
View Full Code Here

    }

    private Message receiveMessageFromStunServer() throws IOException {
        final ServerSocket serverSocket = this.createBoundServerSocket();
        final Socket socket = serverSocket.accept();
        final Message receivedMessage = this.messageReader.readSTUNMessage(socket.getInputStream());
        serverSocket.close();
        socket.close();
        return receivedMessage;
    }
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.