TODO: admission control with tc / htb
(label string, dst, src net.Conn, wg *sync.WaitGroup)
| 164 | |
| 165 | // TODO: admission control with tc / htb |
| 166 | func proxyCopy(label string, dst, src net.Conn, wg *sync.WaitGroup) { |
| 167 | defer wg.Done() |
| 168 | |
| 169 | // Before we unwrap src and/or dst, copy any buffered data. |
| 170 | if wc, ok := src.(*Conn); ok && len(wc.Peeked) > 0 { |
| 171 | if _, err := dst.Write(wc.Peeked); err != nil { |
| 172 | log.Print(label, " peek ", err) |
| 173 | return |
| 174 | } |
| 175 | wc.Peeked = nil |
| 176 | } |
| 177 | |
| 178 | // Unwrap the src and dst from *Conn to *net.TCPConn so Go |
| 179 | // 1.11's splice optimization kicks in. |
| 180 | src = underlyingConn(src) |
| 181 | dst = underlyingConn(dst) |
| 182 | |
| 183 | if n, err := io.Copy(dst, src); err == nil { |
| 184 | from := src.RemoteAddr() |
| 185 | to := dst.RemoteAddr() |
| 186 | leg := src.LocalAddr() |
| 187 | returnleg := dst.LocalAddr() |
| 188 | log.Printf("%s; [src %s (via %s)] -> [dst %s via (%s)]; tx: %d", label, from, leg, to, returnleg, n) |
| 189 | } else { |
| 190 | log.Print(label, " copy ", err) |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | // always "tcp" for now, because for web properties that are ipv4-only |
| 195 | // cause connect-timeouts from incoming ipv6 connections. Instead of |
no test coverage detected