Browse Source

Use remotePeer for test switch

pull/1520/head
Alexander Simmerl 7 years ago
parent
commit
c5f45275ec
No known key found for this signature in database GPG Key ID: 4694E95C9CC61BDA
2 changed files with 34 additions and 2 deletions
  1. +1
    -1
      p2p/peer_test.go
  2. +33
    -1
      p2p/test_util.go

+ 1
- 1
p2p/peer_test.go View File

@ -154,7 +154,7 @@ func (p *remotePeer) accept(l net.Listener) {
_, err = pc.HandshakeTimeout(NodeInfo{
ID: p.Addr().ID,
Moniker: "remote_peer",
Network: "testing",
Network: "localhost",
Version: "123.123.123",
ListenAddr: l.Addr().String(),
Channels: []byte{testCh},


+ 33
- 1
p2p/test_util.go View File

@ -1,7 +1,9 @@
package p2p
import (
"fmt"
"net"
"time"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
@ -80,7 +82,37 @@ func MakeConnectedSwitches(cfg *cfg.P2PConfig, n int, initSwitch func(int, *Swit
func Connect2Switches(switches []*Switch, i, j int) {
switchI := switches[i]
switchJ := switches[j]
c1, c2 := conn.NetPipe()
p1 := &remotePeer{
Config: switchJ.peerConfig,
PrivKey: switchJ.nodeKey.PrivKey,
}
p1.Start()
c1, err := net.DialTimeout(
"tcp",
fmt.Sprintf("%s:%d", p1.addr.IP.String(), p1.addr.Port),
100*time.Millisecond,
)
if err != nil {
panic(err)
}
p2 := &remotePeer{
Config: switchI.peerConfig,
PrivKey: switchI.nodeKey.PrivKey,
}
p2.Start()
c2, err := net.DialTimeout(
"tcp",
fmt.Sprintf("%s:%d", p2.addr.IP.String(), p2.addr.Port),
100*time.Millisecond,
)
if err != nil {
panic(err)
}
doneCh := make(chan struct{})
go func() {
err := switchI.addPeerWithConnection(c1)


Loading…
Cancel
Save