Commit af92856b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 94746190
......@@ -156,7 +156,7 @@ func (nt *NodeTable) Get(nid proto.NodeID) *PeerNode {
func (nt *NodeTable) Update(nodeInfo proto.NodeInfo) *PeerNode {
node := nt.Get(nodeInfo.NID)
if node == nil {
node = &PeerNode{localNode: nt.localNode}
node = &PeerNode{link: &_PeerLink{localNode: nt.localNode}}
nt.nodev = append(nt.nodev, node)
}
......@@ -224,9 +224,10 @@ func (nt *NodeTable) Clone() *NodeTable {
// See also: Link, ResetLink, Dial.
func (p *PeerNode) SetLink(link *neonet.NodeLink) {
// XXX see Link about locking - whether it is needed here or not
p.linkMu.Lock()
p.link = link
p.linkMu.Unlock()
l := p.link
l.linkMu.Lock()
l.link = link
l.linkMu.Unlock()
}
// Link returns current link to peer node.
......@@ -237,19 +238,21 @@ func (p *PeerNode) SetLink(link *neonet.NodeLink) {
func (p *PeerNode) Link() *neonet.NodeLink {
// XXX do we need lock here?
// XXX usages where Link is used (contrary to Dial) there is no need for lock
p.linkMu.Lock()
link := p.link
p.linkMu.Unlock()
l := p.link
l.linkMu.Lock()
link := l.link
l.linkMu.Unlock()
return link
}
// ResetLink closes link to peer and sets it to nil.
func (p *PeerNode) ResetLink(ctx context.Context) {
p.linkMu.Lock()
link := p.link
p.link = nil
p.dialing = nil // XXX what if dialing is in progress? -> cancel dialing with err?
p.linkMu.Unlock()
l := p.link
l.linkMu.Lock()
link := l.link
l.link = nil
l.dialing = nil // XXX what if dialing is in progress? -> cancel dialing with err?
l.linkMu.Unlock()
if link != nil {
log.Infof(ctx, "%s: closing link", link)
......@@ -263,7 +266,7 @@ func (p *PeerNode) ResetLink(ctx context.Context) {
// dial does low-level work to dial peer
// XXX p.* reading without lock - ok?
func (p *PeerNode) dial(ctx context.Context) (_ *neonet.NodeLink, err error) {
node := p.localNode
node := p.link.localNode
s := node.stateLog.ReadHead() // XXX better Dial gets the state from the caller? (as here it can be different from the context in which caller thinks it operates)
defer task.Runningf(&ctx, "dial %s", p.NID)(&err)
......
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