packet-trace.diff 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. diff --git a/Temp/inproxy-proto2/inproxy/inproxy_test.go b/Temp/inproxy-proto2/inproxy/inproxy_test.go
  2. index 334befb1..6da022d3 100644
  3. --- a/Temp/inproxy-proto2/inproxy/inproxy_test.go
  4. +++ b/Temp/inproxy-proto2/inproxy/inproxy_test.go
  5. @@ -80,12 +80,15 @@ func runTestInProxy() error {
  6. //numProxies := 10
  7. //proxyMaxClients := 5
  8. //numClients := 100
  9. - numProxies := 5
  10. - proxyMaxClients := 2
  11. - numClients := 10
  12. + numProxies := 1
  13. + proxyMaxClients := 1
  14. + numClients := 5
  15. + // *TEMP*
  16. + //bytesToSend := 1 << 20
  17. + //messageSize := 1 << 10
  18. bytesToSend := 1 << 20
  19. - messageSize := 1 << 10
  20. + messageSize := 1024
  21. targetElapsedSeconds := 2
  22. baseMetrics := common.APIParameters{
  23. @@ -349,6 +352,9 @@ func runTestInProxy() error {
  24. makeClientFunc := func(isTCP bool) func() error {
  25. + // *TEMP*
  26. + isTCP = false
  27. +
  28. // *DOC* use echo server address as proxy destination; alternate TCP/UDP
  29. var network, addr string
  30. if isTCP {
  31. @@ -429,6 +435,10 @@ func runTestInProxy() error {
  32. if bytesToSend-n < m {
  33. m = bytesToSend - n
  34. }
  35. +
  36. + // *TEMP*
  37. + fmt.Printf(" > SEND: %x\n", prefix(sendBytes[n:n+m]))
  38. +
  39. _, err := conn.Write(sendBytes[n : n+m])
  40. if err != nil {
  41. return errors.Trace(err)
  42. @@ -446,7 +456,15 @@ func runTestInProxy() error {
  43. if err != nil {
  44. return errors.Trace(err)
  45. }
  46. +
  47. + // *TEMP*
  48. + fmt.Printf(" > RECV: %x\n", prefix(buf[:m]))
  49. +
  50. if !bytes.Equal(sendBytes[n:n+m], buf[:m]) {
  51. +
  52. + // *TEMP*
  53. + fmt.Printf(" > RECV: !EQUAL\n")
  54. +
  55. // *DOC* index logged to diagnose out-of-order or dropped message vs. entirely wrong bytes
  56. return errors.Tracef(
  57. "unexpected bytes: expected at index %d, received at index %d",
  58. @@ -636,6 +654,13 @@ func runTCPEchoServer(listener net.Listener) {
  59. }
  60. }
  61. +func prefix(b []byte) []byte {
  62. + if len(b) <= 8 {
  63. + return b
  64. + }
  65. + return b[:8]
  66. +}
  67. +
  68. func runUDPEchoServer(packetConn net.PacketConn) {
  69. buf := make([]byte, 65536)
  70. for {
  71. @@ -643,6 +668,10 @@ func runUDPEchoServer(packetConn net.PacketConn) {
  72. if err != nil {
  73. return
  74. }
  75. +
  76. + // *TEMP*
  77. + fmt.Printf(" > RELAY: %x\n", prefix(buf[:n]))
  78. +
  79. _, err = packetConn.WriteTo(buf[:n], addr)
  80. if err != nil {
  81. return
  82. diff --git a/Temp/inproxy-proto2/inproxy/proxy.go b/Temp/inproxy-proto2/inproxy/proxy.go
  83. index fd6e158f..2531e276 100644
  84. --- a/Temp/inproxy-proto2/inproxy/proxy.go
  85. +++ b/Temp/inproxy-proto2/inproxy/proxy.go
  86. @@ -27,6 +27,8 @@ import (
  87. "sync/atomic"
  88. "time"
  89. + "fmt"
  90. +
  91. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  92. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  93. "github.com/pion/webrtc/v3"
  94. @@ -403,11 +405,45 @@ func (p *Proxy) proxyOneClient(ctx context.Context) error {
  95. waitGroup := new(sync.WaitGroup)
  96. relayErrors := make(chan error, 2)
  97. + // *TEMP*
  98. + myCopy := func(dst io.Writer, src io.Reader, buf []byte) (written int64, err error) {
  99. + for {
  100. + nr, er := src.Read(buf)
  101. + if nr > 0 {
  102. + fmt.Printf(" > COPY: %x\n", prefix(buf[:nr]))
  103. + nw, ew := dst.Write(buf[0:nr])
  104. + if nw < 0 || nr < nw {
  105. + nw = 0
  106. + if ew == nil {
  107. + ew = errors.TraceNew("write invalid")
  108. + }
  109. + }
  110. + written += int64(nw)
  111. + if ew != nil {
  112. + err = ew
  113. + break
  114. + }
  115. + if nr != nw {
  116. + err = io.ErrShortWrite
  117. + break
  118. + }
  119. + }
  120. + if er != nil {
  121. + if er != io.EOF {
  122. + err = er
  123. + }
  124. + break
  125. + }
  126. + }
  127. + return written, err
  128. + }
  129. +
  130. waitGroup.Add(1)
  131. go func() {
  132. defer waitGroup.Done()
  133. - // *TODO* doc: for packet conn, io.Copy buffer must be packet MTU; it's 32K
  134. - _, err = io.Copy(webRTCConn, upstreamConn)
  135. + // *TODO* doc: for packet conn, io.Copy buffer must be packet MTU; it's 32K; need 64K?
  136. + var buf [65536]byte
  137. + _, err = io.CopyBuffer(webRTCConn, upstreamConn, buf[:])
  138. if err != nil {
  139. relayErrors <- errors.Trace(err)
  140. return
  141. @@ -417,7 +453,10 @@ func (p *Proxy) proxyOneClient(ctx context.Context) error {
  142. waitGroup.Add(1)
  143. go func() {
  144. defer waitGroup.Done()
  145. - _, err := io.Copy(upstreamConn, webRTCConn)
  146. + var buf [65536]byte
  147. + // *TEMP*
  148. + //_, err := io.CopyBuffer(upstreamConn, webRTCConn, buf[:])
  149. + _, err := myCopy(upstreamConn, webRTCConn, buf[:])
  150. if err != nil {
  151. relayErrors <- errors.Trace(err)
  152. return