예제 #1
0
// Connect connects to the server and starts the main threads
func (s *session) Connect(password string) error {
	if !s.IsDisconnected() {
		return nil
	}

	s.setStatus(CONNECTING)

	if s.connectionLogger == nil {
		s.connectionLogger = newLogger()
	}

	conf := s.GetConfig()
	policy := config.ConnectionPolicy{
		Logger:     s.connectionLogger,
		XMPPLogger: s.xmppLogger,
	}

	conn, err := policy.Connect(password, conf)
	if err != nil {
		s.alert(err.Error())
		s.setStatus(DISCONNECTED)

		return err
	}

	s.conn = conn
	s.setStatus(CONNECTED)

	s.conn.SignalPresence("")
	go s.watchRoster()
	go s.watchTimeout()
	go s.watchStanzas()

	return nil
}
예제 #2
0
func requestAndRenderRegistrationForm(server string, formHandler data.FormCallback, saveFn func(), errorFn func(error), df interfaces.DialerFactory, verifier tls.Verifier) {
	policy := config.ConnectionPolicy{DialerFactory: df}

	//TODO: this would not be necessary if RegisterAccount did not use it
	conf := &config.Account{
		Account: "@" + server,
		Proxies: []string{"tor-auto://"},
	}

	//TODO: this should receive only a JID domainpart
	_, err := policy.RegisterAccount(formHandler, conf, verifier)

	if err != nil {
		errorFn(err)
		return
	}

	go saveFn()
}
예제 #3
0
func requestAndRenderRegistrationForm(server string, formHandler data.FormCallback, saveFn func(), df func() interfaces.Dialer) error {
	policy := config.ConnectionPolicy{DialerFactory: df}

	//TODO: this would not be necessary if RegisterAccount did not use it
	conf := &config.Account{
		Account: "@" + server,
		Proxies: []string{"tor-auto://"},
	}

	//TODO: this should receive only a JID domainpart
	_, err := policy.RegisterAccount(formHandler, conf)

	if err != nil {
		//TODO: show something in the UI
		log.Println("Registration failed:", err)
		return err
	}

	go saveFn()

	return nil
}
예제 #4
0
func requestAndRenderRegistrationForm(server string, formHandler xmpp.FormCallback, saveFn func()) error {
	policy := config.ConnectionPolicy{}

	//TODO: this would not be necessary if RegisterAccount did not use it
	conf := &config.Account{
		Account:    "@" + server,
		RequireTor: true,
	}

	//TODO: this should receive only a JID domainpart
	_, err := policy.RegisterAccount(formHandler, conf)

	if err != nil {
		//TODO: show something in the UI
		log.Println("Registration failed:", err)
		return err
	}

	go saveFn()

	return nil
}
예제 #5
0
파일: session.go 프로젝트: twstrike/coyim
// Connect connects to the server and starts the main threads
func (s *session) Connect(password string, verifier tls.Verifier) error {
	if !s.IsDisconnected() {
		return nil
	}

	s.setStatus(CONNECTING)

	conf := s.GetConfig()
	policy := config.ConnectionPolicy{
		Logger:        s.connectionLogger,
		XMPPLogger:    s.xmppLogger,
		DialerFactory: s.dialerFactory,
	}

	conn, err := policy.Connect(password, conf, verifier)
	if err != nil {
		s.setStatus(DISCONNECTED)

		return err
	}

	if s.connStatus == CONNECTING {
		s.conn = conn
		s.setStatus(CONNECTED)

		conn.SignalPresence("")
		go s.watchRoster()
		go s.getVCard()
		go s.watchTimeout()
		go s.watchStanzas()
	} else {
		if s.conn != nil {
			s.conn.Close()
		}
	}

	return nil
}