diff options
author | xengineering <me@xengineering.eu> | 2023-06-03 21:14:51 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-06-03 21:14:51 +0200 |
commit | 3d2bd84e683e414fc6c8ac2634165fccba641b72 (patch) | |
tree | e972f819485b4e188bcb71c6f76b1556b29709e5 /xmpp/session.go | |
parent | e313bce92afea09b2da657b5a4f7de2c958c0100 (diff) | |
download | limox-3d2bd84e683e414fc6c8ac2634165fccba641b72.tar limox-3d2bd84e683e414fc6c8ac2634165fccba641b72.tar.zst limox-3d2bd84e683e414fc6c8ac2634165fccba641b72.zip |
Re-implement transport setup in session
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 +} |