From f6cd49ac51964c016f2181291a67c8253e0f6a33 Mon Sep 17 00:00:00 2001 From: Javed Khan Date: Fri, 21 Oct 2016 22:57:29 +0530 Subject: [PATCH] peer: rename peer.Connect to AssociateConnection --- peer/example_test.go | 4 ++-- peer/peer.go | 6 +++--- peer/peer_test.go | 20 ++++++++++---------- server.go | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/peer/example_test.go b/peer/example_test.go index ff524efc..e4429f85 100644 --- a/peer/example_test.go +++ b/peer/example_test.go @@ -39,7 +39,7 @@ func mockRemotePeer() error { // Create and start the inbound peer. p := peer.NewInboundPeer(peerCfg) - p.Connect(conn) + p.AssociateConnection(conn) }() return nil @@ -90,7 +90,7 @@ func Example_newOutboundPeer() { fmt.Printf("net.Dial: error %v\n", err) return } - p.Connect(conn) + p.AssociateConnection(conn) // Wait for the verack message or timeout in case of failure. select { diff --git a/peer/peer.go b/peer/peer.go index fbb011cc..cfd0fd41 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -1860,9 +1860,9 @@ func (p *Peer) QueueInventory(invVect *wire.InvVect) { p.outputInvChan <- invVect } -// Connect uses the given conn to connect to the peer. Calling this function when -// the peer is already connected will have no effect. -func (p *Peer) Connect(conn net.Conn) { +// AssociateConnection associates the given conn to the peer. Calling this +// function when the peer is already connected will have no effect. +func (p *Peer) AssociateConnection(conn net.Conn) { // Already connected? if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) { return diff --git a/peer/peer_test.go b/peer/peer_test.go index b949fe6c..2db631af 100644 --- a/peer/peer_test.go +++ b/peer/peer_test.go @@ -249,13 +249,13 @@ func TestPeerConnection(t *testing.T) { &conn{raddr: "10.0.0.2:8333"}, ) inPeer := peer.NewInboundPeer(peerCfg) - inPeer.Connect(inConn) + inPeer.AssociateConnection(inConn) outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333") if err != nil { return nil, nil, err } - outPeer.Connect(outConn) + outPeer.AssociateConnection(outConn) for i := 0; i < 4; i++ { select { @@ -275,13 +275,13 @@ func TestPeerConnection(t *testing.T) { &conn{raddr: "10.0.0.2:8333"}, ) inPeer := peer.NewInboundPeer(peerCfg) - inPeer.Connect(inConn) + inPeer.AssociateConnection(inConn) outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333") if err != nil { return nil, nil, err } - outPeer.Connect(outConn) + outPeer.AssociateConnection(outConn) for i := 0; i < 4; i++ { select { @@ -397,7 +397,7 @@ func TestPeerListeners(t *testing.T) { &conn{raddr: "10.0.0.2:8333"}, ) inPeer := peer.NewInboundPeer(peerCfg) - inPeer.Connect(inConn) + inPeer.AssociateConnection(inConn) peerCfg.Listeners = peer.MessageListeners{ OnVerAck: func(p *peer.Peer, msg *wire.MsgVerAck) { @@ -409,7 +409,7 @@ func TestPeerListeners(t *testing.T) { t.Errorf("NewOutboundPeer: unexpected err %v\n", err) return } - outPeer.Connect(outConn) + outPeer.AssociateConnection(outConn) for i := 0; i < 2; i++ { select { @@ -549,8 +549,8 @@ func TestOutboundPeer(t *testing.T) { } // Test trying to connect twice. - p.Connect(c) - p.Connect(c) + p.AssociateConnection(c) + p.AssociateConnection(c) disconnected := make(chan struct{}) go func() { @@ -603,7 +603,7 @@ func TestOutboundPeer(t *testing.T) { t.Errorf("NewOutboundPeer: unexpected err - %v\n", err) return } - p1.Connect(c1) + p1.AssociateConnection(c1) // Test update latest block latestBlockHash, err := chainhash.NewHashFromStr("1a63f9cdff1752e6375c8c76e543a71d239e1a2e5c6db1aa679") @@ -633,7 +633,7 @@ func TestOutboundPeer(t *testing.T) { t.Errorf("NewOutboundPeer: unexpected err - %v\n", err) return } - p2.Connect(c2) + p2.AssociateConnection(c2) // Test PushXXX var addrs []*wire.NetAddress diff --git a/server.go b/server.go index 7221c2fd..53db4bc2 100644 --- a/server.go +++ b/server.go @@ -1624,7 +1624,7 @@ func (s *server) listenHandler(listener net.Listener) { sp := newServerPeer(s, false) sp.Peer = peer.NewInboundPeer(newPeerConfig(sp)) go s.peerDoneHandler(sp) - sp.Connect(conn) + sp.AssociateConnection(conn) } s.wg.Done() srvrLog.Tracef("Listener handler done for %s", listener.Addr()) @@ -1720,7 +1720,7 @@ func (s *server) establishConn(sp *serverPeer) error { if err != nil { return err } - sp.Connect(conn) + sp.AssociateConnection(conn) s.addrManager.Attempt(sp.NA()) return nil }