summaryrefslogtreecommitdiffstats
path: root/gateway/gateway.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-09-19 23:05:49 +0200
committerWim <wim@42.be>2016-09-19 23:05:49 +0200
commit4737442185a751d4f35ce7eca973b23020625ea8 (patch)
treeb41f9a802a483493e0c3e363c5b32040a87695cb /gateway/gateway.go
parent596096d6dac2eae4143e6a9b596df309bc2dc2be (diff)
downloadmatterbridge-msglm-4737442185a751d4f35ce7eca973b23020625ea8.tar.gz
matterbridge-msglm-4737442185a751d4f35ce7eca973b23020625ea8.tar.bz2
matterbridge-msglm-4737442185a751d4f35ce7eca973b23020625ea8.zip
Connect only once to each bridge
Diffstat (limited to 'gateway/gateway.go')
-rw-r--r--gateway/gateway.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/gateway/gateway.go b/gateway/gateway.go
index 6ac36d40..e1131f19 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -23,15 +23,27 @@ func New(cfg *config.Config, gateway *config.Gateway) error {
gw.Name = gateway.Name
gw.Config = cfg
gw.MyConfig = gateway
- for _, br := range gateway.In {
+ exists := make(map[string]bool)
+ for _, br := range append(gateway.In, gateway.Out...) {
+ if exists[br.Account+br.Channel] {
+ continue
+ }
+ log.Infof("Starting bridge: %s channel: %s", br.Account, br.Channel)
gw.Bridges = append(gw.Bridges, bridge.New(cfg, &br, c))
+ exists[br.Account+br.Channel] = true
}
gw.mapChannels()
gw.mapIgnores()
+ exists = make(map[string]bool)
for _, br := range gw.Bridges {
br.Connect()
- for _, channel := range gw.ChannelsOut[br.FullOrigin()] {
+ for _, channel := range append(gw.ChannelsOut[br.FullOrigin()], gw.ChannelsIn[br.FullOrigin()]...) {
+ if exists[br.FullOrigin()+channel] {
+ continue
+ }
+ log.Infof("%s: joining %s", br.FullOrigin(), channel)
br.JoinChannel(channel)
+ exists[br.FullOrigin()+channel] = true
}
}
gw.handleReceive(c)
@@ -85,7 +97,6 @@ func (gw *Gateway) handleMessage(msg config.Message, dest bridge.Bridge) {
for _, channel := range channels {
// do not send the message to the bridge we come from if also the channel is the same
if msg.FullOrigin == dest.FullOrigin() && msg.Channel == channel {
- log.Debug("continue", msg.Protocol, msg.Origin, dest.Protocol(), dest.Origin())
continue
}
msg.Channel = channel