container: refactor strong/weak peer connecting
This commit is contained in:
parent
c6dac0d378
commit
e4f6d4f964
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue