diff --git a/cmd/apps/therealssh-client/therealssh-client.go b/cmd/apps/therealssh-client/therealssh-client.go index 900310b59f..50129f186c 100644 --- a/cmd/apps/therealssh-client/therealssh-client.go +++ b/cmd/apps/therealssh-client/therealssh-client.go @@ -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" diff --git a/cmd/apps/therealssh/therealssh.go b/cmd/apps/therealssh/therealssh.go index 29935c0c95..17c4fd3836 100644 --- a/cmd/apps/therealssh/therealssh.go +++ b/cmd/apps/therealssh/therealssh.go @@ -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" diff --git a/cmd/messaging-server/commands/root.go b/cmd/messaging-server/commands/root.go index 9a4017c597..37c039d089 100644 --- a/cmd/messaging-server/commands/root.go +++ b/cmd/messaging-server/commands/root.go @@ -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" ) diff --git a/cmd/setup-node/commands/root.go b/cmd/setup-node/commands/root.go index 98013074ca..91bef18199 100644 --- a/cmd/setup-node/commands/root.go +++ b/cmd/setup-node/commands/root.go @@ -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" diff --git a/cmd/skywire-cli/commands/rtfind/root.go b/cmd/skywire-cli/commands/rtfind/root.go index a05f9502d3..c36aa5f37b 100644 --- a/cmd/skywire-cli/commands/rtfind/root.go +++ b/cmd/skywire-cli/commands/rtfind/root.go @@ -1,6 +1,7 @@ package rtfind import ( + "context" "fmt" "time" @@ -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 @@ -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]) }, } diff --git a/cmd/skywire-cli/commands/tpdisc/root.go b/cmd/skywire-cli/commands/tpdisc/root.go index 129220e095..7dbe67a270 100644 --- a/cmd/skywire-cli/commands/tpdisc/root.go +++ b/cmd/skywire-cli/commands/tpdisc/root.go @@ -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" diff --git a/cmd/skywire-cli/internal/internal.go b/cmd/skywire-cli/internal/internal.go index 783c35bd47..e79539cea0 100644 --- a/cmd/skywire-cli/internal/internal.go +++ b/cmd/skywire-cli/internal/internal.go @@ -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") diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index 79e164faed..49e35b2a27 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -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" diff --git a/cmd/therealssh-cli/commands/root.go b/cmd/therealssh-cli/commands/root.go index d4c8b54f08..c3bb4d65bb 100644 --- a/cmd/therealssh-cli/commands/root.go +++ b/cmd/therealssh-cli/commands/root.go @@ -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" diff --git a/go.sum b/go.sum index bea634b844..906b41300f 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/therealproxy/client.go b/internal/therealproxy/client.go index 167b70a5bb..171fcc9ade 100644 --- a/internal/therealproxy/client.go +++ b/internal/therealproxy/client.go @@ -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 diff --git a/internal/therealproxy/server.go b/internal/therealproxy/server.go index d1e94286b0..53eb68888f 100644 --- a/internal/therealproxy/server.go +++ b/internal/therealproxy/server.go @@ -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. diff --git a/pkg/httputil/httputil.go b/pkg/httputil/httputil.go index 8dcb7fcd7e..53ce9ce2d0 100644 --- a/pkg/httputil/httputil.go +++ b/pkg/httputil/httputil.go @@ -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") diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index bd8049586c..ad35ade421 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -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" diff --git a/pkg/route-finder/client/client.go b/pkg/route-finder/client/client.go index a096a953a9..6c8ec3e5ae 100644 --- a/pkg/route-finder/client/client.go +++ b/pkg/route-finder/client/client.go @@ -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" @@ -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 @@ -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 @@ -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) @@ -104,7 +99,7 @@ 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 { @@ -112,19 +107,19 @@ func (c *apiClient) PairedRoutes(source, destiny cipher.PubKey, minHops, maxHops 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 { diff --git a/pkg/route-finder/client/mock.go b/pkg/route-finder/client/mock.go index 0ebdba97ea..93e5e1557c 100644 --- a/pkg/route-finder/client/mock.go +++ b/pkg/route-finder/client/mock.go @@ -1,6 +1,9 @@ package client import ( + "context" + "fmt" + "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" @@ -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 } diff --git a/pkg/router/route_manager.go b/pkg/router/route_manager.go index c23f4e56ae..a221658872 100644 --- a/pkg/router/route_manager.go +++ b/pkg/router/route_manager.go @@ -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. diff --git a/pkg/router/route_manager_test.go b/pkg/router/route_manager_test.go index b6c3024baa..fd8bdcbb83 100644 --- a/pkg/router/route_manager_test.go +++ b/pkg/router/route_manager_test.go @@ -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" diff --git a/pkg/router/router.go b/pkg/router/router.go index f1f48a0e6a..2ccc0d5489 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -14,10 +14,10 @@ import ( "github.com/SkycoinProject/skycoin/src/util/logging" "github.com/SkycoinProject/skywire-mainnet/pkg/app" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" routeFinder "github.com/SkycoinProject/skywire-mainnet/pkg/route-finder/client" "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/transport" ) @@ -408,14 +408,18 @@ func (r *Router) destroyLoop(loop routing.Loop) error { return r.rm.RemoveLoopRule(loop) } -func (r *Router) fetchBestRoutes(source, destination cipher.PubKey) (fwd routing.Route, rev routing.Route, err error) { +func (r *Router) fetchBestRoutes(source, destination cipher.PubKey) (fwd routing.Path, rev routing.Path, err error) { r.Logger.Infof("Requesting new routes from %s to %s", source, destination) timer := time.NewTimer(time.Second * 10) defer timer.Stop() + forward := [2]cipher.PubKey{source, destination} + backward := [2]cipher.PubKey{destination, source} fetchRoutesAgain: - fwdRoutes, revRoutes, err := r.conf.RouteFinder.PairedRoutes(source, destination, minHops, maxHops) + ctx := context.Background() + paths, err := r.conf.RouteFinder.FindRoutes(ctx, []routing.PathEdges{forward, backward}, + &routeFinder.RouteOptions{MinHops: minHops, MaxHops: maxHops}) if err != nil { select { case <-timer.C: @@ -425,8 +429,8 @@ fetchRoutesAgain: } } - r.Logger.Infof("Found routes Forward: %s. Reverse %s", fwdRoutes, revRoutes) - return fwdRoutes[0], revRoutes[0], nil + r.Logger.Infof("Found routes Forward: %s. Reverse %s", paths[forward], paths[backward]) + return paths[forward][0], paths[backward][0], nil } // SetupIsTrusted checks if setup node is trusted. diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index fbdba26099..5d6406e516 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -7,16 +7,16 @@ import ( "testing" "time" - "github.com/sirupsen/logrus" "github.com/SkycoinProject/dmsg" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" routeFinder "github.com/SkycoinProject/skywire-mainnet/pkg/route-finder/client" + "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest" - "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" ) diff --git a/pkg/routing/loop.go b/pkg/routing/loop.go index b975e74dd1..297816d4ea 100644 --- a/pkg/routing/loop.go +++ b/pkg/routing/loop.go @@ -21,8 +21,8 @@ func (l Loop) String() string { // LoopDescriptor defines a loop over a pair of routes. type LoopDescriptor struct { Loop Loop - Forward Route - Reverse Route + Forward Path + Reverse Path KeepAlive time.Duration } diff --git a/pkg/routing/packet_test.go b/pkg/routing/packet_test.go index 2558da29cd..c400da81dc 100644 --- a/pkg/routing/packet_test.go +++ b/pkg/routing/packet_test.go @@ -1,9 +1,12 @@ package routing import ( + "encoding/json" "testing" + "github.com/SkycoinProject/dmsg/cipher" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestMakePacket(t *testing.T) { @@ -18,3 +21,22 @@ func TestMakePacket(t *testing.T) { assert.Equal(t, RouteID(2), packet.RouteID()) assert.Equal(t, []byte("foo"), packet.Payload()) } + +func TestEncoding(t *testing.T) { + pka, _ := cipher.GenerateKeyPair() + pkb, _ := cipher.GenerateKeyPair() + + edges1 := PathEdges{pka, pkb} + edges2 := PathEdges{pkb, pka} + + m := map[PathEdges]string{edges1: "a", edges2: "b"} + + b, err := json.Marshal(m) + require.NoError(t, err) + + m2 := make(map[PathEdges]string) + + err = json.Unmarshal(b, &m2) + require.NoError(t, err) + assert.Equal(t, m, m2) +} diff --git a/pkg/routing/route.go b/pkg/routing/route.go index ec2de39071..019e908e08 100644 --- a/pkg/routing/route.go +++ b/pkg/routing/route.go @@ -3,10 +3,11 @@ package routing import ( + "bytes" "fmt" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" ) // Hop defines a route hop between 2 nodes. @@ -20,6 +21,41 @@ func (h Hop) String() string { return fmt.Sprintf("%s -> %s @ %s", h.From, h.To, h.Transport) } +// PathEdges are the edge nodes of a path +type PathEdges [2]cipher.PubKey + +// MarshalText implements encoding.TextMarshaler +func (p PathEdges) MarshalText() ([]byte, error) { + b1, err := p[0].MarshalText() + if err != nil { + return nil, err + } + b2, err := p[1].MarshalText() + if err != nil { + return nil, err + } + res := bytes.NewBuffer(b1) + res.WriteString(":") // nolint + res.Write(b2) // nolint + return res.Bytes(), nil +} + +// UnmarshalText implements json.Unmarshaler +func (p *PathEdges) UnmarshalText(b []byte) error { + err := p[0].UnmarshalText(b[:66]) + if err != nil { + return err + } + err = p[1].UnmarshalText(b[67:]) + if err != nil { + return err + } + return nil +} + +// Path is a list of hops between nodes (transports), and indicates a route between the edges +type Path []Hop + // Route is a succession of transport entries that denotes a path from source node to destination node type Route []*Hop diff --git a/pkg/routing/routing_table_test.go b/pkg/routing/routing_table_test.go index 625a560dfd..151be626ee 100644 --- a/pkg/routing/routing_table_test.go +++ b/pkg/routing/routing_table_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/google/uuid" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/routing/rule.go b/pkg/routing/rule.go index 8061850051..703ee04169 100644 --- a/pkg/routing/rule.go +++ b/pkg/routing/rule.go @@ -7,8 +7,8 @@ import ( "fmt" "time" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" ) // RuleHeaderSize represents the base size of a rule. diff --git a/pkg/routing/rule_test.go b/pkg/routing/rule_test.go index 604a75f966..cf36cfd701 100644 --- a/pkg/routing/rule_test.go +++ b/pkg/routing/rule_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" "github.com/stretchr/testify/assert" ) diff --git a/pkg/setup/idreservoir.go b/pkg/setup/idreservoir.go index 9f21b99abb..95605568c7 100644 --- a/pkg/setup/idreservoir.go +++ b/pkg/setup/idreservoir.go @@ -19,7 +19,7 @@ type idReservoir struct { mx sync.Mutex } -func newIDReservoir(routes ...routing.Route) (*idReservoir, int) { +func newIDReservoir(routes ...routing.Path) (*idReservoir, int) { rec := make(map[cipher.PubKey]uint8) var total int @@ -130,7 +130,7 @@ func GenerateRules(idc *idReservoir, ld routing.LoopDescriptor) (rules RulesMap, // - firstRID: the first visor's route ID. // - lastRID: the last visor's route ID (note that there is no rule set for this ID yet). // - err: an error (if any). -func SaveForwardRules(rules RulesMap, idc *idReservoir, keepAlive time.Duration, route routing.Route) (firstRID, lastRID routing.RouteID, err error) { +func SaveForwardRules(rules RulesMap, idc *idReservoir, keepAlive time.Duration, route routing.Path) (firstRID, lastRID routing.RouteID, err error) { // 'firstRID' is the first visor's key routeID - this is to be returned. var ok bool diff --git a/pkg/setup/node.go b/pkg/setup/node.go index bcf65763cd..80991596a5 100644 --- a/pkg/setup/node.go +++ b/pkg/setup/node.go @@ -12,9 +12,9 @@ import ( "github.com/SkycoinProject/dmsg/disc" "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/skywire-mainnet/pkg/metrics" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" + "github.com/SkycoinProject/skywire-mainnet/pkg/snet" ) // Node performs routes setup operations over messaging channel. @@ -222,7 +222,7 @@ func (sn *Node) handleCreateLoop(ctx context.Context, ld routing.LoopDescriptor) return nil } -func (sn *Node) reserveRouteIDs(ctx context.Context, fwd, rev routing.Route) (*idReservoir, error) { +func (sn *Node) reserveRouteIDs(ctx context.Context, fwd, rev routing.Path) (*idReservoir, error) { idc, total := newIDReservoir(fwd, rev) sn.Logger.Infof("There are %d route IDs to reserve.", total) diff --git a/pkg/setup/node_test.go b/pkg/setup/node_test.go index d1bb46964c..0fb5c8cfaa 100644 --- a/pkg/setup/node_test.go +++ b/pkg/setup/node_test.go @@ -12,8 +12,8 @@ import ( "testing" "time" -"github.com/SkycoinProject/dmsg" -"github.com/SkycoinProject/dmsg/cipher" + "github.com/SkycoinProject/dmsg" + "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/dmsg/disc" "github.com/stretchr/testify/require" "golang.org/x/net/nettest" diff --git a/pkg/therealssh/channel.go b/pkg/therealssh/channel.go index 356c8a0b06..b263aa292f 100644 --- a/pkg/therealssh/channel.go +++ b/pkg/therealssh/channel.go @@ -12,8 +12,8 @@ import ( "strings" "sync" - "github.com/creack/pty" "github.com/SkycoinProject/dmsg/cipher" + "github.com/creack/pty" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" ) diff --git a/pkg/therealssh/client.go b/pkg/therealssh/client.go index 3280e71974..52c24e20c5 100644 --- a/pkg/therealssh/client.go +++ b/pkg/therealssh/client.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/creack/pty" "github.com/SkycoinProject/dmsg/cipher" + "github.com/creack/pty" "github.com/SkycoinProject/skywire-mainnet/internal/netutil" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" diff --git a/pkg/therealssh/pty_test.go b/pkg/therealssh/pty_test.go index 42338c9148..5e779bb360 100644 --- a/pkg/therealssh/pty_test.go +++ b/pkg/therealssh/pty_test.go @@ -9,9 +9,9 @@ import ( "os/user" "testing" - "github.com/creack/pty" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/creack/pty" "github.com/stretchr/testify/require" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" diff --git a/pkg/therealssh/session.go b/pkg/therealssh/session.go index ba1b0a06ff..2691ef70d2 100644 --- a/pkg/therealssh/session.go +++ b/pkg/therealssh/session.go @@ -11,8 +11,8 @@ import ( "sync" "syscall" - "github.com/creack/pty" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/creack/pty" ) // Log is the package level logger, which can be replaced from outside diff --git a/pkg/transport-discovery/client/client.go b/pkg/transport-discovery/client/client.go index a2e3152782..d29ec03d0b 100644 --- a/pkg/transport-discovery/client/client.go +++ b/pkg/transport-discovery/client/client.go @@ -11,9 +11,9 @@ import ( "io/ioutil" "net/http" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/internal/httpauth" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" diff --git a/pkg/transport/discovery.go b/pkg/transport/discovery.go index 4d88c02279..fe727561f4 100644 --- a/pkg/transport/discovery.go +++ b/pkg/transport/discovery.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" ) // DiscoveryClient performs Transport discovery operations. diff --git a/pkg/transport/entry.go b/pkg/transport/entry.go index 2ddd3595ca..889b81b124 100644 --- a/pkg/transport/entry.go +++ b/pkg/transport/entry.go @@ -4,8 +4,8 @@ import ( "fmt" "strings" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" ) // Entry is the unsigned representation of a Transport. diff --git a/pkg/transport/handshake.go b/pkg/transport/handshake.go index aa5180c5ad..535eb743c6 100644 --- a/pkg/transport/handshake.go +++ b/pkg/transport/handshake.go @@ -7,8 +7,9 @@ import ( "fmt" "io" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/dmsg/cipher" + + "github.com/SkycoinProject/skywire-mainnet/pkg/snet" ) func makeEntry(pk1, pk2 cipher.PubKey, tpType string) Entry { diff --git a/pkg/transport/managed_transport.go b/pkg/transport/managed_transport.go index 153200b754..1bbaaf3ce5 100644 --- a/pkg/transport/managed_transport.go +++ b/pkg/transport/managed_transport.go @@ -8,8 +8,9 @@ import ( "sync" "sync/atomic" "time" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" + "github.com/SkycoinProject/skywire-mainnet/pkg/routing" + "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 41b99ab448..d1b8c6de05 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -7,12 +7,12 @@ import ( "strings" "sync" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" + "github.com/SkycoinProject/skywire-mainnet/pkg/snet" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/google/uuid" ) // ManagerConfig configures a Manager. diff --git a/pkg/transport/manager_test.go b/pkg/transport/manager_test.go index 0bfc1c4413..7015093c45 100644 --- a/pkg/transport/manager_test.go +++ b/pkg/transport/manager_test.go @@ -7,10 +7,11 @@ import ( "os" "testing" "time" + "github.com/SkycoinProject/skycoin/src/util/logging" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" + "github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" "github.com/SkycoinProject/dmsg" diff --git a/pkg/transport/transport.go b/pkg/transport/transport.go index 6cb51e1fbe..353bf45086 100644 --- a/pkg/transport/transport.go +++ b/pkg/transport/transport.go @@ -6,9 +6,9 @@ import ( "crypto/sha256" "math/big" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/google/uuid" ) var log = logging.MustGetLogger("transport") diff --git a/pkg/visor/config.go b/pkg/visor/config.go index 5727b47129..ef6de08c48 100644 --- a/pkg/visor/config.go +++ b/pkg/visor/config.go @@ -10,6 +10,7 @@ import ( "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/dmsg/disc" + "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" trClient "github.com/SkycoinProject/skywire-mainnet/pkg/transport-discovery/client" diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index bc6daf17bf..e15e4105ba 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -7,8 +7,8 @@ import ( "path/filepath" "time" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" + "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/pkg/app" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index 0c9f271b0b..51410e53d4 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -3,17 +3,18 @@ package visor import ( "encoding/binary" "fmt" - "github.com/SkycoinProject/skywire-mainnet/pkg/router" "math/rand" "net/http" "net/rpc" "sync" "time" - "github.com/google/uuid" "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/google/uuid" + "github.com/SkycoinProject/skywire-mainnet/pkg/app" + "github.com/SkycoinProject/skywire-mainnet/pkg/router" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" ) diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index ddb7016a09..e1e7b512dc 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -19,12 +19,13 @@ import ( "syscall" "time" - "github.com/SkycoinProject/skywire-mainnet/pkg/snet" - "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/dmsg" + "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/dmsg/noise" "github.com/SkycoinProject/skycoin/src/util/logging" + "github.com/SkycoinProject/skywire-mainnet/pkg/snet" + "github.com/SkycoinProject/skywire-mainnet/pkg/app" routeFinder "github.com/SkycoinProject/skywire-mainnet/pkg/route-finder/client" "github.com/SkycoinProject/skywire-mainnet/pkg/router"