Tai7sy / v2ray_mobile_lib

v2ray mobile library for Android/iOS
GNU Lesser General Public License v3.0
67 stars 35 forks source link

能否出一个IOS接入demo #4

Open thomashooo opened 4 years ago

thomashooo commented 4 years ago

这个和https://github.com/hello-david/SwiftV2Ray编译的v2ray提供的接口差异很大啊,如调用接入呢? `package tun2socks

import ( "context" "runtime" "runtime/debug" "strings" "time"

"github.com/eycorsican/go-tun2socks/common/log"
"github.com/eycorsican/go-tun2socks/core"
"github.com/eycorsican/go-tun2socks/proxy/v2ray"
vcore "v2ray.com/core"
vproxyman "v2ray.com/core/app/proxyman"

)

type PacketFlow interface { WritePacket(packet []byte) }

func InputPacket(data []byte) { lwipStack.Write(data) }

var lwipStack core.LWIPStack

func StartV2Ray(packetFlow PacketFlow, configBytes []byte) { if packetFlow == nil { return }

lwipStack = core.NewLWIPStack()
v, err := vcore.StartInstance("json", configBytes)
if err != nil {
    log.Fatalf("start V instance failed: %v", err)
}

sniffingConfig := &vproxyman.SniffingConfig{
    Enabled:             true,
    DestinationOverride: strings.Split("tls,http", ","),
}

debug.SetGCPercent(5)
ctx := vproxyman.ContextWithSniffingConfig(context.Background(), sniffingConfig)
core.RegisterTCPConnHandler(v2ray.NewTCPHandler(ctx, v))
core.RegisterUDPConnHandler(v2ray.NewUDPHandler(ctx, v, 30*time.Second))
core.RegisterOutputFn(func(data []byte) (int, error) {
    packetFlow.WritePacket(data)
    runtime.GC()
    debug.FreeOSMemory()
    return len(data), nil
})

}`

Tai7sy commented 4 years ago

ios建议参考 pototso源码, 里面有内置的tun2socks + ss-libev 把ss替换成这个库就ok了

Diuyon commented 4 years ago

研究了半天,还是不知道咋接入

thomashooo commented 4 years ago

@Tai7sy 能否指点一下出一个接入IOS的版本吗?

Tai7sy commented 4 years ago

@Tai7sy 能否指点一下出一个接入IOS的版本吗?

可以定制

nahddw commented 4 years ago

@Tai7sy 老哥给个联系方式

thomashooo commented 4 years ago

1、用这个链接吧,先把SS运行成功:https://github.com/ShadowsocksR-Live/iShadowsocksR 2、然后把PacketTunnelProvider中startShadowsocks和startSocksProxy注释,只保留startHttpProxy 导入v2Core的Framework并启动startV2Ray(config, &error);//start vmess config中的inbounds的socks端口和startHttpProxy中端口保持一致,就可以启动了。 3、然并卵:IOS内存并没有什么改善

zzw169 commented 4 years ago

内存问题有谁解决了吗