mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
Compare commits
4 Commits
9585b520a2
...
6c84eb93db
Author | SHA1 | Date | |
---|---|---|---|
|
6c84eb93db | ||
|
de19f927e8 | ||
|
256e9d8c3d | ||
|
828ba83ef3 |
|
@ -165,6 +165,8 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
|
|||
mapping["udp"] = p.SupportUDP()
|
||||
mapping["xudp"] = p.SupportXUDP()
|
||||
mapping["tfo"] = p.SupportTFO()
|
||||
mapping["mptcp"] = p.SupportMPTCP()
|
||||
mapping["smux"] = p.SupportSMUX()
|
||||
return json.Marshal(mapping)
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,16 @@ func (b *Base) SupportTFO() bool {
|
|||
return b.tfo
|
||||
}
|
||||
|
||||
// SupportMPTCP implements C.ProxyAdapter
|
||||
func (b *Base) SupportMPTCP() bool {
|
||||
return b.mpTcp
|
||||
}
|
||||
|
||||
// SupportSMUX implements C.ProxyAdapter
|
||||
func (b *Base) SupportSMUX() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsL3Protocol implements C.ProxyAdapter
|
||||
func (b *Base) IsL3Protocol(metadata *C.Metadata) bool {
|
||||
return false
|
||||
|
|
|
@ -97,6 +97,10 @@ func (s *SingMux) SupportUOT() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (s *SingMux) SupportSMUX() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func closeSingMux(s *SingMux) {
|
||||
_ = s.client.Close()
|
||||
}
|
||||
|
|
|
@ -625,6 +625,20 @@ func (r *refProxyAdapter) SupportTFO() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (r *refProxyAdapter) SupportMPTCP() bool {
|
||||
if r.proxyAdapter != nil {
|
||||
return r.proxyAdapter.SupportMPTCP()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *refProxyAdapter) SupportSMUX() bool {
|
||||
if r.proxyAdapter != nil {
|
||||
return r.proxyAdapter.SupportSMUX()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *refProxyAdapter) MarshalJSON() ([]byte, error) {
|
||||
if r.proxyAdapter != nil {
|
||||
return r.proxyAdapter.MarshalJSON()
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/metacubex/mihomo/adapter/outbound"
|
||||
|
@ -134,31 +134,31 @@ func (lb *LoadBalance) IsL3Protocol(metadata *C.Metadata) bool {
|
|||
}
|
||||
|
||||
func strategyRoundRobin(url string) strategyFn {
|
||||
var availableProxies []C.Proxy
|
||||
idx := 0
|
||||
idxMutex := sync.Mutex{}
|
||||
|
||||
return func(proxies []C.Proxy, metadata *C.Metadata, touch bool) C.Proxy {
|
||||
idxMutex.Lock()
|
||||
defer idxMutex.Unlock()
|
||||
|
||||
i := 0
|
||||
length := len(proxies)
|
||||
|
||||
if touch {
|
||||
defer func() {
|
||||
idx = (idx + i) % length
|
||||
}()
|
||||
}
|
||||
|
||||
for ; i < length; i++ {
|
||||
id := (idx + i) % length
|
||||
proxy := proxies[id]
|
||||
if proxy.AliveForTestUrl(url) {
|
||||
i++
|
||||
return proxy
|
||||
// check list
|
||||
availableProxies = []C.Proxy{}
|
||||
for _, proxy := range proxies {
|
||||
if proxy.AliveForTestUrl(url) {
|
||||
availableProxies = append(availableProxies, proxy)
|
||||
}
|
||||
}
|
||||
// fallback
|
||||
if len(availableProxies) == 0 {
|
||||
return proxies[0]
|
||||
}
|
||||
}
|
||||
|
||||
return proxies[0]
|
||||
proxy := availableProxies[idx]
|
||||
// reset idx
|
||||
idx = (idx + 1) % len(availableProxies)
|
||||
return proxy
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,8 @@ type ProxyAdapter interface {
|
|||
SupportUDP() bool
|
||||
SupportXUDP() bool
|
||||
SupportTFO() bool
|
||||
SupportMPTCP() bool
|
||||
SupportSMUX() bool
|
||||
MarshalJSON() ([]byte, error)
|
||||
|
||||
// Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.
|
||||
|
|
Loading…
Reference in New Issue
Block a user