Comment Connected function in peer.

While here, also rearrange the functions slightly to logically group them.
This commit is contained in:
Dave Collins 2013-10-04 10:44:36 -05:00
parent 689c699bc5
commit c3a17de326

37
peer.go
View file

@ -1029,6 +1029,25 @@ func (p *peer) QueueInventory(invVect *btcwire.InvVect) {
p.outputInvChan <- 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 // Start begins processing input and output messages. It also sends the initial
// version message for outbound connections to start the negotiation process. // version message for outbound connections to start the negotiation process.
func (p *peer) Start() error { func (p *peer) Start() error {
@ -1057,19 +1076,6 @@ func (p *peer) Start() error {
return nil 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 // Shutdown gracefully shuts down the peer by disconnecting it and waiting for
// all goroutines to finish. // all goroutines to finish.
func (p *peer) Shutdown() { func (p *peer) Shutdown() {
@ -1209,8 +1215,3 @@ func (p *peer) logError(fmt string, args ...interface{}) {
log.Debugf(fmt, args...) log.Debugf(fmt, args...)
} }
} }
func (p *peer) Connected() bool {
return atomic.LoadInt32(&p.connected) != 0 &&
atomic.LoadInt32(&p.disconnect) == 0
}