call: Update Call Transport

This commit is contained in:
Shtorm
2026-12-01 01:27:01 +03:00
parent ae1042d1bd
commit ffbb5b481c
55 changed files with 4731 additions and 1039 deletions
+31 -18
View File
@@ -38,7 +38,12 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
if options.Platform == "" {
return nil, E.New("missing platform")
}
outboundDialer, err := dialer.New(ctx, options.DialerOptions, true)
outboundDialer, err := dialer.NewWithOptions(dialer.Options{
Context: ctx,
Options: options.DialerOptions,
RemoteIsDomain: true,
ResolverOnDetour: true,
})
if err != nil {
return nil, err
}
@@ -68,30 +73,38 @@ func (h *Inbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
func (h *Inbound) run() {
dnsRouter := service.FromContext[adapter.DNSRouter](h.ctx)
initializeBridge := func(bridge *call.Bridge) {
bridge.SetAcceptHandler(func(conn net.Conn, destination string) {
h.handleConnection(conn, M.ParseSocksaddr(destination))
})
bridge.SetUDPAcceptHandler(func(conn net.Conn, destination string) {
h.handlePacketConnection(bufio.NewUnbindPacketConnWithAddr(conn, M.ParseSocksaddr(destination)), M.ParseSocksaddr(destination))
})
}
bridge, err := call.Connect(h.ctx, call.Config{
Platform: h.options.Platform,
Mode: h.options.Mode,
JoinLink: h.options.JoinLink,
CookieString: h.options.Cookies.Header(),
Email: h.options.Email,
Password: h.options.Password,
ReadBuffer: h.options.ReadBuffer,
Role: call.RoleCreator,
Dialer: h.dialer,
DNSRouter: dnsRouter,
Logger: h.logger,
Platform: h.options.Platform,
Mode: h.options.Mode,
JoinLink: h.options.JoinLink,
CookieString: h.options.Cookies.Header(),
CredentialsPath: h.options.CredentialsPath,
Email: h.options.Email,
Password: h.options.Password,
ReadBuffer: h.options.ReadBuffer,
MaxBufferedAmount: h.options.MaxBufferedAmount,
Role: call.RoleCreator,
Dialer: h.dialer,
DNSRouter: dnsRouter,
Logger: h.logger,
InitializeBridge: initializeBridge,
})
if err != nil {
h.logger.ErrorContext(h.ctx, err)
return
}
h.bridge = bridge
bridge.SetAcceptHandler(func(conn net.Conn, destination string) {
h.handleConnection(conn, M.ParseSocksaddr(destination))
})
bridge.SetUDPAcceptHandler(func(conn net.Conn, destination string) {
h.handlePacketConnection(bufio.NewUnbindPacketConnWithAddr(conn, M.ParseSocksaddr(destination)), M.ParseSocksaddr(destination))
})
if h.options.Platform != "blink" {
initializeBridge(bridge)
}
}
func (h *Inbound) handleConnection(conn net.Conn, destination M.Socksaddr) {
+22 -10
View File
@@ -31,6 +31,7 @@ type Outbound struct {
options option.CallOutboundOptions
dialer N.Dialer
bridge *call.Bridge
startupError error
startHandler func()
await chan struct{}
}
@@ -42,7 +43,12 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
if options.Platform == "" {
return nil, E.New("missing platform")
}
outboundDialer, err := dialer.New(ctx, options.DialerOptions, true)
outboundDialer, err := dialer.NewWithOptions(dialer.Options{
Context: ctx,
Options: options.DialerOptions,
RemoteIsDomain: true,
ResolverOnDetour: true,
})
if err != nil {
return nil, err
}
@@ -58,17 +64,20 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
ob.startHandler = func() {
defer close(ob.await)
bridge, err := call.Connect(ctx, call.Config{
Platform: options.Platform,
Mode: options.Mode,
JoinLink: options.JoinLink,
CookieString: options.Cookies.Header(),
ReadBuffer: options.ReadBuffer,
Role: call.RoleJoiner,
Dialer: outboundDialer,
DNSRouter: dnsRouter,
Logger: logger,
Platform: options.Platform,
Mode: options.Mode,
JoinLink: options.JoinLink,
CookieString: options.Cookies.Header(),
CredentialsPath: options.CredentialsPath,
ReadBuffer: options.ReadBuffer,
MaxBufferedAmount: options.MaxBufferedAmount,
Role: call.RoleJoiner,
Dialer: outboundDialer,
DNSRouter: dnsRouter,
Logger: logger,
})
if err != nil {
ob.startupError = err
logger.ErrorContext(ctx, err)
return
}
@@ -126,6 +135,9 @@ func (o *Outbound) awaitBridge(ctx context.Context) error {
case <-ctx.Done():
return ctx.Err()
}
if o.startupError != nil {
return o.startupError
}
if o.bridge == nil {
return E.New("call: tunnel not initialized")
}