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 {
for i, v := range bc.validators {
istClient := v.NewIstanbulClient()
for j, v := range bc.validators {
if (strong && j > i) || (!strong && j == i+1) {
err := istClient.AddPeer(context.Background(), v.NodeAddress())
if err != nil {
return err
for idx, v := range bc.validators {
if strong {
for _, vv := range bc.validators {
if v.ContainerID() != vv.ContainerID() {
if err := v.AddPeer(vv.NodeAddress()); err != nil {
return err
}
}
}
} else {
nextValidator := bc.validators[(idx+1)%len(bc.validators)]
if err := v.AddPeer(nextValidator.NodeAddress()); err != nil {
return err
}
}
}
return nil