예제 #1
0
        /**
         * Called to notify this provider for an incoming message.
         * @param event the event object that contains the new message.
         */
        public virtual void HandleMessageEvent(StunMessageEvent @event)
        {
            Message msg = @event.GetMessage();

            //request
            if (msg is Request)
            {
                TransactionID serverTid = TransactionID.
                                          CreateTransactionID(msg.GetTransactionID());

                serverTransactions.Add(serverTid);
                if (requestListener != null)
                {
                    requestListener.requestReceived(@event);
                }
            }
            //response
            else if (msg is Response)
            {
                TransactionID tid = TransactionID.
                                    CreateTransactionID(msg.GetTransactionID());

                StunClientTransaction tran = (StunClientTransaction)clientTransactions[tid];
                clientTransactions.Remove(tid);

                if (tran != null)
                {
                    tran.HandleResponse(@event);
                }
                else
                {
                    //do nothing - just drop the phantom response.
                }
            }
        }
예제 #2
0
        /**
         * Creates a client transaction
         * @param providerCallback the provider that created us.
         * @param request the request that we are living for.
         * @param requestDestination the destination of the request.
         * @param apDescriptor the access point through which we are supposed to
         * @param responseCollector the instance that should receive this request's
         * response.
         * retransmit.
         */
        public StunClientTransaction(StunProvider providerCallback,
                                     Request request,
                                     StunAddress requestDestination,
                                     NetAccessPointDescriptor apDescriptor,
                                     ResponseCollector responseCollector)
        {
            this.providerCallback   = providerCallback;
            this.request            = request;
            this.apDescriptor       = apDescriptor;
            this.responseCollector  = responseCollector;
            this.requestDestination = requestDestination;

            this.transactionID = TransactionID.CreateTransactionID();

            request.SetTransactionID(transactionID.GetTransactionID());

            runningThread = new Thread(new ThreadStart(this.Run));
        }
예제 #3
0
        /**
         * Sends the specified response message through the specified access point.
         *
         * @param transactionID the id of the transaction to use when sending the
         *    response. Actually we are getting kind of redundant here as we already
         *    have the id in the response object, but I am bringing out as an extra
         *    parameter as the user might otherwise forget to explicitly set it.
         * @param response      the message to send.
         * @param sendThrough   the access point to use when sending the message.
         * @param sendTo        the destination of the message.
         * @throws StunException TRANSACTION_DOES_NOT_EXIST if the response message
         * has an invalid transaction id. <br/>
         * ILLEGAL_STATE if the stun stack is not started. <br/>
         * ILLEGAL_ARGUMENT if the apDescriptor references an access point that had
         * not been installed <br/>
         * NETWORK_ERROR if an error occurs while sending message bytes through the
         * network socket. <br/>
         */
        public virtual void SendResponse(byte[]                   transactionID,
                                         Response response,
                                         NetAccessPointDescriptor sendThrough,
                                         StunAddress sendTo)
        {
            stunStack.CheckStarted();

            TransactionID tid = TransactionID.CreateTransactionID(transactionID);


            serverTransactions.Remove(tid);
#if false
            throw new StunException(StunException.TRANSACTION_DOES_NOT_EXIST,
                                    "The trensaction specified in the response "
                                    + "object does not exist.");
#endif

            response.SetTransactionID(transactionID);
            GetNetAccessManager().SendMessage(response, sendThrough, sendTo);
        }