|
@ -1,12 +1,13 @@ |
|
|
package p2p |
|
|
package p2p |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
"fmt" |
|
|
"math/rand" |
|
|
"math/rand" |
|
|
"net" |
|
|
"net" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
|
|
|
|
crypto "github.com/tendermint/go-crypto" |
|
|
crypto "github.com/tendermint/go-crypto" |
|
|
cfg "github.com/tendermint/tendermint/config" |
|
|
cfg "github.com/tendermint/tendermint/config" |
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
|
cmn "github.com/tendermint/tmlibs/common" |
|
@ -174,17 +175,13 @@ func (sw *Switch) SetNodePrivKey(nodePrivKey crypto.PrivKeyEd25519) { |
|
|
|
|
|
|
|
|
// OnStart implements BaseService. It starts all the reactors, peers, and listeners.
|
|
|
// OnStart implements BaseService. It starts all the reactors, peers, and listeners.
|
|
|
func (sw *Switch) OnStart() error { |
|
|
func (sw *Switch) OnStart() error { |
|
|
if err := sw.BaseService.OnStart(); err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
// Start reactors
|
|
|
// Start reactors
|
|
|
for _, reactor := range sw.reactors { |
|
|
for _, reactor := range sw.reactors { |
|
|
err := reactor.Start() |
|
|
err := reactor.Start() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
return errors.Wrapf(err, "failed to start %v", reactor) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Start listeners
|
|
|
// Start listeners
|
|
|
for _, listener := range sw.listeners { |
|
|
for _, listener := range sw.listeners { |
|
|
go sw.listenerRoutine(listener) |
|
|
go sw.listenerRoutine(listener) |
|
@ -194,7 +191,6 @@ func (sw *Switch) OnStart() error { |
|
|
|
|
|
|
|
|
// OnStop implements BaseService. It stops all listeners, peers, and reactors.
|
|
|
// OnStop implements BaseService. It stops all listeners, peers, and reactors.
|
|
|
func (sw *Switch) OnStop() { |
|
|
func (sw *Switch) OnStop() { |
|
|
sw.BaseService.OnStop() |
|
|
|
|
|
// Stop listeners
|
|
|
// Stop listeners
|
|
|
for _, listener := range sw.listeners { |
|
|
for _, listener := range sw.listeners { |
|
|
listener.Stop() |
|
|
listener.Stop() |
|
|