connmgr: Remove type defs for callbacks.

This removes the type definitions for the callback functions in favor of
declaring them directly in the Config struct.  This is more consistent
with the rest of the code base and is preferred since it means callers
reviewing the documentation don't have to follow another level of
indirection to figure out the signature.
This commit is contained in:
Dave Collins 2016-11-03 22:49:22 -05:00
parent 2c6f864b55
commit ea9bf748bb
No known key found for this signature in database
GPG key ID: B8904D9D9C93D1F2
2 changed files with 9 additions and 23 deletions

View file

@ -37,12 +37,6 @@ var (
defaultTargetOutbound = uint32(8)
)
// DialFunc defines a function that dials a connection.
type DialFunc func(string, string) (net.Conn, error)
// AddressFunc defines a function that returns a network address to connect to.
type AddressFunc func() (string, error)
// ConnState represents the state of the requested connection.
type ConnState uint8
@ -57,14 +51,6 @@ const (
ConnFailed
)
// OnConnectionFunc is the signature of the callback function which is used to
// subscribe to new connections.
type OnConnectionFunc func(*ConnReq, net.Conn)
// OnDisconnectionFunc is the signature of the callback function which is used to
// notify disconnections.
type OnDisconnectionFunc func(*ConnReq)
// ConnReq is the connection request to a network address. If permanent, the
// connection will be retried on disconnection.
type ConnReq struct {
@ -118,20 +104,20 @@ type Config struct {
// requests. Defaults to 5s.
RetryDuration time.Duration
// OnConnection is a callback that is fired when a new connection is
// established.
OnConnection OnConnectionFunc
// OnConnection is a callback that is fired when a new outbound
// connection is established.
OnConnection func(*ConnReq, net.Conn)
// OnDisconnection is a callback that is fired when a connection is
// disconnected.
OnDisconnection OnDisconnectionFunc
// OnDisconnection is a callback that is fired when an outbound
// connection is disconnected.
OnDisconnection func(*ConnReq)
// GetNewAddress is a way to get an address to make a network connection
// to. If nil, no new connections will be made automatically.
GetNewAddress AddressFunc
GetNewAddress func() (string, error)
// Dial connects to the address on the named network. It cannot be nil.
Dial DialFunc
Dial func(string, string) (net.Conn, error)
}
// handleConnected is used to queue a successful connection.

View file

@ -2426,7 +2426,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
// specified peers and actively avoid advertising and connecting to
// discovered peers in order to prevent it from becoming a public test
// network.
var newAddressFunc connmgr.AddressFunc
var newAddressFunc func() (string, error)
if !cfg.SimNet && len(cfg.ConnectPeers) == 0 {
newAddressFunc = func() (string, error) {
for tries := 0; tries < 100; tries++ {