Преглед изворни кода

Do not use unnecessary lock in connRewind

tags/v2.1.11^2^2
9seconds пре 2 месеци
родитељ
комит
e50cee5748
2 измењених фајлова са 4 додато и 12 уклоњено
  1. 2
    10
      mtglib/conns.go
  2. 2
    2
      mtglib/proxy.go

+ 2
- 10
mtglib/conns.go Прегледај датотеку

@@ -4,7 +4,6 @@ import (
4 4
 	"bytes"
5 5
 	"context"
6 6
 	"io"
7
-	"sync"
8 7
 
9 8
 	"github.com/9seconds/mtg/v2/essentials"
10 9
 )
@@ -40,22 +39,15 @@ func (c connTraffic) Write(b []byte) (int, error) {
40 39
 type connRewind struct {
41 40
 	essentials.Conn
42 41
 
43
-	active io.Reader
44 42
 	buf    bytes.Buffer
45
-	mutex  sync.RWMutex
43
+	active io.Reader
46 44
 }
47 45
 
48 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 50
 func (c *connRewind) Rewind() {
56
-	c.mutex.Lock()
57
-	defer c.mutex.Unlock()
58
-
59 51
 	c.active = io.MultiReader(&c.buf, c.Conn)
60 52
 }
61 53
 

+ 2
- 2
mtglib/proxy.go Прегледај датотеку

@@ -243,14 +243,14 @@ func (p *Proxy) doTelegramCall(ctx *streamContext) error {
243 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 247
 	if err != nil {
248 248
 		conn.Close()
249 249
 		return fmt.Errorf("cannot perform server handshake: %w", err)
250 250
 	}
251 251
 
252 252
 	ctx.telegramConn = connTraffic{
253
-		Conn:     conn,
253
+		Conn:     tgConn,
254 254
 		streamID: ctx.streamID,
255 255
 		stream:   p.eventStream,
256 256
 		ctx:      ctx,

Loading…
Откажи
Сачувај