inproxy_disabled.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. readyToProxyAwaitTimeout = 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. UseMediaStreams bool
  58. TrafficShapingParameters *TrafficShapingParameters
  59. ReliableTransport bool
  60. }
  61. func (conn *webRTCConn) SetRemoteSDP(
  62. peerSDP WebRTCSessionDescription,
  63. hasPersonalCompartmentIDs bool) error {
  64. return errors.Trace(errNotEnabled)
  65. }
  66. func (conn *webRTCConn) AwaitReadyToProxy(ctx context.Context, connectionID ID) error {
  67. return errors.Trace(errNotEnabled)
  68. }
  69. func (conn *webRTCConn) Close() error {
  70. return errors.Trace(errNotEnabled)
  71. }
  72. func (conn *webRTCConn) IsClosed() bool {
  73. return false
  74. }
  75. func (conn *webRTCConn) Read(p []byte) (int, error) {
  76. return 0, errors.Trace(errNotEnabled)
  77. }
  78. func (conn *webRTCConn) Write(p []byte) (int, error) {
  79. return 0, errors.Trace(errNotEnabled)
  80. }
  81. func (conn *webRTCConn) LocalAddr() net.Addr {
  82. return nil
  83. }
  84. func (conn *webRTCConn) RemoteAddr() net.Addr {
  85. return nil
  86. }
  87. func (conn *webRTCConn) SetDeadline(t time.Time) error {
  88. return errors.Trace(errNotEnabled)
  89. }
  90. func (conn *webRTCConn) SetReadDeadline(t time.Time) error {
  91. return errors.Trace(errNotEnabled)
  92. }
  93. func (conn *webRTCConn) SetWriteDeadline(t time.Time) error {
  94. return errors.Trace(errNotEnabled)
  95. }
  96. func (conn *webRTCConn) GetMetrics() common.LogFields {
  97. return nil
  98. }
  99. func GetQUICMaxPacketSizeAdjustment() int {
  100. return 0
  101. }
  102. type webRTCSDPMetrics struct {
  103. iceCandidateTypes []ICECandidateType
  104. hasIPv6 bool
  105. hasPrivateIP bool
  106. filteredICECandidates []string
  107. }
  108. func newWebRTCConnForOffer(
  109. ctx context.Context,
  110. config *webRTCConfig,
  111. hasPersonalCompartmentIDs bool) (
  112. *webRTCConn, WebRTCSessionDescription, *webRTCSDPMetrics, error) {
  113. return nil, WebRTCSessionDescription{}, nil, errors.Trace(errNotEnabled)
  114. }
  115. func newWebRTCConnForAnswer(
  116. ctx context.Context,
  117. config *webRTCConfig,
  118. peerSDP WebRTCSessionDescription,
  119. hasPersonalCompartmentIDs bool) (
  120. *webRTCConn, WebRTCSessionDescription, *webRTCSDPMetrics, error) {
  121. return nil, WebRTCSessionDescription{}, nil, errors.Trace(errNotEnabled)
  122. }
  123. func filterSDPAddresses(
  124. encodedSDP []byte,
  125. errorOnNoCandidates bool,
  126. lookupGeoIP LookupGeoIP,
  127. expectedGeoIPData common.GeoIPData,
  128. allowPrivateIPAddressCandidates bool,
  129. filterPrivateIPAddressCandidates bool) ([]byte, *webRTCSDPMetrics, error) {
  130. return nil, nil, errors.Trace(errNotEnabled)
  131. }
  132. func initPortMapper(coordinator WebRTCDialCoordinator) {
  133. }
  134. type PortMappingProbe struct {
  135. }
  136. func probePortMapping(
  137. ctx context.Context,
  138. logger common.Logger) (PortMappingTypes, *PortMappingProbe, error) {
  139. return nil, nil, errors.Trace(errNotEnabled)
  140. }
  141. func discoverNATMapping(
  142. ctx context.Context,
  143. conn net.PacketConn,
  144. serverAddress string) (NATMapping, error) {
  145. return NATMappingUnknown, errors.Trace(errNotEnabled)
  146. }
  147. func discoverNATFiltering(
  148. ctx context.Context,
  149. conn net.PacketConn,
  150. serverAddress string) (NATFiltering, error) {
  151. return NATFilteringUnknown, errors.Trace(errNotEnabled)
  152. }