Integrate Amnezia 1.5

This commit is contained in:
Shtorm
2025-09-15 01:25:19 +03:00
parent c1ced4d495
commit 13c826bfa3
9 changed files with 189 additions and 81 deletions

View File

@@ -68,15 +68,26 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
var amnezia *wireguard.AmneziaOptions
if options.Amnezia != nil {
amnezia = &wireguard.AmneziaOptions{
JC: options.Amnezia.JC,
JMin: options.Amnezia.JMin,
JMax: options.Amnezia.JMax,
S1: options.Amnezia.S1,
S2: options.Amnezia.S2,
H1: options.Amnezia.H1,
H2: options.Amnezia.H2,
H3: options.Amnezia.H3,
H4: options.Amnezia.H4,
JC: options.Amnezia.JC,
JMin: options.Amnezia.JMin,
JMax: options.Amnezia.JMax,
S1: options.Amnezia.S1,
S2: options.Amnezia.S2,
S3: options.Amnezia.S3,
S4: options.Amnezia.S4,
H1: options.Amnezia.H1,
H2: options.Amnezia.H2,
H3: options.Amnezia.H3,
H4: options.Amnezia.H4,
I1: options.Amnezia.I1,
I2: options.Amnezia.I2,
I3: options.Amnezia.I3,
I4: options.Amnezia.I4,
I5: options.Amnezia.I5,
J1: options.Amnezia.J1,
J2: options.Amnezia.J2,
J3: options.Amnezia.J3,
ITime: options.Amnezia.ITime,
}
}
wgEndpoint, err := wireguard.NewEndpoint(wireguard.EndpointOptions{

View File

@@ -16,6 +16,7 @@ import (
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json/badoption"
M "github.com/sagernet/sing/common/metadata"
@@ -41,10 +42,8 @@ func NewWARPEndpoint(ctx context.Context, router adapter.Router, logger log.Cont
if options.Detour != "" {
dependencies = append(dependencies, options.Detour)
}
if options.Profile != nil {
if options.Profile.Detour != "" {
dependencies = append(dependencies, options.Profile.Detour)
}
if options.Profile.Detour != "" {
dependencies = append(dependencies, options.Profile.Detour)
}
warpEndpoint := &WARPEndpoint{
Adapter: endpoint.NewAdapter(C.TypeWARP, tag, []string{N.NetworkTCP, N.NetworkUDP}, dependencies),
@@ -80,17 +79,15 @@ func NewWARPEndpoint(ctx context.Context, router adapter.Router, logger log.Cont
}
}
opts := make([]cloudflare.CloudflareApiOption, 0, 1)
if options.Profile != nil {
if options.Profile.Detour != "" {
detour, ok := service.FromContext[adapter.OutboundManager](ctx).Outbound(options.Profile.Detour)
if !ok {
logger.ErrorContext(ctx, E.New("outbound detour not found: ", options.Profile.Detour))
return
}
opts = append(opts, cloudflare.WithDialContext(func(ctx context.Context, network, addr string) (net.Conn, error) {
return detour.DialContext(ctx, network, M.ParseSocksaddr(addr))
}))
if options.Profile.Detour != "" {
detour, ok := service.FromContext[adapter.OutboundManager](ctx).Outbound(options.Profile.Detour)
if !ok {
logger.ErrorContext(ctx, E.New("outbound detour not found: ", options.Profile.Detour))
return
}
opts = append(opts, cloudflare.WithDialContext(func(ctx context.Context, network, addr string) (net.Conn, error) {
return detour.DialContext(ctx, network, M.ParseSocksaddr(addr))
}))
}
api := cloudflare.NewCloudflareApi(opts...)
var profile *cloudflare.CloudflareProfile
@@ -185,10 +182,7 @@ func (w *WARPEndpoint) Start(stage adapter.StartStage) error {
}
func (w *WARPEndpoint) Close() error {
if ok := w.isEndpointInitialized(); !ok {
return E.New("endpoint not initialized")
}
return w.endpoint.Close()
return common.Close(w.endpoint)
}
func (w *WARPEndpoint) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {

View File

@@ -82,15 +82,26 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
var amnezia *wireguard.AmneziaOptions
if options.Amnezia != nil {
amnezia = &wireguard.AmneziaOptions{
JC: options.Amnezia.JC,
JMin: options.Amnezia.JMin,
JMax: options.Amnezia.JMax,
S1: options.Amnezia.S1,
S2: options.Amnezia.S2,
H1: options.Amnezia.H1,
H2: options.Amnezia.H2,
H3: options.Amnezia.H3,
H4: options.Amnezia.H4,
JC: options.Amnezia.JC,
JMin: options.Amnezia.JMin,
JMax: options.Amnezia.JMax,
S1: options.Amnezia.S1,
S2: options.Amnezia.S2,
S3: options.Amnezia.S3,
S4: options.Amnezia.S4,
H1: options.Amnezia.H1,
H2: options.Amnezia.H2,
H3: options.Amnezia.H3,
H4: options.Amnezia.H4,
I1: options.Amnezia.I1,
I2: options.Amnezia.I2,
I3: options.Amnezia.I3,
I4: options.Amnezia.I4,
I5: options.Amnezia.I5,
J1: options.Amnezia.J1,
J2: options.Amnezia.J2,
J3: options.Amnezia.J3,
ITime: options.Amnezia.ITime,
}
}
wgEndpoint, err := wireguard.NewEndpoint(wireguard.EndpointOptions{