mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-29 22:21:21 +00:00
Make Connect2Switches blocking
This commit is contained in:
parent
58e42397f8
commit
2b750ea49f
14
switch.go
14
switch.go
@ -483,13 +483,23 @@ func MakeConnectedSwitches(n int, initSwitch func(int, *Switch) *Switch, connect
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Will connect switches i and j via net.Pipe()
|
// Will connect switches i and j via net.Pipe()
|
||||||
|
// Blocks until a conection is established.
|
||||||
// NOTE: caller ensures i and j are within bounds
|
// NOTE: caller ensures i and j are within bounds
|
||||||
func Connect2Switches(switches []*Switch, i, j int) {
|
func Connect2Switches(switches []*Switch, i, j int) {
|
||||||
switchI := switches[i]
|
switchI := switches[i]
|
||||||
switchJ := switches[j]
|
switchJ := switches[j]
|
||||||
c1, c2 := net.Pipe()
|
c1, c2 := net.Pipe()
|
||||||
go switchI.AddPeerWithConnection(c1, false) // AddPeer is blocking, requires handshake.
|
doneCh := make(chan struct{})
|
||||||
go switchJ.AddPeerWithConnection(c2, true)
|
go func() {
|
||||||
|
switchI.AddPeerWithConnection(c1, false) // AddPeer is blocking, requires handshake.
|
||||||
|
doneCh <- struct{}{}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
switchJ.AddPeerWithConnection(c2, true)
|
||||||
|
doneCh <- struct{}{}
|
||||||
|
}()
|
||||||
|
<-doneCh
|
||||||
|
<-doneCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartSwitches(switches []*Switch) error {
|
func StartSwitches(switches []*Switch) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user