proxy.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. // Package proxy contains all proxies used by Xray.
  2. //
  3. // To implement an inbound or outbound proxy, one needs to do the following:
  4. // 1. Implement the interface(s) below.
  5. // 2. Register a config creator through common.RegisterConfig.
  6. package proxy
  7. import (
  8. "bytes"
  9. "context"
  10. "crypto/rand"
  11. "io"
  12. "math/big"
  13. "runtime"
  14. "strconv"
  15. "time"
  16. "github.com/pires/go-proxyproto"
  17. "github.com/xtls/xray-core/app/dispatcher"
  18. "github.com/xtls/xray-core/common/buf"
  19. "github.com/xtls/xray-core/common/errors"
  20. "github.com/xtls/xray-core/common/net"
  21. "github.com/xtls/xray-core/common/protocol"
  22. "github.com/xtls/xray-core/common/session"
  23. "github.com/xtls/xray-core/common/signal"
  24. "github.com/xtls/xray-core/features/routing"
  25. "github.com/xtls/xray-core/features/stats"
  26. "github.com/xtls/xray-core/transport"
  27. "github.com/xtls/xray-core/transport/internet"
  28. "github.com/xtls/xray-core/transport/internet/reality"
  29. "github.com/xtls/xray-core/transport/internet/stat"
  30. "github.com/xtls/xray-core/transport/internet/tls"
  31. )
  32. var (
  33. Tls13SupportedVersions = []byte{0x00, 0x2b, 0x00, 0x02, 0x03, 0x04}
  34. TlsClientHandShakeStart = []byte{0x16, 0x03}
  35. TlsServerHandShakeStart = []byte{0x16, 0x03, 0x03}
  36. TlsApplicationDataStart = []byte{0x17, 0x03, 0x03}
  37. Tls13CipherSuiteDic = map[uint16]string{
  38. 0x1301: "TLS_AES_128_GCM_SHA256",
  39. 0x1302: "TLS_AES_256_GCM_SHA384",
  40. 0x1303: "TLS_CHACHA20_POLY1305_SHA256",
  41. 0x1304: "TLS_AES_128_CCM_SHA256",
  42. 0x1305: "TLS_AES_128_CCM_8_SHA256",
  43. }
  44. )
  45. const (
  46. TlsHandshakeTypeClientHello byte = 0x01
  47. TlsHandshakeTypeServerHello byte = 0x02
  48. CommandPaddingContinue byte = 0x00
  49. CommandPaddingEnd byte = 0x01
  50. CommandPaddingDirect byte = 0x02
  51. )
  52. // An Inbound processes inbound connections.
  53. type Inbound interface {
  54. // Network returns a list of networks that this inbound supports. Connections with not-supported networks will not be passed into Process().
  55. Network() []net.Network
  56. // Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
  57. Process(context.Context, net.Network, stat.Connection, routing.Dispatcher) error
  58. }
  59. // An Outbound process outbound connections.
  60. type Outbound interface {
  61. // Process processes the given connection. The given dialer may be used to dial a system outbound connection.
  62. Process(context.Context, *transport.Link, internet.Dialer) error
  63. }
  64. // UserManager is the interface for Inbounds and Outbounds that can manage their users.
  65. type UserManager interface {
  66. // AddUser adds a new user.
  67. AddUser(context.Context, *protocol.MemoryUser) error
  68. // RemoveUser removes a user by email.
  69. RemoveUser(context.Context, string) error
  70. // Get user by email.
  71. GetUser(context.Context, string) *protocol.MemoryUser
  72. // Get all users.
  73. GetUsers(context.Context) []*protocol.MemoryUser
  74. // Get users count.
  75. GetUsersCount(context.Context) int64
  76. }
  77. type GetInbound interface {
  78. GetInbound() Inbound
  79. }
  80. type GetOutbound interface {
  81. GetOutbound() Outbound
  82. }
  83. // TrafficState is used to track uplink and downlink of one connection
  84. // It is used by XTLS to determine if switch to raw copy mode, It is used by Vision to calculate padding
  85. type TrafficState struct {
  86. UserUUID []byte
  87. NumberOfPacketToFilter int
  88. EnableXtls bool
  89. IsTLS12orAbove bool
  90. IsTLS bool
  91. Cipher uint16
  92. RemainingServerHello int32
  93. // reader link state
  94. WithinPaddingBuffers bool
  95. ReaderSwitchToDirectCopy bool
  96. RemainingCommand int32
  97. RemainingContent int32
  98. RemainingPadding int32
  99. CurrentCommand int
  100. // write link state
  101. IsPadding bool
  102. WriterSwitchToDirectCopy bool
  103. }
  104. func NewTrafficState(userUUID []byte) *TrafficState {
  105. return &TrafficState{
  106. UserUUID: userUUID,
  107. NumberOfPacketToFilter: 8,
  108. EnableXtls: false,
  109. IsTLS12orAbove: false,
  110. IsTLS: false,
  111. Cipher: 0,
  112. RemainingServerHello: -1,
  113. WithinPaddingBuffers: true,
  114. ReaderSwitchToDirectCopy: false,
  115. RemainingCommand: -1,
  116. RemainingContent: -1,
  117. RemainingPadding: -1,
  118. CurrentCommand: 0,
  119. IsPadding: true,
  120. WriterSwitchToDirectCopy: false,
  121. }
  122. }
  123. // VisionReader is used to read xtls vision protocol
  124. // Note Vision probably only make sense as the inner most layer of reader, since it need assess traffic state from origin proxy traffic
  125. type VisionReader struct {
  126. buf.Reader
  127. trafficState *TrafficState
  128. ctx context.Context
  129. }
  130. func NewVisionReader(reader buf.Reader, state *TrafficState, context context.Context) *VisionReader {
  131. return &VisionReader{
  132. Reader: reader,
  133. trafficState: state,
  134. ctx: context,
  135. }
  136. }
  137. func (w *VisionReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
  138. buffer, err := w.Reader.ReadMultiBuffer()
  139. if !buffer.IsEmpty() {
  140. if w.trafficState.WithinPaddingBuffers || w.trafficState.NumberOfPacketToFilter > 0 {
  141. mb2 := make(buf.MultiBuffer, 0, len(buffer))
  142. for _, b := range buffer {
  143. newbuffer := XtlsUnpadding(b, w.trafficState, w.ctx)
  144. if newbuffer.Len() > 0 {
  145. mb2 = append(mb2, newbuffer)
  146. }
  147. }
  148. buffer = mb2
  149. if w.trafficState.RemainingContent > 0 || w.trafficState.RemainingPadding > 0 || w.trafficState.CurrentCommand == 0 {
  150. w.trafficState.WithinPaddingBuffers = true
  151. } else if w.trafficState.CurrentCommand == 1 {
  152. w.trafficState.WithinPaddingBuffers = false
  153. } else if w.trafficState.CurrentCommand == 2 {
  154. w.trafficState.WithinPaddingBuffers = false
  155. w.trafficState.ReaderSwitchToDirectCopy = true
  156. } else {
  157. errors.LogInfo(w.ctx, "XtlsRead unknown command ", w.trafficState.CurrentCommand, buffer.Len())
  158. }
  159. }
  160. if w.trafficState.NumberOfPacketToFilter > 0 {
  161. XtlsFilterTls(buffer, w.trafficState, w.ctx)
  162. }
  163. }
  164. return buffer, err
  165. }
  166. // VisionWriter is used to write xtls vision protocol
  167. // Note Vision probably only make sense as the inner most layer of writer, since it need assess traffic state from origin proxy traffic
  168. type VisionWriter struct {
  169. buf.Writer
  170. trafficState *TrafficState
  171. ctx context.Context
  172. writeOnceUserUUID []byte
  173. }
  174. func NewVisionWriter(writer buf.Writer, state *TrafficState, context context.Context) *VisionWriter {
  175. w := make([]byte, len(state.UserUUID))
  176. copy(w, state.UserUUID)
  177. return &VisionWriter{
  178. Writer: writer,
  179. trafficState: state,
  180. ctx: context,
  181. writeOnceUserUUID: w,
  182. }
  183. }
  184. func (w *VisionWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
  185. if w.trafficState.NumberOfPacketToFilter > 0 {
  186. XtlsFilterTls(mb, w.trafficState, w.ctx)
  187. }
  188. if w.trafficState.IsPadding {
  189. if len(mb) == 1 && mb[0] == nil {
  190. mb[0] = XtlsPadding(nil, CommandPaddingContinue, &w.writeOnceUserUUID, true, w.ctx) // we do a long padding to hide vless header
  191. return w.Writer.WriteMultiBuffer(mb)
  192. }
  193. mb = ReshapeMultiBuffer(w.ctx, mb)
  194. longPadding := w.trafficState.IsTLS
  195. for i, b := range mb {
  196. if w.trafficState.IsTLS && b.Len() >= 6 && bytes.Equal(TlsApplicationDataStart, b.BytesTo(3)) {
  197. if w.trafficState.EnableXtls {
  198. w.trafficState.WriterSwitchToDirectCopy = true
  199. }
  200. var command byte = CommandPaddingContinue
  201. if i == len(mb)-1 {
  202. command = CommandPaddingEnd
  203. if w.trafficState.EnableXtls {
  204. command = CommandPaddingDirect
  205. }
  206. }
  207. mb[i] = XtlsPadding(b, command, &w.writeOnceUserUUID, true, w.ctx)
  208. w.trafficState.IsPadding = false // padding going to end
  209. longPadding = false
  210. continue
  211. } else if !w.trafficState.IsTLS12orAbove && w.trafficState.NumberOfPacketToFilter <= 1 { // For compatibility with earlier vision receiver, we finish padding 1 packet early
  212. w.trafficState.IsPadding = false
  213. mb[i] = XtlsPadding(b, CommandPaddingEnd, &w.writeOnceUserUUID, longPadding, w.ctx)
  214. break
  215. }
  216. var command byte = CommandPaddingContinue
  217. if i == len(mb)-1 && !w.trafficState.IsPadding {
  218. command = CommandPaddingEnd
  219. if w.trafficState.EnableXtls {
  220. command = CommandPaddingDirect
  221. }
  222. }
  223. mb[i] = XtlsPadding(b, command, &w.writeOnceUserUUID, longPadding, w.ctx)
  224. }
  225. }
  226. return w.Writer.WriteMultiBuffer(mb)
  227. }
  228. // ReshapeMultiBuffer prepare multi buffer for padding structure (max 21 bytes)
  229. func ReshapeMultiBuffer(ctx context.Context, buffer buf.MultiBuffer) buf.MultiBuffer {
  230. needReshape := 0
  231. for _, b := range buffer {
  232. if b.Len() >= buf.Size-21 {
  233. needReshape += 1
  234. }
  235. }
  236. if needReshape == 0 {
  237. return buffer
  238. }
  239. mb2 := make(buf.MultiBuffer, 0, len(buffer)+needReshape)
  240. toPrint := ""
  241. for i, buffer1 := range buffer {
  242. if buffer1.Len() >= buf.Size-21 {
  243. index := int32(bytes.LastIndex(buffer1.Bytes(), TlsApplicationDataStart))
  244. if index < 21 || index > buf.Size-21 {
  245. index = buf.Size / 2
  246. }
  247. buffer2 := buf.New()
  248. buffer2.Write(buffer1.BytesFrom(index))
  249. buffer1.Resize(0, index)
  250. mb2 = append(mb2, buffer1, buffer2)
  251. toPrint += " " + strconv.Itoa(int(buffer1.Len())) + " " + strconv.Itoa(int(buffer2.Len()))
  252. } else {
  253. mb2 = append(mb2, buffer1)
  254. toPrint += " " + strconv.Itoa(int(buffer1.Len()))
  255. }
  256. buffer[i] = nil
  257. }
  258. buffer = buffer[:0]
  259. errors.LogInfo(ctx, "ReshapeMultiBuffer ", toPrint)
  260. return mb2
  261. }
  262. // XtlsPadding add padding to eliminate length signature during tls handshake
  263. func XtlsPadding(b *buf.Buffer, command byte, userUUID *[]byte, longPadding bool, ctx context.Context) *buf.Buffer {
  264. var contentLen int32 = 0
  265. var paddingLen int32 = 0
  266. if b != nil {
  267. contentLen = b.Len()
  268. }
  269. if contentLen < 900 && longPadding {
  270. l, err := rand.Int(rand.Reader, big.NewInt(500))
  271. if err != nil {
  272. errors.LogDebugInner(ctx, err, "failed to generate padding")
  273. }
  274. paddingLen = int32(l.Int64()) + 900 - contentLen
  275. } else {
  276. l, err := rand.Int(rand.Reader, big.NewInt(256))
  277. if err != nil {
  278. errors.LogDebugInner(ctx, err, "failed to generate padding")
  279. }
  280. paddingLen = int32(l.Int64())
  281. }
  282. if paddingLen > buf.Size-21-contentLen {
  283. paddingLen = buf.Size - 21 - contentLen
  284. }
  285. newbuffer := buf.New()
  286. if userUUID != nil {
  287. newbuffer.Write(*userUUID)
  288. *userUUID = nil
  289. }
  290. newbuffer.Write([]byte{command, byte(contentLen >> 8), byte(contentLen), byte(paddingLen >> 8), byte(paddingLen)})
  291. if b != nil {
  292. newbuffer.Write(b.Bytes())
  293. b.Release()
  294. b = nil
  295. }
  296. newbuffer.Extend(paddingLen)
  297. errors.LogInfo(ctx, "XtlsPadding ", contentLen, " ", paddingLen, " ", command)
  298. return newbuffer
  299. }
  300. // XtlsUnpadding remove padding and parse command
  301. func XtlsUnpadding(b *buf.Buffer, s *TrafficState, ctx context.Context) *buf.Buffer {
  302. if s.RemainingCommand == -1 && s.RemainingContent == -1 && s.RemainingPadding == -1 { // initial state
  303. if b.Len() >= 21 && bytes.Equal(s.UserUUID, b.BytesTo(16)) {
  304. b.Advance(16)
  305. s.RemainingCommand = 5
  306. } else {
  307. return b
  308. }
  309. }
  310. newbuffer := buf.New()
  311. for b.Len() > 0 {
  312. if s.RemainingCommand > 0 {
  313. data, err := b.ReadByte()
  314. if err != nil {
  315. return newbuffer
  316. }
  317. switch s.RemainingCommand {
  318. case 5:
  319. s.CurrentCommand = int(data)
  320. case 4:
  321. s.RemainingContent = int32(data) << 8
  322. case 3:
  323. s.RemainingContent = s.RemainingContent | int32(data)
  324. case 2:
  325. s.RemainingPadding = int32(data) << 8
  326. case 1:
  327. s.RemainingPadding = s.RemainingPadding | int32(data)
  328. errors.LogInfo(ctx, "Xtls Unpadding new block, content ", s.RemainingContent, " padding ", s.RemainingPadding, " command ", s.CurrentCommand)
  329. }
  330. s.RemainingCommand--
  331. } else if s.RemainingContent > 0 {
  332. len := s.RemainingContent
  333. if b.Len() < len {
  334. len = b.Len()
  335. }
  336. data, err := b.ReadBytes(len)
  337. if err != nil {
  338. return newbuffer
  339. }
  340. newbuffer.Write(data)
  341. s.RemainingContent -= len
  342. } else { // remainingPadding > 0
  343. len := s.RemainingPadding
  344. if b.Len() < len {
  345. len = b.Len()
  346. }
  347. b.Advance(len)
  348. s.RemainingPadding -= len
  349. }
  350. if s.RemainingCommand <= 0 && s.RemainingContent <= 0 && s.RemainingPadding <= 0 { // this block done
  351. if s.CurrentCommand == 0 {
  352. s.RemainingCommand = 5
  353. } else {
  354. s.RemainingCommand = -1 // set to initial state
  355. s.RemainingContent = -1
  356. s.RemainingPadding = -1
  357. if b.Len() > 0 { // shouldn't happen
  358. newbuffer.Write(b.Bytes())
  359. }
  360. break
  361. }
  362. }
  363. }
  364. b.Release()
  365. b = nil
  366. return newbuffer
  367. }
  368. // XtlsFilterTls filter and recognize tls 1.3 and other info
  369. func XtlsFilterTls(buffer buf.MultiBuffer, trafficState *TrafficState, ctx context.Context) {
  370. for _, b := range buffer {
  371. if b == nil {
  372. continue
  373. }
  374. trafficState.NumberOfPacketToFilter--
  375. if b.Len() >= 6 {
  376. startsBytes := b.BytesTo(6)
  377. if bytes.Equal(TlsServerHandShakeStart, startsBytes[:3]) && startsBytes[5] == TlsHandshakeTypeServerHello {
  378. trafficState.RemainingServerHello = (int32(startsBytes[3])<<8 | int32(startsBytes[4])) + 5
  379. trafficState.IsTLS12orAbove = true
  380. trafficState.IsTLS = true
  381. if b.Len() >= 79 && trafficState.RemainingServerHello >= 79 {
  382. sessionIdLen := int32(b.Byte(43))
  383. cipherSuite := b.BytesRange(43+sessionIdLen+1, 43+sessionIdLen+3)
  384. trafficState.Cipher = uint16(cipherSuite[0])<<8 | uint16(cipherSuite[1])
  385. } else {
  386. errors.LogInfo(ctx, "XtlsFilterTls short server hello, tls 1.2 or older? ", b.Len(), " ", trafficState.RemainingServerHello)
  387. }
  388. } else if bytes.Equal(TlsClientHandShakeStart, startsBytes[:2]) && startsBytes[5] == TlsHandshakeTypeClientHello {
  389. trafficState.IsTLS = true
  390. errors.LogInfo(ctx, "XtlsFilterTls found tls client hello! ", buffer.Len())
  391. }
  392. }
  393. if trafficState.RemainingServerHello > 0 {
  394. end := trafficState.RemainingServerHello
  395. if end > b.Len() {
  396. end = b.Len()
  397. }
  398. trafficState.RemainingServerHello -= b.Len()
  399. if bytes.Contains(b.BytesTo(end), Tls13SupportedVersions) {
  400. v, ok := Tls13CipherSuiteDic[trafficState.Cipher]
  401. if !ok {
  402. v = "Old cipher: " + strconv.FormatUint(uint64(trafficState.Cipher), 16)
  403. } else if v != "TLS_AES_128_CCM_8_SHA256" {
  404. trafficState.EnableXtls = true
  405. }
  406. errors.LogInfo(ctx, "XtlsFilterTls found tls 1.3! ", b.Len(), " ", v)
  407. trafficState.NumberOfPacketToFilter = 0
  408. return
  409. } else if trafficState.RemainingServerHello <= 0 {
  410. errors.LogInfo(ctx, "XtlsFilterTls found tls 1.2! ", b.Len())
  411. trafficState.NumberOfPacketToFilter = 0
  412. return
  413. }
  414. errors.LogInfo(ctx, "XtlsFilterTls inconclusive server hello ", b.Len(), " ", trafficState.RemainingServerHello)
  415. }
  416. if trafficState.NumberOfPacketToFilter <= 0 {
  417. errors.LogInfo(ctx, "XtlsFilterTls stop filtering", buffer.Len())
  418. }
  419. }
  420. }
  421. // UnwrapRawConn support unwrap stats, tls, utls, reality and proxyproto conn and get raw tcp conn from it
  422. func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) {
  423. var readCounter, writerCounter stats.Counter
  424. if conn != nil {
  425. statConn, ok := conn.(*stat.CounterConnection)
  426. if ok {
  427. conn = statConn.Connection
  428. readCounter = statConn.ReadCounter
  429. writerCounter = statConn.WriteCounter
  430. }
  431. if xc, ok := conn.(*tls.Conn); ok {
  432. conn = xc.NetConn()
  433. } else if utlsConn, ok := conn.(*tls.UConn); ok {
  434. conn = utlsConn.NetConn()
  435. } else if realityConn, ok := conn.(*reality.Conn); ok {
  436. conn = realityConn.NetConn()
  437. } else if realityUConn, ok := conn.(*reality.UConn); ok {
  438. conn = realityUConn.NetConn()
  439. }
  440. if pc, ok := conn.(*proxyproto.Conn); ok {
  441. conn = pc.Raw()
  442. // 8192 > 4096, there is no need to process pc's bufReader
  443. }
  444. }
  445. return conn, readCounter, writerCounter
  446. }
  447. // CopyRawConnIfExist use the most efficient copy method.
  448. // - If caller don't want to turn on splice, do not pass in both reader conn and writer conn
  449. // - writer are from *transport.Link
  450. func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net.Conn, writer buf.Writer, timer *signal.ActivityTimer, inTimer *signal.ActivityTimer) error {
  451. readerConn, readCounter, _ := UnwrapRawConn(readerConn)
  452. writerConn, _, writeCounter := UnwrapRawConn(writerConn)
  453. reader := buf.NewReader(readerConn)
  454. if runtime.GOOS != "linux" && runtime.GOOS != "android" {
  455. return readV(ctx, reader, writer, timer, readCounter)
  456. }
  457. tc, ok := writerConn.(*net.TCPConn)
  458. if !ok || readerConn == nil || writerConn == nil {
  459. return readV(ctx, reader, writer, timer, readCounter)
  460. }
  461. inbound := session.InboundFromContext(ctx)
  462. if inbound == nil || inbound.CanSpliceCopy == 3 {
  463. return readV(ctx, reader, writer, timer, readCounter)
  464. }
  465. outbounds := session.OutboundsFromContext(ctx)
  466. if len(outbounds) == 0 {
  467. return readV(ctx, reader, writer, timer, readCounter)
  468. }
  469. for _, ob := range outbounds {
  470. if ob.CanSpliceCopy == 3 {
  471. return readV(ctx, reader, writer, timer, readCounter)
  472. }
  473. }
  474. for {
  475. inbound := session.InboundFromContext(ctx)
  476. outbounds := session.OutboundsFromContext(ctx)
  477. var splice = inbound.CanSpliceCopy == 1
  478. for _, ob := range outbounds {
  479. if ob.CanSpliceCopy != 1 {
  480. splice = false
  481. }
  482. }
  483. if splice {
  484. errors.LogInfo(ctx, "CopyRawConn splice")
  485. statWriter, _ := writer.(*dispatcher.SizeStatWriter)
  486. //runtime.Gosched() // necessary
  487. time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice
  488. timer.SetTimeout(8 * time.Hour) // prevent leak, just in case
  489. if inTimer != nil {
  490. inTimer.SetTimeout(8 * time.Hour)
  491. }
  492. w, err := tc.ReadFrom(readerConn)
  493. if readCounter != nil {
  494. readCounter.Add(w) // outbound stats
  495. }
  496. if writeCounter != nil {
  497. writeCounter.Add(w) // inbound stats
  498. }
  499. if statWriter != nil {
  500. statWriter.Counter.Add(w) // user stats
  501. }
  502. if err != nil && errors.Cause(err) != io.EOF {
  503. return err
  504. }
  505. return nil
  506. }
  507. buffer, err := reader.ReadMultiBuffer()
  508. if !buffer.IsEmpty() {
  509. if readCounter != nil {
  510. readCounter.Add(int64(buffer.Len()))
  511. }
  512. timer.Update()
  513. if werr := writer.WriteMultiBuffer(buffer); werr != nil {
  514. return werr
  515. }
  516. }
  517. if err != nil {
  518. return err
  519. }
  520. }
  521. }
  522. func readV(ctx context.Context, reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater, readCounter stats.Counter) error {
  523. errors.LogInfo(ctx, "CopyRawConn readv")
  524. if err := buf.Copy(reader, writer, buf.UpdateActivity(timer), buf.AddToStatCounter(readCounter)); err != nil {
  525. return errors.New("failed to process response").Base(err)
  526. }
  527. return nil
  528. }