@@ -15,6 +15,7 @@ import (
1515 "github.com/gotd/td/internal/mt"
1616 "github.com/gotd/td/internal/proto"
1717 "github.com/gotd/td/internal/tmap"
18+ "github.com/gotd/td/telegram/internal/rpc"
1819 "github.com/gotd/td/tg"
1920 "github.com/gotd/td/transport"
2021)
@@ -84,23 +85,14 @@ type Client struct {
8485 updateHandler UpdateHandler // immutable
8586 sessionStorage SessionStorage // immutable
8687
87- // callbacks for RPC requests, protected by rpcMux.
88- // Key is request message id.
89- rpc map [int64 ]func (b * bin.Buffer , rpcErr error ) error
90- rpcMux sync.Mutex
88+ rpc * rpc.Engine
9189
92- // callbacks for ack protected by ackMux
93- ack map [int64 ]func ()
94- ackMux sync.Mutex
9590 // ackSendChan is queue for outgoing message id's that require waiting for
9691 // ack from server.
9792 ackSendChan chan int64
9893 ackBatchSize int
9994 ackInterval time.Duration
10095
101- maxRetries int
102- retryInterval time.Duration
103-
10496 // callbacks for ping results protected by pingMux.
10597 // Key is ping id.
10698 ping map [int64 ]func ()
@@ -140,18 +132,13 @@ func NewClient(appID int, appHash string, opt Options) *Client {
140132 cipher : crypto .NewClientCipher (opt .Random ),
141133 log : opt .Logger ,
142134 ping : map [int64 ]func (){},
143- rpc : map [int64 ]func (b * bin.Buffer , rpcErr error ) error {},
144135
145136 sessionCreated : createCondOnce (),
146137
147- ack : map [int64 ]func (){},
148138 ackSendChan : make (chan int64 ),
149139 ackInterval : opt .AckInterval ,
150140 ackBatchSize : opt .AckBatchSize ,
151141
152- maxRetries : opt .MaxRetries ,
153- retryInterval : opt .RetryInterval ,
154-
155142 ctx : clientCtx ,
156143 cancel : clientCancel ,
157144
@@ -169,6 +156,12 @@ func NewClient(appID int, appHash string, opt Options) *Client {
169156 ),
170157 }
171158
159+ client .rpc = rpc .New (client .write , rpc.Config {
160+ Logger : opt .Logger .Named ("rpc" ),
161+ RetryInterval : opt .RetryInterval ,
162+ MaxRetries : opt .MaxRetries ,
163+ })
164+
172165 // Initializing internal RPC caller.
173166 client .tg = tg .NewClient (client )
174167
0 commit comments