forked from x/ContextOS
opt tcp.dial
This commit is contained in:
parent
2407699d6e
commit
7a752c1c97
@ -1,5 +1,3 @@
|
|||||||
source common.shy
|
source common.shy
|
||||||
source local.shy
|
source local.shy
|
||||||
~ssh
|
|
||||||
remote auto
|
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"init_env": []interface{}{"ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"},
|
"init_env": []interface{}{"ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"},
|
||||||
"script": map[string]interface{}{"sh": "bash", "shy": "source", "py": "python"},
|
"script": map[string]interface{}{"sh": "bash", "shy": "source", "py": "python"},
|
||||||
"init_shy": "etc/init.shy", "exit_shy": "etc/exit.shy",
|
"init_shy": "etc/init.shy", "exit_shy": "etc/exit.shy",
|
||||||
"web_port": ":9094", "ssh_port": ":9090",
|
"web_port": ":9094", "ssh_port": ":9090", "ssh_ports": []interface{}{},
|
||||||
}, Help: "运行环境"},
|
}, Help: "运行环境"},
|
||||||
|
|
||||||
"alias": &ctx.Config{Name: "alias", Value: map[string]interface{}{
|
"alias": &ctx.Config{Name: "alias", Value: map[string]interface{}{
|
||||||
|
@ -1518,7 +1518,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
"remote": &ctx.Command{Name: "remote listen|dial args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"remote": &ctx.Command{Name: "remote listen|dial args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
|
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
|
||||||
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
|
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
|
||||||
if sub.Options("hostport") {
|
if sub.Has("hostport") {
|
||||||
return sub
|
return sub
|
||||||
}
|
}
|
||||||
sub.Sess("ms_source", sub)
|
sub.Sess("ms_source", sub)
|
||||||
|
@ -59,9 +59,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
case "listen":
|
case "listen":
|
||||||
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
||||||
if nfs.Options("hostport") { // 监听端口
|
if nfs.Has("hostport") {
|
||||||
m.Conf("runtime", "ssh_port", nfs.Option("hostport"))
|
m.Conf("runtime", "ssh_ports", nfs.Optionv("hostport"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !m.Confs("runtime", "node.sess") {
|
if !m.Confs("runtime", "node.sess") {
|
||||||
if !m.Confs("runtime", "node.cert") { // 设备注册
|
if !m.Confs("runtime", "node.cert") { // 设备注册
|
||||||
msg := m.Cmd("aaa.rsa", "gen", "common", m.Confv("runtime", "node"))
|
msg := m.Cmd("aaa.rsa", "gen", "common", m.Confv("runtime", "node"))
|
||||||
|
@ -57,18 +57,21 @@ func (tcp *TCP) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
return tcp
|
return tcp
|
||||||
}
|
}
|
||||||
func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
||||||
|
address := []string{}
|
||||||
if arg[1] == "consul" {
|
if arg[1] == "consul" {
|
||||||
if arg[1] = m.Cmdx("web.get", "dev", arg[2], "temp", "hostport.0"); arg[1] == "" {
|
m.Cmd("web.get", "dev", arg[2], "temp", "hostport").Table(func(line map[string]string) {
|
||||||
return true
|
address = append(address, line["value"])
|
||||||
}
|
})
|
||||||
for i := 2; i < len(arg)-1; i++ {
|
for i := 2; i < len(arg)-1; i++ {
|
||||||
arg[i] = arg[i+1]
|
arg[i] = arg[i+1]
|
||||||
}
|
}
|
||||||
if len(arg) > 2 {
|
if len(arg) > 2 {
|
||||||
arg = arg[:len(arg)-1]
|
arg = arg[:len(arg)-1]
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
address = append(address, m.Cap("address", m.Confx("address", arg, 1)))
|
||||||
}
|
}
|
||||||
m.Cap("address", m.Confx("address", arg, 1))
|
|
||||||
m.Cap("security", m.Confx("security", arg, 2))
|
m.Cap("security", m.Confx("security", arg, 2))
|
||||||
m.Cap("protocol", m.Confx("protocol", arg, 3))
|
m.Cap("protocol", m.Confx("protocol", arg, 3))
|
||||||
|
|
||||||
@ -80,14 +83,17 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
conf := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
|
conf := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
|
||||||
|
|
||||||
for i := 0; i < m.Confi("retry", "counts"); i++ {
|
for _, p := range address {
|
||||||
if c, e := tls.Dial(m.Cap("protocol"), m.Cap("address"), conf); e == nil {
|
for i := 0; i < m.Confi("retry", "counts"); i++ {
|
||||||
tcp.Conn = c
|
if c, e := tls.Dial(m.Cap("protocol"), p, conf); e == nil {
|
||||||
break
|
m.Cap("address", p)
|
||||||
} else {
|
tcp.Conn = c
|
||||||
m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e)
|
break
|
||||||
|
} else {
|
||||||
|
m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e)
|
||||||
|
}
|
||||||
|
time.Sleep(kit.Duration(m.Conf("retry", "interval")))
|
||||||
}
|
}
|
||||||
time.Sleep(kit.Duration(m.Conf("retry", "interval")))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < m.Confi("retry", "counts"); i++ {
|
for i := 0; i < m.Confi("retry", "counts"); i++ {
|
||||||
@ -142,7 +148,12 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
m.Cap("stream", fmt.Sprintf("%s", tcp.Addr())))
|
m.Cap("stream", fmt.Sprintf("%s", tcp.Addr())))
|
||||||
|
|
||||||
addr := strings.Split(tcp.Addr().String(), ":")
|
addr := strings.Split(tcp.Addr().String(), ":")
|
||||||
m.Back(m.Spawn(m.Source()).Add("option", "hostport", fmt.Sprintf("%s:%s", m.Cmd("tcp.ifconfig", "eth0").Append("ip"), addr[len(addr)-1])))
|
|
||||||
|
ports := []interface{}{}
|
||||||
|
m.Cmd("tcp.ifconfig").Table(func(line map[string]string) {
|
||||||
|
ports = append(ports, fmt.Sprintf("%s:%s", line["ip"], addr[len(addr)-1]))
|
||||||
|
})
|
||||||
|
m.Back(m.Spawn(m.Source()).Put("option", "hostport", ports))
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -1027,7 +1027,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"/shadow": &ctx.Command{Name: "/shadow", Help: "暗网", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"/shadow": &ctx.Command{Name: "/shadow", Help: "暗网", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
m.Append("hostport", m.Conf("runtime", "ssh_port"))
|
m.Confm("runtime", "ssh_ports", func(index int, value string) {
|
||||||
|
m.Add("append", "hostport", value)
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"/login": &ctx.Command{Name: "/login", Help: "认证", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"/login": &ctx.Command{Name: "/login", Help: "认证", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user