Skip to content

Commit

Permalink
fix: set up tls for redis when it's enabled
Browse files Browse the repository at this point in the history
log error when pubsub fail to publish peer information
  • Loading branch information
VinozzZ committed Aug 19, 2024
1 parent 3084f98 commit 91ee53f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 15 additions & 2 deletions internal/peer/pubsub_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ func (p *RedisPubsubPeers) Start() error {
case <-ticker.Chan():
// publish our presence periodically
ctx, cancel := context.WithTimeout(context.Background(), p.Config.GetPeerTimeout())
p.PubSub.Publish(ctx, "peers", newPeerCommand(Register, myaddr).marshal())
err := p.PubSub.Publish(ctx, "peers", newPeerCommand(Register, myaddr).marshal())
if err != nil {
p.Logger.Error().WithFields(map[string]interface{}{
"error": err,
"hostaddress": myaddr,
}).Logf("failed to publish peer address")
}
cancel()
case <-logTicker.Chan():
p.Logger.Debug().WithFields(map[string]any{
Expand All @@ -191,7 +197,14 @@ func (p *RedisPubsubPeers) stop() {
p.Logger.Error().Logf("failed to get public address")
return
}
p.PubSub.Publish(context.Background(), "peers", newPeerCommand(Unregister, myaddr).marshal())
err = p.PubSub.Publish(context.Background(), "peers", newPeerCommand(Unregister, myaddr).marshal())
if err != nil {
p.Logger.Error().WithFields(map[string]interface{}{
"error": err,
"hostaddress": myaddr,
}).Logf("failed to publish peer address")
}

}

func (p *RedisPubsubPeers) GetPeers() ([]string, error) {
Expand Down
15 changes: 15 additions & 0 deletions pubsub/pubsub_goredis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pubsub

import (
"context"
"crypto/tls"
"strings"
"sync"

Expand Down Expand Up @@ -69,6 +70,20 @@ func (ps *GoRedisPubSub) Start() error {
options.Username = username
options.Password = pw
options.DB = ps.Config.GetRedisDatabase()
useTLS := ps.Config.GetUseTLS()
tlsInsecure := ps.Config.GetUseTLSInsecure()
if useTLS {
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
}

if tlsInsecure {
tlsConfig.InsecureSkipVerify = true
}

options.TLSConfig = tlsConfig
}

}
client := redis.NewUniversalClient(options)

Expand Down

0 comments on commit 91ee53f

Please sign in to comment.