Skip to content

Commit

Permalink
Fix router client wrappers, temporarily add dmsg client wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Dec 10, 2019
1 parent fa64e27 commit 5046914
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/router/routerclient/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package routerclient
import (
"context"
"fmt"
"net"

"github.com/SkycoinProject/dmsg"
"github.com/SkycoinProject/dmsg/cipher"
Expand All @@ -11,6 +12,22 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

// TODO: remove this
// dmsgClientWrapper is a temporary workaround to make dmsg client implement `snet.Dialer`.
// The only reason to use this is because client's `Dial` returns `*dmsg.Stream` instead of `net.Conn`,
// so this stuff should be removed as soon as the func's signature changes
type dmsgClientWrapper struct {
*dmsg.Client
}

func wrapDmsgC(dmsgC *dmsg.Client) *dmsgClientWrapper {
return &dmsgClientWrapper{Client: dmsgC}
}

func (w *dmsgClientWrapper) Dial(ctx context.Context, remote cipher.PubKey, port uint16) (net.Conn, error) {
return w.Client.Dial(ctx, remote, port)
}

// AddEdgeRules is a wrapper for (*Client).AddEdgeRules.
func AddEdgeRules(
ctx context.Context,
Expand All @@ -19,7 +36,7 @@ func AddEdgeRules(
pk cipher.PubKey,
rules routing.EdgeRules,
) (bool, error) {
client, err := NewClient(ctx, dmsgC, pk)
client, err := NewClient(ctx, wrapDmsgC(dmsgC), pk)
if err != nil {
return false, fmt.Errorf("failed to dial remote: %v", err)
}
Expand All @@ -42,7 +59,7 @@ func AddIntermediaryRules(
pk cipher.PubKey,
rules []routing.Rule,
) (bool, error) {
client, err := NewClient(ctx, dmsgC, pk)
client, err := NewClient(ctx, wrapDmsgC(dmsgC), pk)
if err != nil {
return false, fmt.Errorf("failed to dial remote: %v", err)
}
Expand All @@ -65,7 +82,7 @@ func ReserveIDs(
pk cipher.PubKey,
n uint8,
) ([]routing.RouteID, error) {
client, err := NewClient(ctx, dmsgC, pk)
client, err := NewClient(ctx, wrapDmsgC(dmsgC), pk)
if err != nil {
return nil, fmt.Errorf("failed to dial remote: %v", err)
}
Expand Down

0 comments on commit 5046914

Please sign in to comment.