peer: rename peer.Connect to AssociateConnection

This commit is contained in:
Javed Khan 2016-10-21 22:57:29 +05:30 committed by Dave Collins
parent 0731f2ddc9
commit f6cd49ac51
4 changed files with 17 additions and 17 deletions

View file

@ -39,7 +39,7 @@ func mockRemotePeer() error {
// Create and start the inbound peer. // Create and start the inbound peer.
p := peer.NewInboundPeer(peerCfg) p := peer.NewInboundPeer(peerCfg)
p.Connect(conn) p.AssociateConnection(conn)
}() }()
return nil return nil
@ -90,7 +90,7 @@ func Example_newOutboundPeer() {
fmt.Printf("net.Dial: error %v\n", err) fmt.Printf("net.Dial: error %v\n", err)
return return
} }
p.Connect(conn) p.AssociateConnection(conn)
// Wait for the verack message or timeout in case of failure. // Wait for the verack message or timeout in case of failure.
select { select {

View file

@ -1860,9 +1860,9 @@ func (p *Peer) QueueInventory(invVect *wire.InvVect) {
p.outputInvChan <- invVect p.outputInvChan <- invVect
} }
// Connect uses the given conn to connect to the peer. Calling this function when // AssociateConnection associates the given conn to the peer. Calling this
// the peer is already connected will have no effect. // function when the peer is already connected will have no effect.
func (p *Peer) Connect(conn net.Conn) { func (p *Peer) AssociateConnection(conn net.Conn) {
// Already connected? // Already connected?
if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) { if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) {
return return

View file

@ -249,13 +249,13 @@ func TestPeerConnection(t *testing.T) {
&conn{raddr: "10.0.0.2:8333"}, &conn{raddr: "10.0.0.2:8333"},
) )
inPeer := peer.NewInboundPeer(peerCfg) inPeer := peer.NewInboundPeer(peerCfg)
inPeer.Connect(inConn) inPeer.AssociateConnection(inConn)
outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333") outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
outPeer.Connect(outConn) outPeer.AssociateConnection(outConn)
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
select { select {
@ -275,13 +275,13 @@ func TestPeerConnection(t *testing.T) {
&conn{raddr: "10.0.0.2:8333"}, &conn{raddr: "10.0.0.2:8333"},
) )
inPeer := peer.NewInboundPeer(peerCfg) inPeer := peer.NewInboundPeer(peerCfg)
inPeer.Connect(inConn) inPeer.AssociateConnection(inConn)
outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333") outPeer, err := peer.NewOutboundPeer(peerCfg, "10.0.0.2:8333")
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
outPeer.Connect(outConn) outPeer.AssociateConnection(outConn)
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
select { select {
@ -397,7 +397,7 @@ func TestPeerListeners(t *testing.T) {
&conn{raddr: "10.0.0.2:8333"}, &conn{raddr: "10.0.0.2:8333"},
) )
inPeer := peer.NewInboundPeer(peerCfg) inPeer := peer.NewInboundPeer(peerCfg)
inPeer.Connect(inConn) inPeer.AssociateConnection(inConn)
peerCfg.Listeners = peer.MessageListeners{ peerCfg.Listeners = peer.MessageListeners{
OnVerAck: func(p *peer.Peer, msg *wire.MsgVerAck) { 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) t.Errorf("NewOutboundPeer: unexpected err %v\n", err)
return return
} }
outPeer.Connect(outConn) outPeer.AssociateConnection(outConn)
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
select { select {
@ -549,8 +549,8 @@ func TestOutboundPeer(t *testing.T) {
} }
// Test trying to connect twice. // Test trying to connect twice.
p.Connect(c) p.AssociateConnection(c)
p.Connect(c) p.AssociateConnection(c)
disconnected := make(chan struct{}) disconnected := make(chan struct{})
go func() { go func() {
@ -603,7 +603,7 @@ func TestOutboundPeer(t *testing.T) {
t.Errorf("NewOutboundPeer: unexpected err - %v\n", err) t.Errorf("NewOutboundPeer: unexpected err - %v\n", err)
return return
} }
p1.Connect(c1) p1.AssociateConnection(c1)
// Test update latest block // Test update latest block
latestBlockHash, err := chainhash.NewHashFromStr("1a63f9cdff1752e6375c8c76e543a71d239e1a2e5c6db1aa679") latestBlockHash, err := chainhash.NewHashFromStr("1a63f9cdff1752e6375c8c76e543a71d239e1a2e5c6db1aa679")
@ -633,7 +633,7 @@ func TestOutboundPeer(t *testing.T) {
t.Errorf("NewOutboundPeer: unexpected err - %v\n", err) t.Errorf("NewOutboundPeer: unexpected err - %v\n", err)
return return
} }
p2.Connect(c2) p2.AssociateConnection(c2)
// Test PushXXX // Test PushXXX
var addrs []*wire.NetAddress var addrs []*wire.NetAddress

View file

@ -1624,7 +1624,7 @@ func (s *server) listenHandler(listener net.Listener) {
sp := newServerPeer(s, false) sp := newServerPeer(s, false)
sp.Peer = peer.NewInboundPeer(newPeerConfig(sp)) sp.Peer = peer.NewInboundPeer(newPeerConfig(sp))
go s.peerDoneHandler(sp) go s.peerDoneHandler(sp)
sp.Connect(conn) sp.AssociateConnection(conn)
} }
s.wg.Done() s.wg.Done()
srvrLog.Tracef("Listener handler done for %s", listener.Addr()) srvrLog.Tracef("Listener handler done for %s", listener.Addr())
@ -1720,7 +1720,7 @@ func (s *server) establishConn(sp *serverPeer) error {
if err != nil { if err != nil {
return err return err
} }
sp.Connect(conn) sp.AssociateConnection(conn)
s.addrManager.Attempt(sp.NA()) s.addrManager.Attempt(sp.NA())
return nil return nil
} }