From 6713afdff30c188542d7e2eb1f8984eefdc201a5 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 30 Apr 2021 17:55:22 -0400 Subject: [PATCH] lint: fix warning by removing reference to deprecated interface --- agent/consul/server.go | 6 +++--- agent/consul/wanfed/wanfed.go | 29 ++++++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/agent/consul/server.go b/agent/consul/server.go index e44f26d1e9..470ca9c423 100644 --- a/agent/consul/server.go +++ b/agent/consul/server.go @@ -21,7 +21,6 @@ import ( connlimit "github.com/hashicorp/go-connlimit" "github.com/hashicorp/go-hclog" "github.com/hashicorp/go-memdb" - "github.com/hashicorp/memberlist" "github.com/hashicorp/raft" autopilot "github.com/hashicorp/raft-autopilot" raftboltdb "github.com/hashicorp/raft-boltdb" @@ -35,6 +34,7 @@ import ( "github.com/hashicorp/consul/agent/consul/fsm" "github.com/hashicorp/consul/agent/consul/state" "github.com/hashicorp/consul/agent/consul/usagemetrics" + "github.com/hashicorp/consul/agent/consul/wanfed" agentgrpc "github.com/hashicorp/consul/agent/grpc" "github.com/hashicorp/consul/agent/metadata" "github.com/hashicorp/consul/agent/pool" @@ -251,7 +251,7 @@ type Server struct { // serfWAN is the Serf cluster maintained between DC's // which SHOULD only consist of Consul servers serfWAN *serf.Serf - memberlistTransportWAN memberlist.IngestionAwareTransport + memberlistTransportWAN wanfed.IngestionAwareTransport gatewayLocator *GatewayLocator // serverLookup tracks server consuls in the local datacenter. @@ -500,7 +500,7 @@ func NewServer(config *Config, flat Deps) (*Server, error) { // This is always a *memberlist.NetTransport or something which wraps // it which satisfies this interface. - s.memberlistTransportWAN = config.SerfWANConfig.MemberlistConfig.Transport.(memberlist.IngestionAwareTransport) + s.memberlistTransportWAN = config.SerfWANConfig.MemberlistConfig.Transport.(wanfed.IngestionAwareTransport) // See big comment above why we are doing this. if serfBindPortWAN == 0 { diff --git a/agent/consul/wanfed/wanfed.go b/agent/consul/wanfed/wanfed.go index 5f620ee2fd..0afc0d6d6c 100644 --- a/agent/consul/wanfed/wanfed.go +++ b/agent/consul/wanfed/wanfed.go @@ -8,10 +8,11 @@ import ( "strings" "time" + "github.com/hashicorp/memberlist" + "github.com/hashicorp/consul/agent/pool" "github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/tlsutil" - "github.com/hashicorp/memberlist" ) const ( @@ -29,9 +30,15 @@ const ( type MeshGatewayResolver func(datacenter string) string +type IngestionAwareTransport interface { + memberlist.NodeAwareTransport + IngestPacket(conn net.Conn, addr net.Addr, now time.Time, shouldClose bool) error + IngestStream(conn net.Conn) error +} + func NewTransport( tlsConfigurator *tlsutil.Configurator, - transport memberlist.NodeAwareTransport, + transport IngestionAwareTransport, datacenter string, gwResolver MeshGatewayResolver, ) (*Transport, error) { @@ -48,17 +55,17 @@ func NewTransport( } t := &Transport{ - NodeAwareTransport: transport, - tlsConfigurator: tlsConfigurator, - datacenter: datacenter, - gwResolver: gwResolver, - pool: cp, + IngestionAwareTransport: transport, + tlsConfigurator: tlsConfigurator, + datacenter: datacenter, + gwResolver: gwResolver, + pool: cp, } return t, nil } type Transport struct { - memberlist.NodeAwareTransport + IngestionAwareTransport tlsConfigurator *tlsutil.Configurator datacenter string @@ -71,7 +78,7 @@ var _ memberlist.NodeAwareTransport = (*Transport)(nil) // Shutdown implements memberlist.Transport. func (t *Transport) Shutdown() error { err1 := t.pool.Close() - err2 := t.NodeAwareTransport.Shutdown() + err2 := t.IngestionAwareTransport.Shutdown() if err2 != nil { // the more important error is err2 return err2 @@ -118,7 +125,7 @@ func (t *Transport) WriteToAddress(b []byte, addr memberlist.Address) (time.Time return time.Now(), nil } - return t.NodeAwareTransport.WriteToAddress(b, addr) + return t.IngestionAwareTransport.WriteToAddress(b, addr) } // DialAddressTimeout implements memberlist.NodeAwareTransport. @@ -137,7 +144,7 @@ func (t *Transport) DialAddressTimeout(addr memberlist.Address, timeout time.Dur return t.dial(dc, node, pool.ALPN_WANGossipStream, gwAddr) } - return t.NodeAwareTransport.DialAddressTimeout(addr, timeout) + return t.IngestionAwareTransport.DialAddressTimeout(addr, timeout) } // NOTE: There is a close mirror of this method in agent/pool/pool.go:DialTimeoutWithRPCType