consul: Provide logger to yamux

This commit is contained in:
Armon Dadgar 2014-05-28 16:32:10 -07:00
parent 6b2fe4869b
commit 319ab05b8c
4 changed files with 16 additions and 5 deletions

View File

@ -99,7 +99,7 @@ func NewClient(config *Config) (*Client, error) {
// Create server
c := &Client{
config: config,
connPool: NewPool(clientRPCCache, clientMaxStreams, tlsConfig),
connPool: NewPool(config.LogOutput, clientRPCCache, clientMaxStreams, tlsConfig),
eventCh: make(chan serf.Event, 256),
logger: logger,
shutdownCh: make(chan struct{}),

View File

@ -7,6 +7,7 @@ import (
"github.com/hashicorp/yamux"
"github.com/inconshreveable/muxado"
"github.com/ugorji/go/codec"
"io"
"net"
"net/rpc"
"sync"
@ -110,6 +111,9 @@ func (c *Conn) returnClient(client *StreamClient) {
type ConnPool struct {
sync.Mutex
// LogOutput is used to control logging
logOutput io.Writer
// The maximum time to keep a connection open
maxTime time.Duration
@ -132,8 +136,9 @@ type ConnPool struct {
// Set maxTime to 0 to disable reaping. maxStreams is used to control
// the number of idle streams allowed.
// If TLS settings are provided outgoing connections use TLS.
func NewPool(maxTime time.Duration, maxStreams int, tlsConfig *tls.Config) *ConnPool {
func NewPool(logOutput io.Writer, maxTime time.Duration, maxStreams int, tlsConfig *tls.Config) *ConnPool {
pool := &ConnPool{
logOutput: logOutput,
maxTime: maxTime,
maxStreams: maxStreams,
pool: make(map[string]*Conn),
@ -235,8 +240,12 @@ func (p *ConnPool) getNewConn(addr net.Addr, version int) (*Conn, error) {
return nil, err
}
// Setup the logger
conf := yamux.DefaultConfig()
conf.LogOutput = nil
// Create a multiplexed session
session, _ = yamux.Client(conn, nil)
session, _ = yamux.Client(conn, conf)
}
// Wrap the connection

View File

@ -130,7 +130,9 @@ func (s *Server) handleMultiplex(conn net.Conn) {
// using the Yamux multiplexer
func (s *Server) handleMultiplexV2(conn net.Conn) {
defer conn.Close()
server, _ := yamux.Server(conn, nil)
conf := yamux.DefaultConfig()
conf.LogOutput = s.config.LogOutput
server, _ := yamux.Server(conn, conf)
for {
sub, err := server.Accept()
if err != nil {

View File

@ -163,7 +163,7 @@ func NewServer(config *Config) (*Server, error) {
// Create server
s := &Server{
config: config,
connPool: NewPool(serverRPCCache, serverMaxStreams, tlsConfig),
connPool: NewPool(config.LogOutput, serverRPCCache, serverMaxStreams, tlsConfig),
eventChLAN: make(chan serf.Event, 256),
eventChWAN: make(chan serf.Event, 256),
localConsuls: make(map[string]*serverParts),