feat(protocol): allow override of dial func

This commit is contained in:
2024-08-05 18:10:19 +02:00
parent b976bde363
commit 6842d4d88a
16 changed files with 158 additions and 18 deletions

View File

@ -6,6 +6,7 @@ func init() {
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
return &Protocol{
logger: opts.Logger,
dial: opts.Dial,
}, nil
})
}

View File

@ -18,6 +18,8 @@ type Operations struct {
client *socketio.Client
mutex sync.RWMutex
logger logger.Logger
dial protocol.DialFunc
}
// Close implements protocol.Operations.
@ -49,12 +51,12 @@ func (o *Operations) Connect(ctx context.Context) error {
o.client.Close()
}
endpoint, err := socketio.EndpointFromHAddr(o.addr)
endpoint, err := socketio.EndpointFromAddr(o.addr)
if err != nil {
return errors.WithStack(err)
}
client := socketio.NewClient(endpoint)
client := socketio.NewClient(endpoint, socketio.WithDialFunc(socketio.DialFunc(o.dial)))
o.logger.Debug("connecting", logger.Attr("endpoint", endpoint))

View File

@ -16,6 +16,7 @@ const compatibleVersionConstraint = "^2.24"
type Protocol struct {
logger logger.Logger
dial protocol.DialFunc
}
// Available implements protocol.Protocol.
@ -59,7 +60,7 @@ func (p *Protocol) Identifier() protocol.Identifier {
// Operations implements protocol.Protocol.
func (p *Protocol) Operations(addr string) protocol.Operations {
return &Operations{addr: addr, logger: p.logger}
return &Operations{addr: addr, logger: p.logger, dial: p.dial}
}
var _ protocol.Protocol = &Protocol{}