コード例 #1
0
ファイル: session.go プロジェクト: grayleonard/coyim
// 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
ファイル: registration.go プロジェクト: rosatolen/coyim
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
ファイル: registration.go プロジェクト: VKCheung/coyim
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
ファイル: registration.go プロジェクト: PMaynard/coyim
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
}