Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/route finder single route #4

2 changes: 1 addition & 1 deletion cmd/apps/therealssh-client/therealssh-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"flag"
"net/http"

"github.com/sirupsen/logrus"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/sirupsen/logrus"

"github.com/SkycoinProject/skywire-mainnet/pkg/app"
ssh "github.com/SkycoinProject/skywire-mainnet/pkg/therealssh"
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/therealssh/therealssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package main
import (
"flag"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
"github.com/SkycoinProject/skycoin/src/util/logging"

"github.com/SkycoinProject/skywire-mainnet/pkg/app"
ssh "github.com/SkycoinProject/skywire-mainnet/pkg/therealssh"
Expand Down
4 changes: 2 additions & 2 deletions cmd/messaging-server/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"os"
"path/filepath"

"github.com/prometheus/client_golang/prometheus/promhttp"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/SkycoinProject/dmsg"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/dmsg/disc"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/prometheus/client_golang/prometheus/promhttp"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"net/http"
"os"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/prometheus/client_golang/prometheus/promhttp"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/SkycoinProject/skywire-mainnet/pkg/metrics"
Expand Down
13 changes: 9 additions & 4 deletions cmd/skywire-cli/commands/rtfind/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rtfind

import (
"context"
"fmt"
"time"

Expand All @@ -9,6 +10,7 @@ import (

"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/internal"
"github.com/SkycoinProject/skywire-mainnet/pkg/route-finder/client"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

var frAddr string
Expand All @@ -33,11 +35,14 @@ var RootCmd = &cobra.Command{
var srcPK, dstPK cipher.PubKey
internal.Catch(srcPK.Set(args[0]))
internal.Catch(dstPK.Set(args[1]))

forward, reverse, err := rfc.PairedRoutes(srcPK, dstPK, frMinHops, frMaxHops)
forward := [2]cipher.PubKey{srcPK, dstPK}
backward := [2]cipher.PubKey{dstPK, srcPK}
ctx := context.Background()
routes, err := rfc.FindRoutes(ctx, []routing.PathEdges{forward, backward},
&client.RouteOptions{MinHops: frMinHops, MaxHops: frMaxHops})
internal.Catch(err)

fmt.Println("forward: ", forward)
fmt.Println("reverse: ", reverse)
fmt.Println("forward: ", routes[forward][0])
fmt.Println("reverse: ", routes[backward][0])
},
}
2 changes: 1 addition & 1 deletion cmd/skywire-cli/commands/tpdisc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"text/tabwriter"
"time"

"github.com/google/uuid"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/google/uuid"
"github.com/spf13/cobra"

"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/internal"
Expand Down
2 changes: 1 addition & 1 deletion cmd/skywire-cli/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package internal
import (
"fmt"

"github.com/google/uuid"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/google/uuid"
)

var log = logging.MustGetLogger("skywire-cli")
Expand Down
3 changes: 2 additions & 1 deletion cmd/skywire-visor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
"syscall"
"time"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/pkg/profile"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/SkycoinProject/skywire-mainnet/internal/utclient"
"github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil"
"github.com/SkycoinProject/skywire-mainnet/pkg/visor"
Expand Down
2 changes: 1 addition & 1 deletion cmd/therealssh-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"syscall"
"time"

"github.com/creack/pty"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/creack/pty"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/skycoin/dmsg v0.0.0-20190805065636-70f4c32a994f h1:WWjaxOXoj6oYelm67MNtJbg51HQALjKAyhs2WAHgpZs=
github.com/skycoin/dmsg v0.0.0-20190805065636-70f4c32a994f/go.mod h1:obZYZp8eKR7Xqz+KNhJdUE6Gvp6rEXbDO8YTlW2YXgU=
github.com/skycoin/skycoin v0.26.0 h1:xDxe2r8AclMntZ550Y/vUQgwgLtwrf9Wu5UYiYcN5/o=
github.com/skycoin/skycoin v0.26.0/go.mod h1:78nHjQzd8KG0jJJVL/j0xMmrihXi70ti63fh8vXScJw=
Expand All @@ -118,6 +119,7 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
2 changes: 1 addition & 1 deletion internal/therealproxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io"
"net"

"github.com/hashicorp/yamux"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/hashicorp/yamux"
)

// Log is therealproxy package level logger, it can be replaced with a different one from outside the package
Expand Down
2 changes: 1 addition & 1 deletion internal/therealproxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"net"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/armon/go-socks5"
"github.com/hashicorp/yamux"
"github.com/SkycoinProject/skycoin/src/util/logging"
)

// Server implements multiplexing proxy server using yamux.
Expand Down
2 changes: 1 addition & 1 deletion pkg/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net"
"net/http"

"github.com/gorilla/handlers"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/gorilla/handlers"
)

var log = logging.MustGetLogger("httputil")
Expand Down
7 changes: 4 additions & 3 deletions pkg/hypervisor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"sync"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/google/uuid"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/dmsg/noise"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/google/uuid"

"github.com/SkycoinProject/skywire-mainnet/pkg/app"
"github.com/SkycoinProject/skywire-mainnet/pkg/httputil"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
Expand Down
55 changes: 25 additions & 30 deletions pkg/route-finder/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"time"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"

"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
Expand All @@ -21,18 +20,16 @@ const defaultContextTimeout = 10 * time.Second

var log = logging.MustGetLogger("route-finder")

