Просмотр исходного кода

Do not use unnecessary lock in connRewind

tags/v2.1.11^2^2
9seconds 2 месяцев назад
Родитель
Сommit
e50cee5748
2 измененных файлов: 4 добавлений и 12 удалений
  1. 2
    10
      mtglib/conns.go
  2. 2
    2
      mtglib/proxy.go

+ 2
- 10
mtglib/conns.go Просмотреть файл

4
 	"bytes"
4
 	"bytes"
5
 	"context"
5
 	"context"
6
 	"io"
6
 	"io"
7
-	"sync"
8
 
7
 
9
 	"github.com/9seconds/mtg/v2/essentials"
8
 	"github.com/9seconds/mtg/v2/essentials"
10
 )
9
 )
40
 type connRewind struct {
39
 type connRewind struct {
41
 	essentials.Conn
40
 	essentials.Conn
42
 
41
 
43
-	active io.Reader
44
 	buf    bytes.Buffer
42
 	buf    bytes.Buffer
45
-	mutex  sync.RWMutex
43
+	active io.Reader
46
 }
44
 }
47
 
45
 
48
 func (c *connRewind) Read(p []byte) (int, error) {
46
 func (c *connRewind) Read(p []byte) (int, error) {
49
-	c.mutex.RLock()
50
-	defer c.mutex.RUnlock()
51
-
52
-	return c.active.Read(p) //nolint: wrapcheck
47
+	return c.active.Read(p)
53
 }
48
 }
54
 
49
 
55
 func (c *connRewind) Rewind() {
50
 func (c *connRewind) Rewind() {
56
-	c.mutex.Lock()
57
-	defer c.mutex.Unlock()
58
-
59
 	c.active = io.MultiReader(&c.buf, c.Conn)
51
 	c.active = io.MultiReader(&c.buf, c.Conn)
60
 }
52
 }
61
 
53
 

+ 2
- 2
mtglib/proxy.go Просмотреть файл

243
 		return fmt.Errorf("no addresses to call: %w", err)
243
 		return fmt.Errorf("no addresses to call: %w", err)
244
 	}
244
 	}
245
 
245
 
246
-	conn, err = foundAddr.Obfuscator.SendHandshake(conn, ctx.dc)
246
+	tgConn, err := foundAddr.Obfuscator.SendHandshake(conn, ctx.dc)
247
 	if err != nil {
247
 	if err != nil {
248
 		conn.Close()
248
 		conn.Close()
249
 		return fmt.Errorf("cannot perform server handshake: %w", err)
249
 		return fmt.Errorf("cannot perform server handshake: %w", err)
250
 	}
250
 	}
251
 
251
 
252
 	ctx.telegramConn = connTraffic{
252
 	ctx.telegramConn = connTraffic{
253
-		Conn:     conn,
253
+		Conn:     tgConn,
254
 		streamID: ctx.streamID,
254
 		streamID: ctx.streamID,
255
 		stream:   p.eventStream,
255
 		stream:   p.eventStream,
256
 		ctx:      ctx,
256
 		ctx:      ctx,

Загрузка…
Отмена
Сохранить