Comment Connected function in peer.
While here, also rearrange the functions slightly to logically group them.
This commit is contained in:
parent
689c699bc5
commit
c3a17de326
1 changed files with 19 additions and 18 deletions
37
peer.go
37
peer.go
|
@ -1029,6 +1029,25 @@ func (p *peer) QueueInventory(invVect *btcwire.InvVect) {
|
|||
p.outputInvChan <- invVect
|
||||
}
|
||||
|
||||
// Connected returns whether or not the peer is currently connected.
|
||||
func (p *peer) Connected() bool {
|
||||
return atomic.LoadInt32(&p.connected) != 0 &&
|
||||
atomic.LoadInt32(&p.disconnect) == 0
|
||||
}
|
||||
|
||||
// Disconnect disconnects the peer by closing the connection. It also sets
|
||||
// a flag so the impending shutdown can be detected.
|
||||
func (p *peer) Disconnect() {
|
||||
// did we win the race?
|
||||
if atomic.AddInt32(&p.disconnect, 1) != 1 {
|
||||
return
|
||||
}
|
||||
close(p.quit)
|
||||
if atomic.LoadInt32(&p.connected) != 0 {
|
||||
p.conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Start begins processing input and output messages. It also sends the initial
|
||||
// version message for outbound connections to start the negotiation process.
|
||||
func (p *peer) Start() error {
|
||||
|
@ -1057,19 +1076,6 @@ func (p *peer) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Disconnect disconnects the peer by closing the connection. It also sets
|
||||
// a flag so the impending shutdown can be detected.
|
||||
func (p *peer) Disconnect() {
|
||||
// did we win the race?
|
||||
if atomic.AddInt32(&p.disconnect, 1) != 1 {
|
||||
return
|
||||
}
|
||||
close(p.quit)
|
||||
if atomic.LoadInt32(&p.connected) != 0 {
|
||||
p.conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown gracefully shuts down the peer by disconnecting it and waiting for
|
||||
// all goroutines to finish.
|
||||
func (p *peer) Shutdown() {
|
||||
|
@ -1209,8 +1215,3 @@ func (p *peer) logError(fmt string, args ...interface{}) {
|
|||
log.Debugf(fmt, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *peer) Connected() bool {
|
||||
return atomic.LoadInt32(&p.connected) != 0 &&
|
||||
atomic.LoadInt32(&p.disconnect) == 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue