-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2pv1: change dynamic-nodes connections to static-node connections in static-node mode. #230
Conversation
peersChan := make(chan []*pb.PeerInfo, len(addresses)) | ||
done := make(chan struct{}) | ||
|
||
for _, addr := range addresses { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用sync.Mutex
来保护remotePeers
,直接在闭包里面append remotePeers
,可以不用channel来交互
bcs/network/p2pv1/conn.go
Outdated
ctx: ctx, | ||
}, nil | ||
} | ||
cp.staticModeOn = len(ctx.P2PConf.BootNodes) == 0 && len(ctx.P2PConf.StaticNodes) > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免一行里面有复杂逻辑,改成
if len(ctx.P2PConf.BootNodes) == 0 && len(ctx.P2PConf.StaticNodes) > 0 {
cp.staticModeOn = true
}
bcs/network/p2pv1/client.go
Outdated
@@ -202,6 +202,31 @@ func (p *P2PServerV1) GetPeerIdByAccount(account string) (string, error) { | |||
if value, ok := p.accounts.Get(account); ok { | |||
return value.(string), nil | |||
} | |||
|
|||
// xchain address can not mapping, try getPeerInfo again. | |||
if p.pool.staticModeOn && len(p.accounts.Items()) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用提前返回错误的方式来处理这种场景,避免深度嵌套if
语句,这里可以改成
if !p.pool.staticModeOn {
return "", ErrAccountNotExist
}
另外accounts.Items
为空判断有逻辑错误,不用判断。
Codecov Report
@@ Coverage Diff @@
## master #230 +/- ##
==========================================
+ Coverage 47.33% 47.51% +0.18%
==========================================
Files 133 133
Lines 11411 11455 +44
==========================================
+ Hits 5401 5443 +42
Misses 4876 4876
- Partials 1134 1136 +2
Continue to review full report at Codecov.
|
… static-node mode. (OpenAtomFoundation#230) (cherry picked from commit 4a9d712)
Description
Add router in static-node mode.
Fixes # (issue)
Type of change
Brief of your solution
Nodes can refresh their router info by the function GetPeerInfo.
How Has This Been Tested?
Use testnet and xfront.