mirror of
https://shylinux.com/x/icebergs
synced 2025-04-29 02:29:22 +08:00
opt some
This commit is contained in:
parent
9c4e24cc5c
commit
c0e59eec3c
@ -44,78 +44,65 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func _space_handle(m *ice.Message, safe bool, frame *Frame, c *websocket.Conn, name string) bool {
|
func _space_handle(m *ice.Message, safe bool, f *Frame, conn *websocket.Conn, name string) bool {
|
||||||
for {
|
for {
|
||||||
_, b, e := c.ReadMessage()
|
_, b, e := conn.ReadMessage()
|
||||||
if m.Warn(e, SPACE, name) {
|
if m.Warn(e, SPACE, name) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
msg := m.Spawn(b)
|
msg := m.Spawn(b)
|
||||||
socket, source, target := c, kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
source, target := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
||||||
msg.Log("recv", "%v<-%v %s %v", target, source, msg.Detailv(), msg.FormatMeta())
|
msg.Log("recv", "%v->%v %s %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||||
if len(target) == 0 {
|
if len(target) == 0 {
|
||||||
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令
|
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令
|
||||||
gdb.Event(msg, SPACE_LOGIN)
|
gdb.Event(msg, SPACE_LOGIN)
|
||||||
} else { // 上行请求
|
} else { // 上行请求
|
||||||
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||||
}
|
}
|
||||||
msg.Go(func() { _space_exec(msg, source, target, c, name) })
|
msg.Go(func() { _space_exec(msg, source, target, conn) })
|
||||||
} else if mdb.HashSelectDetail(msg, target[0], func(value ice.Map) {
|
} else if mdb.HashSelectDetail(msg, target[0], func(value ice.Map) {
|
||||||
if s, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, target[0]) { // 转发报文
|
if conn, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, target[0]) {
|
||||||
socket, source, target = s, source, target[1:]
|
_space_echo(msg, source, target, conn) // 转发报文
|
||||||
_space_echo(msg, source, target, socket, kit.Select("", target))
|
|
||||||
} else if msg.Option(ice.MSG_HANDLE) != ice.TRUE { // 下发失败
|
|
||||||
source, target = []string{}, kit.Revert(source)[1:]
|
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
} else if res, ok := frame.getSend(msg.Option(ice.MSG_TARGET)); !m.Warn(!ok || len(target) != 1) {
|
} else if res, ok := f.getSend(msg.Option(ice.MSG_TARGET)); !m.Warn(!ok || len(target) != 1) {
|
||||||
back(res, msg) // 接收响应
|
back(res, msg) // 接收响应
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func _space_domain(m *ice.Message) (link string) {
|
func _space_domain(m *ice.Message) (link string) {
|
||||||
if link = ice.Info.Domain; link == "" {
|
return kit.GetValid(
|
||||||
m.Optionv(ice.MSG_OPTS, ice.MSG_USERNAME)
|
func() string { return ice.Info.Domain },
|
||||||
link = m.CmdAppend(SPACE, ice.OPS, cli.PWD, mdb.LINK)
|
func() string {
|
||||||
}
|
return m.CmdAppend(SPACE, ice.OPS, cli.PWD, kit.Dict(ice.MSG_OPTS, ice.MSG_USERNAME), mdb.LINK)
|
||||||
if link == "" {
|
},
|
||||||
link = m.CmdAppend(SPACE, ice.DEV, cli.PWD, mdb.LINK)
|
func() string { return m.CmdAppend(SPACE, ice.DEV, cli.PWD, mdb.LINK) },
|
||||||
}
|
func() string { return m.CmdAppend(SPACE, ice.SHY, cli.PWD, mdb.LINK) },
|
||||||
if link == "" {
|
func() string { return tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB)) },
|
||||||
link = m.CmdAppend(SPACE, ice.SHY, cli.PWD, mdb.LINK)
|
func() string {
|
||||||
}
|
return kit.Format("http://%s:%s", m.CmdAppend(tcp.HOST, aaa.IP), kit.Select(m.Option(tcp.PORT), m.CmdAppend(SERVE, tcp.PORT)))
|
||||||
if link == "" {
|
})
|
||||||
link = m.Option(ice.MSG_USERWEB)
|
|
||||||
}
|
|
||||||
if link == "" {
|
|
||||||
link = kit.Format("http://localhost:%s", kit.Select(m.Option(tcp.PORT), m.CmdAppend(SERVE, tcp.PORT)))
|
|
||||||
}
|
|
||||||
return tcp.PublishLocalhost(m, link)
|
|
||||||
}
|
}
|
||||||
func _space_exec(msg *ice.Message, source, target []string, c *websocket.Conn, name string) {
|
func _space_exec(msg *ice.Message, source, target []string, conn *websocket.Conn) {
|
||||||
switch msg.Detailv()[0] {
|
switch kit.Select(msg.Detailv(), 0) {
|
||||||
case "pwd":
|
case "pwd":
|
||||||
msg.Push(mdb.LINK, kit.MergePOD(_space_domain(msg), name))
|
msg.Push(mdb.LINK, kit.MergePOD(_space_domain(msg), kit.Select("", source, -1)))
|
||||||
default:
|
default:
|
||||||
if aaa.Right(msg, msg.Detailv()) {
|
if aaa.Right(msg, msg.Detailv()) {
|
||||||
msg = msg.Cmd()
|
msg = msg.Cmd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg.Set(ice.MSG_OPTS)
|
_space_echo(msg.Set(ice.MSG_OPTS), []string{}, kit.Revert(kit.Simple(source)), conn)
|
||||||
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
|
|
||||||
msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.FormatSize()))
|
msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.FormatSize()))
|
||||||
}
|
}
|
||||||
func _space_echo(msg *ice.Message, source, target []string, c *websocket.Conn, name string) {
|
func _space_echo(msg *ice.Message, source, target []string, conn *websocket.Conn) {
|
||||||
msg.Optionv(ice.MSG_SOURCE, source)
|
if msg.Optionv(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:]); msg.Warn(conn.WriteMessage(1, []byte(msg.FormatMeta()))) {
|
||||||
msg.Optionv(ice.MSG_TARGET, target)
|
msg.Go(func() { mdb.HashRemove(msg, mdb.NAME, target[0]) })
|
||||||
if e := c.WriteMessage(1, []byte(msg.FormatMeta())); msg.Warn(e) { // 回复失败
|
conn.Close()
|
||||||
msg.Go(func() { mdb.HashRemove(msg, mdb.NAME, name) })
|
} else {
|
||||||
c.Close()
|
msg.Log("send", "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
target = append([]string{name}, target...)
|
|
||||||
msg.Log("send", "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatMeta())
|
|
||||||
}
|
}
|
||||||
func _space_send(m *ice.Message, space string, arg ...string) {
|
func _space_send(m *ice.Message, space string, arg ...string) {
|
||||||
if space == "" || space == MYSELF || space == ice.Info.NodeName {
|
if space == "" || space == MYSELF || space == ice.Info.NodeName {
|
||||||
@ -134,9 +121,9 @@ func _space_send(m *ice.Message, space string, arg ...string) {
|
|||||||
m.Optionv(ice.MSG_OPTION, m.Optionv(ice.MSG_OPTS))
|
m.Optionv(ice.MSG_OPTION, m.Optionv(ice.MSG_OPTS))
|
||||||
target, id, f := kit.Split(space, ice.PT, ice.PT), "", m.Target().Server().(*Frame)
|
target, id, f := kit.Split(space, ice.PT, ice.PT), "", m.Target().Server().(*Frame)
|
||||||
if m.Warn(!mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
if m.Warn(!mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
||||||
if socket, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotFound, mdb.TARGET) {
|
if conn, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotFound, mdb.TARGET) {
|
||||||
id = f.addSend(kit.Format(m.Target().ID()), m)
|
id = f.addSend(kit.Format(m.Target().ID()), m)
|
||||||
_space_echo(m, []string{id}, target[1:], socket, target[0])
|
_space_echo(m, []string{id}, target, conn)
|
||||||
}
|
}
|
||||||
}), ice.ErrNotFound, space) {
|
}), ice.ErrNotFound, space) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user