github.com/TykTechnologies/tyk/tcp
No package summary is available.
Package
Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Constants
const (
Active ConnState = iota
Open
Closed
)
Vars
var log = logger.Get().WithField("prefix", "tcp-proxy")
Types
ConnState
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| type |
|
No comment on field. |
type ConnState uint
Modifier
Modifier define rules for tranforming incoming and outcoming TCP messages To filter response set data to empty To close connection, return error
| Field name | Field type | Comment |
|---|---|---|
| ModifyRequest |
|
No comment on field. |
| ModifyResponse |
|
No comment on field. |
type Modifier struct {
ModifyRequest func(src, dst net.Conn, data []byte) ([]byte, error)
ModifyResponse func(src, dst net.Conn, data []byte) ([]byte, error)
}
Proxy
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
|
No comment on field. | |
| DialTLS |
|
No comment on field. |
| Dial |
|
No comment on field. |
| TLSConfigTarget |
|
No comment on field. |
| ReadTimeout |
|
No comment on field. |
| WriteTimeout |
|
No comment on field. |
| muxer |
|
Domain to config mapping |
| SyncStats |
|
No comment on field. |
| StatsSyncInterval |
|
Duration in which connection stats will be flushed. Defaults to one second. |
type Proxy struct {
sync.RWMutex
DialTLS func(network, addr string) (net.Conn, error)
Dial func(network, addr string) (net.Conn, error)
TLSConfigTarget *tls.Config
ReadTimeout time.Duration
WriteTimeout time.Duration
// Domain to config mapping
muxer map[string]*targetConfig
SyncStats func(Stat)
// Duration in which connection stats will be flushed. Defaults to one second.
StatsSyncInterval time.Duration
}
Stat
Stat defines basic statistics about a tcp connection
| Field name | Field type | Comment |
|---|---|---|
| State |
|
No comment on field. |
| BytesIn |
|
No comment on field. |
| BytesOut |
|
No comment on field. |
type Stat struct {
State ConnState
BytesIn int64
BytesOut int64
}
pipeOpts
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| modifier |
|
No comment on field. |
| onReadError |
|
No comment on field. |
| onWriteError |
|
No comment on field. |
| beforeExit |
|
No comment on field. |
type pipeOpts struct {
modifier func(net.Conn, net.Conn, []byte) ([]byte, error)
onReadError func(error)
onWriteError func(error)
beforeExit func()
}
targetConfig
This type doesn't have documentation.
| Field name | Field type | Comment |
|---|---|---|
| modifier |
|
No comment on field. |
| target |
|
No comment on field. |
type targetConfig struct {
modifier *Modifier
target string
}
Functions
func IsSocketClosed
IsSocketClosed returns true if err is a result of reading from closed network connection
func IsSocketClosed(err error) bool {
return strings.Contains(err.Error(), "use of closed network connection")
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*Proxy) AddDomainHandler
func (p *Proxy) AddDomainHandler(domain, target string, modifier *Modifier) {
p.Lock()
defer p.Unlock()
if p.muxer == nil {
p.muxer = make(map[string]*targetConfig)
}
if modifier == nil {
modifier = &Modifier{}
}
p.muxer[domain] = &targetConfig{
modifier: modifier,
target: target,
}
}
Cognitive complexity: 6, Cyclomatic complexity: 3
func (*Proxy) RemoveDomainHandler
func (p *Proxy) RemoveDomainHandler(domain string) {
p.Lock()
defer p.Unlock()
delete(p.muxer, domain)
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*Proxy) Serve
func (p *Proxy) Serve(l net.Listener) error {
for {
conn, err := l.Accept()
if err != nil {
log.WithError(err).Warning("Can't accept connection")
return err
}
go func() {
if err := p.handleConn(conn); err != nil {
log.WithError(err).Warning("Can't handle connection")
}
}()
}
}
Cognitive complexity: 7, Cyclomatic complexity: 4
func (*Proxy) Swap
func (p *Proxy) Swap(new *Proxy) {
p.Lock()
defer p.Unlock()
p.muxer = new.muxer
p.TLSConfigTarget = new.TLSConfigTarget
}
Cognitive complexity: 0, Cyclomatic complexity: 1
func (*Stat) Flush
func (s *Stat) Flush() Stat {
v := Stat{
BytesIn: atomic.LoadInt64(&s.BytesIn),
BytesOut: atomic.LoadInt64(&s.BytesOut),
}
atomic.StoreInt64(&s.BytesIn, 0)
atomic.StoreInt64(&s.BytesOut, 0)
return v
}
Cognitive complexity: 1, Cyclomatic complexity: 1
Private functions
func clientConn
clientConn (c net.Conn) string
func formatAddress
formatAddress (a,b net.Addr) string
func upstreamConn
upstreamConn (c net.Conn) string
func getTargetConfig
getTargetConfig (conn net.Conn) (*targetConfig, error)
References: errors.New, tls.Conn.
func handleConn
handleConn (conn net.Conn) error
References: atomic.AddInt64, atomic.Value, context.Background, context.WithCancel, errors.Is, errors.New, io.EOF, net.Conn, net.Dial, sync.WaitGroup, time.NewTicker, time.Second, tls.Dial, url.Parse.
func pipe
pipe (src,dst net.Conn, opts pipeOpts)
References: time.Now, time.Time.
Tests
Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 3. Benchmarks: 0.