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
WIP optimize p2p k-bucket refresh #85
Conversation
vntp2p/discovery.go
Outdated
// 刷新K桶 | ||
} | ||
} | ||
//func (vdht *VNTDht) loop(ctx context.Context) { |
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.
不要了可以直接删掉,不用注释
} | ||
|
||
// lookup |
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.
lookup 这行删除,不需要3行注释
vntp2p/dial.go
Outdated
} | ||
} | ||
|
||
//update loopupNode, if need more, launch loopup task |
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.
update loopupNode —> lookupNode,可以开启goland错字提示
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.
// 后添加1个空格,goland也能提示
vntp2p/dial.go
Outdated
|
||
//update loopupNode, if need more, launch loopup task | ||
s.lookupNode = s.lookupNode[:copy(s.lookupNode, s.lookupNode[i:])] | ||
if len(s.lookupNode) < needdial && !s.lookupRunning { |
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.
needdial -> needDial go语言变量是驼峰命名法
@@ -146,7 +162,8 @@ func (s *taskstate) taskDone(t task) { | |||
case *dialTask: | |||
delete(s.dialmap, t.target) | |||
case *lookupTask: | |||
log.Debug("taskDone", "lookupTask") | |||
s.lookupRunning = false |
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.
lookupRunning这个变量起不到作用。newTasks可能建立了多个lookup task,但每一个lookup task执行完,都会执行task done,这就造成有1个task 执行完,这个标记又被设置为false了。
目的是所有lookup都执行完才是一轮lookup done,然后下次执行new task的时候,如果发现连接数不够,才是开启下一轮lookup。
建议:把lookupRunning改成lookupCount,因为存在并发,使用原子操作,创建时+1,每个lookup task执行完,可以自己减一,原子操作使用sync.atomic
go func() { t.Do(ctx, server); taskdone <- t }()
func (s *taskstate) taskDone(t task) {
switch t := t.(type) {
case *dialTask:
delete(s.dialmap, t.target)
case *lookupTask:
s.lookupRunning = false
s.lookupNode = append(s.lookupNode, t.targets...)
}
}
vntp2p/dial.go
Outdated
@@ -196,7 +213,22 @@ func (t *dialTask) dial(ctx context.Context, server *Server, target peer.ID, pid | |||
} | |||
|
|||
func (t *lookupTask) Do(ctx context.Context, server *Server) { | |||
time.Sleep(1 * time.Second) | |||
//give sometime for this lookup task | |||
nextLoopup := server.lastLookup.Add(4 * time.Second) |
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.
这里不需要阻塞,没任何效果
<-time.After()
vntp2p/server.go
Outdated
peerFeed event.Feed | ||
loopWG sync.WaitGroup | ||
cancel context.CancelFunc | ||
lastLookup time.Time |
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.
变量无用
…nto optimize_local
…into optimize_local
Fixes # . optimize p2p k-bucket refresh
Changes proposed in this pull request:
@Shitaibin