Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
f3eee223
Commit
f3eee223
authored
Dec 13, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed route firstRoute function
parent
6cc0606d
Pipeline
#8366
failed with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
8 deletions
+19
-8
local.go
internal/peermgr/local.go
+1
-1
map.go
internal/port/map.go
+4
-5
router.go
internal/router/router.go
+14
-2
No files found.
internal/peermgr/local.go
View file @
f3eee223
...
...
@@ -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"
)
...
...
internal/port/map.go
View file @
f3eee223
...
...
@@ -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
{
r
andPort
=
pt
r
eturn
pt
}
j
++
}
return
randPort
return
nil
}
func
(
p
*
PortMap
)
Remove
(
pt
Port
)
{
...
...
internal/router/router.go
View file @
f3eee223
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment