Skip to content

Commit

Permalink
app/dial: Add raft external dial method
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
  • Loading branch information
masnax committed Feb 2, 2022
1 parent ac4e13b commit 8fe4215
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package app
import (
"context"
"crypto/tls"
"fmt"
"net"

"github.com/canonical/go-dqlite/client"
"github.com/pkg/errors"
)

// Like client.DialFuncWithTLS but also starts the proxy, since the raft
Expand All @@ -29,7 +29,7 @@ func makeNodeDialFunc(config *tls.Config) client.DialFunc {
}
goUnix, cUnix, err := socketpair()
if err != nil {
return nil, errors.Wrap(err, "create pair of Unix sockets")
return nil, fmt.Errorf("create pair of Unix sockets: %w", err)
}

go proxy(context.Background(), conn, goUnix, clonedConfig)
Expand All @@ -39,3 +39,21 @@ func makeNodeDialFunc(config *tls.Config) client.DialFunc {

return dial
}

func extDialFuncWithProxy(dialFunc client.DialFunc) client.DialFunc {
return func(ctx context.Context, addr string) (net.Conn, error) {
goUnix, cUnix, err := socketpair()
if err != nil {
return nil, fmt.Errorf("create pair of Unix sockets: %w", err)
}

conn, err := dialFunc(ctx, addr)
if err != nil {
return nil, err
}

go proxy(context.Background(), conn, goUnix, nil)

return cUnix, nil
}
}

0 comments on commit 8fe4215

Please sign in to comment.