示例#1
0
        public void Shutdown(bool force)
        {
            if (IS_TRACE_LEVEL)
            {
                logger.Trace("%s shutdown called force: %b, shutdown: %b, managedChannel: %s");
            }
            if (shutdown)
            {
                return;
            }

            shutdown = true;
            Channel lchannel = managedChannel;

            // let all referenced resource finalize
            managedChannel = null;
            ecl            = null;
            dfs            = null;
            if (lchannel == null)
            {
                return;
            }

            if (force)
            {
                try
                {
                    lchannel.ShutdownAsync().Wait();
                }
                catch (Exception e)
                {
                    logger.WarnException(e.Message, e);
                }
            }
            else
            {
                bool isTerminated = false;

                try
                {
                    isTerminated = lchannel.ShutdownAsync().Wait(3 * 1000);
                }
                catch (Exception e)
                {
                    logger.DebugException(e.Message, e); //best effort
                }

                if (!isTerminated)
                {
                    try
                    {
                        lchannel.ShutdownAsync().Wait();
                    }
                    catch (Exception e)
                    {
                        logger.WarnException(e.Message, e);
                    }
                }
            }
        }
示例#2
0
 /**
  * Construct client for accessing Peer server using the existing channel.
  *
  * @param channelBuilder The ChannelBuilder to build the endorser client
  */
 public EndorserClient(string channelName, string name, Endpoint endpoint)
 {
     managedChannel = endpoint.BuildChannel();
     ecl            = new Endorser.EndorserClient(managedChannel);
     dfs            = new Protos.Discovery.Discovery.DiscoveryClient(managedChannel);
     toString       = $"EndorserClient{{id: {Config.Instance.GetNextID()}, channel: {channelName}, name:{name}, url: {endpoint.Url}}}";
     logger.Trace("Created " + this);
 }
示例#3
0
        public void SelfSignedTLSCertTest()
        {
            bool   handshakeOccured = false;
            Server sv = new Server();
            TLSCertificateKeyPair serverCert  = TLSCertificateKeyPair.CreateServerCert("localhost");
            TLSCertificateKeyPair clientCert  = TLSCertificateKeyPair.CreateClientCert();
            KeyCertificatePair    pair        = new KeyCertificatePair(serverCert.CertPEMBytes.ToUTF8String(), serverCert.KeyPEMBytes.ToUTF8String());
            ServerCredentials     credentials = new SslServerCredentials(new[] { pair }, clientCert.CertPEMBytes.ToUTF8String(), true);

            sv.Ports.Add(new ServerPort("localhost", 0, credentials));
            sv.Services.Add(Endorser.BindService(new MockEndorser()).Intercept(new MultalTLSInterceptor(clientCert.CertPEMBytes, (b) => handshakeOccured = b)));
            sv.Start();
            int port = sv.Ports.First().BoundPort;
            ChannelCredentials cred = new SslCredentials(serverCert.CertPEMBytes.ToUTF8String(), new KeyCertificatePair(clientCert.CertPEMBytes.ToUTF8String(), clientCert.KeyPEMBytes.ToUTF8String()));
            Channel            chan = new Channel("localhost", port, cred);
            SignedProposal     prop = new SignedProposal();

            Endorser.EndorserClient cl = new Endorser.EndorserClient(chan);
            cl.ProcessProposal(prop);
            Assert.IsTrue(handshakeOccured, "Handshake didn't occur");
            chan.ShutdownAsync().RunAndUnwrap();
            sv.ShutdownAsync().RunAndUnwrap();
        }