trying to add client-side peer name
This commit is contained in:
parent
55fc4bdfcb
commit
7cea612ae5
@ -33,6 +33,7 @@ type json_in_client_conn struct {
|
||||
|
||||
type json_in_client_route struct {
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientPeerName string `json:"client-peer-name"`
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
ServerPeerServiceAddr string `json:"server-peer-service-addr"` // desired listening address on the server side
|
||||
ServerPeerServiceNet string `json:"server-peer-service-net"` // permitted network in prefix notation
|
||||
@ -58,6 +59,7 @@ type json_out_client_route_id struct {
|
||||
type json_out_client_route struct {
|
||||
Id RouteId `json:"id"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientPeerName string `json:"client-peer-name"`
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
ServerPeerListenAddr string `json:"server-peer-service-addr"`
|
||||
ServerPeerNet string `json:"server-peer-service-net"`
|
||||
@ -354,6 +356,7 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
jsp = append(jsp, json_out_client_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.peer_addr,
|
||||
ClientPeerName: r.peer_name,
|
||||
ServerPeerListenAddr: r.server_peer_listen_addr.String(),
|
||||
ServerPeerNet: r.server_peer_net,
|
||||
ServerPeerOption: r.server_peer_option.string(),
|
||||
@ -375,7 +378,7 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
goto oops
|
||||
}
|
||||
|
||||
if jcr.ClientPeerAddr == "" {
|
||||
if jcr.ClientPeerAddr == "" {
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
err = fmt.Errorf("blank client-peer-addr")
|
||||
goto oops;
|
||||
@ -388,7 +391,7 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
goto oops
|
||||
}
|
||||
|
||||
r, err = cts.AddNewClientRoute(jcr.ClientPeerAddr, jcr.ServerPeerServiceAddr, jcr.ServerPeerServiceNet, server_peer_option)
|
||||
r, err = cts.AddNewClientRoute(jcr.ClientPeerAddr, jcr.ClientPeerName, jcr.ServerPeerServiceAddr, jcr.ServerPeerServiceNet, server_peer_option)
|
||||
if err != nil {
|
||||
status_code = http.StatusInternalServerError; w.WriteHeader(status_code)
|
||||
if err = je.Encode(json_errmsg{Text: err.Error()}); err != nil { goto oops }
|
||||
|
10
client.go
10
client.go
@ -104,6 +104,7 @@ type ClientRoute struct {
|
||||
cts *ClientConn
|
||||
id RouteId
|
||||
peer_addr string
|
||||
peer_name string
|
||||
peer_option RouteOption
|
||||
|
||||
server_peer_listen_addr *net.TCPAddr // actual service-side service address
|
||||
@ -157,7 +158,7 @@ func (g *GuardedPacketStreamClient) Context() context.Context {
|
||||
}*/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
func NewClientRoute(cts *ClientConn, id RouteId, client_peer_addr string, server_peer_svc_addr string, server_peer_svc_net string, server_peer_option RouteOption) *ClientRoute {
|
||||
func NewClientRoute(cts *ClientConn, id RouteId, client_peer_addr string, client_peer_name string, server_peer_svc_addr string, server_peer_svc_net string, server_peer_option RouteOption) *ClientRoute {
|
||||
var r ClientRoute
|
||||
|
||||
r.cts = cts
|
||||
@ -165,6 +166,7 @@ func NewClientRoute(cts *ClientConn, id RouteId, client_peer_addr string, server
|
||||
r.ptc_map = make(ClientPeerConnMap)
|
||||
r.ptc_cancel_map = make(ClientPeerCancelFuncMap)
|
||||
r.peer_addr = client_peer_addr // client-side peer
|
||||
r.peer_name = client_peer_name
|
||||
// if the client_peer_addr is a domain name, it can't tell between tcp4 and tcp6
|
||||
r.peer_option = string_to_route_option(tcp_addr_str_class(client_peer_addr))
|
||||
|
||||
@ -592,7 +594,7 @@ func NewClientConn(c *Client, cfg *ClientConfig) *ClientConn {
|
||||
return &cts
|
||||
}
|
||||
|
||||
func (cts *ClientConn) AddNewClientRoute(addr string, server_peer_svc_addr string, server_peer_svc_net string, option RouteOption) (*ClientRoute, error) {
|
||||
func (cts *ClientConn) AddNewClientRoute(addr string, name string, server_peer_svc_addr string, server_peer_svc_net string, option RouteOption) (*ClientRoute, error) {
|
||||
var r *ClientRoute
|
||||
var start_id RouteId
|
||||
|
||||
@ -611,7 +613,7 @@ func (cts *ClientConn) AddNewClientRoute(addr string, server_peer_svc_addr strin
|
||||
}
|
||||
}
|
||||
|
||||
r = NewClientRoute(cts, cts.route_next_id, addr, server_peer_svc_addr, server_peer_svc_net, option)
|
||||
r = NewClientRoute(cts, cts.route_next_id, addr, name, server_peer_svc_addr, server_peer_svc_net, option)
|
||||
cts.route_map[r.id] = r
|
||||
cts.route_next_id++
|
||||
cts.cli.stats.routes.Add(1)
|
||||
@ -746,7 +748,7 @@ func (cts *ClientConn) AddClientRoutes(peer_addrs []string) error {
|
||||
option |= RouteOption(ROUTE_OPTION_HTTPS)
|
||||
}
|
||||
|
||||
_, err = cts.AddNewClientRoute(va[0], svc_addr, "", option)
|
||||
_, err = cts.AddNewClientRoute(va[0], svc_addr, svc_addr/* TODO: accept name form parameter*/, "", option)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add client route for %s - %s", v, err.Error())
|
||||
}
|
||||
|
129
hodu.pb.go
129
hodu.pb.go
@ -216,19 +216,22 @@ type RouteDesc struct {
|
||||
// C->S(ROUTE_START): client-side peer address
|
||||
// S->C(ROUTE_STARTED): server-side listening address
|
||||
TargetAddrStr string `protobuf:"bytes,2,opt,name=TargetAddrStr,proto3" json:"TargetAddrStr,omitempty"`
|
||||
// C->S(ROUTE_START): human-readable name of client-side peer
|
||||
// S->C(ROUTE_STARTED): clone as sent by C
|
||||
TargetNameStr string `protobuf:"bytes,3,opt,name=TargetNameStr,proto3" json:"TargetNameStr,omitempty"`
|
||||
// C->S(ROUTE_START): desired listening option on the server-side(e.g. tcp, tcp4, tcp6) +
|
||||
//
|
||||
// hint to the service-side peer(e.g. local) +
|
||||
// hint to the client-side peer(e.g. tty, http, https)
|
||||
//
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C.
|
||||
ServiceOption uint32 `protobuf:"varint,3,opt,name=ServiceOption,proto3" json:"ServiceOption,omitempty"`
|
||||
ServiceOption uint32 `protobuf:"varint,4,opt,name=ServiceOption,proto3" json:"ServiceOption,omitempty"`
|
||||
// C->S(ROUTE_START): desired lisening address on the service-side
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C
|
||||
ServiceAddrStr string `protobuf:"bytes,4,opt,name=ServiceAddrStr,proto3" json:"ServiceAddrStr,omitempty"`
|
||||
ServiceAddrStr string `protobuf:"bytes,5,opt,name=ServiceAddrStr,proto3" json:"ServiceAddrStr,omitempty"`
|
||||
// C->S(ROUTE_START): permitted network of server-side peers.
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C.
|
||||
ServiceNetStr string `protobuf:"bytes,5,opt,name=ServiceNetStr,proto3" json:"ServiceNetStr,omitempty"`
|
||||
ServiceNetStr string `protobuf:"bytes,6,opt,name=ServiceNetStr,proto3" json:"ServiceNetStr,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RouteDesc) Reset() {
|
||||
@ -275,6 +278,13 @@ func (x *RouteDesc) GetTargetAddrStr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RouteDesc) GetTargetNameStr() string {
|
||||
if x != nil {
|
||||
return x.TargetNameStr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *RouteDesc) GetServiceOption() uint32 {
|
||||
if x != nil {
|
||||
return x.ServiceOption
|
||||
@ -534,65 +544,68 @@ var file_hodu_proto_rawDesc = []byte{
|
||||
0x53, 0x65, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x46,
|
||||
0x6c, 0x61, 0x67, 0x73, 0x22, 0xbf, 0x01, 0x0a, 0x09, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65,
|
||||
0x6c, 0x61, 0x67, 0x73, 0x22, 0xe5, 0x01, 0x0a, 0x09, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65,
|
||||
0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x0d,
|
||||
0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x0d, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x64, 0x64, 0x72, 0x53,
|
||||
0x74, 0x72, 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69,
|
||||
0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72,
|
||||
0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4e, 0x65, 0x74, 0x53, 0x74,
|
||||
0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||
0x4e, 0x65, 0x74, 0x53, 0x74, 0x72, 0x22, 0x86, 0x01, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44,
|
||||
0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50,
|
||||
0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41,
|
||||
0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x52, 0x65,
|
||||
0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x12, 0x22, 0x0a, 0x0c, 0x4c,
|
||||
0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x22,
|
||||
0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x52,
|
||||
0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f,
|
||||
0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74,
|
||||
0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x20, 0x0a, 0x04,
|
||||
0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x50, 0x41, 0x43,
|
||||
0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x22,
|
||||
0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e,
|
||||
0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x05, 0x52, 0x6f, 0x75,
|
||||
0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
|
||||
0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x48, 0x00, 0x52, 0x04, 0x50,
|
||||
0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04,
|
||||
0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x55, 0x2a, 0x5e, 0x0a, 0x0c, 0x52, 0x4f, 0x55,
|
||||
0x54, 0x45, 0x5f, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x4e, 0x53,
|
||||
0x50, 0x45, 0x43, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x43, 0x50, 0x10, 0x01, 0x12, 0x08,
|
||||
0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10, 0x02, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x36,
|
||||
0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x54, 0x59, 0x10, 0x08, 0x12, 0x08, 0x0a, 0x04, 0x48,
|
||||
0x54, 0x54, 0x50, 0x10, 0x10, 0x12, 0x09, 0x0a, 0x05, 0x48, 0x54, 0x54, 0x50, 0x53, 0x10, 0x20,
|
||||
0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x48, 0x10, 0x40, 0x2a, 0xb5, 0x01, 0x0a, 0x0b, 0x50, 0x41,
|
||||
0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53,
|
||||
0x45, 0x52, 0x56, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45,
|
||||
0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54,
|
||||
0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54,
|
||||
0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52,
|
||||
0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x04, 0x12, 0x10,
|
||||
0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10, 0x05,
|
||||
0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50, 0x45, 0x44,
|
||||
0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54,
|
||||
0x45, 0x44, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46,
|
||||
0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x54, 0x41, 0x10,
|
||||
0x09, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x64, 0x75, 0x12, 0x19, 0x0a, 0x07, 0x47, 0x65, 0x74,
|
||||
0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65,
|
||||
0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0c, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x53, 0x74,
|
||||
0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e,
|
||||
0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06,
|
||||
0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x74, 0x72, 0x12, 0x24, 0x0a, 0x0d, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65,
|
||||
0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x54, 0x61, 0x72, 0x67, 0x65,
|
||||
0x74, 0x4e, 0x61, 0x6d, 0x65, 0x53, 0x74, 0x72, 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||
0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26,
|
||||
0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72,
|
||||
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41,
|
||||
0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x12, 0x24, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||
0x65, 0x4e, 0x65, 0x74, 0x53, 0x74, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x53,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4e, 0x65, 0x74, 0x53, 0x74, 0x72, 0x22, 0x86, 0x01, 0x0a,
|
||||
0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75,
|
||||
0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74,
|
||||
0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65, 0x72, 0x49, 0x64, 0x12, 0x24, 0x0a, 0x0d, 0x52,
|
||||
0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74, 0x72, 0x18, 0x03, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74,
|
||||
0x72, 0x12, 0x22, 0x0a, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x53, 0x74,
|
||||
0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x41, 0x64,
|
||||
0x64, 0x72, 0x53, 0x74, 0x72, 0x22, 0x50, 0x0a, 0x08, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61, 0x74,
|
||||
0x61, 0x12, 0x18, 0x0a, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0d, 0x52, 0x07, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x50,
|
||||
0x65, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x50, 0x65, 0x65,
|
||||
0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28,
|
||||
0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x95, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x63, 0x6b,
|
||||
0x65, 0x74, 0x12, 0x20, 0x0a, 0x04, 0x4b, 0x69, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e,
|
||||
0x32, 0x0c, 0x2e, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x52, 0x04,
|
||||
0x4b, 0x69, 0x6e, 0x64, 0x12, 0x22, 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x44, 0x65, 0x73, 0x63, 0x48,
|
||||
0x00, 0x52, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x50, 0x65, 0x65, 0x72,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x65, 0x73,
|
||||
0x63, 0x48, 0x00, 0x52, 0x04, 0x50, 0x65, 0x65, 0x72, 0x12, 0x1f, 0x0a, 0x04, 0x44, 0x61, 0x74,
|
||||
0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x50, 0x65, 0x65, 0x72, 0x44, 0x61,
|
||||
0x74, 0x61, 0x48, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x42, 0x03, 0x0a, 0x01, 0x55, 0x2a,
|
||||
0x5e, 0x0a, 0x0c, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x12,
|
||||
0x0a, 0x0a, 0x06, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x54,
|
||||
0x43, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x54, 0x43, 0x50, 0x34, 0x10, 0x02, 0x12, 0x08,
|
||||
0x0a, 0x04, 0x54, 0x43, 0x50, 0x36, 0x10, 0x04, 0x12, 0x07, 0x0a, 0x03, 0x54, 0x54, 0x59, 0x10,
|
||||
0x08, 0x12, 0x08, 0x0a, 0x04, 0x48, 0x54, 0x54, 0x50, 0x10, 0x10, 0x12, 0x09, 0x0a, 0x05, 0x48,
|
||||
0x54, 0x54, 0x50, 0x53, 0x10, 0x20, 0x12, 0x07, 0x0a, 0x03, 0x53, 0x53, 0x48, 0x10, 0x40, 0x2a,
|
||||
0xb5, 0x01, 0x0a, 0x0b, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x54, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x12,
|
||||
0x0c, 0x0a, 0x08, 0x52, 0x45, 0x53, 0x45, 0x52, 0x56, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a,
|
||||
0x0b, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x10, 0x01, 0x12, 0x0e,
|
||||
0x0a, 0x0a, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x10, 0x02, 0x12, 0x11,
|
||||
0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x41, 0x52, 0x54, 0x45, 0x44, 0x10,
|
||||
0x03, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x4f, 0x55, 0x54, 0x45, 0x5f, 0x53, 0x54, 0x4f, 0x50, 0x50,
|
||||
0x45, 0x44, 0x10, 0x04, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53, 0x54, 0x41,
|
||||
0x52, 0x54, 0x45, 0x44, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52, 0x5f, 0x53,
|
||||
0x54, 0x4f, 0x50, 0x50, 0x45, 0x44, 0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x45, 0x45, 0x52,
|
||||
0x5f, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x45, 0x44, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x45,
|
||||
0x45, 0x52, 0x5f, 0x45, 0x4f, 0x46, 0x10, 0x08, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x45, 0x45, 0x52,
|
||||
0x5f, 0x44, 0x41, 0x54, 0x41, 0x10, 0x09, 0x32, 0x49, 0x0a, 0x04, 0x48, 0x6f, 0x64, 0x75, 0x12,
|
||||
0x19, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x53, 0x65, 0x65, 0x64, 0x12, 0x05, 0x2e, 0x53, 0x65, 0x65,
|
||||
0x64, 0x1a, 0x05, 0x2e, 0x53, 0x65, 0x65, 0x64, 0x22, 0x00, 0x12, 0x26, 0x0a, 0x0c, 0x50, 0x61,
|
||||
0x63, 0x6b, 0x65, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x07, 0x2e, 0x50, 0x61, 0x63,
|
||||
0x6b, 0x65, 0x74, 0x1a, 0x07, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x22, 0x00, 0x28, 0x01,
|
||||
0x30, 0x01, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x2f, 0x68, 0x6f, 0x64, 0x75, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
10
hodu.proto
10
hodu.proto
@ -36,19 +36,23 @@ message RouteDesc {
|
||||
// S->C(ROUTE_STARTED): server-side listening address
|
||||
string TargetAddrStr = 2;
|
||||
|
||||
// C->S(ROUTE_START): human-readable name of client-side peer
|
||||
// S->C(ROUTE_STARTED): clone as sent by C
|
||||
string TargetNameStr = 3;
|
||||
|
||||
// C->S(ROUTE_START): desired listening option on the server-side(e.g. tcp, tcp4, tcp6) +
|
||||
// hint to the service-side peer(e.g. local) +
|
||||
// hint to the client-side peer(e.g. tty, http, https)
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C.
|
||||
uint32 ServiceOption = 3;
|
||||
uint32 ServiceOption = 4;
|
||||
|
||||
// C->S(ROUTE_START): desired lisening address on the service-side
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C
|
||||
string ServiceAddrStr = 4;
|
||||
string ServiceAddrStr = 5;
|
||||
|
||||
// C->S(ROUTE_START): permitted network of server-side peers.
|
||||
// S->C(ROUTE_STARTED): cloned as sent by C.
|
||||
string ServiceNetStr = 5;
|
||||
string ServiceNetStr = 6;
|
||||
};
|
||||
|
||||
message PeerDesc {
|
||||
|
@ -16,6 +16,7 @@ type json_out_server_conn struct {
|
||||
type json_out_server_route struct {
|
||||
Id RouteId `json:"id"`
|
||||
ClientPeerAddr string `json:"client-peer-addr"`
|
||||
ClientPeerName string `json:"client-peer-name"`
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
ServerPeerServiceAddr string `json:"server-peer-service-addr"` // actual listening address
|
||||
ServerPeerServiceNet string `json:"server-peer-service-net"`
|
||||
@ -95,6 +96,7 @@ func (ctl *server_ctl_server_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
jsp = append(jsp, json_out_server_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.ptc_addr,
|
||||
ClientPeerName: r.ptc_name,
|
||||
ServerPeerServiceAddr: r.svc_addr.String(),
|
||||
ServerPeerServiceNet: r.svc_permitted_net.String(),
|
||||
ServerPeerOption: r.svc_option.string(),
|
||||
@ -177,6 +179,7 @@ func (ctl *server_ctl_server_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
||||
jsp = append(jsp, json_out_server_route{
|
||||
Id: r.id,
|
||||
ClientPeerAddr: r.ptc_addr,
|
||||
ClientPeerName: r.ptc_name,
|
||||
ServerPeerServiceAddr: r.svc_addr.String(),
|
||||
ServerPeerServiceNet: r.svc_permitted_net.String(),
|
||||
ServerPeerOption: r.svc_option.string(),
|
||||
|
@ -369,7 +369,6 @@ type server_proxy_xterm_file struct {
|
||||
}
|
||||
|
||||
type server_proxy_xterm_session_info struct {
|
||||
RouteName string
|
||||
ConnId string
|
||||
RouteId string
|
||||
}
|
||||
@ -407,7 +406,6 @@ func (pxy *server_proxy_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
w.WriteHeader(http.StatusOK)
|
||||
tmpl.Execute(w,
|
||||
&server_proxy_xterm_session_info{
|
||||
RouteName: "Terminal",
|
||||
ConnId: req.PathValue("conn_id"),
|
||||
RouteId: req.PathValue("route_id"),
|
||||
})
|
||||
|
@ -103,6 +103,7 @@ type ServerRoute struct {
|
||||
svc_option RouteOption
|
||||
|
||||
ptc_addr string
|
||||
ptc_name string
|
||||
id RouteId
|
||||
|
||||
pts_mtx sync.Mutex
|
||||
@ -964,6 +965,7 @@ func NewServer(ctx context.Context, logger Logger, ctl_addrs []string, rpc_addrs
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
s.pxy_ws.ServeWebsocket(ws)
|
||||
}))
|
||||
s.pxy_mux.Handle("/_ssh/server-conns/{conn_id}/routes/{route_id}", &server_ctl_server_conns_id_routes_id{s: &s})
|
||||
s.pxy_mux.Handle("/_ssh/{conn_id}/{route_id}/", &server_proxy_xterm_file{s: &s, file: "xterm.html"})
|
||||
s.pxy_mux.Handle("/_ssh/xterm.js", &server_proxy_xterm_file{s: &s, file: "xterm.js"})
|
||||
s.pxy_mux.Handle("/_ssh/xterm-addon-fit.js", &server_proxy_xterm_file{s: &s, file: "xterm-addon-fit.js"})
|
||||
|
74
xterm.html
74
xterm.html
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>{{ .RouteName }}</title>
|
||||
<title>Terminal</title>
|
||||
<link rel="stylesheet" href="/_ssh/xterm.css" />
|
||||
<style>
|
||||
body {
|
||||
@ -19,11 +19,17 @@
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
#terminal-status-container {
|
||||
#terminal-info-container {
|
||||
vertical-align: middle;
|
||||
padding: 3px;
|
||||
}
|
||||
|
||||
#terminal-target {
|
||||
display: inline-block;
|
||||
height: 100%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#terminal-status {
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
@ -74,6 +80,11 @@
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
|
||||
text-align: center;
|
||||
}
|
||||
#login-form-title {
|
||||
line-height: 2em;
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
<script src="/_ssh/xterm.js"></script>
|
||||
<script src="/_ssh/xterm-addon-fit.js"></script>
|
||||
@ -81,11 +92,13 @@
|
||||
<script>
|
||||
window.onload = function(event) {
|
||||
const terminal_container = document.getElementById('terminal-container');
|
||||
const terminal_target = document.getElementById('terminal-target');
|
||||
const terminal_status = document.getElementById('terminal-status');
|
||||
const terminal_errmsg = document.getElementById('terminal-errmsg');
|
||||
const terminal_view_container = document.getElementById('terminal-view-container');
|
||||
const terminal_disconnect = document.getElementById('terminal-disconnect');
|
||||
const login_container = document.getElementById('login-container');
|
||||
const login_form_title = document.getElementById('login-form-title');
|
||||
const login_form = document.getElementById('login-form');
|
||||
const username_field = document.getElementById('username');
|
||||
const password_field= document.getElementById('password');
|
||||
@ -97,25 +110,48 @@ window.onload = function(event) {
|
||||
term.loadAddon(fit_addon)
|
||||
term.open(terminal_view_container);
|
||||
|
||||
let set_terminal_target = function(name) {
|
||||
terminal_target.innerHTML = name;
|
||||
login_form_title.innerHTML = name
|
||||
}
|
||||
|
||||
let set_terminal_status = function(msg, errmsg) {
|
||||
if (msg != null) terminal_status.innerHTML = msg;
|
||||
if (errmsg != null) terminal_errmsg.innerHTML = errmsg
|
||||
}
|
||||
|
||||
let adjust_terminal_size_unconnected = function() {
|
||||
fit_addon.fit();
|
||||
}
|
||||
|
||||
let fetch_session_info = async function() {
|
||||
let url = window.location.protocol + '//' + window.location.host + '/_ssh/server-conns/{{ .ConnId }}//routes/{{ .RouteId }}';
|
||||
try {
|
||||
const resp = await fetch(url);
|
||||
if (!resp.ok) throw new Error(`HTTP error in getting route({{ .ConnId }}, {{ .RouteId }}) info - status ${resp.status}`);
|
||||
const route = await resp.json()
|
||||
if ('client-peer-name' in route) {
|
||||
set_terminal_target(route['client-peer-name']) // change to the name
|
||||
document.title = route['client-peer-name']
|
||||
}
|
||||
} catch (e) {
|
||||
set_terminal_target('');
|
||||
document.title = 'Terminal';
|
||||
set_terminal_status (null, e);
|
||||
}
|
||||
}
|
||||
|
||||
let toggle_login_form = function(visible) {
|
||||
if (visible) fetch_session_info();
|
||||
login_container.style.visibility = (visible? 'visible': 'hidden');
|
||||
terminal_disconnect.style.visibility = (visible? 'hidden': 'visible');
|
||||
if (visible) username_field.focus();
|
||||
else term.focus();
|
||||
}
|
||||
|
||||
let resize_term_unconnected = function() {
|
||||
fit_addon.fit();
|
||||
}
|
||||
|
||||
toggle_login_form(true);
|
||||
window.onresize = resize_term_unconnected;
|
||||
resize_term_unconnected()
|
||||
window.onresize = adjust_terminal_size_unconnected;
|
||||
adjust_terminal_size_unconnected()
|
||||
|
||||
login_form.onsubmit = async function(event) {
|
||||
event.preventDefault();
|
||||
@ -130,7 +166,7 @@ window.onload = function(event) {
|
||||
|
||||
set_terminal_status('Connecting...', '');
|
||||
|
||||
const resize_term_connected = function() {
|
||||
const adjust_terminal_size_connected = function() {
|
||||
fit_addon.fit();
|
||||
if (socket.readyState == 1) // if open
|
||||
socket.send(JSON.stringify({ type: 'size', data: [term.rows.toString(), term.cols.toString()] }));
|
||||
@ -151,7 +187,8 @@ window.onload = function(event) {
|
||||
if (msg.data.length >= 1) {
|
||||
if (msg.data[0] == 'opened') {
|
||||
set_terminal_status('Connected', '');
|
||||
resize_term_connected()
|
||||
adjust_terminal_size_connected()
|
||||
term.clear()
|
||||
} else if (msg.data[0] == 'closed') {
|
||||
// doesn't really matter
|
||||
// socket.onclose() will be executed anyway
|
||||
@ -159,28 +196,26 @@ window.onload = function(event) {
|
||||
}
|
||||
} else if (msg.type == "error") {
|
||||
toggle_login_form(true);
|
||||
window.onresize = resize_term_unconnected;
|
||||
window.onresize = adjust_terminal_size_unconnected;
|
||||
set_terminal_status(null, msg.data.join(' '))
|
||||
}
|
||||
} catch (e) {
|
||||
set_terminal_status('Disconnected', e);
|
||||
toggle_login_form(true)
|
||||
window.onresize = resize_term_unconnected;
|
||||
window.onresize = adjust_terminal_size_unconnected;
|
||||
}
|
||||
};
|
||||
|
||||
socket.onerror = function(event) {
|
||||
set_terminal_status('Disconnected', event);
|
||||
toggle_login_form(true)
|
||||
window.onresize = resize_term_unconnected;
|
||||
term.write("\r\n")
|
||||
window.onresize = adjust_terminal_size_unconnected;
|
||||
};
|
||||
|
||||
socket.onclose = function() {
|
||||
set_terminal_status('Disconnected', null);
|
||||
toggle_login_form(true)
|
||||
window.onresize = resize_term_unconnected;
|
||||
term.write("\r\n")
|
||||
window.onresize = adjust_terminal_size_unconnected;
|
||||
};
|
||||
|
||||
term.onData(function(data) {
|
||||
@ -188,7 +223,7 @@ window.onload = function(event) {
|
||||
socket.send(JSON.stringify({ type: 'iov', data: [data] }));
|
||||
});
|
||||
|
||||
window.onresize = resize_term_connected;
|
||||
window.onresize = adjust_terminal_size_connected;
|
||||
terminal_disconnect.onclick = function(event) {
|
||||
socket.send(JSON.stringify({ type: 'close', data: [""] }));
|
||||
//socket.close()
|
||||
@ -202,7 +237,7 @@ window.onload = function(event) {
|
||||
|
||||
<div id="login-container">
|
||||
<div id="login-form-container">
|
||||
<h2>{{ .RouteName }}</h2>
|
||||
<div id="login-form-title"></div>
|
||||
<form id="login-form">
|
||||
<label>
|
||||
Username: <input type="text" id="username" required />
|
||||
@ -218,7 +253,8 @@ window.onload = function(event) {
|
||||
</div>
|
||||
|
||||
<div id="terminal-container">
|
||||
<div id="terminal-status-container">
|
||||
<div id="terminal-info-container">
|
||||
<div id="terminal-target"></div>
|
||||
<div id="terminal-status"></div>
|
||||
<div id="terminal-errmsg"></div>
|
||||
<div id="terminal-control">
|
||||
|
Loading…
x
Reference in New Issue
Block a user