mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt space
This commit is contained in:
parent
9a4e1a266a
commit
9d24461de8
@ -1,6 +1,8 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -26,6 +28,7 @@ func init() {
|
||||
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), arg[1]).Table(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]), arg[1], arg[2:], ice.OptionFields(""))
|
||||
})
|
||||
_waitMap.Range(func(key, cb ice.Any) bool { cb.(func(*ice.Message, ...string))(m, arg...); return true })
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELDS, "time,id,cmd"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
@ -56,3 +59,17 @@ func EventDeferEvent(m *ice.Message, key string, arg ...ice.Any) func(string, ..
|
||||
Event(m, key, arg...)
|
||||
return func(key string, args ...ice.Any) { Event(m, key, args...) }
|
||||
}
|
||||
|
||||
var _waitMap = sync.Map{}
|
||||
|
||||
func WaitEvent(m *ice.Message, key string, cb func(*ice.Message, ...string) bool) {
|
||||
wg := sync.WaitGroup{}
|
||||
h := kit.HashsUniq()
|
||||
defer _waitMap.Delete(h)
|
||||
_waitMap.Store(h, func(m *ice.Message, arg ...string) {
|
||||
m.Info("WaitEvent %v %v", key, kit.FileLine(cb, 3))
|
||||
kit.If((key == "" || m.Option(EVENT) == key) && cb(m, arg...), func() { wg.Done() })
|
||||
})
|
||||
wg.Add(1)
|
||||
defer wg.Wait()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package tcp
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -12,11 +13,18 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _host_publish(m *ice.Message) string {
|
||||
if p := mdb.Config(m, DOMAIN); p != "" {
|
||||
return p
|
||||
}
|
||||
return m.Cmdv(HOST, mdb.Config(m, ice.MAIN), aaa.IP)
|
||||
func _host_domain(m *ice.Message) string {
|
||||
return kit.GetValid(
|
||||
func() string { return m.Option("tcp_domain") },
|
||||
func() string { return mdb.Config(m, DOMAIN) },
|
||||
func() string { return os.Getenv("tcp_domain") },
|
||||
func() string {
|
||||
if !kit.IsIn(m.ActionKey(), "", ice.LIST) {
|
||||
return m.Cmdv(HOST, mdb.Config(m, ice.MAIN), aaa.IP)
|
||||
}
|
||||
return ""
|
||||
},
|
||||
)
|
||||
}
|
||||
func _host_list(m *ice.Message, name string) {
|
||||
if ifs, e := net.Interfaces(); m.Assert(e) {
|
||||
@ -39,7 +47,7 @@ func _host_list(m *ice.Message, name string) {
|
||||
m.Push(mdb.INDEX, -1).Push(mdb.NAME, LOCALHOST).Push(aaa.IP, "127.0.0.1").Push("mask", "255.0.0.0").Push("hard", "")
|
||||
}
|
||||
m.SortInt(mdb.INDEX)
|
||||
m.StatusTimeCount(mdb.ConfigSimple(m, ice.MAIN, DOMAIN))
|
||||
m.StatusTimeCount(DOMAIN, _host_domain(m))
|
||||
}
|
||||
|
||||
const (
|
||||
@ -79,9 +87,9 @@ func init() {
|
||||
}},
|
||||
PUBLISH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.Contains(arg[0], LOCALHOST) {
|
||||
arg[0] = strings.Replace(arg[0], LOCALHOST, _host_publish(m), 1)
|
||||
arg[0] = strings.Replace(arg[0], LOCALHOST, _host_domain(m), 1)
|
||||
} else if strings.Contains(arg[0], "127.0.0.1") {
|
||||
arg[0] = strings.Replace(arg[0], "127.0.0.1", _host_publish(m), 1)
|
||||
arg[0] = strings.Replace(arg[0], "127.0.0.1", _host_domain(m), 1)
|
||||
}
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
|
@ -81,11 +81,11 @@ func _dream_start(m *ice.Message, name string) {
|
||||
cli.CTX_OPS, Domain(tcp.LOCALHOST, m.Cmdv(SERVE, tcp.PORT)), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_PID, ice.VAR_LOG_ICE_PID,
|
||||
cli.CTX_ROOT, kit.Path(""), cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username,
|
||||
)...), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
defer m.Sleep3s()
|
||||
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE))
|
||||
kit.If(m.Option(nfs.BINARY), func(p string) { _dream_binary(m, p) })
|
||||
kit.If(m.Option(nfs.TEMPLATE), func(p string) { _dream_template(m, p) })
|
||||
m.Cmd(cli.DAEMON, bin, SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME), cli.DAEMON, ice.OPS)
|
||||
gdb.WaitEvent(m, DREAM_OPEN, func(m *ice.Message, arg ...string) bool { return m.Option(mdb.NAME) == name })
|
||||
}
|
||||
func _dream_binary(m *ice.Message, p string) {
|
||||
if bin := path.Join(m.Option(cli.CMD_DIR), ice.BIN_ICE_BIN); nfs.Exists(m, bin) {
|
||||
@ -265,6 +265,8 @@ func init() {
|
||||
DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Switch(m.Option(mdb.TYPE), []string{WORKER, SERVER}, func() { m.PushButton(OPEN, ice.MAIN) })
|
||||
}},
|
||||
DREAM_OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
}},
|
||||
STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 {
|
||||
stats := map[string]int{}
|
||||
|
@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"math/rand"
|
||||
"net"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -28,7 +29,7 @@ func _space_qrcode(m *ice.Message, dev string) {
|
||||
}
|
||||
func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
u := kit.ParseURL(kit.MergeURL2(strings.Replace(m.Cmdv(SPIDE, dev, CLIENT_ORIGIN), HTTP, "ws", 1), PP(SPACE), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name,
|
||||
nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), arg))
|
||||
nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), "goos", runtime.GOOS, "goarch", runtime.GOARCH, arg))
|
||||
args := kit.SimpleKV("type,name,host,port", u.Scheme, dev, u.Hostname(), kit.Select(kit.Select("443", "80", u.Scheme == "ws"), u.Port()))
|
||||
gdb.Go(m, func() {
|
||||
once := sync.Once{}
|
||||
@ -47,6 +48,22 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
}
|
||||
}, kit.Join(kit.Simple(SPACE, name), lex.SP))
|
||||
}
|
||||
func _space_agent(m *ice.Message, args ...string) []string {
|
||||
kit.If(m.Option("goos"), func(p string) { args = append(args, "system", p) })
|
||||
for _, p := range []string{"Android", "iPhone", "Mac", "Windows"} {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
args = append(args, "system", p)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, p := range []string{"MicroMessenger", "Alipay", "Edg", "Chrome", "Safari", "Go-http-client"} {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
args = append(args, "agent", p)
|
||||
break
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
||||
func _space_fork(m *ice.Message) {
|
||||
addr := kit.Select(m.R.RemoteAddr, m.R.Header.Get(ice.MSG_USERADDR))
|
||||
text := strings.ReplaceAll(kit.Select(addr, m.Option(mdb.TEXT)), "%2F", nfs.PS)
|
||||
@ -67,6 +84,7 @@ func _space_fork(m *ice.Message) {
|
||||
args := kit.Simple(mdb.TYPE, kit.Select(WORKER, m.Option(mdb.TYPE)), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(nfs.MODULE, nfs.VERSION, cli.DAEMON))
|
||||
args = append(args, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
args = append(args, aaa.UA, m.Option(ice.MSG_USERUA), aaa.IP, m.Option(ice.MSG_USERIP))
|
||||
args = _space_agent(m, args...)
|
||||
if c, e := websocket.Upgrade(m.W, m.R); !m.Warn(e) {
|
||||
gdb.Go(m, func() {
|
||||
defer mdb.HashCreateDeferRemove(m, args, kit.Dict(mdb.TARGET, c))()
|
||||
@ -291,7 +309,7 @@ func init() {
|
||||
}
|
||||
}},
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { _space_fork(m) }},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,module,version,ip,usernick,username,userrole", ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000)), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,module,version,agent,system,ip,usernick,username,userrole", ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000)), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
if len(arg) == 1 && strings.Contains(arg[0], nfs.PT) {
|
||||
ls := kit.Split(arg[0], nfs.PT)
|
||||
|
@ -62,7 +62,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
default:
|
||||
m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, HTTP, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(l net.Listener) {
|
||||
defer mdb.HashCreateDeferRemove(m, m.OptionSimple(mdb.NAME, tcp.PROTO), arg, cli.STATUS, tcp.START)()
|
||||
gdb.Event(m, SERVE_START, arg)
|
||||
gdb.Event(m.Spawn(), SERVE_START, arg)
|
||||
m.Warn(f.Server.Serve(l))
|
||||
})
|
||||
kit.If(m.IsErr(), func() { fmt.Println(); fmt.Println(m.Result()); m.Cmd(ice.QUIT) })
|
||||
|
@ -47,6 +47,7 @@ func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
m.Options(nfs.DIR_ROOT, "").OptionDefault(ice.MSG_USERNAME, "demo")
|
||||
for _, k := range kit.Default(arg, ice.MISC) {
|
||||
m.Options(web.DOMAIN, web.UserHost(m), cli.CTX_ENV, kit.Select("", lex.SP+kit.JoinKV(mdb.EQ, lex.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != ""))
|
||||
m.Option("tcp_domain", kit.ParseURL(web.UserHost(m)).Hostname())
|
||||
switch k {
|
||||
case INSTALL:
|
||||
m.Option("format", "raw")
|
||||
@ -57,6 +58,7 @@ func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
case nfs.SOURCE, ice.DEV:
|
||||
m.Options(nfs.SOURCE, ice.Info.Make.Remote)
|
||||
case nfs.BINARY, ice.APP:
|
||||
|
||||
case "curl", "wget":
|
||||
case "manual":
|
||||
m.Options(nfs.BINARY, "ice.linux.amd64")
|
||||
|
Loading…
x
Reference in New Issue
Block a user