Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 9d78f954aed7349a79cd612c2f81c203719727f0 Author: Wim <wim@42.be> Date: Sat Oct 29 18:59:12 2016 +0000 Wait until the welcome message before connection is ok (irc). Fixes #62 diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index ea040af..e5b6858 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -26 +27 @@ package birc    import (   "crypto/tls" + "fmt"   "github.com/42wim/matterbridge/bridge/config"   log "github.com/Sirupsen/logrus"   ircm "github.com/sorcix/irc" @@ -1413 +1514 @@ import (  )    type Birc struct { - i *irc.Connection - Nick string - names map[string][]string - Config *config.Protocol - origin string - protocol string - Remote chan config.Message + i *irc.Connection + Nick string + names map[string][]string + Config *config.Protocol + origin string + protocol string + Remote chan config.Message + connected chan struct{}  }    var flog *log.Entry @@ -386 +407 @@ func New(config config.Protocol, origin string, c chan config.Message) *Birc {   b.names = make(map[string][]string)   b.origin = origin   b.protocol = protocol + b.connected = make(chan struct{})   return b  }   @@ -709 +7314 @@ func (b *Birc) Connect() error {   if err != nil {   return err   } - flog.Info("Connection succeeded") - i.Debug = false   b.i = i + select { + case <-b.connected: + flog.Info("Connection succeeded") + case <-time.After(time.Second * 30): + return fmt.Errorf("connection timed out") + } + i.Debug = false   return nil  }   @@ -1436 +1518 @@ func (b *Birc) handleNewConnection(event *irc.Event) {   flog.Debugf("PING/PONG")   })   i.AddCallback("*", b.handleOther) + // we are now fully connected + b.connected <- struct{}{}  }    func (b *Birc) handleNotice(event *irc.Event) {