client.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  2. * Copyright (c) 2023, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package inproxy
  20. import (
  21. "context"
  22. "fmt"
  23. "net"
  24. "net/netip"
  25. "sync"
  26. "time"
  27. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  28. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  29. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
  30. )
  31. const (
  32. clientOfferRetryDelay = 1 * time.Second
  33. clientOfferRetryJitter = 0.3
  34. )
  35. // ClientConn is a network connection to an in-proxy, which is relayed to a
  36. // Psiphon server destination. Psiphon clients use a ClientConn in place of a
  37. // physical TCP or UDP socket connection, passing the ClientConn into tunnel
  38. // protocol dials. ClientConn implements both net.Conn and net.PacketConn,
  39. // with net.PacketConn's ReadFrom/WriteTo behaving as if connected to the
  40. // initial dial address.
  41. type ClientConn struct {
  42. config *ClientConfig
  43. webRTCConn *webRTCConn
  44. connectionID ID
  45. remoteAddr net.Addr
  46. metrics common.LogFields
  47. relayMutex sync.Mutex
  48. initialRelayPacket []byte
  49. }
  50. // ClientConfig specifies the configuration for a ClientConn dial.
  51. type ClientConfig struct {
  52. // Logger is used to log events.
  53. Logger common.Logger
  54. // EnableWebRTCDebugLogging indicates whether to emit WebRTC debug logs.
  55. EnableWebRTCDebugLogging bool
  56. // BaseAPIParameters should be populated with Psiphon handshake metrics
  57. // parameters. These will be sent to and logger by the broker.
  58. BaseAPIParameters common.APIParameters
  59. // BrokerClient is the BrokerClient to use for broker API calls. The
  60. // BrokerClient may be shared with other client dials, allowing for
  61. // connection and session reuse.
  62. BrokerClient *BrokerClient
  63. // WebRTCDialCoordinator specifies specific WebRTC dial strategies and
  64. // settings; WebRTCDialCoordinator also facilities dial replay by
  65. // receiving callbacks when individual dial steps succeed or fail.
  66. WebRTCDialCoordinator WebRTCDialCoordinator
  67. // ReliableTransport specifies whether to use reliable delivery with the
  68. // underlying WebRTC DataChannel that relays the ClientConn traffic. When
  69. // using a ClientConn to proxy traffic that expects reliable delivery, as
  70. // if the physical network protocol were TCP, specify true. When using a
  71. // ClientConn to proxy traffic that expects unreliable delivery, such as
  72. // QUIC protocols expecting the physical network protocol UDP, specify
  73. // false.
  74. ReliableTransport bool
  75. // DialNetworkProtocol specifies whether the in-proxy will relay TCP or UDP
  76. // traffic.
  77. DialNetworkProtocol NetworkProtocol
  78. // DialAddress is the host:port destination network address the in-proxy
  79. // will relay traffic to.
  80. DialAddress string
  81. // RemoteAddrOverride, when specified, is the address to be returned by
  82. // ClientConn.RemoteAddr. When not specified, ClientConn.RemoteAddr
  83. // returns a zero-value address.
  84. RemoteAddrOverride string
  85. // PackedDestinationServerEntry is a signed Psiphon server entry
  86. // corresponding to the destination dial address. This signed server
  87. // entry is sent to the broker, which will use it to validate that the
  88. // server is a valid in-proxy destination.
  89. //
  90. // The expected format is CBOR-encoded protoco.PackedServerEntryFields,
  91. // with the caller invoking ServerEntryFields.RemoveUnsignedFields to
  92. // prune local, unnsigned fields before sending.
  93. PackedDestinationServerEntry []byte
  94. // MustUpgrade is a callback that is invoked when a MustUpgrade flag is
  95. // received from the broker. When MustUpgrade is received, the client
  96. // should be stopped and the user should be prompted to upgrade before
  97. // restarting the client.
  98. //
  99. // In Psiphon, MustUpgrade may be ignored when not running in
  100. // in-proxy-only personal pairing mode, as other tunnel protocols remain
  101. // available.
  102. MustUpgrade func()
  103. }
  104. // DialClient establishes an in-proxy connection for relaying traffic to the
  105. // specified destination. DialClient first contacts the broker and initiates
  106. // an in-proxy pairing. config.BrokerClient may be shared by multiple dials,
  107. // and may have a preexisting connection and session with the broker.
  108. func DialClient(
  109. ctx context.Context,
  110. config *ClientConfig) (retConn *ClientConn, retErr error) {
  111. startTime := time.Now()
  112. metrics := common.LogFields{}
  113. // Configure the value returned by ClientConn.RemoteAddr. If no
  114. // config.RemoteAddrOverride is specified, RemoteAddr will return a
  115. // zero-value, non-nil net.Addr. The underlying webRTCConn.RemoteAddr
  116. // returns only nil.
  117. var remoteAddr net.Addr
  118. var addrPort netip.AddrPort
  119. if config.RemoteAddrOverride != "" {
  120. // ParseAddrPort does not perform any domain resolution. The addr
  121. // portion must be an IP address.
  122. var err error
  123. addrPort, err = netip.ParseAddrPort(config.RemoteAddrOverride)
  124. if err != nil {
  125. return nil, errors.Trace(err)
  126. }
  127. }
  128. switch config.DialNetworkProtocol {
  129. case NetworkProtocolTCP:
  130. remoteAddr = net.TCPAddrFromAddrPort(addrPort)
  131. case NetworkProtocolUDP:
  132. remoteAddr = net.UDPAddrFromAddrPort(addrPort)
  133. default:
  134. return nil, errors.TraceNew("unexpected DialNetworkProtocol")
  135. }
  136. // Reset and configure port mapper component, as required. See
  137. // initPortMapper comment.
  138. initPortMapper(config.WebRTCDialCoordinator)
  139. // Future improvements:
  140. //
  141. // - The broker connection and session, when not already established,
  142. // could be established concurrent with the WebRTC offer setup
  143. // (STUN/ICE gathering).
  144. //
  145. // - The STUN state used for NAT discovery could be reused for the WebRTC
  146. // dial.
  147. //
  148. // - A subsequent WebRTC offer setup could be run concurrent with the
  149. // client offer request, in case that request or WebRTC connections
  150. // fails, so that the offer is immediately ready for a retry.
  151. if config.WebRTCDialCoordinator.DiscoverNAT() {
  152. // NAT discovery, using the RFC5780 algorithms is optional and
  153. // conditional on the DiscoverNAT flag. Discovery is performed
  154. // synchronously, so that NAT topology metrics can be reported to the
  155. // broker in the ClientOffer request. For clients, NAT discovery is
  156. // intended to be performed at a low sampling rate, since the RFC5780
  157. // traffic may be unusual (differs from standard STUN requests for
  158. // ICE), the port mapping probe traffic may be unusual, and since
  159. // this step delays the dial. Clients should to cache their NAT
  160. // discovery outcomes, associated with the current network by network
  161. // ID, so metrics can be reported even without a discovery step; this
  162. // is facilitated by WebRTCDialCoordinator.
  163. //
  164. // NAT topology metrics are used by the broker to optimize client and
  165. // in-proxy matching.
  166. NATDiscover(
  167. ctx,
  168. &NATDiscoverConfig{
  169. Logger: config.Logger,
  170. WebRTCDialCoordinator: config.WebRTCDialCoordinator,
  171. })
  172. duration := time.Since(startTime)
  173. metrics["inproxy_dial_nat_discovery_duration"] = fmt.Sprintf("%d", duration/time.Millisecond)
  174. config.Logger.WithTraceFields(
  175. common.LogFields{"duration": duration.String()}).Info("NAT discovery complete")
  176. startTime = time.Now()
  177. }
  178. var result *clientWebRTCDialResult
  179. var lastErr error
  180. for attempt := 0; ; attempt += 1 {
  181. previousAttemptsDuration := time.Since(startTime)
  182. // Repeatedly try to establish in-proxy/WebRTC connection until the
  183. // dial context is canceled or times out.
  184. //
  185. // If a broker request fails, the WebRTCDialCoordinator
  186. // BrokerClientRoundTripperFailed callback will be invoked, so the
  187. // Psiphon client will have an opportunity to select new broker
  188. // connection parameters before a retry. Similarly, when STUN servers
  189. // fail, WebRTCDialCoordinator STUNServerAddressFailed will be
  190. // invoked, giving the Psiphon client an opportunity to select new
  191. // STUN server parameter -- although, in this failure case, the
  192. // WebRTC connection attempt can succeed with other ICE candidates or
  193. // no ICE candidates.
  194. err := ctx.Err()
  195. if err != nil {
  196. if lastErr != nil {
  197. err = fmt.Errorf(
  198. "%w, attempts: %d, lastErr: %w", err, attempt, lastErr)
  199. }
  200. return nil, errors.Trace(err)
  201. }
  202. var retry bool
  203. result, retry, err = dialClientWebRTCConn(ctx, config)
  204. if err == nil {
  205. if attempt > 0 {
  206. // Record the time elapsed in previous attempts.
  207. metrics["inproxy_dial_failed_attempts_duration"] =
  208. fmt.Sprintf("%d", previousAttemptsDuration/time.Millisecond)
  209. config.Logger.WithTraceFields(
  210. common.LogFields{
  211. "duration": previousAttemptsDuration.String()}).Info("previous failed attempts")
  212. }
  213. break
  214. }
  215. lastErr = err
  216. if retry {
  217. config.Logger.WithTraceFields(common.LogFields{"error": err}).Warning("dial failed")
  218. // This delay is intended avoid overloading the broker with
  219. // repeated requests. A jitter is applied to mitigate a traffic
  220. // fingerprint.
  221. brokerCoordinator := config.BrokerClient.GetBrokerDialCoordinator()
  222. common.SleepWithJitter(
  223. ctx,
  224. common.ValueOrDefault(brokerCoordinator.OfferRetryDelay(), clientOfferRetryDelay),
  225. common.ValueOrDefault(brokerCoordinator.OfferRetryJitter(), clientOfferRetryJitter))
  226. continue
  227. }
  228. return nil, errors.Trace(err)
  229. }
  230. metrics.Add(result.metrics)
  231. return &ClientConn{
  232. config: config,
  233. webRTCConn: result.conn,
  234. connectionID: result.connectionID,
  235. remoteAddr: remoteAddr,
  236. metrics: metrics,
  237. initialRelayPacket: result.relayPacket,
  238. }, nil
  239. }
  240. // GetConnectionID returns the in-proxy connection ID, which the client should
  241. // include with its Psiphon handshake parameters.
  242. func (conn *ClientConn) GetConnectionID() ID {
  243. return conn.connectionID
  244. }
  245. // InitialRelayPacket returns the initial packet in the broker->server
  246. // messaging session. The client must relay these packets to facilitate this
  247. // message exchange. Session security ensures clients cannot decrypt, modify,
  248. // or replay these session packets. The Psiphon client will sent the initial
  249. // packet as a parameter in the Psiphon server handshake request.
  250. func (conn *ClientConn) InitialRelayPacket() []byte {
  251. conn.relayMutex.Lock()
  252. defer conn.relayMutex.Unlock()
  253. relayPacket := conn.initialRelayPacket
  254. conn.initialRelayPacket = nil
  255. return relayPacket
  256. }
  257. // RelayPacket takes any server->broker messaging session packets the client
  258. // receives and relays them back to the broker. RelayPacket returns the next
  259. // broker->server packet, if any, or nil when the message exchange is
  260. // complete. Psiphon clients receive a server->broker packet in the Psiphon
  261. // server handshake response and exchange additional packets in a
  262. // post-handshake Psiphon server request.
  263. //
  264. // If RelayPacket fails, the client should close the ClientConn and redial.
  265. func (conn *ClientConn) RelayPacket(
  266. ctx context.Context, in []byte) ([]byte, error) {
  267. // Future improvement: the client relaying these packets back to the
  268. // broker is potentially an inter-flow fingerprint, alternating between
  269. // the WebRTC flow and the client's broker connection. It may be possible
  270. // to avoid this by having the client connect to the broker via the
  271. // tunnel, resuming its broker session and relaying any further packets.
  272. // Limitation: here, this mutex only ensures that this ClientConn doesn't
  273. // make concurrent ClientRelayedPacket requests. The client must still
  274. // ensure that the packets are delivered in the correct relay sequence.
  275. conn.relayMutex.Lock()
  276. defer conn.relayMutex.Unlock()
  277. // ClientRelayedPacket applies
  278. // BrokerDialCoordinator.RelayedPacketRequestTimeout as the request
  279. // timeout.
  280. relayResponse, err := conn.config.BrokerClient.ClientRelayedPacket(
  281. ctx,
  282. &ClientRelayedPacketRequest{
  283. ConnectionID: conn.connectionID,
  284. PacketFromServer: in,
  285. })
  286. if err != nil {
  287. return nil, errors.Trace(err)
  288. }
  289. return relayResponse.PacketToServer, nil
  290. }
  291. type clientWebRTCDialResult struct {
  292. conn *webRTCConn
  293. connectionID ID
  294. relayPacket []byte
  295. metrics common.LogFields
  296. }
  297. func dialClientWebRTCConn(
  298. ctx context.Context,
  299. config *ClientConfig) (retResult *clientWebRTCDialResult, retRetry bool, retErr error) {
  300. startTime := time.Now()
  301. metrics := common.LogFields{}
  302. brokerCoordinator := config.BrokerClient.GetBrokerDialCoordinator()
  303. personalCompartmentIDs := brokerCoordinator.PersonalCompartmentIDs()
  304. commonCompartmentIDs := brokerCoordinator.CommonCompartmentIDs()
  305. if len(personalCompartmentIDs) == 0 && len(commonCompartmentIDs) == 0 {
  306. return nil, false, errors.TraceNew("no compartment IDs")
  307. }
  308. // In personal pairing mode, RFC 1918/4193 private IP addresses are
  309. // included in SDPs.
  310. hasPersonalCompartmentIDs := len(personalCompartmentIDs) > 0
  311. // Initialize the WebRTC offer
  312. doTLSRandomization := config.WebRTCDialCoordinator.DoDTLSRandomization()
  313. useMediaStreams := config.WebRTCDialCoordinator.UseMediaStreams()
  314. trafficShapingParameters := config.WebRTCDialCoordinator.TrafficShapingParameters()
  315. clientRootObfuscationSecret := config.WebRTCDialCoordinator.ClientRootObfuscationSecret()
  316. webRTCConn, SDP, SDPMetrics, err := newWebRTCConnForOffer(
  317. ctx, &webRTCConfig{
  318. Logger: config.Logger,
  319. EnableDebugLogging: config.EnableWebRTCDebugLogging,
  320. WebRTCDialCoordinator: config.WebRTCDialCoordinator,
  321. ClientRootObfuscationSecret: clientRootObfuscationSecret,
  322. DoDTLSRandomization: doTLSRandomization,
  323. UseMediaStreams: useMediaStreams,
  324. TrafficShapingParameters: trafficShapingParameters,
  325. ReliableTransport: config.ReliableTransport,
  326. },
  327. hasPersonalCompartmentIDs)
  328. if err != nil {
  329. return nil, true, errors.Trace(err)
  330. }
  331. defer func() {
  332. // Cleanup on early return
  333. if retErr != nil {
  334. webRTCConn.Close()
  335. }
  336. }()
  337. duration := time.Since(startTime)
  338. metrics["inproxy_dial_webrtc_ice_gathering_duration"] = fmt.Sprintf("%d", duration/time.Millisecond)
  339. config.Logger.WithTraceFields(
  340. common.LogFields{"duration": duration.String()}).Info("ICE gathering complete")
  341. startTime = time.Now()
  342. // Send the ClientOffer request to the broker
  343. apiParams := common.APIParameters{}
  344. apiParams.Add(config.BaseAPIParameters)
  345. apiParams.Add(common.APIParameters(brokerCoordinator.MetricsForBrokerRequests()))
  346. packedParams, err := protocol.EncodePackedAPIParameters(apiParams)
  347. if err != nil {
  348. return nil, false, errors.Trace(err)
  349. }
  350. // Here, WebRTCDialCoordinator.NATType may be populated from discovery, or
  351. // replayed from a previous run on the same network ID.
  352. // WebRTCDialCoordinator.PortMappingTypes/PortMappingProbe may be
  353. // populated via the optional NATDiscover run above or in a previous dial.
  354. // ClientOffer applies BrokerDialCoordinator.OfferRequestTimeout or
  355. // OfferRequestPersonalTimeout as the request timeout.
  356. offerResponse, err := config.BrokerClient.ClientOffer(
  357. ctx,
  358. &ClientOfferRequest{
  359. Metrics: &ClientMetrics{
  360. BaseAPIParameters: packedParams,
  361. ProtocolVersion: LatestProtocolVersion,
  362. NATType: config.WebRTCDialCoordinator.NATType(),
  363. PortMappingTypes: config.WebRTCDialCoordinator.PortMappingTypes(),
  364. },
  365. CommonCompartmentIDs: commonCompartmentIDs,
  366. PersonalCompartmentIDs: personalCompartmentIDs,
  367. ClientOfferSDP: SDP,
  368. ICECandidateTypes: SDPMetrics.iceCandidateTypes,
  369. ClientRootObfuscationSecret: clientRootObfuscationSecret,
  370. DoDTLSRandomization: doTLSRandomization,
  371. UseMediaStreams: useMediaStreams,
  372. TrafficShapingParameters: trafficShapingParameters,
  373. PackedDestinationServerEntry: config.PackedDestinationServerEntry,
  374. NetworkProtocol: config.DialNetworkProtocol,
  375. DestinationAddress: config.DialAddress,
  376. },
  377. hasPersonalCompartmentIDs)
  378. if err != nil {
  379. return nil, false, errors.Trace(err)
  380. }
  381. duration = time.Since(startTime)
  382. metrics["inproxy_dial_broker_offer_duration"] = fmt.Sprintf("%d", duration/time.Millisecond)
  383. config.Logger.WithTraceFields(
  384. common.LogFields{"duration": duration.String()}).Info("Broker offer complete")
  385. startTime = time.Now()
  386. // MustUpgrade has precedence over other cases to ensure the callback is
  387. // invoked. No retry when rate/entry limited or must upgrade; do retry on
  388. // no-match, as a match may soon appear.
  389. if offerResponse.MustUpgrade {
  390. if config.MustUpgrade != nil {
  391. config.MustUpgrade()
  392. }
  393. return nil, false, errors.TraceNew("must upgrade")
  394. } else if offerResponse.Limited {
  395. // Note that the Limited return flag is now returned by the broker in
  396. // non-rate limiting cases, including invalid server entry tags and
  397. // proxy answer failures. The Limited flag has been overloaded these
  398. // cases since it's the current best choice, in these scenarios, for
  399. // having existing clients abort the in-proxy dial without discarding
  400. // the broker client.
  401. return nil, false, errors.TraceNew("limited")
  402. } else if offerResponse.NoMatch {
  403. return nil, true, errors.TraceNew("no match")
  404. }
  405. if offerResponse.SelectedProtocolVersion < ProtocolVersion1 ||
  406. (useMediaStreams &&
  407. offerResponse.SelectedProtocolVersion < ProtocolVersion2) ||
  408. offerResponse.SelectedProtocolVersion > LatestProtocolVersion {
  409. return nil, false, errors.Tracef(
  410. "Unsupported protocol version: %d",
  411. offerResponse.SelectedProtocolVersion)
  412. }
  413. // Establish the WebRTC DataChannel connection
  414. err = webRTCConn.SetRemoteSDP(
  415. offerResponse.ProxyAnswerSDP, hasPersonalCompartmentIDs)
  416. if err != nil {
  417. return nil, true, errors.Trace(err)
  418. }
  419. awaitReadyToProxyCtx, awaitReadyToProxyCancelFunc := context.WithTimeout(
  420. ctx,
  421. common.ValueOrDefault(
  422. config.WebRTCDialCoordinator.WebRTCAwaitReadyToProxyTimeout(), readyToProxyAwaitTimeout))
  423. defer awaitReadyToProxyCancelFunc()
  424. err = webRTCConn.AwaitReadyToProxy(awaitReadyToProxyCtx, offerResponse.ConnectionID)
  425. if err != nil {
  426. return nil, true, errors.Trace(err)
  427. }
  428. duration = time.Since(startTime)
  429. metrics["inproxy_dial_webrtc_connection_duration"] = fmt.Sprintf("%d", duration/time.Millisecond)
  430. config.Logger.WithTraceFields(
  431. common.LogFields{"duration": duration.String()}).Info("WebRTC connection complete")
  432. return &clientWebRTCDialResult{
  433. conn: webRTCConn,
  434. connectionID: offerResponse.ConnectionID,
  435. relayPacket: offerResponse.RelayPacketToServer,
  436. metrics: metrics,
  437. }, false, nil
  438. }
  439. // GetMetrics implements the common.MetricsSource interface.
  440. func (conn *ClientConn) GetMetrics() common.LogFields {
  441. metrics := common.LogFields{}
  442. metrics.Add(conn.metrics)
  443. metrics.Add(conn.webRTCConn.GetMetrics())
  444. return metrics
  445. }
  446. func (conn *ClientConn) Close() error {
  447. return errors.Trace(conn.webRTCConn.Close())
  448. }
  449. func (conn *ClientConn) IsClosed() bool {
  450. return conn.webRTCConn.IsClosed()
  451. }
  452. func (conn *ClientConn) Read(p []byte) (int, error) {
  453. n, err := conn.webRTCConn.Read(p)
  454. return n, errors.Trace(err)
  455. }
  456. // Write relays p through the in-proxy connection. len(p) should be under
  457. // 32K.
  458. func (conn *ClientConn) Write(p []byte) (int, error) {
  459. n, err := conn.webRTCConn.Write(p)
  460. return n, errors.Trace(err)
  461. }
  462. func (conn *ClientConn) LocalAddr() net.Addr {
  463. return conn.webRTCConn.LocalAddr()
  464. }
  465. func (conn *ClientConn) RemoteAddr() net.Addr {
  466. // Do not return conn.webRTCConn.RemoteAddr(), which is always nil.
  467. return conn.remoteAddr
  468. }
  469. func (conn *ClientConn) SetDeadline(t time.Time) error {
  470. return conn.webRTCConn.SetDeadline(t)
  471. }
  472. func (conn *ClientConn) SetReadDeadline(t time.Time) error {
  473. return conn.webRTCConn.SetReadDeadline(t)
  474. }
  475. func (conn *ClientConn) SetWriteDeadline(t time.Time) error {
  476. // Limitation: this is a workaround; webRTCConn doesn't support
  477. // SetWriteDeadline, but common/quic calls SetWriteDeadline on
  478. // net.PacketConns to avoid hanging on EAGAIN when the conn is an actual
  479. // UDP socket. See the comment in common/quic.writeTimeoutUDPConn. In
  480. // this case, the conn is not a UDP socket and that particular
  481. // SetWriteDeadline use case doesn't apply. Silently ignore the deadline
  482. // and report no error.
  483. return nil
  484. }
  485. func (conn *ClientConn) ReadFrom(b []byte) (int, net.Addr, error) {
  486. n, err := conn.webRTCConn.Read(b)
  487. return n, conn.webRTCConn.RemoteAddr(), err
  488. }
  489. func (conn *ClientConn) WriteTo(b []byte, _ net.Addr) (int, error) {
  490. n, err := conn.webRTCConn.Write(b)
  491. return n, err
  492. }