container: refactor strong/weak peer connecting

This commit is contained in:
Alan Chen 2017-08-24 12:21:45 +08:00
parent c6dac0d378
commit e4f6d4f964
1 changed files with 12 additions and 7 deletions

View File

@ -216,15 +216,20 @@ func (bc *blockchain) addValidators(numOfValidators int) error {
} }
func (bc *blockchain) connectAll(strong bool) error { func (bc *blockchain) connectAll(strong bool) error {
for i, v := range bc.validators { for idx, v := range bc.validators {
istClient := v.NewIstanbulClient() if strong {
for j, v := range bc.validators { for _, vv := range bc.validators {
if (strong && j > i) || (!strong && j == i+1) { if v.ContainerID() != vv.ContainerID() {
err := istClient.AddPeer(context.Background(), v.NodeAddress()) if err := v.AddPeer(vv.NodeAddress()); err != nil {
if err != nil { return err
return err }
} }
} }
} else {
nextValidator := bc.validators[(idx+1)%len(bc.validators)]
if err := v.AddPeer(nextValidator.NodeAddress()); err != nil {
return err
}
} }
} }
return nil return nil