Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package rwc
  2. import (
  3. "context"
  4. "io"
  5. )
  6. type wrapperPing struct {
  7. parent io.ReadWriteCloser
  8. ctx context.Context
  9. channelPing chan<- struct{}
  10. }
  11. func (w *wrapperPing) Read(p []byte) (int, error) {
  12. n, err := w.parent.Read(p)
  13. if err == nil {
  14. select {
  15. case <-w.ctx.Done():
  16. case w.channelPing <- struct{}{}:
  17. }
  18. }
  19. return n, err // nolint: wrapcheck
  20. }
  21. func (w *wrapperPing) Write(p []byte) (int, error) {
  22. n, err := w.parent.Write(p)
  23. if err == nil {
  24. select {
  25. case <-w.ctx.Done():
  26. case w.channelPing <- struct{}{}:
  27. }
  28. }
  29. return n, err // nolint: wrapcheck
  30. }
  31. func (w *wrapperPing) Close() error {
  32. return w.parent.Close() // nolint: wrapcheck
  33. }
  34. func NewPing(ctx context.Context, parent io.ReadWriteCloser, channelPing chan<- struct{}) io.ReadWriteCloser {
  35. return &wrapperPing{
  36. parent: parent,
  37. ctx: ctx,
  38. channelPing: channelPing,
  39. }
  40. }