Exemplo n.º 1
0
func (c *tunnelRemoton) Start(session *remoton.SessionClient, password string) error {
	if c.xpraSrv == nil {
		c.xpraSrv = &xpra.Xpra{}
	}
	c.xpraSrv.SetPassword(password)

	rpconn, err := session.Dial("rpc")
	if err != nil {
		return err
	}
	defer rpconn.Close()

	rpcclient := rpc.NewClient(rpconn)
	defer rpcclient.Close()

	var capsClient common.Capabilities
	err = rpcclient.Call("RemotonClient.GetCapabilities", struct{}{}, &capsClient)
	if err != nil {
		return err
	}
	if !strings.EqualFold(capsClient.XpraVersion, c.xpraSrv.Version()) {
		return fmt.Errorf("mismatch xpra version was %s expected %s",
			capsClient.XpraVersion, c.xpraSrv.Version())
	}

	serverDirect := false
	var clientExternalIP net.IP
	var clientExternalPort int
	err = rpcclient.Call("RemotonClient.GetExternalIP", struct{}{}, &clientExternalIP)
	if err == nil {
		rpcclient.Call("RemotonClient.GetExternalPort", struct{}{}, &clientExternalPort)
		conn, err := net.DialTimeout("tcp",
			fmt.Sprintf("%s:%d", clientExternalIP.String(), clientExternalPort),
			time.Second*3)
		if err == nil {
			conn.Close()
			serverDirect = true
		} else {
			log.Infof("failed connect direct to client %s:%d fallback to server",
				clientExternalIP, clientExternalPort)
		}

	}

	//BUG --auth=file xpra not work, so we secure it over tunnel SSL
	var clientOS string
	rpcclient.Call("RemotonClient.GetOS", struct{}{}, &clientOS)
	if clientOS == "windows" {
		serverDirect = false
	}

	if serverDirect {
		return c.srvDirect(session, clientExternalIP)
	}
	return c.srvTunnel(session)
}
Exemplo n.º 2
0
func (c *chatRemoton) Start(session *remoton.SessionClient) error {
	chatConn, err := session.Dial("chat")
	if err != nil {
		return err
	}
	c.conn = chatConn
	c.init()
	go c.handle()
	return nil
}