"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/tcp/proxy.go" between
traefik-v2.3.2.src.tar.gz and traefik-v2.3.3.src.tar.gz

About: Traefik is a cloud native edge router, a reverse proxy and load balancer for HTTP and TCP-based applications.

proxy.go  (traefik-v2.3.2.src):proxy.go  (traefik-v2.3.3.src)
skipping to change at line 13 skipping to change at line 13
import ( import (
"io" "io"
"net" "net"
"time" "time"
"github.com/traefik/traefik/v2/pkg/log" "github.com/traefik/traefik/v2/pkg/log"
) )
// Proxy forwards a TCP request to a TCP service. // Proxy forwards a TCP request to a TCP service.
type Proxy struct { type Proxy struct {
address string
target *net.TCPAddr target *net.TCPAddr
terminationDelay time.Duration terminationDelay time.Duration
refreshTarget bool
} }
// NewProxy creates a new Proxy. // NewProxy creates a new Proxy.
func NewProxy(address string, terminationDelay time.Duration) (*Proxy, error) { func NewProxy(address string, terminationDelay time.Duration) (*Proxy, error) {
tcpAddr, err := net.ResolveTCPAddr("tcp", address) tcpAddr, err := net.ResolveTCPAddr("tcp", address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Proxy{target: tcpAddr, terminationDelay: terminationDelay}, nil // enable the refresh of the target only if the address in an IP
refreshTarget := false
if host, _, err := net.SplitHostPort(address); err == nil && net.ParseIP(
host) == nil {
refreshTarget = true
}
return &Proxy{
address: address,
target: tcpAddr,
refreshTarget: refreshTarget,
terminationDelay: terminationDelay,
}, nil
} }
// ServeTCP forwards the connection to a service. // ServeTCP forwards the connection to a service.
func (p *Proxy) ServeTCP(conn WriteCloser) { func (p *Proxy) ServeTCP(conn WriteCloser) {
log.Debugf("Handling connection from %s", conn.RemoteAddr()) log.Debugf("Handling connection from %s", conn.RemoteAddr())
// needed because of e.g. server.trackedConnection // needed because of e.g. server.trackedConnection
defer conn.Close() defer conn.Close()
if p.refreshTarget {
tcpAddr, err := net.ResolveTCPAddr("tcp", p.address)
if err != nil {
log.Errorf("Error resolving tcp address: %v", err)
return
}
p.target = tcpAddr
}
connBackend, err := net.DialTCP("tcp", nil, p.target) connBackend, err := net.DialTCP("tcp", nil, p.target)
if err != nil { if err != nil {
log.Errorf("Error while connection to backend: %v", err) log.Errorf("Error while connection to backend: %v", err)
return return
} }
// maybe not needed, but just in case // maybe not needed, but just in case
defer connBackend.Close() defer connBackend.Close()
errChan := make(chan error) errChan := make(chan error)
 End of changes. 4 change blocks. 
1 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)