Skip to content

Commit

Permalink
Merge branch 'main' into drop-only
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 authored Sep 17, 2024
2 parents 6a95e6b + 3b2ae3a commit 3d6838c
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 277 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/trigger-downstream-flake-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# _
# __| | __ _ ___
# / _` |/ _` |/ _ \
# | (_| | (_| | __/
# \__,_|\__,_|\___|
#
# Copyright (C) 2024 @daeuniverse <https://github.com/daeuniverse>
#
# This is a open-source software, liscensed under the AGPL-3.0 License.
# See /License for more information.

---
name: Trigger downstream sync workflow

on:
workflow_dispatch:
push:
branches:
- 'main'

env:
DOWNSTREAM_REPO: flake.nix
WORKFLOW_BRANCH: unstable
WORKFLOW_FILE: sync-upstream.yml

jobs:
dispatch-downstream-workflow:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub auth token
# https://github.com/tibdex/github-app-token
id: generate_token
uses: tibdex/[email protected]
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}

- name: Dispatch
uses: convictional/[email protected]
with:
owner: ${{ github.repository_owner }}
repo: ${{ env.DOWNSTREAM_REPO }}
github_token: ${{ steps.generate_token.outputs.token }}
workflow_file_name: ${{ env.WORKFLOW_FILE }}
ref: ${{ env.WORKFLOW_BRANCH }}
client_payload: '{"project":"dae","branch":"${{ env.WORKFLOW_BRANCH }}"}'
trigger_workflow: true
propagate_failure: false
wait_workflow: false
17 changes: 15 additions & 2 deletions CHANGELOGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ curl --silent "https://api.github.com/repos/daeuniverse/dae/releases" | jq -r '.

<!-- BEGIN NEW TOC ENTRY -->

