Skip to content
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

Closed
wants to merge 9 commits into from
Closed

Conversation

c20liu
Copy link
Member

@c20liu c20liu commented May 17, 2019

Fixes # . optimize p2p k-bucket refresh

Changes proposed in this pull request:

  • use libp2p function "BootstrapWithConfig" to refresh k-bucket directly

@Shitaibin

// 刷新K桶
}
}
//func (vdht *VNTDht) loop(ctx context.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要了可以直接删掉,不用注释

}

// lookup

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update loopupNode —> lookupNode,可以开启goland错字提示

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 {

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

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)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

变量无用

@Shitaibin Shitaibin self-assigned this May 17, 2019
@Shitaibin Shitaibin changed the title optimize p2p k-bucket refresh WIP optimize p2p k-bucket refresh May 17, 2019
@c20liu c20liu closed this May 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants