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

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


    }

    private void forwardConnectionRequest(final UserData target, final Message connectionRequestFromSource,
            final Socket controlConnectionToSource) throws Exception {
        final Socket toTarget = target.getSocketToUser();
        final Message connectionRequest = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.CONNECTION_REQUEST, connectionRequestFromSource.getHeader().getTransactionId());
        connectionRequest.addAttribute(new HolePunchingAttribute());
        connectionRequest.addAttribute(connectionRequestFromSource.getAttribute(Token.class));
        // public endpoint
        connectionRequest.addAttribute(this.createXorMappedAddressFromSocket(controlConnectionToSource,
                connectionRequest.getHeader().getTransactionId()));
        // private endpoint
        connectionRequest.addAttribute(connectionRequestFromSource.getAttribute(XorMappedAddress.class));
        logger.debug("Forwarding endpoints to target {}", toTarget.toString()); //$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

        return connectedSocket;
    }

    private NATBehavior requestTargetNatBehavior(final String targetId) throws Exception {
        NATBehavior result = new NATBehavior();
        final Message requestMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.NAT_REQUEST);
        requestMessage.addAttribute(new Username(targetId));
        requestMessage.writeTo(this.mediatorConnection.getControlConnection().getOutputStream());
        final MessageReader messageReader = MessageReader
                .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
        final Message response = messageReader.readSTUNMessage(this.mediatorConnection.getControlConnection()
                .getInputStream());
        if (response.hasAttribute(NATBehavior.class)) {
            result = response.getAttribute(NATBehavior.class);
        }
        this.logger.debug("target {} is behind nat {}", targetId, result.toString()); //$NON-NLS-1$
        return result;
    }
View Full Code Here

    }

    private List<NATTraversalTechniqueAttribute> requestSupportedTraversalTechniquesOfTarget(final String targetId)
            throws Exception {
        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.mediatorConnection.getControlConnection().getOutputStream());
        final MessageReader messageReader = MessageReader
                .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
        final Message response = messageReader.readSTUNMessage(this.mediatorConnection.getControlConnection()
                .getInputStream());
        if (response.hasAttribute(NATTraversalTechniqueAttribute.class)) {
            for (final NATTraversalTechniqueAttribute ntta : response
                    .getAttributes(NATTraversalTechniqueAttribute.class)) {
                result.add(ntta);
            }
        } else {
            logger.debug("No supported traversal techniques for {} returned.", targetId);
View Full Code Here

        CompletionService<Socket> complServiceConnEst = null;
        while (true) {
            final Future<Message> waitingResult = complServiceConnReq.poll();
            if (null != waitingResult) {
                try {
                    final Message connRequest = waitingResult.get();
                    final NATTraversalTechnique usedNatTraversalTechnique = this
                            .getUsedTraversalTechniqueFromMessage(connRequest);
                    final ExecutorService estabExecutor = Executors.newSingleThreadExecutor();
                    complServiceConnEst = new ExecutorCompletionService<Socket>(estabExecutor);
                    logger.debug(
View Full Code Here

            this.controlConnection = controlConnection;
        }

        @Override
        public Message call() throws Exception {
            Message result = null;
            final MessageReader messageReader = MessageReader
                    .createMessageReaderWithCustomAttributeTypeDecoder(new NATAttributeTypeDecoder());
            UnsecureTargetSideConnectionEstablishment.this.logger.debug(
                    "waiting for connection request message from {}", this.controlConnection.toString()); //$NON-NLS-1$
            while (this.controlConnection.isConnected()) {
                final Message inMessage = messageReader.readSTUNMessage(this.controlConnection.getInputStream());
                if (inMessage.isMethod(STUNMessageMethod.CONNECTION_REQUEST)) {
                    UnsecureTargetSideConnectionEstablishment.this.logger.debug("Got connection request message"); //$NON-NLS-1$
                    result = inMessage;
                    break;
                }
View Full Code Here

        this.startKeepAlive(targetId, this.getKeepAliveInSeconds());
    }

    private void sendRegisterMessage(final String targetId, final NATBehavior natBehavior,
            final List<NATTraversalTechniqueAttribute> supportedTraversalTechniques) throws Exception {
        final Message registerMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.REGISTER);
        registerMessage.addAttribute(new Username(targetId));
        registerMessage.addAttribute(natBehavior);
        for (final NATTraversalTechniqueAttribute natTraversalTechniqueAttribute : supportedTraversalTechniques) {
            registerMessage.addAttribute(natTraversalTechniqueAttribute);
        }
        registerMessage.writeTo(this.controlConnection.getOutputStream());
    }
View Full Code Here

        }
        registerMessage.writeTo(this.controlConnection.getOutputStream());
    }

    private void waitForDeRegisterResponseMessage() throws Exception {
        final Message response = this.messageReader.readSTUNMessage(this.controlConnection.getInputStream());
        if (response.isSuccessResponse()) {
            this.logger.debug("Target successfully (de)registered"); //$NON-NLS-1$
        } else {
            final ErrorCode errorCode = response.getAttribute(ErrorCode.class);
            final String errorMessage = "Could not (de)register target: " + errorCode.getErrorNumber() + " " + errorCode.getReasonPhrase(); //$NON-NLS-1$ //$NON-NLS-2$
            throw new Exception(errorMessage);
        }
    }
View Full Code Here

        this.waitForDeRegisterResponseMessage();
        this.keepAliveExecutor.shutdownNow();
    }

    private void sendDeregisterMesage(final String targetId) throws Exception {
        final Message deregisterMessage = MessageStaticFactory.newSTUNMessageInstance(STUNMessageClass.REQUEST,
                STUNMessageMethod.DEREGISTER);
        deregisterMessage.addAttribute(new Username(targetId));
        deregisterMessage.writeTo(this.controlConnection.getOutputStream());
    }
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();
        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.