@@ -7,15 +7,15 @@ import (
7
7
"net"
8
8
"runtime/debug"
9
9
"sync"
10
- "sync/atomic"
11
10
"time"
12
11
12
+ "github.com/metacubex/mihomo/common/atomic"
13
+ "github.com/metacubex/mihomo/common/buf"
14
+ "github.com/metacubex/mihomo/common/pool"
13
15
"github.com/metacubex/mihomo/constant"
14
16
"github.com/metacubex/mihomo/log"
15
17
"github.com/metacubex/mihomo/transport/anytls/padding"
16
18
"github.com/metacubex/mihomo/transport/anytls/util"
17
- singAtomic "github.com/sagernet/sing/common/atomic"
18
- "github.com/sagernet/sing/common/buf"
19
19
)
20
20
21
21
type Session struct {
@@ -33,7 +33,7 @@ type Session struct {
33
33
// pool
34
34
seq uint64
35
35
idleSince time.Time
36
- padding * singAtomic .TypedValue [* padding.PaddingFactory ]
36
+ padding * atomic .TypedValue [* padding.PaddingFactory ]
37
37
38
38
// client
39
39
isClient bool
@@ -45,7 +45,7 @@ type Session struct {
45
45
onNewStream func (stream * Stream )
46
46
}
47
47
48
- func NewClientSession (conn net.Conn , _padding * singAtomic .TypedValue [* padding.PaddingFactory ]) * Session {
48
+ func NewClientSession (conn net.Conn , _padding * atomic .TypedValue [* padding.PaddingFactory ]) * Session {
49
49
s := & Session {
50
50
conn : conn ,
51
51
isClient : true ,
@@ -56,7 +56,7 @@ func NewClientSession(conn net.Conn, _padding *singAtomic.TypedValue[*padding.Pa
56
56
return s
57
57
}
58
58
59
- func NewServerSession (conn net.Conn , onNewStream func (stream * Stream ), _padding * singAtomic .TypedValue [* padding.PaddingFactory ]) * Session {
59
+ func NewServerSession (conn net.Conn , onNewStream func (stream * Stream ), _padding * atomic .TypedValue [* padding.PaddingFactory ]) * Session {
60
60
s := & Session {
61
61
conn : conn ,
62
62
onNewStream : onNewStream ,
@@ -169,17 +169,17 @@ func (s *Session) recvLoop() error {
169
169
switch hdr .Cmd () {
170
170
case cmdPSH :
171
171
if hdr .Length () > 0 {
172
- buffer := buf .Get (int (hdr .Length ()))
172
+ buffer := pool .Get (int (hdr .Length ()))
173
173
if _ , err := io .ReadFull (s .conn , buffer ); err == nil {
174
174
s .streamLock .RLock ()
175
175
stream , ok := s .streams [sid ]
176
176
s .streamLock .RUnlock ()
177
177
if ok {
178
178
stream .pipeW .Write (buffer )
179
179
}
180
- buf .Put (buffer )
180
+ pool .Put (buffer )
181
181
} else {
182
- buf .Put (buffer )
182
+ pool .Put (buffer )
183
183
return err
184
184
}
185
185
}
@@ -211,18 +211,18 @@ func (s *Session) recvLoop() error {
211
211
//logrus.Debugln("stream fin", sid, s.streams)
212
212
case cmdWaste :
213
213
if hdr .Length () > 0 {
214
- buffer := buf .Get (int (hdr .Length ()))
214
+ buffer := pool .Get (int (hdr .Length ()))
215
215
if _ , err := io .ReadFull (s .conn , buffer ); err != nil {
216
- buf .Put (buffer )
216
+ pool .Put (buffer )
217
217
return err
218
218
}
219
- buf .Put (buffer )
219
+ pool .Put (buffer )
220
220
}
221
221
case cmdSettings :
222
222
if hdr .Length () > 0 {
223
- buffer := buf .Get (int (hdr .Length ()))
223
+ buffer := pool .Get (int (hdr .Length ()))
224
224
if _ , err := io .ReadFull (s .conn , buffer ); err != nil {
225
- buf .Put (buffer )
225
+ pool .Put (buffer )
226
226
return err
227
227
}
228
228
if ! s .isClient {
@@ -235,31 +235,31 @@ func (s *Session) recvLoop() error {
235
235
f .data = paddingF .RawScheme
236
236
_ , err = s .writeFrame (f )
237
237
if err != nil {
238
- buf .Put (buffer )
238
+ pool .Put (buffer )
239
239
return err
240
240
}
241
241
}
242
242
}
243
- buf .Put (buffer )
243
+ pool .Put (buffer )
244
244
}
245
245
case cmdAlert :
246
246
if hdr .Length () > 0 {
247
- buffer := buf .Get (int (hdr .Length ()))
247
+ buffer := pool .Get (int (hdr .Length ()))
248
248
if _ , err := io .ReadFull (s .conn , buffer ); err != nil {
249
- buf .Put (buffer )
249
+ pool .Put (buffer )
250
250
return err
251
251
}
252
252
if s .isClient {
253
253
log .Errorln ("[Alert from server] %s" , string (buffer ))
254
254
}
255
- buf .Put (buffer )
255
+ pool .Put (buffer )
256
256
return nil
257
257
}
258
258
case cmdUpdatePaddingScheme :
259
259
if hdr .Length () > 0 {
260
- buffer := buf .Get (int (hdr .Length ()))
260
+ buffer := pool .Get (int (hdr .Length ()))
261
261
if _ , err := io .ReadFull (s .conn , buffer ); err != nil {
262
- buf .Put (buffer )
262
+ pool .Put (buffer )
263
263
return err
264
264
}
265
265
if s .isClient {
@@ -269,7 +269,7 @@ func (s *Session) recvLoop() error {
269
269
log .Warnln ("[Update padding failed] %x\n " , md5 .Sum (buffer ))
270
270
}
271
271
}
272
- buf .Put (buffer )
272
+ pool .Put (buffer )
273
273
}
274
274
default :
275
275
// I don't know what command it is (can't have data)
0 commit comments