From c3a17de326409398e003a4456c1343f15158f785 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 4 Oct 2013 10:44:36 -0500 Subject: [PATCH] Comment Connected function in peer. While here, also rearrange the functions slightly to logically group them. --- peer.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/peer.go b/peer.go index 3fb600f0..7bc1957b 100644 --- a/peer.go +++ b/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 -}