- [v0.7.1 (Latest)](#v071-latest)
- [v0.8.0rc1 (Pre-release)](#v080rc1-pre-release)
- [v0.7.0 (Latest)](#v070-latest)
- [v0.7.0](#v070)
- [v0.6.0](#v060)
- [v0.5.1](#v051)
- [v0.5.0](#v050)
Expand All @@ -41,6 +42,18 @@ curl --silent "https://api.github.com/repos/daeuniverse/dae/releases" | jq -r '.
- [v0.1.0](#v010)
<!-- BEGIN NEW CHANGELOGS -->

### v0.7.1 (Latest)

> Release date: 2024/08/21
#### Bug Fixes

- fix(cmd/run.go): always check whether network online (#588)
- fix(udp_task_pool): panic: close of closed channel (#570)
- fix: unknown tls implementation (#569)

#### Bug Fixes

### v0.8.0rc1 (Pre-release)

> Release date: 2024/07/22
Expand Down Expand Up @@ -78,7 +91,7 @@ curl --silent "https://api.github.com/repos/daeuniverse/dae/releases" | jq -r '.

**Full Changelog**: https://github.com/daeuniverse/dae/compare/v0.7.0...v0.8.0rc1

### v0.7.0 (Latest)
### v0.7.0

> Release date: 2024/07/21
Expand Down
6 changes: 3 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c
}
// Resolve subscriptions to nodes.
resolvingfailed := false
if !conf.Global.DisableWaitingNetwork && len(conf.Subscription) > 0 {
if !conf.Global.DisableWaitingNetwork {
epo := 5 * time.Second
client := http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) {
cd := netproxy.ContextDialerConverter{Dialer: direct.SymmetricDirect}
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae), addr)
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func newControlPlane(log *logrus.Logger, bpf interface{}, dnsCache map[string]*c
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) {
cd := netproxy.ContextDialerConverter{Dialer: direct.SymmetricDirect}
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae), addr)
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", conf.Global.SoMarkFromDae, conf.Global.Mptcp), addr)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ nextLink:
return Deduplicate(defaultIfs), nil
}

func MagicNetwork(network string, mark uint32) string {
if mark == 0 {
func MagicNetwork(network string, mark uint32, mptcp bool) string {
if mark == 0 && !mptcp {
return network
} else {
return netproxy.MagicNetwork{
Network: network,
Mark: mark,
Mptcp: mptcp,
}.Encode()
}
}
Expand Down
23 changes: 19 additions & 4 deletions component/outbound/dialer/connectivity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"sync"
"time"
"unsafe"

"github.com/daeuniverse/dae/common"

Expand Down Expand Up @@ -282,8 +283,10 @@ func (d *Dialer) ActivateCheck() {
func (d *Dialer) aliveBackground() {
cycle := d.CheckInterval
var tcpSomark uint32
var mptcp bool
if network, err := netproxy.ParseMagicNetwork(d.TcpCheckOptionRaw.ResolverNetwork); err == nil {
tcpSomark = network.Mark
mptcp = network.Mptcp
}
tcp4CheckOpt := &CheckOption{
networkType: &NetworkType{
Expand All @@ -304,7 +307,7 @@ func (d *Dialer) aliveBackground() {
}).Debugln("Skip check due to no DNS record.")
return false, nil
}
return d.HttpCheck(ctx, opt.Url, opt.Ip4, opt.Method, tcpSomark)
return d.HttpCheck(ctx, opt.Url, opt.Ip4, opt.Method, tcpSomark, mptcp)
},
}
tcp6CheckOpt := &CheckOption{
Expand All @@ -326,7 +329,7 @@ func (d *Dialer) aliveBackground() {
}).Debugln("Skip check due to no DNS record.")
return false, nil
}
return d.HttpCheck(ctx, opt.Url, opt.Ip6, opt.Method, tcpSomark)
return d.HttpCheck(ctx, opt.Url, opt.Ip6, opt.Method, tcpSomark, mptcp)
},
}
tcpNetwork := netproxy.MagicNetwork{
Expand Down Expand Up @@ -450,6 +453,18 @@ func (d *Dialer) aliveBackground() {
}
}
}()
var unused int
for _, opt := range CheckOpts {
if len(d.mustGetCollection(opt.networkType).AliveDialerSetSet) == 0 {
unused++
}
}
if unused == len(CheckOpts) {
d.Log.WithField("dialer", d.Property().Name).
WithField("p", unsafe.Pointer(d)).
Traceln("cleaned up due to unused")
return
}
var wg sync.WaitGroup
for range d.checkCh {
for _, opt := range CheckOpts {
Expand Down Expand Up @@ -580,7 +595,7 @@ func (d *Dialer) Check(opts *CheckOption) (ok bool, err error) {
return ok, err
}

func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr, method string, soMark uint32) (ok bool, err error) {
func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr, method string, soMark uint32, mptcp bool) (ok bool, err error) {
// HTTP(S) check.
if method == "" {
method = http.MethodGet
Expand All @@ -590,7 +605,7 @@ func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr,
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (c net.Conn, err error) {
// Force to dial "ip".
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", soMark), net.JoinHostPort(ip.String(), u.Port()))
conn, err := cd.DialContext(ctx, common.MagicNetwork("tcp", soMark, mptcp), net.JoinHostPort(ip.String(), u.Port()))
if err != nil {
return nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions component/outbound/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import (
"fmt"
"sync"
"time"
"unsafe"

"github.com/daeuniverse/dae/common"
"github.com/daeuniverse/dae/config"
D "github.com/daeuniverse/outbound/dialer"
"github.com/daeuniverse/outbound/netproxy"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -60,6 +63,21 @@ type Property struct {

type AliveDialerSetSet map[*AliveDialerSet]int

func NewGlobalOption(global *config.Global, log *logrus.Logger) *GlobalOption {
return &GlobalOption{
ExtraOption: D.ExtraOption{
AllowInsecure: global.AllowInsecure,
TlsImplementation: global.TlsImplementation,
UtlsImitate: global.UtlsImitate},
Log: log,
TcpCheckOptionRaw: TcpCheckOptionRaw{Raw: global.TcpCheckUrl, Log: log, ResolverNetwork: common.MagicNetwork("udp", global.SoMarkFromDae, global.Mptcp), Method: global.TcpCheckHttpMethod},
CheckDnsOptionRaw: CheckDnsOptionRaw{Raw: global.UdpCheckDns, ResolverNetwork: common.MagicNetwork("udp", global.SoMarkFromDae, global.Mptcp), Somark: global.SoMarkFromDae},
CheckInterval: global.CheckInterval,
CheckTolerance: global.CheckTolerance,
CheckDnsTcp: true,
}
}

// NewDialer is for register in general.
func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOption, property *Property) *Dialer {
var collections [6]*collection
Expand All @@ -80,9 +98,16 @@ func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOpt
ctx: ctx,
cancel: cancel,
}
option.Log.WithField("dialer", d.Property().Name).
WithField("p", unsafe.Pointer(d)).
Traceln("NewDialer")
return d
}

func (d *Dialer) Clone() *Dialer {
return NewDialer(d.Dialer, d.GlobalOption, d.InstanceOption, d.property)
}

func (d *Dialer) Close() error {
d.cancel()
d.tickerMu.Lock()
Expand Down
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Global struct {
TlsImplementation string `mapstructure:"tls_implementation" default:"tls"`
UtlsImitate string `mapstructure:"utls_imitate" default:"chrome_auto"`
PprofPort uint16 `mapstructure:"pprof_port" default:"0"`
Mptcp bool `mapstructure:"mptcp" default:"false"`
}

type Utls struct {
Expand Down Expand Up @@ -88,6 +89,12 @@ type Group struct {
Filter [][]*config_parser.Function `mapstructure:"filter" repeatable:""`
FilterAnnotation [][]*config_parser.Param `mapstructure:"_"`
Policy FunctionListOrString `mapstructure:"policy" required:""`

TcpCheckUrl []string `mapstructure:"tcp_check_url"`
TcpCheckHttpMethod string `mapstructure:"tcp_check_http_method"`
UdpCheckDns []string `mapstructure:"udp_check_dns"`
CheckInterval time.Duration `mapstructure:"check_interval"`
CheckTolerance time.Duration `mapstructure:"check_tolerance"`
}

type DnsRequestRouting struct {
Expand Down
6 changes: 6 additions & 0 deletions config/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var GlobalDesc = Desc{
"sniffing_timeout": "Timeout to waiting for first data sending for sniffing. It is always 0 if dial_mode is ip. Set it higher is useful in high latency LAN network.",
"tls_implementation": "TLS implementation. \"tls\" is to use Go's crypto/tls. \"utls\" is to use uTLS, which can imitate browser's Client Hello.",
"utls_imitate": "The Client Hello ID for uTLS to imitate. This takes effect only if tls_implementation is utls. See more: https://github.com/daeuniverse/dae/blob/331fa23c16/component/outbound/transport/tls/utls.go#L17",
"mptcp": "Enable Multipath TCP. If is true, dae will try to use MPTCP to connect all nodes, but it will only take effects when the node supports MPTCP. It can use for load balance and failover to multiple interfaces and IPs.",
}

var DnsDesc = Desc{
Expand Down Expand Up @@ -84,4 +85,9 @@ min: Select node by the latency of last check.
min_avg10: Select node by the average of latencies of last 10 checks.
min_moving_avg: Select node by the moving average of latencies of checks, which means more recent latencies have higher weight.
`,
"tcp_check_url": "Override global config.",
"tcp_check_http_method": "Override global config.",
"udp_check_dns": "Override global config.",
"check_interval": "Override global config.",
"check_tolerance": "Override global config.",
}
Loading

0 comments on commit 3d6838c

Please sign in to comment.