diff options
author | xengineering <me@xengineering.eu> | 2023-04-16 10:26:41 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-04-16 10:46:36 +0200 |
commit | 22d06e868237dcec1ad01d7512679c14d97b275c (patch) | |
tree | 8cc694afd2007ba3691e733ed2641e20d03ac4bf | |
parent | a2af6617175d95fa4937b8aa38ed0bfc955085a8 (diff) | |
download | limox-22d06e868237dcec1ad01d7512679c14d97b275c.tar limox-22d06e868237dcec1ad01d7512679c14d97b275c.tar.zst limox-22d06e868237dcec1ad01d7512679c14d97b275c.zip |
Implement fallback DNS resolution
This uses A / AAAA records while the preferred method in XMPP are SRV
records.
-rw-r--r-- | go/main.go | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -3,6 +3,7 @@ package main import ( "image/color" "log" + "net" "os" "gioui.org/app" @@ -28,6 +29,7 @@ type Limox struct { JidEditor widget.Editor PwdEditor widget.Editor MainButton widget.Clickable + XmppError chan error State LimoxState Window *app.Window Operations op.Ops @@ -56,21 +58,26 @@ func NewLimox() Limox { ), Operations: op.Ops{}, Theme: material.NewTheme(gofont.Collection()), + XmppError: make(chan error), State: Disconnected, } } func (l *Limox) run() error { for { - e := <-l.Window.Events() - switch e := e.(type) { - case system.DestroyEvent: - return e.Err - case system.FrameEvent: - if l.MainButton.Clicked() { - l.buttonCallback() + select { + case e := <-l.Window.Events(): + switch e := e.(type) { + case system.DestroyEvent: + return e.Err + case system.FrameEvent: + if l.MainButton.Clicked() { + l.buttonCallback() + } + l.draw(e) } - l.draw(e) + case <-l.XmppError: + l.State = Disconnected } } } @@ -79,7 +86,7 @@ func (l *Limox) buttonCallback() { switch l.State { case Disconnected: log.Println("Starting connection establishment") - go xmpp(l.JidEditor.Text(), l.PwdEditor.Text()) + go l.xmpp(l.JidEditor.Text(), l.PwdEditor.Text()) l.State = Connecting case Connecting: log.Println("Aborted connection establishment") @@ -90,9 +97,19 @@ func (l *Limox) buttonCallback() { } } -func xmpp(jid string, pwd string) { +func (l *Limox) xmpp(jid string, pwd string) { log.Printf("JID: '%s' PWD: '%s'\n", jid, pwd) - log.Printf("Domain: '%s'\n", domainpart(jid)) + + domain := domainpart(jid) + log.Printf("Domain: '%s'\n", domain) + + tcpServer, err := net.ResolveTCPAddr("tcp", domain+":"+"5222") + if err != nil { + log.Print(err) + l.XmppError <- err + return + } + log.Printf("Server: %s\n", tcpServer) } // domainpart extracts the domain name from a JID / XMPP address. See @@ -100,17 +117,15 @@ func xmpp(jid string, pwd string) { func domainpart(jid string) string { list := []rune(jid) - for i, v := range(list) { + for i, v := range list { if v == '/' { - log.Printf("Index of / rune: %d\n", i) list = list[:i] break } } - for i, v := range(list) { + for i, v := range list { if v == '@' { - log.Printf("Index of @ rune: %d\n", i) list = list[i+1:] break } |