MCPcopy Create free account
hub / github.com/celzero/midway / proxyCopy

Function proxyCopy

midway/relay/proxy.go:166–192  ·  view source on GitHub ↗

TODO: admission control with tc / htb

(label string, dst, src net.Conn, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

164
165// TODO: admission control with tc / htb
166func 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

Callers 1

ForwardMethod · 0.85

Calls 4

underlyingConnFunction · 0.85
RemoteAddrMethod · 0.80
LocalAddrMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected