interfaces.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package lib
  2. import (
  3. "io"
  4. "net"
  5. )
  6. type Connector interface {
  7. Connect() error
  8. }
  9. type Resetter interface {
  10. Reset()
  11. WaitForReset()
  12. }
  13. // Interface for a single remote WebRTC peer.
  14. // In the Client context, "Snowflake" refers to the remote browser proxy.
  15. type Snowflake interface {
  16. io.ReadWriteCloser
  17. Resetter
  18. Connector
  19. }
  20. // Interface for catching Snowflakes. (aka the remote dialer)
  21. type Tongue interface {
  22. Catch() (Snowflake, error)
  23. }
  24. // Interface for collecting some number of Snowflakes, for passing along
  25. // ultimately to the SOCKS handler.
  26. type SnowflakeCollector interface {
  27. // Add a Snowflake to the collection.
  28. // Implementation should decide how to connect and maintain the webRTCConn.
  29. Collect() (Snowflake, error)
  30. // Remove and return the most available Snowflake from the collection.
  31. Pop() Snowflake
  32. // Signal when the collector has stopped collecting.
  33. Melted() <-chan struct{}
  34. }
  35. // Interface to adapt to goptlib's SocksConn struct.
  36. type SocksConnector interface {
  37. Grant(*net.TCPAddr) error
  38. Reject() error
  39. net.Conn
  40. }
  41. // Interface for the Snowflake's transport. (Typically just webrtc.DataChannel)
  42. type SnowflakeDataChannel interface {
  43. io.Closer
  44. Send([]byte) error
  45. }