diff --git a/wire/fakeconn_test.go b/wire/fakeconn_test.go deleted file mode 100644 index e2777daf..00000000 --- a/wire/fakeconn_test.go +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2013-2016 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -package wire - -import ( - "net" - "time" -) - -// fakeConn implements the net.Conn interface and is used to test functions -// which work with a net.Conn without having to actually make any real -// connections. -type fakeConn struct { - localAddr net.Addr - remoteAddr net.Addr -} - -// Read doesn't do anything. It just satisfies the net.Conn interface. -func (c *fakeConn) Read(b []byte) (n int, err error) { - return 0, nil -} - -// Write doesn't do anything. It just satisfies the net.Conn interface. -func (c *fakeConn) Write(b []byte) (n int, err error) { - return 0, nil -} - -// Close doesn't do anything. It just satisfies the net.Conn interface. -func (c *fakeConn) Close() error { - return nil -} - -// LocalAddr returns the localAddr field of the fake connection and satisfies -// the net.Conn interface. -func (c *fakeConn) LocalAddr() net.Addr { - return c.localAddr -} - -// RemoteAddr returns the remoteAddr field of the fake connection and satisfies -// the net.Conn interface. -func (c *fakeConn) RemoteAddr() net.Addr { - return c.remoteAddr -} - -// SetDeadline doesn't do anything. It just satisfies the net.Conn interface. -func (c *fakeConn) SetDeadline(t time.Time) error { - return nil -} - -// SetReadDeadline doesn't do anything. It just satisfies the net.Conn -// interface. -func (c *fakeConn) SetReadDeadline(t time.Time) error { - return nil -} - -// SetWriteDeadline doesn't do anything. It just satisfies the net.Conn -// interface. -func (c *fakeConn) SetWriteDeadline(t time.Time) error { - return nil -} diff --git a/wire/msgversion.go b/wire/msgversion.go index 55bdc135..d6a3061f 100644 --- a/wire/msgversion.go +++ b/wire/msgversion.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "io" - "net" "strings" "time" ) @@ -239,27 +238,6 @@ func NewMsgVersion(me *NetAddress, you *NetAddress, nonce uint64, } } -// NewMsgVersionFromConn is a convenience function that extracts the remote -// and local address from conn and returns a new bitcoin version message that -// conforms to the Message interface. See NewMsgVersion. -func NewMsgVersionFromConn(conn net.Conn, nonce uint64, - lastBlock int32) (*MsgVersion, error) { - - // Don't assume any services until we know otherwise. - lna, err := NewNetAddress(conn.LocalAddr(), 0) - if err != nil { - return nil, err - } - - // Don't assume any services until we know otherwise. - rna, err := NewNetAddress(conn.RemoteAddr(), 0) - if err != nil { - return nil, err - } - - return NewMsgVersion(lna, rna, nonce, lastBlock), nil -} - // validateUserAgent checks userAgent length against MaxUserAgentLen func validateUserAgent(userAgent string) error { if len(userAgent) > MaxUserAgentLen { diff --git a/wire/msgversion_test.go b/wire/msgversion_test.go index 5d57b8b0..0290c4e4 100644 --- a/wire/msgversion_test.go +++ b/wire/msgversion_test.go @@ -131,45 +131,6 @@ func TestVersion(t *testing.T) { t.Errorf("HasService: SFNodeNetwork service not set") } - // Use a fake connection. - conn := &fakeConn{localAddr: tcpAddrMe, remoteAddr: tcpAddrYou} - msg, err = NewMsgVersionFromConn(conn, nonce, lastBlock) - if err != nil { - t.Errorf("NewMsgVersionFromConn: %v", err) - } - - // Ensure we get the correct connection data back out. - if !msg.AddrMe.IP.Equal(tcpAddrMe.IP) { - t.Errorf("NewMsgVersionFromConn: wrong me ip - got %v, want %v", - msg.AddrMe.IP, tcpAddrMe.IP) - } - if !msg.AddrYou.IP.Equal(tcpAddrYou.IP) { - t.Errorf("NewMsgVersionFromConn: wrong you ip - got %v, want %v", - msg.AddrYou.IP, tcpAddrYou.IP) - } - - // Use a fake connection with local UDP addresses to force a failure. - conn = &fakeConn{ - localAddr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8333}, - remoteAddr: tcpAddrYou, - } - msg, err = NewMsgVersionFromConn(conn, nonce, lastBlock) - if err != ErrInvalidNetAddr { - t.Errorf("NewMsgVersionFromConn: expected error not received "+ - "- got %v, want %v", err, ErrInvalidNetAddr) - } - - // Use a fake connection with remote UDP addresses to force a failure. - conn = &fakeConn{ - localAddr: tcpAddrMe, - remoteAddr: &net.UDPAddr{IP: net.ParseIP("192.168.0.1"), Port: 8333}, - } - msg, err = NewMsgVersionFromConn(conn, nonce, lastBlock) - if err != ErrInvalidNetAddr { - t.Errorf("NewMsgVersionFromConn: expected error not received "+ - "- got %v, want %v", err, ErrInvalidNetAddr) - } - return }