Пример #1
0
        //--------------- SENDING MESSAGES -----------------------------------------

        /**
         * Sends the specified stun message through the specified access point.
         * @param stunMessage the message to send
         * @param apDescriptor the access point to use to send the message
         * @param address the destination of the message.
         * @throws StunException if message encoding fails, ILLEGAL_ARGUMENT if the
         * apDescriptor references an access point that had not been installed,
         * NETWORK_ERROR if an error occurs while sending message bytes through the
         * network socket.
         */
        public virtual void SendMessage(Message stunMessage,
                                        NetAccessPointDescriptor apDescriptor,
                                        StunAddress address)
        {
            byte[]         bytes = stunMessage.Encode();
            NetAccessPoint ap    = (NetAccessPoint)netAccessPoints[apDescriptor];

            if (ap == null)
            {
                throw new StunException(
                          StunException.ILLEGAL_ARGUMENT,
                          "The specified access point had not been installed.");
            }

            try
            {
                ap.SendMessage(bytes, address);
            }
            catch (Exception ex)
            {
                throw new StunException(StunException.NETWORK_ERROR,
                                        "An Exception occurred while sending message bytes "
                                        + "through a network socket!",
                                        ex);
            }
        }
Пример #2
0
        /**
         * Stops and deletes the specified access point.
         * @param apDescriptor the access  point to remove
         */
        public virtual void RemoveNetAccessPoint(NetAccessPointDescriptor apDescriptor)
        {
            NetAccessPoint ap = (NetAccessPoint)netAccessPoints[apDescriptor];

            netAccessPoints.Remove(apDescriptor);

            if (ap != null)
            {
                ap.Stop();
            }
        }
Пример #3
0
        /**
         * Creates and starts a new access point according to the given descriptor.
         * If the specified access point has already been installed the method
         * has no effect.
         *
         * @param apDescriptor   a description of the access point to create.
         * @throws StunException if we fail to create or start the accesspoint.
         */
        public virtual void InstallNetAccessPoint(NetAccessPointDescriptor apDescriptor)
        {
            if (netAccessPoints.ContainsKey(apDescriptor))
            {
                return;
            }

            NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this);

            netAccessPoints[apDescriptor] = ap;

            ap.Start();
        }
Пример #4
0
        /**
         * Clears the faulty thread and tries to repair the damage and instanciate
         * a replacement.
         *
         * @param callingThread the thread where the error occurred.
         * @param message       A description of the error
         * @param error         The error itself
         */
        public void HandleFatalError(Runnable callingThread, String message, Exception error)
        {
            if (callingThread is NetAccessPoint)
            {
                NetAccessPoint ap      = (NetAccessPoint)callingThread;
                bool           running = ap.IsRunning();

                //make sure socket is closed
                RemoveNetAccessPoint(ap.GetDescriptor());

                if (running)
                {
                    try
                    {
                        Console.WriteLine("An access point has unexpectedly "
                                          + "stopped. AP: {0}", ap.ToString());

                        InstallNetAccessPoint(ap.GetDescriptor());
                        /** @todo: log fixing the error*/
                    }
                    catch (StunException ex)
                    {
                        //make sure nothing's left and notify user
                        RemoveNetAccessPoint(ap.GetDescriptor());
                        Console.WriteLine("Failed to relaunch accesspoint: {0} {1} {2}", ap, ex.Message, ex.StackTrace);
                        /** @todo notify user and log */
                    }
                }

                return;
            }
            else if (callingThread is MessageProcessor)
            {
                MessageProcessor mp = (MessageProcessor)callingThread;

                //make sure the guy's dead.
                mp.Stop();
                messageProcessors.Remove(mp);

                mp = new MessageProcessor(messageQueue, messageEventHandler, this);
                mp.Start();
                Console.WriteLine("A message processor has been relaunched because of an error.");
            }
            Console.WriteLine("Error was: {0} {1}", error.Message, error.StackTrace);
        }
Пример #5
0
        /**
         * Creates and starts a new access point based on the specified socket.
         * If the specified access point has already been installed the method
         * has no effect.
         *
         * @param  socket   the socket that the access point should use.
         * @return an access point descriptor to allow further management of the
         * newly created access point.
         * @throws StunException if we fail to create or start the accesspoint.
         */

        public NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient socket)
        {
            //no null check - let it through a null pointer exception
            StunAddress address = new StunAddress(socket.GetAddress().ToString(), socket.GetPort());
            NetAccessPointDescriptor apDescriptor = new NetAccessPointDescriptor(address);

            if (netAccessPoints.ContainsKey(apDescriptor))
            {
                return(apDescriptor);
            }

            NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this);

            //call the useExternalSocket method to avoid closing the socket when
            //removing the accesspoint. Bug Report - Dave Stuart - SipQuest
            ap.UseExternalSocket(socket);
            netAccessPoints[apDescriptor] = (ap);

            ap.Start();

            return(apDescriptor);
        }
Пример #6
0
        /**
         * Creates and starts a new access point based on the specified socket.
         * If the specified access point has already been installed the method
         * has no effect.
         *
         * @param  socket   the socket that the access point should use.
         * @return an access point descriptor to allow further management of the
         * newly created access point.
         * @throws StunException if we fail to create or start the accesspoint.
         */
        public NetAccessPointDescriptor InstallNetAccessPoint(MyUdpClient socket)
        {
            //no null check - let it through a null pointer exception
            StunAddress address = new StunAddress(socket.GetAddress().ToString(), socket.GetPort());
            NetAccessPointDescriptor apDescriptor = new NetAccessPointDescriptor(address);

            if(netAccessPoints.ContainsKey(apDescriptor))
                return apDescriptor;

            NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this);
            //call the useExternalSocket method to avoid closing the socket when
            //removing the accesspoint. Bug Report - Dave Stuart - SipQuest
            ap.UseExternalSocket(socket);
            netAccessPoints[apDescriptor] = (ap);

            ap.Start();

            return apDescriptor;
        }
Пример #7
0
        /**
         * Creates and starts a new access point according to the given descriptor.
         * If the specified access point has already been installed the method
         * has no effect.
         *
         * @param apDescriptor   a description of the access point to create.
         * @throws StunException if we fail to create or start the accesspoint.
         */
        public virtual void InstallNetAccessPoint(NetAccessPointDescriptor apDescriptor)
        {
            if(netAccessPoints.ContainsKey(apDescriptor))
                return;

            NetAccessPoint ap = new NetAccessPoint(apDescriptor, messageQueue, this);
            netAccessPoints[apDescriptor] = ap;

            ap.Start();
        }