inproxy_disabled.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //go:build !PSIPHON_ENABLE_INPROXY
  2. /*
  3. * Copyright (c) 2024, Psiphon Inc.
  4. * All rights reserved.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. package inproxy
  21. import (
  22. "context"
  23. std_errors "errors"
  24. "net"
  25. "time"
  26. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  27. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  28. )
  29. // The inproxy package has a broad API that referenced throughout the psiphon
  30. // and psiphon/server packages.
  31. //
  32. // When PSIPHON_ENABLE_INPROXY is not specified, inproxy components are
  33. // disabled and large dependencies, including pion and tailscale, are not
  34. // referenced and excluded from builds. The stub types and functions here are
  35. // sufficient to omit all pion and tailscale references. The remaining, broad
  36. // inproxy API surface is not stubbed out.
  37. //
  38. // Client/proxy and server/broker integrations in psiphon and psiphon/server
  39. // should all check inproxy.Enabled and, when false, skip or fail early
  40. // before trying to use inproxy components.
  41. // Enabled indicates if in-proxy functionality is enabled.
  42. func Enabled() bool {
  43. return false
  44. }
  45. var errNotEnabled = std_errors.New("operation not enabled")
  46. const (
  47. dataChannelAwaitTimeout = time.Duration(0)
  48. )
  49. type webRTCConn struct {
  50. }
  51. type webRTCConfig struct {
  52. Logger common.Logger
  53. EnableDebugLogging bool
  54. WebRTCDialCoordinator WebRTCDialCoordinator
  55. ClientRootObfuscationSecret ObfuscationSecret
  56. DoDTLSRandomization bool
  57. TrafficShapingParameters *DataChannelTrafficShapingParameters
  58. ReliableTransport bool
  59. }
  60. func (conn *webRTCConn) SetRemoteSDP(peerSDP WebRTCSessionDescription) error {
  61. return errors.Trace(errNotEnabled)
  62. }
  63. // AwaitInitialDataChannel returns when the data channel is established, or
  64. // when an error has occured.
  65. func (conn *webRTCConn) AwaitInitialDataChannel(ctx context.Context) error {
  66. return errors.Trace(errNotEnabled)
  67. }
  68. func (conn *webRTCConn) Close() error {
  69. return errors.Trace(errNotEnabled)
  70. }
  71. func (conn *webRTCConn) IsClosed() bool {
  72. return false
  73. }
  74. func (conn *webRTCConn) Read(p []byte) (int, error) {
  75. return 0, errors.Trace(errNotEnabled)
  76. }
  77. func (conn *webRTCConn) Write(p []byte) (int, error) {
  78. return 0, errors.Trace(errNotEnabled)
  79. }
  80. func (conn *webRTCConn) LocalAddr() net.Addr {
  81. return nil
  82. }
  83. func (conn *webRTCConn) RemoteAddr() net.Addr {
  84. return nil
  85. }
  86. func (conn *webRTCConn) SetDeadline(t time.Time) error {
  87. return errors.Trace(errNotEnabled)
  88. }
  89. func (conn *webRTCConn) SetReadDeadline(t time.Time) error {
  90. return errors.Trace(errNotEnabled)
  91. }
  92. func (conn *webRTCConn) SetWriteDeadline(t time.Time) error {
  93. return errors.Trace(errNotEnabled)
  94. }
  95. func (conn *webRTCConn) GetMetrics() common.LogFields {
  96. return nil
  97. }
  98. type webRTCSDPMetrics struct {
  99. iceCandidateTypes []ICECandidateType
  100. hasIPv6 bool
  101. }
  102. func newWebRTCConnWithOffer(
  103. ctx context.Context,
  104. config *webRTCConfig) (
  105. *webRTCConn, WebRTCSessionDescription, *webRTCSDPMetrics, error) {
  106. return nil, WebRTCSessionDescription{}, nil, errors.Trace(errNotEnabled)
  107. }
  108. func newWebRTCConnWithAnswer(
  109. ctx context.Context,
  110. config *webRTCConfig,
  111. peerSDP WebRTCSessionDescription) (
  112. *webRTCConn, WebRTCSessionDescription, *webRTCSDPMetrics, error) {
  113. return nil, WebRTCSessionDescription{}, nil, errors.Trace(errNotEnabled)
  114. }
  115. func validateSDPAddresses(
  116. encodedSDP []byte,
  117. errorOnNoCandidates bool,
  118. lookupGeoIP LookupGeoIP,
  119. expectedGeoIPData common.GeoIPData) (*webRTCSDPMetrics, error) {
  120. return nil, errors.Trace(errNotEnabled)
  121. }
  122. func initPortMapper(coordinator WebRTCDialCoordinator) {
  123. }
  124. func probePortMapping(
  125. ctx context.Context,
  126. logger common.Logger) (PortMappingTypes, error) {
  127. return nil, errors.Trace(errNotEnabled)
  128. }
  129. func discoverNATMapping(
  130. ctx context.Context,
  131. conn net.PacketConn,
  132. serverAddress string) (NATMapping, error) {
  133. return NATMappingUnknown, errors.Trace(errNotEnabled)
  134. }
  135. func discoverNATFiltering(
  136. ctx context.Context,
  137. conn net.PacketConn,
  138. serverAddress string) (NATFiltering, error) {
  139. return NATFilteringUnknown, errors.Trace(errNotEnabled)
  140. }