diff --git a/base/ctx/display.go b/base/ctx/display.go index 8a46ce06..7be3e797 100644 --- a/base/ctx/display.go +++ b/base/ctx/display.go @@ -51,6 +51,9 @@ func DisplayStoryForm(m *ice.Message, arg ...ice.Any) *ice.Message { func DisplayInputKey(m *ice.Message, arg ...ice.Any) *ice.Message { return DisplayInput(m, "key", arg...) } +func DisplayStoryWeight(m *ice.Message, arg ...ice.Any) *ice.Message { + return DisplayStory(m, "weight", arg...) +} func DisplayStoryPie(m *ice.Message, arg ...ice.Any) *ice.Message { return DisplayStory(m, "pie", arg...) } diff --git a/base/web/dream.go b/base/web/dream.go index 1dd6caea..c35e2db7 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -306,6 +306,9 @@ func init() { list := []string{cli.LINUX, cli.DARWIN, cli.WINDOWS} msg := m.Spawn(ice.Maps{ice.MSG_DAEMON: ""}) func() { + if m.Option(mdb.NAME) != "" { + return + } defer ToastProcess(m, PUBLISH, ice.Info.Pathname)() m.Cmd(AUTOGEN, BINPACK) kit.For(list, func(goos string) { diff --git a/base/web/serve.go b/base/web/serve.go index c180e0c1..22a030a2 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -35,10 +35,6 @@ func _serve_start(m *ice.Message) { }).Sleep(cli.TIME_1s) cli.NodeInfo(m, kit.Select(kit.Split(ice.Info.Hostname, nfs.PT)[0], m.Option(tcp.NODENAME)), SERVER, mdb.Config(m, mdb.ICONS)) kit.If(ice.HasVar(), func() { m.Cmd(nfs.SAVE, ice.VAR_LOG_ICE_PORT, m.Option(tcp.PORT)) }) - m.Spawn(ice.Maps{TOKEN: ""}).Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...) - if m.Cmd(tcp.HOST).Length() == 0 { - return - } kit.For(kit.Split(m.Option(ice.DEV)), func(dev string) { if strings.HasPrefix(dev, HTTP) { m.Cmd(SPIDE, mdb.CREATE, dev, ice.DEV, "", nfs.REPOS) @@ -47,12 +43,16 @@ func _serve_start(m *ice.Message) { } if msg := m.Cmd(SPIDE, dev); msg.Append(TOKEN) == "" { if m.Option(TOKEN) != "" { - m.Sleep300ms(SPACE, tcp.DIAL, ice.DEV, dev, TOKEN, m.Option(TOKEN)) + m.Cmd(SPACE, tcp.DIAL, ice.DEV, dev, TOKEN, m.Option(TOKEN)) } else { - m.Sleep300ms(SPACE, tcp.DIAL, ice.DEV, dev) + m.Cmd(SPACE, tcp.DIAL, ice.DEV, dev) } } }) + m.Spawn(ice.Maps{TOKEN: ""}).Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...) + if m.Cmd(tcp.HOST).Length() == 0 { + return + } } func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { const ( @@ -65,6 +65,10 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool { } else { return true } + func() { + defer InfoLock.Lock()() + Info.ServeMainCount++ + }() if ip := r.Header.Get(X_REAL_IP); ip != "" { if r.Header.Set(ice.MSG_USERIP, ip); r.Header.Get(X_REAL_PORT) != "" { r.Header.Set(ice.MSG_USERADDR, ip+nfs.DF+r.Header.Get(X_REAL_PORT)) @@ -214,6 +218,20 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response } else { m.CmdHand(cmd, key, cmds...) } + func() { + defer InfoLock.Lock()() + Info.Commands[kit.Select(cmds[0], m.Option(ice.MSG_INDEX))]++ + switch r.Method { + case http.MethodGet: + Info.ServeGetCount++ + case http.MethodPut: + Info.ServePutCount++ + case http.MethodPost: + Info.ServePostCount++ + case http.MethodDelete: + Info.ServeDeleteCount++ + } + }() } } func _serve_domain(m *ice.Message) string { diff --git a/base/web/space.go b/base/web/space.go index 5e6992d7..004d8c00 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -23,8 +23,26 @@ import ( "shylinux.com/x/icebergs/base/web/html" "shylinux.com/x/icebergs/misc/websocket" kit "shylinux.com/x/toolkits" + "shylinux.com/x/toolkits/task" ) +var Info = struct { + ServeMainCount int + ServeGetCount int + ServePutCount int + ServePostCount int + ServeDeleteCount int + SpaceCmdCount int + SpaceReadCount int + SpaceReadByte int + SpaceWriteCount int + SpaceWriteByte int + Commands map[string]int +}{ + Commands: map[string]int{}, +} +var InfoLock = &task.Lock{} + func _space_qrcode(m *ice.Message, dev string) { ssh.PrintQRCode(m, m.Cmdv(SPACE, dev, cli.PWD, mdb.LINK)) } @@ -80,7 +98,7 @@ func _space_fork(m *ice.Message) { if msg := m.Cmd(TOKEN, m.Option(TOKEN)); msg.Append(mdb.TIME) > m.Time() && kit.IsIn(msg.Append(mdb.TYPE), SERVER, SPIDE) { aaa.SessAuth(m, kit.Dict(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME, msg.Append(mdb.NAME))).AppendSimple())) name = SpaceName(kit.Select(name, msg.Append(mdb.TEXT))) - kit.If(ProxyDomain(m, name), func(p string) { text = p }) + kit.If(ProxyDomain(m.Spawn(kit.Dict(ice.MSG_USERROLE, aaa.TECH)), name), func(p string) { text = p }) safe = aaa.IsTechOrRoot(m) } } @@ -127,6 +145,11 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) { if e != nil { break } + func() { + defer InfoLock.Lock()() + Info.SpaceReadCount++ + Info.SpaceReadByte += len(b) + }() msg := m.Spawn(b) if safe && msg.Option(ice.MSG_UNSAFE) != ice.TRUE { // δΈ‹θ‘Œζƒι™ if !aaa.IsTechOrRoot(msg) && msg.Option(ice.MSG_HANDLE) != ice.TRUE { @@ -208,6 +231,11 @@ func _space_exec(m *ice.Message, name string, source, target []string, c *websoc if m.IsErr() { return } + func() { + defer InfoLock.Lock()() + Info.SpaceCmdCount++ + Info.Commands[kit.Select(kit.Select("", m.Detailv(), 0), m.Option(ice.MSG_INDEX))]++ + }() m.Options(ice.MSG_ARGS, "", ice.MSG_COUNT, "0") kit.If(m.Option(ice.MSG_DAEMON), func(p string) { m.Option(ice.MSG_DAEMON0, m.Option(ice.MSG_DAEMON)) @@ -229,6 +257,11 @@ func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) { m.Options(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:]) data := m.FormatMeta() if !m.WarnNotValid(c.WriteMessage(1, []byte(data))) { + func() { + defer InfoLock.Lock()() + Info.SpaceWriteCount++ + Info.SpaceWriteByte += len(data) + }() if source != nil { m.Log(kit.Select(tcp.SEND, tcp.DONE, m.Option(ice.MSG_HANDLE) == ice.TRUE), "%d %v->%v %v %v", len(data), source, target, kit.ReplaceAll(kit.Format("%v", m.Detailv()), "\r\n", "\\r\\n", "\t", "\\t", "\n", "\\n"), data) diff --git a/go.mod b/go.mod index 2f179602..6e197256 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,6 @@ go 1.13 require ( shylinux.com/x/go-git/v5 v5.6.7 shylinux.com/x/go-qrcode v0.0.3 - shylinux.com/x/toolkits v1.0.18 + shylinux.com/x/toolkits v1.0.19 shylinux.com/x/websocket v0.0.4 ) diff --git a/go.sum b/go.sum index 7ebda58f..fb5d0011 100644 --- a/go.sum +++ b/go.sum @@ -4,7 +4,7 @@ shylinux.com/x/go-qrcode v0.0.3 h1:RMo+Vidbgq3HatLBj7DDXcTbTLFUwzis5K7TqBkD38U= shylinux.com/x/go-qrcode v0.0.3/go.mod h1:KAbtU+KwiiABMZ/CJ0zh9PI2AX82Uf9rRYcQ4ODm4po= shylinux.com/x/toolkits v0.7.10 h1:65d5rkQXQ71MD8FzYnZ9DFxb1XcOYSYfmRc4j8qQsUw= shylinux.com/x/toolkits v0.7.10/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q= -shylinux.com/x/toolkits v1.0.18 h1:jtQZhmvU10Ajegc87tU0cYFUBSviaODo5TsCXpYb2O4= -shylinux.com/x/toolkits v1.0.18/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q= +shylinux.com/x/toolkits v1.0.19 h1:Nrx0xYRc5ph1WS66EZ1hJUCe+2FdSWQ4QP6tBlguikQ= +shylinux.com/x/toolkits v1.0.19/go.mod h1:CHDJarGlDkg60kVsvMLYL/a5hAnRLEOShiEsMOuEp0Q= shylinux.com/x/websocket v0.0.4 h1:AJpwblePoOpiE6C8NrvgNYpKTotXMLrDDX2chTvx44Q= shylinux.com/x/websocket v0.0.4/go.mod h1:3UGWkjTu3ie5NAZen7J+uLPBrO7DFeKloj6Jxo13Oiw= diff --git a/meta.go b/meta.go index 0e9692b5..9c759f89 100644 --- a/meta.go +++ b/meta.go @@ -130,6 +130,10 @@ func (m *Message) Push(key string, value Any, arg ...Any) *Message { k = strings.TrimSuffix(k, "*") m.Push(k, kit.Select(kit.Format(val[k]), value[k])) }) + case map[string]int: + kit.For(value, func(key string, value int) { + m.Push(key, value) + }) default: keys := strings.Split(key, ",") kit.For(kit.Simple(value, arg), func(v string, i int) {