pingpong 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # This shell script uses nc-like executables to send and receive the file at
  2. # $1, and prints the checksums. 3 such executables are
  3. # github.com/h2so5/utp/ucat, invoked as h2so5-ucat, libutp-ucat, which is the
  4. # ucat or ucat-static generated by the C++ libutp, and lastly, ./cmd/ucat from
  5. # this repository. A good file in my experiments is no more than a few 100MB,
  6. # or you'll be waiting a while.
  7. set -eu
  8. # set -x
  9. # Passed to invocations of godo for package ./cmd/ucat.
  10. #GODOFLAGS=-race
  11. #export GO_UTP_PACKET_DROP=0.1
  12. export GOPPROF=
  13. # Invokes the implementation to test against. If there's an arg, then it's
  14. # expected to listen.
  15. function other_ucat() {
  16. if [[ $# != 0 ]]; then
  17. libutp-ucat -l -p "$port"
  18. # h2so5-ucat -l :"$port"
  19. else
  20. libutp-ucat localhost "$port"
  21. # h2so5-ucat localhost:"$port"
  22. fi
  23. }
  24. function md5cmd() {
  25. (which md5sum > /dev/null && md5sum "$@") || (which md5 > /dev/null && md5 "$@") || md5sum "$@"
  26. }
  27. # Check what the correct result is.
  28. md5cmd "$1"
  29. rate() {
  30. pv -a -W -b
  31. }
  32. port=4000
  33. echo 'utp->other_ucat'
  34. # Send from this uTP implementation to another client.
  35. other_ucat -l | rate | md5cmd &
  36. # sleep 1
  37. godo ${GODOFLAGS-} ./cmd/ucat localhost "$port" < "$1"
  38. wait
  39. echo 'other_ucat->utp'
  40. # Send from the other implementation, to this one.
  41. GO_UTP_LOGGING=0 godo ${GODOFLAGS-} ./cmd/ucat -l -p "$port" | rate | md5cmd &
  42. # Never receive from h2so5's ucat without a small sleep first. Don't know why.
  43. sleep 1
  44. other_ucat < "$1"
  45. wait
  46. echo 'libutp->libutp'
  47. libutp-ucat -l -p "$port" | rate | md5cmd &
  48. libutp-ucat localhost "$port" < "$1"
  49. wait
  50. echo 'utp->utp'
  51. godo ./cmd/ucat -l -p "$port" | rate | md5cmd &
  52. sleep 1
  53. godo ./cmd/ucat localhost "$port" < "$1"
  54. wait
  55. # Now check the hashes match (yes you).