diff options
Diffstat (limited to 'xmpp/session.go')
-rw-r--r-- | xmpp/session.go | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/xmpp/session.go b/xmpp/session.go index 2e7bade..d8e4973 100644 --- a/xmpp/session.go +++ b/xmpp/session.go @@ -1,44 +1,67 @@ package xmpp import ( + "crypto/tls" + "crypto/x509" "log" - "time" ) type SessionConnect struct{} type SessionDisconnect struct{} type SessionShouldDisconnect struct{} -type Session struct { - in, out chan any +type session struct { + in, out chan any + jid string + transport *tls.Conn } func StartSession(out chan any, jid string, pwd string) chan any { - s := Session{} + s := session{} s.in = make(chan any) s.out = out + s.jid = jid go s.run() return s.in } -func (s *Session) run() { +func (s *session) run() { defer func() { s.out <- SessionDisconnect{} }() - time.Sleep(time.Second) // faked connect time + err := s.startTransport() + if err != nil { return } + defer s.transport.Close() + s.out <- SessionConnect{} for { select { case data := <-s.in: switch data.(type) { - case SessionShouldDisconnect: - return - default: - log.Printf("Unknown data '%d'!\n", data) + case SessionShouldDisconnect: return + default: log.Printf("Unknown data '%d'!\n", data) } } } } + +func (s *session) startTransport() error { + domain := domainpart(s.jid) + + roots, err := x509.SystemCertPool() + if err != nil { + log.Println(err) + return err + } + + s.transport, err = tls.Dial("tcp", domain+":"+"5223", &tls.Config{RootCAs: roots}) + if err != nil { + log.Println(err) + return err + } + + return nil +} |