Exemple #1
0
 public static DebugNode Create(int idx, Interrupters ints, IDatagramEventSocket bindedDgramSock, IPEndPoint bindTcpEp, IPEndPoint bindUdpEp, int gw_port)
 {
     string db_path = string.Format ("db{0}{1}.sqlite", Path.DirectorySeparatorChar, idx);
     ITcpListener listener = new p2pncs.Net.TcpListener ();
     listener.Bind (bindTcpEp);
     listener.ListenStart ();
     return new DebugNode (idx, ints, listener, bindedDgramSock, bindTcpEp, bindUdpEp, gw_port, db_path);
 }
Exemple #2
0
        public void Run()
        {
            _running = true;
            try {
                if (!LoadConfig (_config)) {
                    throw new ConfigFileInitializedException ();
                }

                ushort bindUdp = (ushort)_config.GetValue<int> (ConfigFields.NetBindUdp);
                ushort bindTcp = (ushort)_config.GetValue<int> (ConfigFields.NetBindTcp);
                int gwBindTcp = _config.GetValue<int> (ConfigFields.GwBindTcp);
                _url = string.Format ("http://127.0.0.1:{0}/", gwBindTcp);
                using (IDatagramEventSocket dgramSock = UdpSocket.CreateIPv4 ())
                using (TcpListener listener = new TcpListener ()) {
                    dgramSock.Bind (new IPEndPoint (IPAddress.Any, bindUdp));
                    listener.Bind (new IPEndPoint (IPAddress.Any, bindTcp));
                    listener.ListenStart ();
                    CreateDatabaseConnectionDelegate create_session_db = delegate () {
                        IDbConnection connection = new Mono.Data.Sqlite.SqliteConnection ();
                        connection.ConnectionString = "Data Source=http-session.sqlite,DateTimeFormat=Ticks,Pooling=False";
                        connection.Open ();
                        return connection;
                    };
                    using (Interrupters ints = new Interrupters ())
                    using (Node node = new Node (ints, dgramSock, listener, "database.sqlite", bindUdp, bindTcp))
                    using (WebApp app = new WebApp (node, ints))
                    using (SessionMiddleware mid1 = new SessionMiddleware (create_session_db, app))
                    using (HttpServer.CreateEmbedHttpServer (mid1, null, true, true, _config.GetValue<bool> (ConfigFields.GwBindAny), gwBindTcp, 16)) {
                        InitNodeList initNodeList = new InitNodeList (node.PortOpenChecker);
                        _app = app;
                        _node = node;
                        _startupWaitHandle.Set ();
                        if (Started != null) {
                            try {
                                Started (this, EventArgs.Empty);
                            } catch {}
                        }
                        initNodeList.Load ();
                        app.ExitWaitHandle.WaitOne ();
                        initNodeList.Save ();
                        app.CreateStatisticsXML ().Save ("statistics-" + DateTime.Now.ToString ("yyyyMMddHHmmss") + ".xml");
                        _waitHandle.Set ();
                    }
                }
            } finally {
                _running = false;
                _startupWaitHandle.Set ();
            }
        }