Beispiel #1
0
        /// <summary>
        /// 获取 需要背书的节点
        /// </summary>
        /// <param name="ChannelId"></param>
        /// <param name="chainCode"></param>
        /// <returns></returns>
        public List <IPeer> GetEndorsePeer(Chaincode chainCode)
        {
            _logger.LogInformation("获取背书需要的节点");

            var list = new List <IPeer>();
            //如果是其他 获取最新配置
            var channelconfig = _dataManager.GetChannelConfig();
            //获取链码名称的背书策略
            var chaincodeConfig = channelconfig.ChainCodeConfigs.Where(p => p.Name == chainCode.Name).FirstOrDefault();

            foreach (var item in chaincodeConfig.Policy.OrgIds)
            {
                var org  = channelconfig.OrgConfigs.Where(p => p.OrgId == item).FirstOrDefault();
                var peer = _peersprovider.Get(org.Address);
                list.Add(peer);
            }
            return(list);
        }
Beispiel #2
0
 public Node(
     IFiniteStateMachine fsm,
     ILog log,
     ISettings settings,
     IPeersProvider peersProvider)
 {
     //dont think rules should be injected at the moment..EEK UNCLE BOB
     _rules         = new Rules();
     _fsm           = fsm;
     _log           = log;
     _random        = new RandomDelay();
     _settings      = settings;
     _peersProvider = peersProvider;
     _getPeers      = state => {
         var peers = _peersProvider.Get();
         var peersThatAreNotThisServer = peers.Where(p => p?.Id != state.Id).ToList();
         return(peersThatAreNotThisServer);
     };
 }
Beispiel #3
0
 public Node(
     IFiniteStateMachine fsm,
     ILog log,
     ISettings settings,
     IPeersProvider peersProvider,
     ILoggerFactory loggerFactory)
 {
     _loggerFactory = loggerFactory;
     _logger        = _loggerFactory.CreateLogger <Node>();
     _fsm           = fsm;
     _log           = log;
     _random        = new RandomDelay();
     _settings      = settings;
     _peersProvider = peersProvider;
     _getPeers      = state => {
         var peers = _peersProvider.Get();
         var peersThatAreNotThisServer = peers.Where(p => p?.Id != state.Id).ToList();
         return(peersThatAreNotThisServer);
     };
 }
Beispiel #4
0
        /// <summary>
        /// Join joins a node, identified by id and located at addr, to this store.
        /// The node must be ready to respond to Raft communications at that address.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="addr"></param>
        /// <param name="metadata"></param>
        public void Join(string id, string addr, IDictionary <string, string> metadata)
        {
            logger.LogInformation($"received request to join node at {addr}");
            if (!IsLeader)
            {
                throw new NotLeaderException();
            }

            // If a node already exists with either the joining node's ID or address,
            // that node may need to be removed from the config first.
            var srv = Nodes.SingleOrDefault(s => s.Id == id || s.Addr == addr);

            if (srv != null)
            {
                // However if *both* the ID and the address are the same, the no
                // join is actually needed.
                if (srv.Addr == addr && srv.Id == id)
                {
                    logger.LogInformation($"node {id} at {addr} already member of cluster, ignoring join request");
                    return;
                }
                try
                {
                    remove(id);
                }
                catch (Exception ex)
                {
                    logger.LogError($"failed to remove node: {ex}");
                    throw;
                }
            }

            raftPeers.Get().Add(new Server {
                Id = id, Addr = addr
            });
            setMetadata(id, metadata);
            logger.LogInformation($"node at {addr} joined successfully");
        }
Beispiel #5
0
 public List <IPeer> GetAllPeer()
 {
     return(_peersProvider.Get());
 }