wire: Remove unused NewMsgVersionFromConn.

This function is a legacy function from way back during initial
development.  Nothing actually uses it and it's not very useful anyways
since it requires the connection to be a specific type (net.TCPConn) and
therefore doesn't work right with things that typically provide their
own net.Conn implementation like proxies.
This commit is contained in:
Dave Collins 2016-11-03 20:09:46 -05:00
parent 2510baac35
commit 6bb8d297a6
No known key found for this signature in database
GPG Key ID: B8904D9D9C93D1F2
3 changed files with 0 additions and 123 deletions

View File

@ -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
}

View File

@ -8,7 +8,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"net"
"strings" "strings"
"time" "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 // validateUserAgent checks userAgent length against MaxUserAgentLen
func validateUserAgent(userAgent string) error { func validateUserAgent(userAgent string) error {
if len(userAgent) > MaxUserAgentLen { if len(userAgent) > MaxUserAgentLen {

View File

@ -131,45 +131,6 @@ func TestVersion(t *testing.T) {
t.Errorf("HasService: SFNodeNetwork service not set") 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 return
} }