Commit f3eee223 authored by suyanlong's avatar suyanlong

Fixed route firstRoute function

parent 6cc0606d
Pipeline #8366 failed with stages
......@@ -2,12 +2,12 @@ package peermgr
import (
"errors"
"gitlab.33.cn/link33/sidecar/internal/loggers"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/sirupsen/logrus"
"gitlab.33.cn/link33/sidecar/internal/loggers"
"gitlab.33.cn/link33/sidecar/internal/port"
"gitlab.33.cn/link33/sidecar/model/pb"
)
......
......@@ -132,17 +132,16 @@ func (p *PortMap) AllRouterPort() []Port {
func (p *PortMap) RandRouterPort() Port {
p.rw.RLock()
defer p.rw.RUnlock()
var randPort Port
l := len(p.peerPort)
i := rand.Intn(l + 1)
i := rand.Intn(l)
j := 0
for _, pt := range p.peerPort {
j++
if i == j {
randPort = pt
return pt
}
j++
}
return randPort
return nil
}
func (p *PortMap) Remove(pt Port) {
......
......@@ -231,8 +231,20 @@ func (r *router) isRouter(ibtpx *pb.IBTPX) bool {
// TODO
func (r *router) firstRoute(msg *pb.Message) {
p := r.portMap.RandRouterPort()
_ = p.AsyncSend(msg)
return
if p == nil {
r.logger.WithFields(logrus.Fields{
"error": "port == nil",
"func": "firstRoute",
}).Error("port == nil")
} else {
err := p.AsyncSend(msg)
if err != nil {
r.logger.WithFields(logrus.Fields{
"error": "p.AsyncSend return error",
"func": "firstRoute",
}).Error(err.Error())
}
}
}
func (r *router) getHub() (port.Port, bool) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment