many fixes for lint and context.Context usage (#5)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -50,17 +50,17 @@ func (t *tunBroker) Address() string {
|
||||
}
|
||||
|
||||
func (t *tunBroker) Connect(ctx context.Context) error {
|
||||
return t.tunnel.Connect()
|
||||
return t.tunnel.Connect(ctx)
|
||||
}
|
||||
|
||||
func (t *tunBroker) Disconnect(ctx context.Context) error {
|
||||
return t.tunnel.Close()
|
||||
return t.tunnel.Close(ctx)
|
||||
}
|
||||
|
||||
func (t *tunBroker) Publish(ctx context.Context, topic string, m *broker.Message, opts ...broker.PublishOption) error {
|
||||
// TODO: this is probably inefficient, we might want to just maintain an open connection
|
||||
// it may be easier to add broadcast to the tunnel
|
||||
c, err := t.tunnel.Dial(topic, tunnel.DialMode(tunnel.Multicast))
|
||||
c, err := t.tunnel.Dial(ctx, topic, tunnel.DialMode(tunnel.Multicast))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func (t *tunBroker) Publish(ctx context.Context, topic string, m *broker.Message
|
||||
}
|
||||
|
||||
func (t *tunBroker) Subscribe(ctx context.Context, topic string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||
l, err := t.tunnel.Listen(topic, tunnel.ListenMode(tunnel.Multicast))
|
||||
l, err := t.tunnel.Listen(ctx, topic, tunnel.ListenMode(tunnel.Multicast))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ func (t *tunTransport) Init(opts ...transport.Option) error {
|
||||
|
||||
// close the existing tunnel
|
||||
if t.tunnel != nil {
|
||||
t.tunnel.Close()
|
||||
t.tunnel.Close(context.TODO())
|
||||
}
|
||||
|
||||
// get the tunnel
|
||||
@@ -47,12 +47,12 @@ func (t *tunTransport) Init(opts ...transport.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *tunTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) {
|
||||
if err := t.tunnel.Connect(); err != nil {
|
||||
func (t *tunTransport) Dial(ctx context.Context, addr string, opts ...transport.DialOption) (transport.Client, error) {
|
||||
if err := t.tunnel.Connect(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err := t.tunnel.Dial(addr)
|
||||
c, err := t.tunnel.Dial(ctx, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,12 +60,12 @@ func (t *tunTransport) Dial(addr string, opts ...transport.DialOption) (transpor
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (t *tunTransport) Listen(addr string, opts ...transport.ListenOption) (transport.Listener, error) {
|
||||
if err := t.tunnel.Connect(); err != nil {
|
||||
func (t *tunTransport) Listen(ctx context.Context, addr string, opts ...transport.ListenOption) (transport.Listener, error) {
|
||||
if err := t.tunnel.Connect(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
l, err := t.tunnel.Listen(addr)
|
||||
l, err := t.tunnel.Listen(ctx, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
@@ -55,15 +56,15 @@ type Tunnel interface {
|
||||
// Address returns the address the tunnel is listening on
|
||||
Address() string
|
||||
// Connect connects the tunnel
|
||||
Connect() error
|
||||
Connect(ctx context.Context) error
|
||||
// Close closes the tunnel
|
||||
Close() error
|
||||
Close(ctx context.Context) error
|
||||
// Links returns all the links the tunnel is connected to
|
||||
Links() []Link
|
||||
// Dial allows a client to connect to a channel
|
||||
Dial(channel string, opts ...DialOption) (Session, error)
|
||||
Dial(ctx context.Context, channel string, opts ...DialOption) (Session, error)
|
||||
// Listen allows to accept connections on a channel
|
||||
Listen(channel string, opts ...ListenOption) (Listener, error)
|
||||
Listen(ctx context.Context, channel string, opts ...ListenOption) (Listener, error)
|
||||
// String returns the name of the tunnel implementation
|
||||
String() string
|
||||
}
|
||||
|
Reference in New Issue
Block a user