mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt some
This commit is contained in:
parent
ee976ee357
commit
577dd9cafc
@ -8,6 +8,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
func _hash_fields(m *ice.Message) []string {
|
||||
@ -145,6 +146,9 @@ func StatusHashAction(arg ...Any) ice.Actions {
|
||||
}},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func ExitClearHashAction() ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{ ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", HASH, "") }} })
|
||||
}
|
||||
|
||||
func HashKey(m *ice.Message) string {
|
||||
if m.Option(HASH) != "" {
|
||||
@ -163,7 +167,7 @@ func HashCreate(m *ice.Message, arg ...Any) string {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, m.OptionSimple(HashField(m)))
|
||||
}
|
||||
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH), arg...)...)).Result()
|
||||
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH, logs.FileLineMeta(logs.FileLine(-1))), arg...)...)).Result()
|
||||
}
|
||||
func HashRemove(m *ice.Message, arg ...Any) *ice.Message {
|
||||
if args := kit.Simple(arg); len(args) == 0 {
|
||||
|
@ -79,6 +79,7 @@ func init() {
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_host_list(m, kit.Select("", arg, 0))
|
||||
m.Debug(m.FormatChain())
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package web
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -29,7 +29,6 @@ func _broad_serve(m *ice.Message, host, port string) {
|
||||
if s, e := net.ListenUDP("udp", _broad_addr(m, "0.0.0.0", port)); m.Assert(e) {
|
||||
defer s.Close()
|
||||
mdb.HashCreate(m, tcp.HOST, host, tcp.PORT, port, kit.Dict(mdb.TARGET, s))
|
||||
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
for {
|
||||
n, addr, err := s.ReadFromUDP(buf[:])
|
||||
@ -37,12 +36,10 @@ func _broad_serve(m *ice.Message, host, port string) {
|
||||
break
|
||||
}
|
||||
m.Logs(mdb.IMPORT, BROAD, string(buf[:n]), "from", addr)
|
||||
|
||||
msg := m.Spawn(buf[:n])
|
||||
if m.Cmd(BROAD, kit.Format("%s,%s", msg.Option(tcp.HOST), msg.Option(tcp.PORT))).Length() > 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if remote, err := net.ResolveUDPAddr("udp4", kit.Format("%s:%s", msg.Option(tcp.HOST), msg.Option(tcp.PORT))); !m.Warn(err) {
|
||||
m.Cmd(BROAD, func(value ice.Maps) {
|
||||
m.Logs(mdb.EXPORT, BROAD, kit.Format(value), "to", kit.Format(remote))
|
||||
@ -53,31 +50,18 @@ func _broad_serve(m *ice.Message, host, port string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func _broad_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
mdb.HashSelectValue(m, func(value ice.Map) {
|
||||
if !strings.Contains(kit.Format(value[tcp.HOST]), name) {
|
||||
return
|
||||
}
|
||||
m.PushSearch(mdb.TYPE, FRIEND, mdb.TEXT, kit.Format("http://%s:%s", value[tcp.HOST], value[tcp.PORT]), value)
|
||||
})
|
||||
}
|
||||
|
||||
const BROAD = "broad"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BROAD: {Name: "broad hash auto serve", Help: "广播", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_broad_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}},
|
||||
SERVE: {Name: "broad port=9020", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
SERVE: {Name: "serve port=9020", Hand: func(m *ice.Message, arg ...string) {
|
||||
_broad_serve(m, m.Cmd(tcp.HOST).Append(aaa.IP), m.Option(tcp.PORT))
|
||||
}},
|
||||
SPACE: {Name: "space dev", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, mdb.NAME, m.Option(ice.DEV), ADDRESS,
|
||||
kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||
m.Cmd(SPACE, tcp.DIAL, m.OptionSimple(ice.DEV))
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessOpen(m, kit.Format("http://%s:%s", m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port", mdb.ACTION, SPACE))},
|
||||
}, mdb.HashAction(mdb.SHORT, "host,port", mdb.FIELD, "time,hash,host,port", mdb.ACTION, OPEN), mdb.ExitClearHashAction())},
|
||||
})
|
||||
}
|
||||
|
@ -152,7 +152,6 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf("", mdb.HASH, "")
|
||||
cli.NodeInfo(m, ice.Info.PathName, WORKER)
|
||||
aaa.White(m, LOGIN)
|
||||
}},
|
||||
@ -195,7 +194,7 @@ func init() {
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port", tcp.LOCALHOST, ice.TRUE, LOGHEADERS, ice.FALSE,
|
||||
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, INDEX, ice.INDEX_SH, nfs.REPOS, "https://shylinux.com/x/intshell", nfs.BRANCH, nfs.MASTER),
|
||||
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, INDEX, "page/index.html", nfs.REPOS, "https://shylinux.com/x/volcanos", nfs.BRANCH, nfs.MASTER),
|
||||
), ServeAction())},
|
||||
), mdb.ExitClearHashAction(), ServeAction())},
|
||||
PP(ice.INTSHELL): {Name: "/intshell/", Help: "命令行", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
RenderIndex(m, ice.INTSHELL, arg...)
|
||||
}},
|
||||
|
@ -131,6 +131,7 @@ func _space_send(m *ice.Message, space string, arg ...string) {
|
||||
_space_echo(m, []string{addSend(m, m)}, target, conn)
|
||||
}
|
||||
}), ice.ErrNotFound, space) {
|
||||
m.Sleep("30ms")
|
||||
call(m, m.Config(kit.Keys(TIMEOUT, "c")), func(res *ice.Message) { m.Copy(res) })
|
||||
}
|
||||
}
|
||||
@ -159,7 +160,6 @@ const SPACE = "space"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SPACE: {Name: "space name cmd auto", Help: "空间站", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", mdb.HASH, "") }},
|
||||
tcp.DIAL: {Name: "dial dev=ops name", Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.HasPrefix(m.Option(ice.DEV), ice.HTTP) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, ice.DEV, m.Option(ice.DEV))
|
||||
@ -185,7 +185,7 @@ func init() {
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text",
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000), TIMEOUT, kit.Dict("c", "30s"),
|
||||
BUFFER, kit.Dict("r", ice.MOD_BUFS, "w", ice.MOD_BUFS),
|
||||
), SpaceAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
), mdb.ExitClearHashAction(), SpaceAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
mdb.HashSelect(m, arg...).Sort("type,name,text")
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user