private void StartServer(PrivateIdentity myIdentity, string localHostNameOrAddress, int localPort) { onlyClient = false; try { myCert = new X509Certificate2(myIdentity.Pkcs12, "" /* empty password */, X509KeyStorageFlags.Exportable); } catch (Exception e) { Console.Error.WriteLine("Could not import private key. Exception:{0}", e); throw new Exception("Can't start server because private key not decryptable"); } // The `local` parameters override the parameters in // `myIdentity`, unless they're empty or zero. if (localHostNameOrAddress == null || localHostNameOrAddress.Length == 0) { localHostNameOrAddress = myIdentity.HostNameOrAddress; } if (localPort == 0) { localPort = myIdentity.Port; } var address = LookupHostNameOrAddress(localHostNameOrAddress); if (address == null) { Console.Error.WriteLine("ERROR: Could not find any addresses when resolving {0}, which I'm supposed to bind to."); throw new Exception("Can't resolve binding address"); } var myEndpoint = new IPEndPoint(address, localPort); if (verbose) { Console.WriteLine("Starting I/O scheduler as server listening to {0} certified as {1}", myEndpoint, IoScheduler.CertificateToString(myCert)); } sendDispatchThread = new SendDispatchThread(this); Thread st = new Thread(sendDispatchThread.Run); st.Start(); // Start a thread to listen on my binding endpoint. listenerThread = new ListenerThread(this, myEndpoint); Thread lt = new Thread(listenerThread.Run); lt.Start(); }
private void StartClient() { onlyClient = true; myCert = IronfleetCrypto.CreateTransientClientIdentity(); if (verbose) { Console.WriteLine("Starting I/O scheduler as client with certificate {0}", IoScheduler.CertificateToString(myCert)); } sendDispatchThread = new SendDispatchThread(this); Thread st = new Thread(sendDispatchThread.Run); st.Start(); }