// GetRoutesRequest parses json body for /routes endpoint request
type GetRoutesRequest struct {
SrcPK cipher.PubKey `json:"src_pk,omitempty"`
DstPK cipher.PubKey `json:"dst_pk,omitempty"`
MinHops uint16 `json:"min_hops,omitempty"`
MaxHops uint16 `json:"max_hops,omitempty"`
// RouteOptions for FindRoutesRequest. If nil MinHops and MaxHops will take default values
type RouteOptions struct {
MinHops uint16
MaxHops uint16
}

// GetRoutesResponse encodes the json body of /routes response
type GetRoutesResponse struct {
Forward []routing.Route `json:"forward"`
Reverse []routing.Route `json:"response"`
// FindRoutesRequest parses json body for /routes endpoint request
type FindRoutesRequest struct {
Edges []routing.PathEdges
Opts *RouteOptions
}

// HTTPResponse represents http response struct
Expand All @@ -49,7 +46,7 @@ type HTTPError struct {

// Client implements route finding operations.
type Client interface {
PairedRoutes(source, destiny cipher.PubKey, minHops, maxHops uint16) ([]routing.Route, []routing.Route, error)
FindRoutes(ctx context.Context, rts []routing.PathEdges, opts *RouteOptions) (map[routing.PathEdges][]routing.Path, error)
}

// APIClient implements Client interface
Expand All @@ -72,26 +69,24 @@ func NewHTTP(addr string, apiTimeout time.Duration) Client {
}
}

// PairedRoutes returns routes from source skywire visor to destiny, that has at least the given minHops and as much
// the given maxHops as well as the reverse routes from destiny to source.
func (c *apiClient) PairedRoutes(source, destiny cipher.PubKey, minHops, maxHops uint16) ([]routing.Route, []routing.Route, error) {
requestBody := &GetRoutesRequest{
SrcPK: source,
DstPK: destiny,
MinHops: minHops,
MaxHops: maxHops,
// FindRoutes returns routes from source skywire visor to destiny, that has at least the given minHops and as much
// the given maxHops.
func (c *apiClient) FindRoutes(ctx context.Context, rts []routing.PathEdges, opts *RouteOptions) (map[routing.PathEdges][]routing.Path, error) {
requestBody := &FindRoutesRequest{
Edges: rts,
Opts: opts,
}
marshaledBody, err := json.Marshal(requestBody)
if err != nil {
return nil, nil, err
return nil, err
}

req, err := http.NewRequest(http.MethodGet, c.addr+"/routes", bytes.NewBuffer(marshaledBody))
if err != nil {
return nil, nil, err
return nil, err
}
req.Header.Set("Content-Type", "application/json")
ctx, cancel := context.WithTimeout(context.Background(), c.apiTimeout)
ctx, cancel := context.WithTimeout(ctx, c.apiTimeout)
defer cancel()
req = req.WithContext(ctx)

Expand All @@ -104,27 +99,27 @@ func (c *apiClient) PairedRoutes(source, destiny cipher.PubKey, minHops, maxHops
}()
}
if err != nil {
return nil, nil, err
return nil, err
}

if res.StatusCode != http.StatusOK {
var apiErr HTTPResponse

err = json.NewDecoder(res.Body).Decode(&apiErr)
if err != nil {
return nil, nil, err
return nil, err
}

return nil, nil, errors.New(apiErr.Error.Message)
return nil, errors.New(apiErr.Error.Message)
}

var routes GetRoutesResponse
err = json.NewDecoder(res.Body).Decode(&routes)
var paths map[routing.PathEdges][]routing.Path
err = json.NewDecoder(res.Body).Decode(&paths)
if err != nil {
return nil, nil, err
return nil, err
}

return routes.Forward, routes.Reverse, nil
return paths, nil
}

func sanitizedAddr(addr string) string {
Expand Down
34 changes: 17 additions & 17 deletions pkg/route-finder/client/mock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package client

import (
"context"
"fmt"

"github.com/SkycoinProject/dmsg/cipher"

"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
Expand All @@ -23,27 +26,24 @@ func (r *mockClient) SetError(err error) {
r.err = err
}

// PairedRoutes implements Client for MockClient
func (r *mockClient) PairedRoutes(src, dst cipher.PubKey, minHops, maxHops uint16) ([]routing.Route, []routing.Route, error) {
// FindRoutes implements Client for MockClient
func (r *mockClient) FindRoutes(ctx context.Context, rts []routing.PathEdges, opts *RouteOptions) (map[routing.PathEdges][]routing.Path, error) {
if r.err != nil {
return nil, nil, r.err
return nil, r.err
}

return []routing.Route{
{
&routing.Hop{
From: src,
To: dst,
Transport: transport.MakeTransportID(src, dst, ""),
},
},
}, []routing.Route{
if len(rts) == 0 {
return nil, fmt.Errorf("no edges provided to returns routes from")
}
return map[routing.PathEdges][]routing.Path{
[2]cipher.PubKey{rts[0][0], rts[0][1]}: {
{
&routing.Hop{
From: src,
To: dst,
Transport: transport.MakeTransportID(src, dst, ""),
routing.Hop{
From: rts[0][0],
To: rts[0][1],
Transport: transport.MakeTransportID(rts[0][0], rts[0][1], ""),
},
},
}, nil
},
}, nil
}
6 changes: 3 additions & 3 deletions pkg/router/route_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"net"
"time"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/google/uuid"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"

"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
"github.com/SkycoinProject/skywire-mainnet/pkg/setup"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet"
)

// RMConfig represents route manager configuration.
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/route_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/setup"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest"

"github.com/google/uuid"
"github.com/SkycoinProject/dmsg/cipher"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
Loading