initBPNodeIDs initializes BlockProducer route and map from config file and DNS Seed.
()
| 121 | |
| 122 | // initBPNodeIDs initializes BlockProducer route and map from config file and DNS Seed. |
| 123 | func initBPNodeIDs() (bpNodeIDs NodeIDAddressMap) { |
| 124 | if conf.GConf == nil { |
| 125 | log.Fatal("call conf.LoadConfig to init conf first") |
| 126 | } |
| 127 | |
| 128 | // clear address map before init |
| 129 | resolver.bpNodeIDs = make(NodeIDAddressMap) |
| 130 | bpNodeIDs = resolver.bpNodeIDs |
| 131 | |
| 132 | var err error |
| 133 | |
| 134 | if conf.GConf.DNSSeed.Domain != "" { |
| 135 | var bpIndex int |
| 136 | dc := IPv6SeedClient{} |
| 137 | bpIndex = rand.Intn(conf.GConf.DNSSeed.BPCount) |
| 138 | bpDomain := fmt.Sprintf("bp%02d.%s", bpIndex, conf.GConf.DNSSeed.Domain) |
| 139 | log.Infof("Geting bp address from dns: %v", bpDomain) |
| 140 | resolver.bpNodes, err = dc.GetBPFromDNSSeed(bpDomain) |
| 141 | if err != nil { |
| 142 | log.WithField("seed", bpDomain).WithError(err).Error( |
| 143 | "getting BP info from DNS failed") |
| 144 | return |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | if resolver.bpNodes == nil { |
| 149 | resolver.bpNodes = make(IDNodeMap) |
| 150 | } |
| 151 | if conf.GConf.KnownNodes != nil { |
| 152 | for _, n := range conf.GConf.KnownNodes { |
| 153 | rawID := n.ID.ToRawNodeID() |
| 154 | if rawID != nil { |
| 155 | if n.Role == proto.Leader || n.Role == proto.Follower { |
| 156 | resolver.bpNodes[*rawID] = n |
| 157 | } |
| 158 | setNodeAddrCache(rawID, n.Addr) |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | conf.GConf.SeedBPNodes = make([]proto.Node, 0, len(resolver.bpNodes)) |
| 164 | for _, n := range resolver.bpNodes { |
| 165 | rawID := n.ID.ToRawNodeID() |
| 166 | if rawID != nil { |
| 167 | conf.GConf.SeedBPNodes = append(conf.GConf.SeedBPNodes, n) |
| 168 | setNodeAddrCache(rawID, n.Addr) |
| 169 | resolver.bpNodeIDs[*rawID] = n.Addr |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return resolver.bpNodeIDs |
| 174 | } |
| 175 | |
| 176 | // GetBPs returns the known BP node id list. |
| 177 | func GetBPs() (bpAddrs []proto.NodeID) { |