Commit af92856b authored by Kirill Smelkov's avatar Kirill Smelkov

.

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