NewServer returns a proxy implementation with no iptables/tc dependencies. The proxy layer overhead is <1ms.
(cfg ServerConfig)
| 192 | // NewServer returns a proxy implementation with no iptables/tc dependencies. |
| 193 | // The proxy layer overhead is <1ms. |
| 194 | func NewServer(cfg ServerConfig) Server { |
| 195 | s := &server{ |
| 196 | lg: cfg.Logger, |
| 197 | |
| 198 | from: cfg.From, |
| 199 | to: cfg.To, |
| 200 | |
| 201 | tlsInfo: cfg.TLSInfo, |
| 202 | dialTimeout: cfg.DialTimeout, |
| 203 | |
| 204 | bufferSize: cfg.BufferSize, |
| 205 | retryInterval: cfg.RetryInterval, |
| 206 | |
| 207 | readyc: make(chan struct{}), |
| 208 | donec: make(chan struct{}), |
| 209 | errc: make(chan error, 16), |
| 210 | |
| 211 | pauseAcceptc: make(chan struct{}), |
| 212 | pauseTxc: make(chan struct{}), |
| 213 | pauseRxc: make(chan struct{}), |
| 214 | } |
| 215 | |
| 216 | _, fromPort, err := net.SplitHostPort(cfg.From.Host) |
| 217 | if err == nil { |
| 218 | s.fromPort, _ = strconv.Atoi(fromPort) |
| 219 | } |
| 220 | var toPort string |
| 221 | _, toPort, err = net.SplitHostPort(cfg.To.Host) |
| 222 | if err == nil { |
| 223 | s.toPort, _ = strconv.Atoi(toPort) |
| 224 | } |
| 225 | |
| 226 | if s.dialTimeout == 0 { |
| 227 | s.dialTimeout = defaultDialTimeout |
| 228 | } |
| 229 | if s.bufferSize == 0 { |
| 230 | s.bufferSize = defaultBufferSize |
| 231 | } |
| 232 | if s.retryInterval == 0 { |
| 233 | s.retryInterval = defaultRetryInterval |
| 234 | } |
| 235 | |
| 236 | close(s.pauseAcceptc) |
| 237 | close(s.pauseTxc) |
| 238 | close(s.pauseRxc) |
| 239 | |
| 240 | if strings.HasPrefix(s.from.Scheme, "http") { |
| 241 | s.from.Scheme = "tcp" |
| 242 | } |
| 243 | if strings.HasPrefix(s.to.Scheme, "http") { |
| 244 | s.to.Scheme = "tcp" |
| 245 | } |
| 246 | |
| 247 | addr := fmt.Sprintf(":%d", s.fromPort) |
| 248 | if s.fromPort == 0 { // unix |
| 249 | addr = s.from.Host |
| 250 | } |
| 251 |
searching dependent graphs…