Skip to content

Commit

Permalink
Merge branch 'SagerNet:dev-next' into dev-next
Browse files Browse the repository at this point in the history
  • Loading branch information
vAHiD55555 committed Jul 12, 2023
2 parents c7f6b91 + 1121517 commit 3174785
Show file tree
Hide file tree
Showing 68 changed files with 1,014 additions and 712 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ lib:

lib_install:
go get -v -d
go install -v github.com/sagernet/gomobile/cmd/[email protected]20230413023804-244d7ff07035
go install -v github.com/sagernet/gomobile/cmd/[email protected]20230413023804-244d7ff07035
go install -v github.com/sagernet/gomobile/cmd/[email protected]20230701084532-493ee2e45182
go install -v github.com/sagernet/gomobile/cmd/[email protected]20230701084532-493ee2e45182

clean:
rm -rf bin dist sing-box
Expand Down
1 change: 1 addition & 0 deletions adapter/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Tracker interface {
}

type OutboundGroup interface {
Outbound
Now() string
All() []string
}
Expand Down
5 changes: 4 additions & 1 deletion adapter/fakeip.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"net/netip"

"github.com/sagernet/sing-dns"
"github.com/sagernet/sing/common/logger"
)

type FakeIPStore interface {
Service
Contains(address netip.Addr) bool
Create(domain string, strategy dns.DomainStrategy) (netip.Addr, error)
Create(domain string, isIPv6 bool) (netip.Addr, error)
Lookup(address netip.Addr) (string, bool)
Reset() error
}
Expand All @@ -18,7 +19,9 @@ type FakeIPStorage interface {
FakeIPMetadata() *FakeIPMetadata
FakeIPSaveMetadata(metadata *FakeIPMetadata) error
FakeIPStore(address netip.Addr, domain string) error
FakeIPStoreAsync(address netip.Addr, domain string, logger logger.Logger)
FakeIPLoad(address netip.Addr) (string, bool)
FakeIPLoadDomain(domain string, isIPv6 bool) (netip.Addr, bool)
FakeIPReset() error
}

Expand Down
10 changes: 2 additions & 8 deletions adapter/prestart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ type PreStarter interface {
PreStart() error
}

