mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
Chore: remove forward compatible code
This commit is contained in:
parent
7267c58913
commit
204a72bbd3
|
@ -47,10 +47,6 @@ type VmessOption struct {
|
||||||
HTTP2Opts HTTP2Options `proxy:"h2-opts,omitempty"`
|
HTTP2Opts HTTP2Options `proxy:"h2-opts,omitempty"`
|
||||||
GrpcOpts GrpcOptions `proxy:"grpc-opts,omitempty"`
|
GrpcOpts GrpcOptions `proxy:"grpc-opts,omitempty"`
|
||||||
WSOpts WSOptions `proxy:"ws-opts,omitempty"`
|
WSOpts WSOptions `proxy:"ws-opts,omitempty"`
|
||||||
|
|
||||||
// TODO: remove these until 2022
|
|
||||||
WSHeaders map[string]string `proxy:"ws-headers,omitempty"`
|
|
||||||
WSPath string `proxy:"ws-path,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPOptions struct {
|
type HTTPOptions struct {
|
||||||
|
@ -80,13 +76,6 @@ func (v *Vmess) StreamConn(c net.Conn, metadata *C.Metadata) (net.Conn, error) {
|
||||||
var err error
|
var err error
|
||||||
switch v.option.Network {
|
switch v.option.Network {
|
||||||
case "ws":
|
case "ws":
|
||||||
if v.option.WSOpts.Path == "" {
|
|
||||||
v.option.WSOpts.Path = v.option.WSPath
|
|
||||||
}
|
|
||||||
if len(v.option.WSOpts.Headers) == 0 {
|
|
||||||
v.option.WSOpts.Headers = v.option.WSHeaders
|
|
||||||
}
|
|
||||||
|
|
||||||
host, port, _ := net.SplitHostPort(v.addr)
|
host, port, _ := net.SplitHostPort(v.addr)
|
||||||
wsOpts := &vmess.WebsocketConfig{
|
wsOpts := &vmess.WebsocketConfig{
|
||||||
Host: host,
|
Host: host,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package cachefile
|
package cachefile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/gob"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -138,69 +136,30 @@ func (c *CacheFile) Close() error {
|
||||||
return c.DB.Close()
|
return c.DB.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove migrateCache until 2022
|
func initCache() {
|
||||||
func migrateCache() {
|
options := bbolt.Options{Timeout: time.Second}
|
||||||
defer func() {
|
db, err := bbolt.Open(C.Path.Cache(), fileMode, &options)
|
||||||
options := bbolt.Options{Timeout: time.Second}
|
switch err {
|
||||||
db, err := bbolt.Open(C.Path.Cache(), fileMode, &options)
|
case bbolt.ErrInvalid, bbolt.ErrChecksum, bbolt.ErrVersionMismatch:
|
||||||
switch err {
|
if err = os.Remove(C.Path.Cache()); err != nil {
|
||||||
case bbolt.ErrInvalid, bbolt.ErrChecksum, bbolt.ErrVersionMismatch:
|
log.Warnln("[CacheFile] remove invalid cache file error: %s", err.Error())
|
||||||
if err = os.Remove(C.Path.Cache()); err != nil {
|
break
|
||||||
log.Warnln("[CacheFile] remove invalid cache file error: %s", err.Error())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
log.Infoln("[CacheFile] remove invalid cache file and create new one")
|
|
||||||
db, err = bbolt.Open(C.Path.Cache(), fileMode, &options)
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
log.Infoln("[CacheFile] remove invalid cache file and create new one")
|
||||||
log.Warnln("[CacheFile] can't open cache file: %s", err.Error())
|
db, err = bbolt.Open(C.Path.Cache(), fileMode, &options)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultCache = &CacheFile{
|
|
||||||
DB: db,
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
buf, err := os.ReadFile(C.Path.OldCache())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
log.Warnln("[CacheFile] can't open cache file: %s", err.Error())
|
||||||
}
|
}
|
||||||
defer os.Remove(C.Path.OldCache())
|
|
||||||
|
|
||||||
// read old cache file
|
defaultCache = &CacheFile{
|
||||||
type cache struct {
|
DB: db,
|
||||||
Selected map[string]string
|
|
||||||
}
|
}
|
||||||
model := &cache{
|
|
||||||
Selected: map[string]string{},
|
|
||||||
}
|
|
||||||
bufReader := bytes.NewBuffer(buf)
|
|
||||||
gob.NewDecoder(bufReader).Decode(model)
|
|
||||||
|
|
||||||
// write to new cache file
|
|
||||||
db, err := bbolt.Open(C.Path.Cache(), fileMode, nil)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
db.Batch(func(t *bbolt.Tx) error {
|
|
||||||
bucket, err := t.CreateBucketIfNotExists(bucketSelected)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for group, selected := range model.Selected {
|
|
||||||
if err := bucket.Put([]byte(group), []byte(selected)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache return singleton of CacheFile
|
// Cache return singleton of CacheFile
|
||||||
func Cache() *CacheFile {
|
func Cache() *CacheFile {
|
||||||
initOnce.Do(migrateCache)
|
initOnce.Do(initCache)
|
||||||
|
|
||||||
return defaultCache
|
return defaultCache
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user