Package de.fhkn.in.uce.stun.attribute

Examples of de.fhkn.in.uce.stun.attribute.XorMappedAddress


    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


    /**
     * Private method for handling connection requests.
     */
    private void handleConnectionRequestMessage(final Message connectionRequestMessage) {
        final XorMappedAddress targetAddress = connectionRequestMessage.getAttribute(XorMappedAddress.class);
        logger.info("ConnectionRequest message from {} with id {}", targetAddress.getEndpoint().toString(), //$NON-NLS-1$
                connectionRequestMessage.getTransactionId());
        try {
            final String hostName = targetAddress.getEndpoint().getHostName();
            final int portNumber = targetAddress.getEndpoint().getPort();
            logger.info("create socket connection to {}:{}", hostName, portNumber); //$NON-NLS-1$
            final Socket socket = new Socket();
            socket.setReuseAddress(true);
            socket.connect(new InetSocketAddress(hostName, portNumber));
            this.blockingSocketQueue.add(socket);
View Full Code Here

                        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);
            }
View Full Code Here

    private InetSocketAddress processConnectionRequestResponse(final Socket controlConnection) throws Exception {
        InetSocketAddress result;
        final MessageReader messageReader = MessageReader.createMessageReader();
        final Message responseMessage = messageReader.readSTUNMessage(controlConnection.getInputStream());
        if (responseMessage.hasAttribute(XorMappedAddress.class)) {
            final XorMappedAddress xorMappedAddress = responseMessage.getAttribute(XorMappedAddress.class);
            result = xorMappedAddress.getEndpoint();
        } else {
            throw new Exception("The target endpoint is not returned by the mediator"); //$NON-NLS-1$
        }
        return result;
    }
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();
        final XorMappedAddress endpointAtRelay = message.getAttribute(XorMappedAddress.class);
        successResponse.addAttribute(endpointAtRelay);
        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }
View Full Code Here

                "Got connection request from list with transactionId={}", String.valueOf(connReq.getConnectionRequestMessage().getHeader().getTransactionId())); //$NON-NLS-1$
        final Message successResponse = connReq.getConnectionRequestMessage().buildSuccessResponse();
        final InetSocketAddress targetEndpoint = new InetSocketAddress(controlConnection.getInetAddress(),
                controlConnection.getPort());
        logger.debug("Sending connection request response with {} to source", targetEndpoint.toString()); //$NON-NLS-1$
        successResponse.addAttribute(new XorMappedAddress(targetEndpoint));
        successResponse.addAttribute(new EndpointClass(EndpointCategory.PUBLIC));
        successResponse.writeTo(connReq.getControlConnection().getOutputStream());
    }
View Full Code Here

        final Message failureResponse = message.buildFailureResponse(errorCode, errorReaon);
        failureResponse.writeTo(out);
    }

    private XorMappedAddress createXorMappedAddressFromSocket(final Socket socket, final byte[] transactionid) {
        XorMappedAddress result;
        if (socket.getInetAddress() instanceof Inet6Address) {
            result = new XorMappedAddress(new InetSocketAddress(socket.getInetAddress(), socket.getPort()), ByteBuffer
                    .wrap(transactionid).getInt());
        } else {
            result = new XorMappedAddress(new InetSocketAddress(socket.getInetAddress(), socket.getPort()));
        }
        return result;
    }
View Full Code Here

    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();
View Full Code Here

    private void handleSimpleBindingRequest(final Message toHandle) throws Exception {
        final Message response = toHandle.buildSuccessResponse();
        final OtherAddress otherAddress = new OtherAddress(this.secondaryAddress);
        response.addAttribute(otherAddress);
        final XorMappedAddress clientAddress = this.getPublicClientAddressAsAttribute(toHandle);
        response.addAttribute(clientAddress);
        response.writeTo(this.socket.getOutputStream());
    }
View Full Code Here

        return this.socket.getLocalAddress().equals(this.primaryAddress.getAddress())
                && this.socket.getLocalPort() == this.primaryAddress.getPort();
    }

    private XorMappedAddress getPublicClientAddressAsAttribute(final Message message) {
        XorMappedAddress clientAddress;
        final InetSocketAddress publicClientAddress = new InetSocketAddress(this.socket.getInetAddress(),
                this.socket.getPort());
        if (publicClientAddress.getAddress() instanceof Inet4Address) {
            clientAddress = new XorMappedAddress(publicClientAddress);
        } else {
            clientAddress = new XorMappedAddress(publicClientAddress, ByteBuffer.wrap(
                    message.getHeader().getTransactionId()).getInt());
        }
        return clientAddress;
    }
View Full Code Here

TOP

Related Classes of de.fhkn.in.uce.stun.attribute.XorMappedAddress

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.