func PreStart(starter any) error {
if preService, ok := starter.(PreStarter); ok {
err := preService.PreStart()
if err != nil {
return err
}
}
return nil
type PostStarter interface {
PostStart() error
}
25 changes: 20 additions & 5 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ func (s *Box) Start() error {

func (s *Box) preStart() error {
for serviceName, service := range s.preServices {
s.logger.Trace("pre-start ", serviceName)
err := adapter.PreStart(service)
if err != nil {
return E.Cause(err, "pre-starting ", serviceName)
if preService, isPreService := service.(adapter.PreStarter); isPreService {
s.logger.Trace("pre-start ", serviceName)
err := preService.PreStart()
if err != nil {
return E.Cause(err, "pre-starting ", serviceName)
}
}
}
err := s.startOutbounds()
Expand Down Expand Up @@ -249,13 +251,26 @@ func (s *Box) start() error {
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
}
}
return nil
}

func (s *Box) postStart() error {
for serviceName, service := range s.postServices {
s.logger.Trace("starting ", service)
err = service.Start()
err := service.Start()
if err != nil {
return E.Cause(err, "start ", serviceName)
}
}
for serviceName, service := range s.outbounds {
if lateService, isLateService := service.(adapter.PostStarter); isLateService {
s.logger.Trace("post-starting ", service)
err := lateService.PostStart()
if err != nil {
return E.Cause(err, "post-start ", serviceName)
}
}
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/build_libbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func buildiOS() {
log.Fatal(err)
}

copyPath := filepath.Join("..", "sing-box-for-ios")
copyPath := filepath.Join("..", "sing-box-for-apple")
if rw.FileExists(copyPath) {
targetDir := filepath.Join(copyPath, "Libbox.xcframework")
targetDir, _ = filepath.Abs(targetDir)
Expand Down
2 changes: 1 addition & 1 deletion common/baderror/baderror.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func WrapQUIC(err error) error {
if err == nil {
return nil
}
if Contains(err, "canceled with error code 0") {
if Contains(err, "canceled by local with error code 0") {
return net.ErrClosed
}
return err
Expand Down
87 changes: 0 additions & 87 deletions common/debugio/log.go

This file was deleted.

19 changes: 0 additions & 19 deletions common/debugio/print.go

This file was deleted.

48 changes: 0 additions & 48 deletions common/debugio/race.go

This file was deleted.

7 changes: 0 additions & 7 deletions common/dialer/tfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ func (c *slowOpenConn) NeedHandshake() bool {
return c.conn == nil
}

func (c *slowOpenConn) ReadFrom(r io.Reader) (n int64, err error) {
if c.conn != nil {
return bufio.Copy(c.conn, r)
}
return bufio.ReadFrom0(c, r)
}

func (c *slowOpenConn) WriteTo(w io.Writer) (n int64, err error) {
if c.conn == nil {
select {
Expand Down
5 changes: 1 addition & 4 deletions common/process/searcher_linux_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"unicode"
"unsafe"

"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
N "github.com/sagernet/sing/common/network"
Expand Down Expand Up @@ -82,9 +81,7 @@ func resolveSocketByNetlink(network string, source netip.AddrPort, destination n
return 0, 0, E.Cause(err, "write netlink request")
}

_buffer := buf.StackNew()
defer common.KeepAlive(_buffer)
buffer := common.Dup(_buffer)
buffer := buf.New()
defer buffer.Release()

n, err := syscall.Read(socket, buffer.FreeBytes())
Expand Down
4 changes: 1 addition & 3 deletions common/sniff/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ func StreamDomainNameQuery(readCtx context.Context, reader io.Reader) (*adapter.
if length == 0 {
return nil, os.ErrInvalid
}
_buffer := buf.StackNewSize(int(length))
defer common.KeepAlive(_buffer)
buffer := common.Dup(_buffer)
buffer := buf.NewSize(int(length))
defer buffer.Release()

readCtx, cancel := context.WithTimeout(readCtx, time.Millisecond*100)
Expand Down
28 changes: 26 additions & 2 deletions common/urltest/urltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/x/list"
)

type History struct {
Expand All @@ -20,6 +21,7 @@ type History struct {
type HistoryStorage struct {
access sync.RWMutex
delayHistory map[string]*History
callbacks list.List[func()]
}

func NewHistoryStorage() *HistoryStorage {
Expand All @@ -28,6 +30,18 @@ func NewHistoryStorage() *HistoryStorage {
}
}

func (s *HistoryStorage) AddListener(listener func()) *list.Element[func()] {
s.access.Lock()
defer s.access.Unlock()
return s.callbacks.PushBack(listener)
}

func (s *HistoryStorage) RemoveListener(element *list.Element[func()]) {
s.access.Lock()
defer s.access.Unlock()
s.callbacks.Remove(element)
}

func (s *HistoryStorage) LoadURLTestHistory(tag string) *History {
if s == nil {
return nil
Expand All @@ -39,14 +53,24 @@ func (s *HistoryStorage) LoadURLTestHistory(tag string) *History {

func (s *HistoryStorage) DeleteURLTestHistory(tag string) {
s.access.Lock()
defer s.access.Unlock()
delete(s.delayHistory, tag)
s.access.Unlock()
s.notifyUpdated()
}

func (s *HistoryStorage) StoreURLTestHistory(tag string, history *History) {
s.access.Lock()
defer s.access.Unlock()
s.delayHistory[tag] = history
s.access.Unlock()
s.notifyUpdated()
}

func (s *HistoryStorage) notifyUpdated() {
s.access.RLock()
defer s.access.RUnlock()
for element := s.callbacks.Front(); element != nil; element = element.Next() {
element.Value()
}
}

func URLTest(ctx context.Context, link string, detour N.Dialer) (t uint16, err error) {
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#### 1.3.1-beta.2

* Fix bugs and update dependencies

#### 1.3.1-beta.1

* Fixes and improvements

#### 1.3.0

* Fix bugs and update dependencies
Expand Down
Loading

0 comments on commit 3174785

Please sign in to comment.