Conn returns a net.Conn that wraps c and injects n's latency into that connection. This function also imposes latency for connection creation. If n's Latency is lower than the measured latency in c, an error is returned.
(c net.Conn)
| 82 | // If n's Latency is lower than the measured latency in c, an error is |
| 83 | // returned. |
| 84 | func (n *Network) Conn(c net.Conn) (net.Conn, error) { |
| 85 | if n.isLocal() { |
| 86 | return c, nil |
| 87 | } |
| 88 | start := now() |
| 89 | nc := &conn{Conn: c, network: n, readBuf: new(bytes.Buffer)} |
| 90 | if err := nc.sync(); err != nil { |
| 91 | return nil, err |
| 92 | } |
| 93 | sleep(start.Add(nc.delay).Sub(now())) |
| 94 | return nc, nil |
| 95 | } |
| 96 | |
| 97 | type conn struct { |
| 98 | net.Conn |