public void deregisterEavesDropper(string target, ClientConnection eavesdropper)
 {
     mutex.WaitOne();
     ArrayList list = (ArrayList)eavesDroppers[target];
     if (list != null)
     {
         list.Remove(eavesdropper);
     }
     mutex.ReleaseMutex();
 }
 /**
  * Removes the designated eavesdropper from all lists
  */
 public void deregisterAllEavesDroppers(ClientConnection eavesdropper)
 {
     mutex.WaitOne();
     IDictionaryEnumerator e = eavesDroppers.GetEnumerator();
     while (e.MoveNext())
     {
         ((ArrayList)(e.Current)).Remove(eavesdropper);
     }
     mutex.ReleaseMutex();
 }
 /**
  * Register an eavesdropper connection for a desigated target
  */
 public void registerEavesDropper(string target, ClientConnection eavesdropper)
 {
     mutex.WaitOne();
     ArrayList targetEavesDroppers = (ArrayList)eavesDroppers[target];
     if (targetEavesDroppers == null)
     {
         targetEavesDroppers = new ArrayList();
         eavesDroppers[target] = targetEavesDroppers;
     }
     targetEavesDroppers.Add(eavesdropper);
     mutex.ReleaseMutex();
 }
 public void registerGlobalEavesDropper(ClientConnection eavesdropper)
 {
     mutex.WaitOne();
     globalEavesDroppers.Add(eavesdropper);
     mutex.ReleaseMutex();
 }
 public void registerListener(ClientConnection cc)
 {
     listeners.Add(cc);
 }
 public void deregisterListener(ClientConnection cc)
 {
     listeners.Remove(cc);
 }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            bool use_block_read = false;
            for (int i=0; i<args.Length; i++)
            {
                if (args[i].Equals("-b"))
                {
                    use_block_read = true;
                    Context.getInstance().getLogger().forceLog("Block-read enabled.");
                }
                if (args[i].Equals("-i"))
                {
                    Logger logger = Context.getInstance().getLogger();
                    logger.CurrentLevel = Logger.LEVEL_INFO;
                    logger.enable();
                    Context.getInstance().getLogger().forceLog("Debugging Enabled at level INFO");
                }
                if (args[i].Equals("-w"))
                {
                    Logger logger = Context.getInstance().getLogger();
                    logger.CurrentLevel = Logger.LEVEL_WARN;
                    logger.enable();
                    Context.getInstance().getLogger().forceLog("Debugging Enabled at level WARN");
                }
                if (args[i].Equals("-d"))
                {
                    Logger logger = Context.getInstance().getLogger();
                    logger.CurrentLevel = Logger.LEVEL_DEBUG;
                    logger.enable();
                    Context.getInstance().getLogger().forceLog("Debugging Enabled at level DEBUG");
                }
                if (args[i].Equals("-s"))
                {
                    Logger logger = Context.getInstance().getLogger();
                    logger.CurrentLevel = Logger.LEVEL_SHOUT;
                    logger.enable();
                    Context.getInstance().getLogger().forceLog("Debugging Enabled at level SHOUT");
                }
                if (args[i].Equals("-r"))
                {
                    Context.getInstance().setAllowDuplicateConnections(false);
                    Context.getInstance().getLogger().forceLog("Disabling duplicate connections");
                }
                if (args[i].Equals("-e"))
                {
                    Context.getInstance().enableEavesDropping();
                    Context.getInstance().getLogger().forceLog("Eavesdropping enabled");
                }
                if (args[i].Equals("-m"))
                {
                    Context.getInstance().enableErrorMessages();
                    Context.getInstance().getLogger().forceLog("error messages enabled");
                }
                if (args[i].IndexOf("-l=") != -1)
                {
                    Context.getInstance().getLogger().setLogFilePath(args[i].Substring(3));
                }
                if (args[i].Equals("-g"))
                {
                    Context.getInstance().getLogger().disable();
                    System.Console.WriteLine("Logging disabled");
                }
                if (args[i].Equals("-l="))
                {
                    Context.getInstance().getLogger().setLogFilePath(args[i].Substring(3));
                    Context.getInstance().logToFile();
                    Context.getInstance().getLogger().forceLog("Log File Set: " + args[i].Substring(3));
                }
                if (args[i].Equals("-q="))
                {
                    int val = Int32.Parse(args[i].Substring(3));
                    if (val > 0)
                    {
                        Context.getInstance().setMaxSendQueueSize(val);
                        Context.getInstance().getLogger().forceLog("Max send queue size set to: " + val);
                    }
                    else
                    {
                        Context.getInstance().getLogger().forceLog("Max send queue size option must be specified");
                        return;
                    }
                }
                if (args[i].Equals("-o"))
                {
                    Context.getInstance().logToStdOut();
                    System.Console.WriteLine("logging to stdout");
                }
                if (args[i].Equals("-c"))
                {
                    Context.getInstance().setSyncSend(true);
                    Context.getInstance().getLogger().forceLog("Synchronous sending enabled");
                }
                if (args[i].Equals("-f"))
                {
                    Context.getInstance().enableStatLogging();
                    Context.getInstance().getLogger().forceLog("Stastics logging enabled");
                }
                if (args[i].Equals("-h"))
                {
                    System.Console.WriteLine("Options are:");
                    System.Console.WriteLine("   -b Block Read enabled");
                    System.Console.WriteLine("   -i Info-level logging enabled");
                    System.Console.WriteLine("   -w Warn-level logging enabled");
                    System.Console.WriteLine("   -d Debug-level logging enabled");
                    System.Console.WriteLine("   -s Shout-level logging enabled");
                    System.Console.WriteLine("   -r Refuse duplicate connections");
                    System.Console.WriteLine("   -e Enable eavesdropping");
                    System.Console.WriteLine("   -m Enable error messages");
                    System.Console.WriteLine("   -l=<path> Set path to log file");
                    System.Console.WriteLine("   -q=<value> Set the max size fo the send queues");
                    System.Console.WriteLine("   -g disable logging");
                    System.Console.WriteLine("   -o log to stdout");
                    System.Console.WriteLine("   -c use syncrhonous sending");
                    System.Console.WriteLine("   -h This help message");

                    return;
                }
            }

            try
            {
                Context.getInstance().getLogger().forceLog("MessageRouter Started");

                Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                server.Bind(new IPEndPoint(IPAddress.Any, 6667));
                server.Listen(30);
                while (true)
                {
                    Socket serverSocket = server.Accept();
                    ClientConnection cc = new ClientConnection(serverSocket, use_block_read);
                    cc.start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Context.getInstance().getLogger().log("System exiting due to exception: " + ex.Message, Logger.LEVEL_DEBUG);
            }
        }
 public void registerConnection(ClientConnection cc, string name)
 {
     map[name] = cc;
 }