Beispiel #1
0
        public virtual async Task <Peer> AddAsync(Properties config, CancellationToken token = default(CancellationToken))
        {
            Properties properties     = new Properties();
            string     protocol       = this.FindClientProp(config, "protocol", "grpcs:");
            string     clientCertFile = this.FindClientProp(config, "clientCertFile", null);
            Peer       peer           = EndpointMap.GetOrNull(Endpoint); // maybe there already.

            if (null != peer)
            {
                return(peer);
            }
            if (null != clientCertFile)
            {
                properties.Set("clientCertFile", clientCertFile);
            }
            string clientKeyFile = this.FindClientProp(config, "clientKeyFile", null);

            if (null != clientKeyFile)
            {
                properties.Set("clientKeyFile", clientKeyFile);
            }
            string clientCertBytes = this.FindClientProp(config, "clientCertBytes", null);

            if (null != clientCertBytes)
            {
                properties.Set("clientCertBytes", clientCertBytes);
            }
            string clientKeyBytes = this.FindClientProp(config, "clientKeyBytes", null);

            if (null != clientKeyBytes)
            {
                properties.Set("clientKeyBytes", clientKeyBytes);
            }
            string hostnameOverride = this.FindClientProp(config, "hostnameOverride", null);

            if (null != hostnameOverride)
            {
                properties.Set("hostnameOverride", hostnameOverride);
            }
            byte[] pemBytes = this.GetAllTLSCerts();
            if (pemBytes?.Length > 0)
            {
                properties.Set("pemBytes", pemBytes);
            }
            peer = Client.NewPeer(Endpoint, protocol + "//" + Endpoint, properties);
            PeerOptions opts = PeerOptions.CreatePeerOptions();

            opts.SetPeerRoles(PeerRole.ENDORSING_PEER, PeerRole.EVENT_SOURCE, PeerRole.LEDGER_QUERY, PeerRole.CHAINCODE_QUERY);
            await Channel.AddPeerAsync(peer, opts, token).ConfigureAwait(false);

            return(peer);
        }
Beispiel #2
0
        private Config()
        {
            string fullpath = Environment.GetEnvironmentVariable(ORG_HYPERLEDGER_FABRIC_SDK_CONFIGURATION);

            if (string.IsNullOrEmpty(fullpath))
            {
                fullpath = Path.Combine(Directory.GetCurrentDirectory(), DEFAULT_CONFIG);
            }
            bool exists = File.Exists(fullpath);

            try
            {
                sdkProperties = new Properties();
                logger.Debug($"Loading configuration from {fullpath} and it is present: {exists}");
                sdkProperties.Load(fullpath);
            }
            catch (Exception)
            {
                logger.Warn($"Failed to load any configuration from: {fullpath}. Using toolkit defaults");
            }
            finally
            {
                // Default values

                /**
                 * Timeout settings
                 **/
                DefaultProperty(PROPOSAL_WAIT_TIME, "30000");
                DefaultProperty(CHANNEL_CONFIG_WAIT_TIME, "15000");
                DefaultProperty(ORDERER_RETRY_WAIT_TIME, "200");
                DefaultProperty(ORDERER_WAIT_TIME, "10000");
                DefaultProperty(PEER_EVENT_REGISTRATION_WAIT_TIME, "5000");
                DefaultProperty(PEER_EVENT_RETRY_WAIT_TIME, "500");
                DefaultProperty(EVENTHUB_CONNECTION_WAIT_TIME, "5000");
                DefaultProperty(GENESISBLOCK_WAIT_TIME, "5000");

                /**
                 * This will NOT complete any transaction futures time out and must be kept WELL above any expected future timeout
                 * for transactions sent to the Orderer. For internal cleanup only.
                 */

                DefaultProperty(TRANSACTION_CLEANUP_UP_TIMEOUT_WAIT_TIME, "600000"); //10 min.

                /**
                 * Crypto configuration settings
                 **/
                DefaultProperty(DEFAULT_CRYPTO_SUITE_FACTORY, "org.hyperledger.fabric.sdk.security.HLSDKJCryptoSuiteFactory");
                DefaultProperty(SECURITY_LEVEL, "256");
                DefaultProperty(SECURITY_CURVE_MAPPING, "256=secp256r1:384=secp384r1");
                DefaultProperty(HASH_ALGORITHM, "SHA2");
                DefaultProperty(ASYMMETRIC_KEY_TYPE, "EC");

                DefaultProperty(CERTIFICATE_FORMAT, "X.509");
                DefaultProperty(SIGNATURE_ALGORITHM, "SHA256withECDSA");

                /**
                 * Connection defaults
                 */

                DefaultProperty(CONN_SSL_PROVIDER, "openSSL");
                DefaultProperty(CONN_SSL_NEGTYPE, "TLS");

                /**
                 * Default HFClient thread executor settings.
                 */

                DefaultProperty(CLIENT_THREAD_EXECUTOR_COREPOOLSIZE, "0");
                DefaultProperty(CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE, "" + int.MaxValue);
                DefaultProperty(CLIENT_THREAD_EXECUTOR_KEEPALIVETIME, "" + "60");
                DefaultProperty(CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT, "SECONDS");

                /**
                 * Logging settings
                 **/
                DefaultProperty(MAX_LOG_STRING_LENGTH, "64");
                DefaultProperty(EXTRALOGLEVEL, "0");
                DefaultProperty(LOGGERLEVEL, null);
                DefaultProperty(DIAGNOTISTIC_FILE_DIRECTORY, null);

                /**
                 * Miscellaneous settings
                 */
                DefaultProperty(PROPOSAL_CONSISTENCY_VALIDATION, "true");
                DefaultProperty(EVENTHUB_RECONNECTION_WARNING_RATE, "50");
                DefaultProperty(PEER_EVENT_RECONNECTION_WARNING_RATE, "50");
                DefaultProperty(SERVICE_DISCOVER_FREQ_SECONDS, "120");
                DefaultProperty(SERVICE_DISCOVER_WAIT_TIME, "5000");


                //LOGGERLEVEL DO NOT WORK WITH Abstract LibLog
                //string inLogLevel = sdkProperties.Get(LOGGERLEVEL);

                /*
                 * if (inLogLevel!=null)
                 * {
                 *  LogLevel setTo=LogLevel.Fatal;
                 *  switch (inLogLevel.ToUpperInvariant())
                 *  {
                 *
                 *      case "TRACE":
                 *          setTo = LogLevel.Trace;
                 *          break;
                 *
                 *      case "DEBUG":
                 *          setTo = LogLevel.Debug;
                 *          break;
                 *
                 *      case "INFO":
                 *          setTo = LogLevel.Info;
                 *          break;
                 *
                 *      case "WARN":
                 *          setTo = LogLevel.Warn;
                 *          break;
                 *
                 *      case "ERROR":
                 *          setTo = LogLevel.Error;
                 *          break;
                 *
                 *      default:
                 *          setTo = LogLevel.Info;
                 *          break;
                 *
                 *  }
                 *
                 *  if (setTo!=LogLevel.Fatal)
                 *  {
                 *
                 *  }
                 *
                 * }
                 */
            }
        }